Browse Source

修改维度初始化逻辑,根据createTime,获取createTime(含)到now(不含)之间的数据插入维度表

dev_shibei_match
wxz 5 years ago
parent
commit
7574c09938
  1. 26
      epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/handler/FieldMetaObjectHandler.java
  2. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimAgencyDao.java
  3. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimCustomerDao.java
  4. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimDateDao.java
  5. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimDepartmentDao.java
  6. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimMonthDao.java
  7. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimQuarterDao.java
  8. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimWeekDao.java
  9. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimYearDao.java
  10. 80
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java
  11. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimAgencyService.java
  12. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimCustomerService.java
  13. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimDepartmentService.java
  14. 19
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimAgencyServiceImpl.java
  15. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimCustomerServiceImpl.java
  16. 24
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java
  17. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDepartmentServiceImpl.java
  18. 21
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java
  19. 25
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimQuarterServiceImpl.java
  20. 14
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimWeekServiceImpl.java
  21. 19
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimYearServiceImpl.java
  22. 20
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimAgencyDao.xml
  23. 14
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimCustomerDao.xml
  24. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimDateDao.xml
  25. 16
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimDepartmentDao.xml
  26. 21
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimMonthDao.xml
  27. 19
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimQuarterDao.xml
  28. 21
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimWeekDao.xml
  29. 14
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimYearDao.xml

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

@ -49,9 +49,9 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
Date date = new Date(); Date date = new Date();
if (metaObject.getOriginalObject() instanceof BaseEpmetEntity) { if (metaObject.getOriginalObject() instanceof BaseEpmetEntity) {
// epmet项目新增的 // epmet项目新增的
setFieldValByName(FieldConstant.CREATED_TIME_HUMP, date, metaObject); setFieldValByName(FieldConstant.CREATED_TIME_HUMP, getCreatedTimeByFieldValue(metaObject), metaObject);
setFieldValByName(FieldConstant.CREATED_BY_HUMP, getCreatedByFieldValue(metaObject), metaObject); setFieldValByName(FieldConstant.CREATED_BY_HUMP, getCreatedByFieldValue(metaObject), metaObject);
setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, date, metaObject); setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, getUpdatedTimeByFieldValue(metaObject), metaObject);
setFieldValByName(FieldConstant.UPDATED_BY_HUMP, getUpdatedByFieldValue(metaObject), metaObject); setFieldValByName(FieldConstant.UPDATED_BY_HUMP, getUpdatedByFieldValue(metaObject), metaObject);
setFieldValByName(FieldConstant.REVISION_HUMP, NumConstant.ZERO, metaObject); setFieldValByName(FieldConstant.REVISION_HUMP, NumConstant.ZERO, metaObject);
//删除标识 //删除标识
@ -92,6 +92,28 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
return value; return value;
} }
public Object getCreatedTimeByFieldValue(MetaObject metaObject) {
Object createdTime = null;
if (metaObject.hasGetter(FieldConstant.CREATED_TIME_HUMP)) {
createdTime = metaObject.getValue(FieldConstant.CREATED_TIME_HUMP);
}
if (createdTime == null) {
createdTime = new Date();
}
return createdTime;
}
public Object getUpdatedTimeByFieldValue(MetaObject metaObject) {
Object createdTime = null;
if (metaObject.hasGetter(FieldConstant.CREATED_TIME_HUMP)) {
createdTime = metaObject.getValue(FieldConstant.CREATED_TIME_HUMP);
}
if (createdTime == null) {
createdTime = new Date();
}
return createdTime;
}
public Object getUpdatedByFieldValue(MetaObject metaObject) { public Object getUpdatedByFieldValue(MetaObject metaObject) {
Object value = loginUserUtil.getLoginUserId(); Object value = loginUserUtil.getLoginUserId();
if (value == null) { if (value == null) {

1
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimAgencyDao.java

@ -123,4 +123,5 @@ public interface DimAgencyDao extends BaseDao<DimAgencyEntity> {
*/ */
String getPidByAgencyId(@Param("agencyId") String agencyId); String getPidByAgencyId(@Param("agencyId") String agencyId);
DimAgencyEntity getLatestCreatedAgencyDimEntity();
} }

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimCustomerDao.java

@ -45,4 +45,6 @@ public interface DimCustomerDao extends BaseDao<DimCustomerEntity> {
List<String> selectCustomerIdPage(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize); List<String> selectCustomerIdPage(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
void insertOne(DimCustomerEntity dim); void insertOne(DimCustomerEntity dim);
DimCustomerEntity getLatestCreatedDimEntity();
} }

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimDateDao.java

@ -38,7 +38,7 @@ public interface DimDateDao extends BaseDao<DimDateEntity> {
/** /**
* 最新的按日维度 * 最新的按日维度
*/ */
DimDateDTO getLatestDimDate(); DimDateDTO getLatestDim();
int insertOne(DimDateEntity dimDateEntity); int insertOne(DimDateEntity dimDateEntity);

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimDepartmentDao.java

@ -40,4 +40,6 @@ public interface DimDepartmentDao extends BaseDao<DimDepartmentEntity> {
* @return * @return
*/ */
List<DimDepartmentEntity> getDepartmentListByCustomerId(@Param("customerId") String customerId); List<DimDepartmentEntity> getDepartmentListByCustomerId(@Param("customerId") String customerId);
DimDepartmentEntity getLatestCreatedDimEntity();
} }

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimMonthDao.java

@ -29,5 +29,5 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface DimMonthDao extends BaseDao<DimMonthEntity> { public interface DimMonthDao extends BaseDao<DimMonthEntity> {
DimMonthEntity getLatestDimEntity();
} }

1
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimQuarterDao.java

@ -31,4 +31,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface DimQuarterDao extends BaseDao<DimQuarterEntity> { public interface DimQuarterDao extends BaseDao<DimQuarterEntity> {
DimQuarterEntity getLatestDimEntity();
} }

1
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimWeekDao.java

@ -30,4 +30,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface DimWeekDao extends BaseDao<DimWeekEntity> { public interface DimWeekDao extends BaseDao<DimWeekEntity> {
DimWeekEntity getLatestDimEntity();
} }

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimYearDao.java

@ -30,4 +30,6 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface DimYearDao extends BaseDao<DimYearEntity> { public interface DimYearDao extends BaseDao<DimYearEntity> {
int insertOne(DimYearEntity entity); int insertOne(DimYearEntity entity);
DimYearEntity getLatestDimEntity();
} }

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

@ -7,8 +7,7 @@ import com.epmet.entity.crm.CustomerEntity;
import com.epmet.entity.org.CustomerAgencyEntity; import com.epmet.entity.org.CustomerAgencyEntity;
import com.epmet.entity.org.CustomerDepartmentEntity; import com.epmet.entity.org.CustomerDepartmentEntity;
import com.epmet.entity.org.CustomerGridEntity; import com.epmet.entity.org.CustomerGridEntity;
import com.epmet.entity.stats.DimGridEntity; import com.epmet.entity.stats.*;
import com.epmet.entity.stats.LastExecRecordEntity;
import com.epmet.service.StatsDimService; import com.epmet.service.StatsDimService;
import com.epmet.service.crm.CustomerService; import com.epmet.service.crm.CustomerService;
import com.epmet.service.org.CustomerAgencyService; import com.epmet.service.org.CustomerAgencyService;
@ -55,21 +54,18 @@ public class StatsDimServiceImpl implements StatsDimService {
@Override @Override
public void initGridDim() { public void initGridDim() {
DimGridEntity lastCreatedGridDim = dimGridService.getLastCreatedGridDim(); DimGridEntity lastDimEntity = dimGridService.getLastCreatedGridDim();
List<CustomerGridEntity> grids; List<CustomerGridEntity> grids;
if (lastCreatedGridDim == null) { Date now = new Date();
if (lastDimEntity == null) {
// 首次初始化 // 首次初始化
grids = customerGridService.listGridsByCreateTime(null, null); grids = customerGridService.listGridsByCreateTime(null, now);
} else { } else {
// 非首次初始化 Date lastInitTime = lastDimEntity.getCreatedTime();
// 结束时间边界与开始时间边界,包含开始时间不包含结束时间。结束时间可以为空,则查询从开始时间往后的所有新创建网格 grids = customerGridService.listGridsByCreateTime(lastInitTime, now);
Date startTimeBorder = DateUtils.parse(DateUtils.format(lastCreatedGridDim.getCreatedTime(), DateUtils.DATE_PATTERN_YYYYMMDD), DateUtils.DATE_PATTERN_YYYYMMDD);
Date endTimeBorder = DateUtils.parse(DateUtils.format(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD), DateUtils.DATE_PATTERN_YYYYMMDD);
grids = customerGridService.listGridsByCreateTime(startTimeBorder, endTimeBorder);
} }
List<DimGridEntity> gridDims = convertCustomerGrid2GridDim(grids); List<DimGridEntity> gridDims = convertCustomerGrid2GridDim(grids, now);
if (!CollectionUtils.isEmpty(gridDims)) { if (!CollectionUtils.isEmpty(gridDims)) {
dimGridService.initGridDims(gridDims); dimGridService.initGridDims(gridDims);
} }
@ -78,9 +74,10 @@ public class StatsDimServiceImpl implements StatsDimService {
/** /**
* 将网格信息转换成网格维度信息 * 将网格信息转换成网格维度信息
* @param grids * @param grids
* @param initTime 创建时间会用来作为下一次查询的输入条件因此必须和本次初始化查询的endTime一致
* @return * @return
*/ */
private List<DimGridEntity> convertCustomerGrid2GridDim(List<CustomerGridEntity> grids) { private List<DimGridEntity> convertCustomerGrid2GridDim(List<CustomerGridEntity> grids, Date initTime) {
return grids.stream().map(grid -> { return grids.stream().map(grid -> {
DimGridEntity dimGrid = new DimGridEntity(); DimGridEntity dimGrid = new DimGridEntity();
dimGrid.setAgencyId(grid.getPid()); dimGrid.setAgencyId(grid.getPid());
@ -90,6 +87,8 @@ public class StatsDimServiceImpl implements StatsDimService {
dimGrid.setCreatedBy(RobotConstant.DIMENSION_ROBOT); dimGrid.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dimGrid.setId(grid.getId()); dimGrid.setId(grid.getId());
dimGrid.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); dimGrid.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dimGrid.setCreatedTime(initTime);
dimGrid.setUpdatedTime(initTime);
return dimGrid; return dimGrid;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
@ -99,20 +98,18 @@ public class StatsDimServiceImpl implements StatsDimService {
*/ */
@Override @Override
public void initAgencyDim() { public void initAgencyDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_AGENCY); DimAgencyEntity latestCreatedAgencyDim = dimAgencyService.getLatestCreatedAgencyDimEntity();
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_AGENCY);
}
Date statsEndTime = DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD); Date now = new Date();
Date statsStartTime = null; Date lastInitTime = null;
if (lastExecRecord.getExecTime() != null) {
statsStartTime = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMMDD); if (latestCreatedAgencyDim != null) {
lastInitTime = latestCreatedAgencyDim.getCreatedTime();
} }
List<CustomerAgencyEntity> agencies = customerAgencyService.listAgenciesByCreateTime(statsStartTime, statsEndTime); List<CustomerAgencyEntity> agencies = customerAgencyService.listAgenciesByCreateTime(lastInitTime, now);
if (!CollectionUtils.isEmpty(agencies)) { if (!CollectionUtils.isEmpty(agencies)) {
dimAgencyService.initAgencyDims(agencies); dimAgencyService.initAgencyDims(agencies, now);
} }
} }
@ -121,39 +118,36 @@ public class StatsDimServiceImpl implements StatsDimService {
*/ */
@Override @Override
public void initCustomerDim() { public void initCustomerDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_CUSTOMER); DimCustomerEntity lastCreateDim = dimCustomerService.getLatestCreatedDimEntity();
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_CUSTOMER);
}
Date statsEndTime = DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD); Date now = new Date();
Date statsStartTime = null; Date lastInitTime = null;
if (lastExecRecord.getExecTime() != null) {
statsStartTime = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMMDD); if (lastCreateDim != null) {
lastInitTime = lastCreateDim.getCreatedTime();
} }
List<CustomerEntity> customers = customerService.listValidCustomersByCreateTime(statsStartTime, statsEndTime); List<CustomerEntity> customers = customerService.listValidCustomersByCreateTime(lastInitTime, now);
if (!CollectionUtils.isEmpty(customers)) { if (!CollectionUtils.isEmpty(customers)) {
dimCustomerService.initCustomerDims(customers); dimCustomerService.initCustomerDims(customers, now);
} }
} }
@Override @Override
public void initDepartmentDim() { public void initDepartmentDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_DEPARTMENT);
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_DEPARTMENT);
}
Date statsEndTime = DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD); DimDepartmentEntity lastCreatedDeptDim = dimDepartmentService.getLatestCreatedDimEntity();
Date statsStartTime = null;
if (lastExecRecord.getExecTime() != null) { Date now = new Date();
statsStartTime = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMMDD); Date lastInitTime = null;
if (lastCreatedDeptDim != null) {
lastInitTime = lastCreatedDeptDim.getCreatedTime();
} }
List<CustomerDepartmentEntity> departments = departmentService.listDepartmentsByCreatedTime(statsStartTime, statsEndTime); List<CustomerDepartmentEntity> departments = departmentService.listDepartmentsByCreatedTime(lastInitTime, now);
if (!CollectionUtils.isEmpty(departments)) { if (!CollectionUtils.isEmpty(departments)) {
dimDepartmentService.initDepartmentDims(departments); dimDepartmentService.initDepartmentDims(departments, now);
} }
} }
} }

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimAgencyService.java

@ -109,7 +109,7 @@ public interface DimAgencyService extends BaseService<DimAgencyEntity> {
* 初始化机关维度 * 初始化机关维度
* @param agencies * @param agencies
*/ */
void initAgencyDims(List<CustomerAgencyEntity> agencies); void initAgencyDims(List<CustomerAgencyEntity> agencies, Date initTime);
/** /**
* @Description 查询所有机关以及它下级机关的信息 * @Description 查询所有机关以及它下级机关的信息
@ -173,4 +173,6 @@ public interface DimAgencyService extends BaseService<DimAgencyEntity> {
* @author zxc * @author zxc
*/ */
String getPidByAgencyId(String agencyId); String getPidByAgencyId(String agencyId);
DimAgencyEntity getLatestCreatedAgencyDimEntity();
} }

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimCustomerService.java

@ -24,6 +24,7 @@ import com.epmet.entity.crm.CustomerEntity;
import com.epmet.entity.org.CustomerDepartmentEntity; import com.epmet.entity.org.CustomerDepartmentEntity;
import com.epmet.entity.stats.DimCustomerEntity; import com.epmet.entity.stats.DimCustomerEntity;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -111,5 +112,7 @@ public interface DimCustomerService extends BaseService<DimCustomerEntity> {
* 添加客户维度 * 添加客户维度
* @param customers * @param customers
*/ */
void initCustomerDims(List<CustomerEntity> customers); void initCustomerDims(List<CustomerEntity> customers, Date initTime);
DimCustomerEntity getLatestCreatedDimEntity();
} }

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimDepartmentService.java

@ -23,6 +23,7 @@ import com.epmet.dto.stats.DimDepartmentDTO;
import com.epmet.entity.org.CustomerDepartmentEntity; import com.epmet.entity.org.CustomerDepartmentEntity;
import com.epmet.entity.stats.DimDepartmentEntity; import com.epmet.entity.stats.DimDepartmentEntity;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -94,7 +95,7 @@ public interface DimDepartmentService extends BaseService<DimDepartmentEntity> {
*/ */
void delete(String[] ids); void delete(String[] ids);
void initDepartmentDims(List<CustomerDepartmentEntity> departments); void initDepartmentDims(List<CustomerDepartmentEntity> departments, Date initTime);
/** /**
* desc: 根据客户Id获取 部门数据 * desc: 根据客户Id获取 部门数据
@ -105,4 +106,6 @@ public interface DimDepartmentService extends BaseService<DimDepartmentEntity> {
* @author: jianjun liu * @author: jianjun liu
*/ */
List<DimDepartmentEntity> getDepartmentListByCustomerId(String customerId); List<DimDepartmentEntity> getDepartmentListByCustomerId(String customerId);
DimDepartmentEntity getLatestCreatedDimEntity();
} }

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

@ -123,16 +123,16 @@ public class DimAgencyServiceImpl extends BaseServiceImpl<DimAgencyDao, DimAgenc
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initAgencyDims(List<CustomerAgencyEntity> agencies) { public void initAgencyDims(List<CustomerAgencyEntity> agencies, Date initTime) {
for (CustomerAgencyEntity agency : agencies) { for (CustomerAgencyEntity agency : agencies) {
initAgencyAllDim(agency); initAgencyAllDim(agency, initTime);
initAgencySelfDim(agency); initAgencySelfDim(agency, initTime);
} }
lastExecRecordDao.updateExecTimeBySubject(new Date(), StatsSubject.DIM_AGENCY); lastExecRecordDao.updateExecTimeBySubject(new Date(), StatsSubject.DIM_AGENCY);
} }
public void initAgencyAllDim(CustomerAgencyEntity agency) { public void initAgencyAllDim(CustomerAgencyEntity agency, Date initTime) {
DimAgencyEntity dimAgencyEntity = new DimAgencyEntity(); DimAgencyEntity dimAgencyEntity = new DimAgencyEntity();
dimAgencyEntity.setAgencyName(agency.getOrganizationName()); dimAgencyEntity.setAgencyName(agency.getOrganizationName());
dimAgencyEntity.setAllParentName(agency.getAllParentName()); dimAgencyEntity.setAllParentName(agency.getAllParentName());
@ -144,6 +144,8 @@ public class DimAgencyServiceImpl extends BaseServiceImpl<DimAgencyDao, DimAgenc
dimAgencyEntity.setCreatedBy(RobotConstant.DIMENSION_ROBOT); dimAgencyEntity.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dimAgencyEntity.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); dimAgencyEntity.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dimAgencyEntity.setId(agency.getId()); dimAgencyEntity.setId(agency.getId());
dimAgencyEntity.setCreatedTime(initTime);
dimAgencyEntity.setUpdatedTime(initTime);
baseDao.insert(dimAgencyEntity); baseDao.insert(dimAgencyEntity);
} }
@ -151,7 +153,7 @@ public class DimAgencyServiceImpl extends BaseServiceImpl<DimAgencyDao, DimAgenc
* 初始化机关单位本身的维度(不包含本身) * 初始化机关单位本身的维度(不包含本身)
* @param agency * @param agency
*/ */
public void initAgencySelfDim(CustomerAgencyEntity agency) { public void initAgencySelfDim(CustomerAgencyEntity agency, Date initTime) {
DimAgencyEntity dimAgencyEntity = new DimAgencyEntity(); DimAgencyEntity dimAgencyEntity = new DimAgencyEntity();
dimAgencyEntity.setAgencyName(agency.getOrganizationName()); dimAgencyEntity.setAgencyName(agency.getOrganizationName());
dimAgencyEntity.setAllParentName(agency.getAllParentName()); dimAgencyEntity.setAllParentName(agency.getAllParentName());
@ -163,6 +165,8 @@ public class DimAgencyServiceImpl extends BaseServiceImpl<DimAgencyDao, DimAgenc
dimAgencyEntity.setCreatedBy(RobotConstant.DIMENSION_ROBOT); dimAgencyEntity.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dimAgencyEntity.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); dimAgencyEntity.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dimAgencyEntity.setId(agency.getId().concat(DimAgencyConstant.TYPE_SELF_ID_SUFFIX)); dimAgencyEntity.setId(agency.getId().concat(DimAgencyConstant.TYPE_SELF_ID_SUFFIX));
dimAgencyEntity.setCreatedTime(initTime);
dimAgencyEntity.setUpdatedTime(initTime);
baseDao.insert(dimAgencyEntity); baseDao.insert(dimAgencyEntity);
} }
@ -246,4 +250,9 @@ public class DimAgencyServiceImpl extends BaseServiceImpl<DimAgencyDao, DimAgenc
return baseDao.getPidByAgencyId(agencyId); return baseDao.getPidByAgencyId(agencyId);
} }
@Override
public DimAgencyEntity getLatestCreatedAgencyDimEntity() {
return baseDao.getLatestCreatedAgencyDimEntity();
}
} }

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

@ -120,15 +120,22 @@ public class DimCustomerServiceImpl extends BaseServiceImpl<DimCustomerDao, DimC
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initCustomerDims(List<CustomerEntity> customers) { public void initCustomerDims(List<CustomerEntity> customers, Date initTime) {
for (CustomerEntity customer : customers) { for (CustomerEntity customer : customers) {
DimCustomerEntity dim = new DimCustomerEntity(); DimCustomerEntity dim = new DimCustomerEntity();
dim.setCustomerName(customer.getCustomerName()); dim.setCustomerName(customer.getCustomerName());
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT); dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setId(customer.getId()); dim.setId(customer.getId());
dim.setCreatedTime(initTime);
dim.setUpdatedTime(initTime);
baseDao.insert(dim); baseDao.insert(dim);
} }
lastExecRecordDao.updateExecTimeBySubject(new Date(), StatsSubject.DIM_CUSTOMER); lastExecRecordDao.updateExecTimeBySubject(new Date(), StatsSubject.DIM_CUSTOMER);
} }
@Override
public DimCustomerEntity getLatestCreatedDimEntity() {
return baseDao.getLatestCreatedDimEntity();
}
} }

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

@ -108,28 +108,20 @@ public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntit
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initDimDate() { public void initDimDate() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_DATE);
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_DATE);
}
Date now = new Date(); DimDateDTO latestDim = baseDao.getLatestDim();
Date targetDate = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYYMMDD); Date now = new Date();
Date lastExecTime = null; Date endDate = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYYMMDD);
if ((lastExecTime = lastExecRecord.getExecTime()) == null) { if (latestDim == null) {
// 首次初始化按日维度 // 首次初始化按日维度
initDimDate(targetDate); initDimDate(endDate);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} else { } else {
Date lastDimDate = DateUtils.integrate(lastExecTime, DateUtils.DATE_PATTERN_YYYYMMDD); Date lastDimDate = DateUtils.integrate(latestDim.getCreatedTime(), DateUtils.DATE_PATTERN_YYYYMMDD);
if (targetDate.after(lastDimDate)) { if (endDate.after(lastDimDate)) {
initDimDate(DateUtils.addDateDays(lastDimDate, 1), targetDate); initDimDate(DateUtils.addDateDays(lastDimDate, 1), endDate);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} }
} }
} }

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

@ -109,7 +109,7 @@ public class DimDepartmentServiceImpl extends BaseServiceImpl<DimDepartmentDao,
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initDepartmentDims(List<CustomerDepartmentEntity> departments) { public void initDepartmentDims(List<CustomerDepartmentEntity> departments, Date initTime) {
for (CustomerDepartmentEntity department : departments) { for (CustomerDepartmentEntity department : departments) {
DimDepartmentEntity dim = new DimDepartmentEntity(); DimDepartmentEntity dim = new DimDepartmentEntity();
dim.setAgencyId(department.getAgencyId()); dim.setAgencyId(department.getAgencyId());
@ -118,6 +118,8 @@ public class DimDepartmentServiceImpl extends BaseServiceImpl<DimDepartmentDao,
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT); dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT);
dim.setId(department.getId()); dim.setId(department.getId());
dim.setCreatedTime(initTime);
dim.setUpdatedTime(initTime);
baseDao.insert(dim); baseDao.insert(dim);
} }
lastExecRecordDao.updateExecTimeBySubject(new Date(), StatsSubject.DIM_DEPARTMENT); lastExecRecordDao.updateExecTimeBySubject(new Date(), StatsSubject.DIM_DEPARTMENT);
@ -130,4 +132,9 @@ public class DimDepartmentServiceImpl extends BaseServiceImpl<DimDepartmentDao,
} }
return baseDao.getDepartmentListByCustomerId(customerId); return baseDao.getDepartmentListByCustomerId(customerId);
} }
@Override
public DimDepartmentEntity getLatestCreatedDimEntity() {
return baseDao.getLatestCreatedDimEntity();
}
} }

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

@ -112,25 +112,18 @@ public class DimMonthServiceImpl extends BaseServiceImpl<DimMonthDao, DimMonthEn
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initMonthDim() { public void initMonthDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_MONTH); DimMonthEntity latestDimEntity = baseDao.getLatestDimEntity();
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_DEPARTMENT);
}
Date now = new Date(); Date now = new Date();
Date startMonth;// 起始月份,包含该月份 Date startMonth;// 起始月份,包含该月份
Date targetMonth = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYYMM);// 统计至当月,包含当月 Date endMonth = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYYMM);// 统计至当月,包含当月
if (lastExecRecord.getExecTime() == null) { if (latestDimEntity == null) {
initMonthDim(targetMonth); initMonthDim(endMonth);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} else { } else {
startMonth = DateUtils.addDateMonths(DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMM), 1); startMonth = DateUtils.addDateMonths(DateUtils.integrate(latestDimEntity.getCreatedTime(), DateUtils.DATE_PATTERN_YYYYMM), 1);
if (targetMonth.after(startMonth) || targetMonth.equals(startMonth)) { if (endMonth.after(startMonth) || endMonth.equals(startMonth)) {
initMonthDims(startMonth, targetMonth); initMonthDims(startMonth, endMonth);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} }
} }
} }

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

@ -115,31 +115,20 @@ public class DimQuarterServiceImpl extends BaseServiceImpl<DimQuarterDao, DimQua
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initQuarterDim() { public void initQuarterDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_QUARTER); DimQuarterEntity latestDimEntity = baseDao.getLatestDimEntity();
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_QUARTER);
}
Date now = new Date(); Date now = new Date();
//Date now = DateUtils.parse(now, DateUtils.DATE_PATTERN_YYYYMMDD);
Date targetQMonth;//初始化至,包含当季 Date endQMonth = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYYMM);;//初始化至当季
Date startQMonth;//从该季开始初始化,不包含该季 Date startQMonth;//从该季开始初始化,不包含该季
targetQMonth = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYYMM); if (latestDimEntity == null) {
// 初始化当前季度
if (lastExecRecord.getExecTime() == null) { initQuarterDim(endQMonth);
// 初始化上一个季度
initQuarterDim(targetQMonth);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} else { } else {
// 连续初始化多个季度 // 连续初始化多个季度
startQMonth = DateUtils.addDateMonths(DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMM), 3); startQMonth = DateUtils.addDateMonths(DateUtils.integrate(latestDimEntity.getCreatedTime(), DateUtils.DATE_PATTERN_YYYYMM), 3);
if (initQuarterDim(startQMonth, targetQMonth)) { initQuarterDim(startQMonth, endQMonth);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
}
} }
} }

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

@ -110,26 +110,18 @@ public class DimWeekServiceImpl extends BaseServiceImpl<DimWeekDao, DimWeekEntit
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initWeekDim() { public void initWeekDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_WEEK); DimWeekEntity latestDimEntity = baseDao.getLatestDimEntity();
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_WEEK);
}
Date now = new Date(); Date now = new Date();
Date startWeekDay; Date startWeekDay;
Date targetWeekDay = DateUtils.getWeekStartAndEnd(now)[0]; Date targetWeekDay = DateUtils.getWeekStartAndEnd(now)[0];
if (lastExecRecord.getExecTime() == null) { if (latestDimEntity == null) {
// 首次执行
initWeekDim(targetWeekDay); initWeekDim(targetWeekDay);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} else { } else {
startWeekDay = DateUtils.addDateWeeks(DateUtils.getWeekStartAndEnd(lastExecRecord.getExecTime())[0], 1); startWeekDay = DateUtils.addDateWeeks(DateUtils.getWeekStartAndEnd(latestDimEntity.getCreatedTime())[0], 1);
if (targetWeekDay.equals(startWeekDay) || targetWeekDay.after(startWeekDay)) { if (targetWeekDay.equals(startWeekDay) || targetWeekDay.after(startWeekDay)) {
initWeekDim(startWeekDay, targetWeekDay); initWeekDim(startWeekDay, targetWeekDay);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} }
} }
} }

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

@ -110,30 +110,19 @@ public class DimYearServiceImpl extends BaseServiceImpl<DimYearDao, DimYearEntit
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void initYearDim() { public void initYearDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_YEAR); DimYearEntity latestDimEntity = baseDao.getLatestDimEntity();
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_YEAR);
}
Date now = new Date(); Date now = new Date();
Date startYear; Date startYear;
Date targetYear; Date targetYear = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYY);
if (latestDimEntity == null) {
targetYear = DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYY);
if (lastExecRecord.getExecTime() == null) {
// 第一次执行统计 // 第一次执行统计
initYearDim(targetYear); initYearDim(targetYear);
lastExecRecord.setExecTime(now);
// 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord);
} else { } else {
startYear = DateUtils.addDateYears(DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYY), 1); startYear = DateUtils.addDateYears(DateUtils.integrate(latestDimEntity.getCreatedTime(), DateUtils.DATE_PATTERN_YYYY), 1);
if (targetYear.equals(startYear) || targetYear.after(startYear)) { if (targetYear.equals(startYear) || targetYear.after(startYear)) {
initYearDims(startYear, targetYear); initYearDims(startYear, targetYear);
lastExecRecord.setExecTime(now);
// 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord);
} }
} }
} }

20
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimAgencyDao.xml

@ -257,4 +257,24 @@
AND id = #{agencyId} AND id = #{agencyId}
</select> </select>
<select id="getLatestCreatedAgencyDimEntity" resultType="com.epmet.entity.stats.DimAgencyEntity">
SELECT id,
agency_name,
customer_id,
pid,
pids,
all_parent_name,
level,
del_flag,
revision,
created_by,
created_time,
updated_by,
updated_time,
agency_dim_type
FROM dim_agency
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper> </mapper>

14
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimCustomerDao.xml

@ -11,4 +11,18 @@
<select id="selectCustomerIdPage" resultType="java.lang.String"> <select id="selectCustomerIdPage" resultType="java.lang.String">
select ID FROM dim_customer WHERE DEL_FLAG = '0' limit #{offset,jdbcType=INTEGER},#{pageSize,jdbcType=INTEGER} select ID FROM dim_customer WHERE DEL_FLAG = '0' limit #{offset,jdbcType=INTEGER},#{pageSize,jdbcType=INTEGER}
</select> </select>
<select id="getLatestCreatedDimEntity" resultType="com.epmet.entity.stats.DimCustomerEntity">
SELECT id,
customer_name,
del_flag,
revision,
created_by,
created_time,
updated_by,
updated_time
FROM dim_customer
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper> </mapper>

2
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimDateDao.xml

@ -4,7 +4,7 @@
<mapper namespace="com.epmet.dao.stats.DimDateDao"> <mapper namespace="com.epmet.dao.stats.DimDateDao">
<!--最新的按日维度--> <!--最新的按日维度-->
<select id="getLatestDimDate" resultType="com.epmet.dto.stats.DimDateDTO"> <select id="getLatestDim" resultType="com.epmet.dto.stats.DimDateDTO">
SELECT * SELECT *
FROM dim_date FROM dim_date
WHERE DEL_FLAG = 0 WHERE DEL_FLAG = 0

16
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimDepartmentDao.xml

@ -19,4 +19,20 @@
WHERE WHERE
DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
</select> </select>
<select id="getLatestCreatedDimEntity" resultType="com.epmet.entity.stats.DimDepartmentEntity">
SELECT id,
department_name,
agency_id,
customer_id,
del_flag,
revision,
created_by,
created_time,
updated_by,
updated_time
FROM dim_department
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper> </mapper>

21
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimMonthDao.xml

@ -2,7 +2,22 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.stats.DimMonthDao"> <mapper namespace="com.epmet.dao.stats.DimMonthDao">
<select id="getLatestDimEntity" resultType="com.epmet.entity.stats.DimMonthEntity">
SELECT id,
month_name,
month_order,
start_date,
end_date,
quarter_id,
year_id,
del_flag,
revision,
created_by,
created_time,
updated_by,
updated_time
FROM dim_month
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper> </mapper>

19
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimQuarterDao.xml

@ -3,6 +3,21 @@
<mapper namespace="com.epmet.dao.stats.DimQuarterDao"> <mapper namespace="com.epmet.dao.stats.DimQuarterDao">
<select id="getLatestDimEntity" resultType="com.epmet.entity.stats.DimQuarterEntity">
SELECT id,
quarter_name,
quarter_order,
start_date,
end_date,
year_id,
del_flag,
revision,
created_by,
created_time,
updated_by,
updated_time
FROM dim_quarter
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper> </mapper>

21
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimWeekDao.xml

@ -2,8 +2,21 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.stats.DimWeekDao"> <mapper namespace="com.epmet.dao.stats.DimWeekDao">
<select id="getLatestDimEntity" resultType="com.epmet.entity.stats.DimWeekEntity">
SELECT id,
week_name,
week_order,
start_date,
end_date,
year_id,
del_flag,
revision,
created_by,
created_time,
updated_by,
updated_time
FROM dim_week
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper> </mapper>

14
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimYearDao.xml

@ -21,5 +21,19 @@
(#{id}, #{yearName}, #{delFlag}, #{revision}, #{createdBy}, #{createdTime}, #{updatedBy}, #{updatedTime}) (#{id}, #{yearName}, #{delFlag}, #{revision}, #{createdBy}, #{createdTime}, #{updatedBy}, #{updatedTime})
</insert> </insert>
<select id="getLatestDimEntity" resultType="com.epmet.entity.stats.DimYearEntity">
SELECT id,
year_name,
del_flag,
revision,
created_by,
created_time,
updated_by,
updated_time
FROM dim_year
ORDER BY CREATED_TIME DESC
LIMIT 1
</select>
</mapper> </mapper>
Loading…
Cancel
Save