Browse Source

1.修改:使用DimRobot

2.修改:MetaObjectField的生成规则
dev
wxz 5 years ago
parent
commit
fd120e70c6
  1. 37
      epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/handler/FieldMetaObjectHandler.java
  2. 8
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java
  3. 5
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/RobotConstant.java
  4. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java
  5. 13
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java
  6. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDemoService.java
  7. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDemoServiceImpl.java
  8. 10
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java
  9. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimWeekService.java
  10. 14
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimAgencyServiceImpl.java
  11. 14
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimCustomerServiceImpl.java
  12. 13
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java
  13. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDepartmentServiceImpl.java
  14. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimGridServiceImpl.java
  15. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java
  16. 12
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimQuarterServiceImpl.java
  17. 77
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimWeekServiceImpl.java
  18. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimYearServiceImpl.java
  19. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/LastExecRecordServiceImpl.java

37
epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/handler/FieldMetaObjectHandler.java

@ -48,14 +48,11 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
public void insertFill(MetaObject metaObject) {
Date date = new Date();
if (metaObject.getOriginalObject() instanceof BaseEpmetEntity) {
String loginUserId = loginUserUtil.getLoginUserId();
// epmet项目新增的
loginUserId = StringUtils.isBlank(loginUserId) ? Constant.APP_USER_FLAG : loginUserId;
//Long deptId = user == null ? null : user.getDeptId();
setFieldValByName(FieldConstant.CREATED_TIME_HUMP, date, metaObject);
setFieldValByName(FieldConstant.CREATED_BY_HUMP, loginUserId, metaObject);
setFieldValByName(FieldConstant.CREATED_BY_HUMP, getCreatedByFieldValue(metaObject), metaObject);
setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, date, metaObject);
setFieldValByName(FieldConstant.UPDATED_BY_HUMP, loginUserId, metaObject);
setFieldValByName(FieldConstant.UPDATED_BY_HUMP, getUpdatedByFieldValue(metaObject), metaObject);
setFieldValByName(FieldConstant.REVISION_HUMP, NumConstant.ZERO, metaObject);
//删除标识
setFieldValByName(FieldConstant.DEL_FLAG_HUMP, EpmetDelFlagEnum.NORMAL.value(), metaObject);
@ -82,6 +79,32 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
}
}
public Object getCreatedByFieldValue(MetaObject metaObject) {
Object value = loginUserUtil.getLoginUserId();
if (value == null) {
if (metaObject.hasGetter(FieldConstant.CREATED_BY_HUMP)) {
value = metaObject.getValue(FieldConstant.CREATED_BY_HUMP);
}
if (value == null) {
value = Constant.APP_USER_FLAG;
}
}
return value;
}
public Object getUpdatedByFieldValue(MetaObject metaObject) {
Object value = loginUserUtil.getLoginUserId();
if (value == null) {
if (metaObject.hasGetter(FieldConstant.UPDATED_BY_HUMP)) {
value = metaObject.getValue(FieldConstant.UPDATED_BY_HUMP);
}
if (value == null) {
value = Constant.APP_USER_FLAG;
}
}
return value;
}
@Override
public void updateFill(MetaObject metaObject) {
@ -111,9 +134,7 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
//更新时间
setFieldValByName(UPDATE_DATE, new Date(), metaObject);
} else if (fillEsuaEntity) {
String loginUserId = loginUserUtil.getLoginUserId();
String userId = StringUtils.isBlank(loginUserId) ? Constant.APP_USER_FLAG : loginUserId;
setFieldValByName(FieldConstant.UPDATED_BY_HUMP, userId, metaObject);
setFieldValByName(FieldConstant.UPDATED_BY_HUMP, getUpdatedByFieldValue(metaObject), metaObject);
setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, new Date(), metaObject);
}
}

8
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java

@ -123,7 +123,13 @@ public class DateUtils {
* @return
*/
public static Date[] getWeekStartAndEnd(Date date) {
return getWeekStartAndEnd(getWeekOfYear(date));
DateTime dateTime = new DateTime(date);
LocalDate localDate = new LocalDate(dateTime);
localDate = localDate.dayOfWeek().withMinimumValue();
Date beginDate = localDate.toDate();
Date endDate = localDate.plusDays(6).toDate();
return new Date[]{beginDate, endDate};
}
/**

5
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/RobotConstant.java

@ -0,0 +1,5 @@
package com.epmet.constant;
public interface RobotConstant {
String DIMENSION_ROBOT = "DimensionRobot";
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java

@ -24,11 +24,6 @@ public class DemoController {
@Autowired
private ExecutorService executorService;
@GetMapping("testlist")
public void testList() {
demoService.testList();
}
@GetMapping("testtx")
public void testTx() {
demoService.testTx();

13
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java

@ -28,6 +28,9 @@ public class DimController {
@Autowired
private DimYearService dimYearService;
@Autowired
private DimWeekService dimWeekService;
@Autowired
private StatsDimService statsDimService;
@ -114,6 +117,16 @@ public class DimController {
return new Result();
}
/**
* 按周维度
* @return
*/
@PostMapping("/week/init")
public Result initWeekDim() {
dimWeekService.initWeekDim();
return new Result();
}
/**
* @Description 所有机构
* @param

1
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsDemoService.java

@ -6,7 +6,6 @@ import java.util.List;
public interface StatsDemoService {
void testList();
void testTx();
Boolean testThreadPool();
void testThreadPoolAsync();

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDemoServiceImpl.java

@ -3,7 +3,6 @@ package com.epmet.service.impl;
import com.epmet.dto.AgencySubTreeDto;
import com.epmet.entity.issue.IssueEntity;
import com.epmet.entity.org.CustomerAgencyEntity;
import com.epmet.service.Issue.DemoIssueService;
import com.epmet.service.StatsDemoService;
import com.epmet.service.org.DemoGovOrgService;
import com.epmet.service.stats.DemoDataStatsService;
@ -23,19 +22,9 @@ public class StatsDemoServiceImpl implements StatsDemoService {
@Autowired
private DemoGovOrgService demoGovOrgService;
@Autowired
private DemoIssueService demoIssueService;
@Autowired
private DemoDataStatsService demoDataStatsService;
@Override
public void testList() {
List<CustomerAgencyEntity> agencies = demoGovOrgService.listAllEntities();
List<IssueEntity> issues = demoIssueService.listAllEntities();
System.out.println(666);
}
//该service不加事务
//@Transactional(rollbackFor = Exception.class)
@Override

10
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java

@ -1,6 +1,7 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.constant.StatsSubject;
import com.epmet.entity.crm.CustomerEntity;
import com.epmet.entity.org.CustomerAgencyEntity;
@ -87,20 +88,15 @@ public class StatsDimServiceImpl implements StatsDimService {
* @return
*/
private List<DimGridEntity> convertCustomerGrid2GridDim(List<CustomerGridEntity> grids) {
Date now = new Date();
return grids.stream().map(grid -> {
DimGridEntity dimGrid = new DimGridEntity();
dimGrid.setAgencyId(grid.getPid());
dimGrid.setAreaCode(grid.getAreaCode());
dimGrid.setCustomerId(grid.getCustomerId());
dimGrid.setGridName(grid.getGridName());
dimGrid.setCreatedBy("APP_USER");
dimGrid.setCreatedTime(now);
dimGrid.setDelFlag("0");
dimGrid.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dimGrid.setId(grid.getId());
dimGrid.setRevision(0);
dimGrid.setUpdatedBy("APP_USER");
dimGrid.setUpdatedTime(now);
dimGrid.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
return dimGrid;
}).collect(Collectors.toList());
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimWeekService.java

@ -92,4 +92,6 @@ public interface DimWeekService extends BaseService<DimWeekEntity> {
* @date 2020-06-16
*/
void delete(String[] ids);
void initWeekDim();
}

14
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimAgencyServiceImpl.java

@ -23,6 +23,7 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.constant.RobotConstant;
import com.epmet.dao.stats.DimAgencyDao;
import com.epmet.dto.AgencySubTreeDto;
import com.epmet.dto.stats.DimAgencyDTO;
@ -112,10 +113,9 @@ public class DimAgencyServiceImpl extends BaseServiceImpl<DimAgencyDao, DimAgenc
return baseDao.selectDimAgencyList(dto);
}
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
public void addAgencyDims(List<CustomerAgencyEntity> agencies) {
Date now = new Date();
for (CustomerAgencyEntity agency : agencies) {
DimAgencyEntity dimAgencyEntity = new DimAgencyEntity();
dimAgencyEntity.setAgencyName(agency.getOrganizationName());
@ -124,14 +124,10 @@ public class DimAgencyServiceImpl extends BaseServiceImpl<DimAgencyDao, DimAgenc
dimAgencyEntity.setLevel(agency.getLevel());
dimAgencyEntity.setPid(agency.getPid());
dimAgencyEntity.setPids(agency.getPids());
dimAgencyEntity.setCreatedBy("APP_USER");
dimAgencyEntity.setUpdatedBy("APP_USER");
dimAgencyEntity.setCreatedTime(now);
dimAgencyEntity.setUpdatedTime(now);
dimAgencyEntity.setRevision(0);
dimAgencyEntity.setDelFlag("0");
dimAgencyEntity.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dimAgencyEntity.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dimAgencyEntity.setId(agency.getId());
baseDao.insertOne(dimAgencyEntity);
baseDao.insert(dimAgencyEntity);
}
}

14
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimCustomerServiceImpl.java

@ -25,6 +25,7 @@ import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.dao.stats.DimCustomerDao;
import com.epmet.dto.stats.DimCustomerDTO;
import com.epmet.entity.crm.CustomerEntity;
@ -111,21 +112,16 @@ public class DimCustomerServiceImpl extends BaseServiceImpl<DimCustomerDao, DimC
return baseDao.selectCustomerIdPage((pageNo - 1) * pageSize,pageSize);
}
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
public void addCustomerDims(List<CustomerEntity> customers) {
Date now = new Date();
for (CustomerEntity customer : customers) {
DimCustomerEntity dim = new DimCustomerEntity();
dim.setCustomerName(customer.getCustomerName());
dim.setCreatedBy("APP_USER");
dim.setCreatedTime(now);
dim.setUpdatedBy("APP_USER");
dim.setUpdatedTime(now);
dim.setDelFlag("0");
dim.setRevision(0);
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setId(customer.getId());
baseDao.insertOne(dim);
baseDao.insert(dim);
}
}
}

13
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java

@ -24,6 +24,7 @@ import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.constant.StatsSubject;
import com.epmet.dao.stats.DimDateDao;
import com.epmet.dto.stats.DimDateDTO;
@ -104,6 +105,7 @@ public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntit
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Transactional(rollbackFor = Exception.class)
@Override
public void initDimDate() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_DATE);
@ -153,11 +155,10 @@ public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntit
*/
public void initDimDate(Date targetDate) {
DimDateEntity dimDateEntity = generateDimDate(targetDate);
int c = baseDao.insertOne(dimDateEntity);
baseDao.insert(dimDateEntity);
}
public DimDateEntity generateDimDate(Date targetDate) {
Date now = new Date();
// 日期id
String id = DimIdGenerator.getDateDimId(targetDate);
// 月份id
@ -177,12 +178,8 @@ public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntit
dimDateEntity.setDayOfWeekName(chineseWeekName);
dimDateEntity.setWeekId(weekId);
dimDateEntity.setMonthId(monthId);
dimDateEntity.setDelFlag("0");
dimDateEntity.setCreatedBy("APP_USER");
dimDateEntity.setCreatedTime(now);
dimDateEntity.setRevision(0);
dimDateEntity.setUpdatedBy("APP_USER");
dimDateEntity.setUpdatedTime(now);
dimDateEntity.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dimDateEntity.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
return dimDateEntity;
}
}

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDepartmentServiceImpl.java

@ -23,6 +23,7 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.dao.stats.DimDepartmentDao;
import com.epmet.dto.stats.DimDepartmentDTO;
import com.epmet.entity.org.CustomerDepartmentEntity;
@ -109,14 +110,10 @@ public class DimDepartmentServiceImpl extends BaseServiceImpl<DimDepartmentDao,
dim.setAgencyId(department.getAgencyId());
dim.setCustomerId(department.getCustomerId());
dim.setDepartmentName(department.getDepartmentName());
dim.setCreatedBy("APP_USER");
dim.setUpdatedBy("APP_USER");
dim.setCreatedTime(now);
dim.setUpdatedTime(now);
dim.setRevision(0);
dim.setDelFlag("0");
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setId(department.getId());
baseDao.insertOne(dim);
baseDao.insert(dim);
}
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimGridServiceImpl.java

@ -103,7 +103,7 @@ public class DimGridServiceImpl extends BaseServiceImpl<DimGridDao, DimGridEntit
return baseDao.getLastCreatedGridDimEntity();
}
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
public void addGridDims(List<DimGridEntity> gridDims) {
for (DimGridEntity gridDim : gridDims) {

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java

@ -24,6 +24,7 @@ import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.constant.StatsSubject;
import com.epmet.dao.stats.DimMonthDao;
import com.epmet.dto.stats.DimMonthDTO;
@ -108,7 +109,7 @@ public class DimMonthServiceImpl extends BaseServiceImpl<DimMonthDao, DimMonthEn
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
public void initMonthDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_MONTH);
@ -149,7 +150,6 @@ public class DimMonthServiceImpl extends BaseServiceImpl<DimMonthDao, DimMonthEn
}
public void initMonthDim(Date targetMonth) {
Date now = new Date();
Date endDate = DateUtils.addDateDays(DateUtils.addDateMonths(targetMonth, 1), -1);
LocalDate localDate = new LocalDate(targetMonth);
@ -160,11 +160,8 @@ public class DimMonthServiceImpl extends BaseServiceImpl<DimMonthDao, DimMonthEn
dim.setMonthOrder(DateUtils.getMonthOfYear(targetMonth));
dim.setQuarterId(localDate.getYear() + "Q" + DateUtils.getQuarterIndex(targetMonth));
dim.setYearId(localDate.getYear() + "");
dim.setCreatedBy("APP_USER");
dim.setUpdatedBy("APP_USER");
dim.setCreatedTime(now);
dim.setUpdatedTime(now);
dim.setDelFlag("0");
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setId(DimIdGenerator.getMonthDimId(targetMonth));
baseDao.insert(dim);
}

12
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimQuarterServiceImpl.java

@ -24,6 +24,7 @@ import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.constant.StatsSubject;
import com.epmet.dao.stats.DimQuarterDao;
import com.epmet.dto.stats.DimQuarterDTO;
@ -111,7 +112,7 @@ public class DimQuarterServiceImpl extends BaseServiceImpl<DimQuarterDao, DimQua
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
public void initQuarterDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_QUARTER);
@ -164,7 +165,6 @@ public class DimQuarterServiceImpl extends BaseServiceImpl<DimQuarterDao, DimQua
* 初始化指定月份维度数据
*/
public void initQuarterDim(Date targetQday) {
Date now = new Date();
DimQuarterEntity dim = new DimQuarterEntity();
String quarterDimId = DimIdGenerator.getQuarterDimId(targetQday);
dim.setId(quarterDimId);
@ -176,12 +176,8 @@ public class DimQuarterServiceImpl extends BaseServiceImpl<DimQuarterDao, DimQua
dim.setEndDate(DateUtils.getQuarterEndDate(yyyy, quarter));
dim.setQuarterOrder(quarter);
dim.setYearId(yyyy);
dim.setDelFlag("0");
dim.setRevision(0);
dim.setCreatedBy("APP_USER");
dim.setCreatedTime(now);
dim.setUpdatedBy("APP_USER");
dim.setUpdatedTime(now);
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dimQuarterDao.insert(dim);
logger.info("初始化季度数据,基于日期:" + targetQday + ",生成的DimId:" + quarterDimId);
}

77
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimWeekServiceImpl.java

@ -23,16 +23,23 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.constant.StatsSubject;
import com.epmet.dao.stats.DimWeekDao;
import com.epmet.dto.stats.DimWeekDTO;
import com.epmet.entity.stats.DimWeekEntity;
import com.epmet.entity.stats.LastExecRecordEntity;
import com.epmet.service.stats.DimWeekService;
import com.epmet.service.stats.LastExecRecordService;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -45,6 +52,9 @@ import java.util.Map;
@Service
public class DimWeekServiceImpl extends BaseServiceImpl<DimWeekDao, DimWeekEntity> implements DimWeekService {
@Autowired
private LastExecRecordService lastExecRecordService;
@Override
public PageData<DimWeekDTO> page(Map<String, Object> params) {
IPage<DimWeekEntity> page = baseDao.selectPage(
@ -97,4 +107,71 @@ public class DimWeekServiceImpl extends BaseServiceImpl<DimWeekDao, DimWeekEntit
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Transactional(rollbackFor = Exception.class)
@Override
public void initWeekDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_WEEK);
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_WEEK);
}
Date now = new Date();
Date startWeekDay;
Date targetWeekDay = DateUtils.getWeekStartAndEnd(DateUtils.addDateDays(now, -7))[0];
if (lastExecRecord.getExecTime() == null) {
// 首次执行
initWeekDim(targetWeekDay);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} else {
startWeekDay = DateUtils.getWeekStartAndEnd(lastExecRecord.getExecTime())[0];
if (targetWeekDay.equals(startWeekDay) || targetWeekDay.after(startWeekDay)) {
initWeekDim(startWeekDay, targetWeekDay);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
}
}
}
/**
* 按周维度连续初始化
* @param startWeekDay
* @param targetWeekDay
*/
private void initWeekDim(Date startWeekDay, Date targetWeekDay) {
LocalDate localStartWeekDay = new LocalDate(startWeekDay);
LocalDate localTargetWeekDay = new LocalDate(targetWeekDay);
while (localTargetWeekDay.isEqual(localStartWeekDay)
|| localTargetWeekDay.isAfter(localStartWeekDay)) {
initWeekDim(localStartWeekDay.toDate());
localStartWeekDay = localStartWeekDay.plusDays(7);
}
}
/**
* 单周初始化
* @param targetWeekDay
*/
private void initWeekDim(Date targetWeekDay) {
Date[] weekBorders = DateUtils.getWeekStartAndEnd(targetWeekDay);
String yyyy = DateUtils.format(targetWeekDay, DateUtils.DATE_PATTERN_YYYY);
int weekOfYear = DateUtils.getWeekOfYear(targetWeekDay);
Date now = new Date();
DimWeekEntity dim = new DimWeekEntity();
dim.setEndDate(weekBorders[1]);
dim.setStartDate(weekBorders[0]);
dim.setWeekName(yyyy + "年第" + weekOfYear + "周");
dim.setWeekOrder(weekOfYear);
dim.setYearId(yyyy);
dim.setId(yyyy.concat("W").concat(String.format("%02d", weekOfYear)));
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
baseDao.insert(dim);
}
}

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimYearServiceImpl.java

@ -24,6 +24,7 @@ import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.RobotConstant;
import com.epmet.constant.StatsSubject;
import com.epmet.dao.stats.DimYearDao;
import com.epmet.dto.stats.DimYearDTO;
@ -106,6 +107,7 @@ public class DimYearServiceImpl extends BaseServiceImpl<DimYearDao, DimYearEntit
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Transactional(rollbackFor = Exception.class)
@Override
public void initYearDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_YEAR);
@ -156,17 +158,12 @@ public class DimYearServiceImpl extends BaseServiceImpl<DimYearDao, DimYearEntit
*/
public void initYearDim(Date targetYear) {
String yyyy = DateUtils.format(targetYear, DateUtils.DATE_PATTERN_YYYY);
Date now = new Date();
DimYearEntity dim = new DimYearEntity();
dim.setId(yyyy);
dim.setYearName(yyyy.concat("年"));
//dim.setUpdatedTime(now);
//dim.setUpdatedBy("APP_USER");
//dim.setCreatedTime(now);
//dim.setCreatedBy("APP_USER");
//dim.setRevision(0);
//dim.setDelFlag("0");
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
baseDao.insert(dim);
}

9
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/LastExecRecordServiceImpl.java

@ -1,5 +1,6 @@
package com.epmet.service.stats.impl;
import com.epmet.constant.RobotConstant;
import com.epmet.dao.stats.LastExecRecordDao;
import com.epmet.entity.stats.LastExecRecordEntity;
import com.epmet.service.stats.LastExecRecordService;
@ -28,12 +29,8 @@ public class LastExecRecordServiceImpl implements LastExecRecordService {
LastExecRecordEntity entity = new LastExecRecordEntity();
entity.setExecTime(now);
entity.setSubject(statsSubject);
entity.setCreatedBy("APP_USER");
entity.setUpdatedBy("APP_USER");
entity.setCreatedTime(now);
entity.setUpdatedTime(now);
entity.setDelFlag("0");
entity.setRevision(0);
entity.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
entity.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
lastExecRecordDao.insert(entity);
return entity;
}

Loading…
Cancel
Save