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