|
|
@ -1,8 +1,6 @@ |
|
|
|
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; |
|
|
|
import com.epmet.entity.org.CustomerDepartmentEntity; |
|
|
@ -18,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -54,6 +53,17 @@ public class StatsDimServiceImpl implements StatsDimService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void initGridDim() { |
|
|
|
List<DimGridEntity> newDimGrids = getNewDimGrids(); |
|
|
|
List<DimGridEntity> changedGrids = getChangedGrids(); |
|
|
|
|
|
|
|
dimGridService.initGridDims(newDimGrids, changedGrids); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化新建网格 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<DimGridEntity> getNewDimGrids() { |
|
|
|
DimGridEntity lastDimEntity = dimGridService.getLastCreatedGridDim(); |
|
|
|
List<CustomerGridEntity> grids; |
|
|
|
Date now = new Date(); |
|
|
@ -65,10 +75,36 @@ public class StatsDimServiceImpl implements StatsDimService { |
|
|
|
grids = customerGridService.listGridsByCreateTime(lastInitTime, now); |
|
|
|
} |
|
|
|
|
|
|
|
List<DimGridEntity> gridDims = convertCustomerGrid2GridDim(grids, now); |
|
|
|
if (!CollectionUtils.isEmpty(gridDims)) { |
|
|
|
dimGridService.initGridDims(gridDims); |
|
|
|
return convertCustomerGrid2GridDim(grids, now); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化变更的网格 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<DimGridEntity> getChangedGrids() { |
|
|
|
DimGridEntity lastUpdatedGridDim = dimGridService.getLastUpdatedGridDim(); |
|
|
|
|
|
|
|
List<CustomerGridEntity> updatedGrids; |
|
|
|
Date now = new Date(); |
|
|
|
if (lastUpdatedGridDim != null) { |
|
|
|
Date lastInitTime = lastUpdatedGridDim.getUpdatedTime(); |
|
|
|
updatedGrids = customerGridService.listUpdatedGridsByUpdateTime(lastInitTime, now); |
|
|
|
ArrayList<DimGridEntity> dimGrids = new ArrayList<>(); |
|
|
|
for (CustomerGridEntity updatedGrid : updatedGrids) { |
|
|
|
DimGridEntity dimGrid = dimGridService.selectById(updatedGrid.getId()); |
|
|
|
if (dimGrid != null) { |
|
|
|
dimGrid.setGridName(updatedGrid.getGridName()); |
|
|
|
dimGrid.setUpdatedTime(now); |
|
|
|
dimGrid.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); |
|
|
|
dimGrids.add(dimGrid); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return dimGrids; |
|
|
|
} |
|
|
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -98,19 +134,41 @@ public class StatsDimServiceImpl implements StatsDimService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void initAgencyDim() { |
|
|
|
Date now = new Date(); |
|
|
|
List<CustomerAgencyEntity> agencies2Add = listAgencies2Add(now); |
|
|
|
List<CustomerAgencyEntity> agencies2Update = listAgencies2Update(now); |
|
|
|
dimAgencyService.initAgencyDims(agencies2Add, agencies2Update, now); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询需要添加的机关ç |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<CustomerAgencyEntity> listAgencies2Add(Date endDate) { |
|
|
|
DimAgencyEntity latestCreatedAgencyDim = dimAgencyService.getLatestCreatedAgencyDimEntity(); |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
Date lastInitTime = null; |
|
|
|
|
|
|
|
if (latestCreatedAgencyDim != null) { |
|
|
|
lastInitTime = latestCreatedAgencyDim.getCreatedTime(); |
|
|
|
} |
|
|
|
|
|
|
|
List<CustomerAgencyEntity> agencies = customerAgencyService.listAgenciesByCreateTime(lastInitTime, now); |
|
|
|
if (!CollectionUtils.isEmpty(agencies)) { |
|
|
|
dimAgencyService.initAgencyDims(agencies, now); |
|
|
|
return customerAgencyService.listAgenciesByCreateTime(lastInitTime, endDate); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询需要更新的机关 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<CustomerAgencyEntity> listAgencies2Update(Date endDate) { |
|
|
|
DimAgencyEntity latestUpdatedAgencyDim = dimAgencyService.getLatestUpdatedAgencyDimEntity(); |
|
|
|
|
|
|
|
if (latestUpdatedAgencyDim != null) { |
|
|
|
// 不是首次初始化,可以更新
|
|
|
|
Date updatedTime = latestUpdatedAgencyDim.getUpdatedTime(); |
|
|
|
return customerAgencyService.listAgenciesByUpdatedTime(updatedTime, endDate); |
|
|
|
} |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -118,24 +176,59 @@ public class StatsDimServiceImpl implements StatsDimService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void initCustomerDim() { |
|
|
|
Date now = new Date(); |
|
|
|
List<CustomerEntity> newCustomers = listNewCustomers(now); |
|
|
|
List<CustomerEntity> updatedCustomers = listUpdatedCustomers(now); |
|
|
|
// System.out.println(666);
|
|
|
|
dimCustomerService.initCustomerDims(newCustomers, updatedCustomers, now); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询新增的客户列表 |
|
|
|
* @param initTime |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<CustomerEntity> listNewCustomers(Date initTime) { |
|
|
|
DimCustomerEntity lastCreateDim = dimCustomerService.getLatestCreatedDimEntity(); |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
Date lastInitTime = null; |
|
|
|
|
|
|
|
if (lastCreateDim != null) { |
|
|
|
lastInitTime = lastCreateDim.getCreatedTime(); |
|
|
|
} |
|
|
|
|
|
|
|
List<CustomerEntity> customers = customerService.listValidCustomersByCreateTime(lastInitTime, now); |
|
|
|
if (!CollectionUtils.isEmpty(customers)) { |
|
|
|
dimCustomerService.initCustomerDims(customers, now); |
|
|
|
List<CustomerEntity> customers = customerService.listValidCustomersByCreateTime(lastInitTime, initTime); |
|
|
|
|
|
|
|
return customers; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询更新的客户列表 |
|
|
|
* @param initTime |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<CustomerEntity> listUpdatedCustomers(Date initTime) { |
|
|
|
DimCustomerEntity lastCreatedDim = dimCustomerService.getLatestUpdatedDimEntity(); |
|
|
|
if (lastCreatedDim != null) { |
|
|
|
// 说明不是首次初始化
|
|
|
|
List<CustomerEntity> customers = customerService.listValidCustomersByUpdatedTime(lastCreatedDim.getUpdatedTime(), initTime); |
|
|
|
return customers; |
|
|
|
} |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化部门维度 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void initDepartmentDim() { |
|
|
|
Date now = new Date(); |
|
|
|
List<CustomerDepartmentEntity> newDepartments = listNewDepartments(now); |
|
|
|
List<CustomerDepartmentEntity> updatedDepartments = listUpdatedDepartments(now); |
|
|
|
dimDepartmentService.initDepartmentDims(newDepartments, updatedDepartments, now); |
|
|
|
} |
|
|
|
|
|
|
|
public List<CustomerDepartmentEntity> listNewDepartments(Date initTime) { |
|
|
|
DimDepartmentEntity lastCreatedDeptDim = dimDepartmentService.getLatestCreatedDimEntity(); |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
@ -144,10 +237,14 @@ public class StatsDimServiceImpl implements StatsDimService { |
|
|
|
if (lastCreatedDeptDim != null) { |
|
|
|
lastInitTime = lastCreatedDeptDim.getCreatedTime(); |
|
|
|
} |
|
|
|
return departmentService.listDepartmentsByCreatedTime(lastInitTime, now); |
|
|
|
} |
|
|
|
|
|
|
|
List<CustomerDepartmentEntity> departments = departmentService.listDepartmentsByCreatedTime(lastInitTime, now); |
|
|
|
if (!CollectionUtils.isEmpty(departments)) { |
|
|
|
dimDepartmentService.initDepartmentDims(departments, now); |
|
|
|
public List<CustomerDepartmentEntity> listUpdatedDepartments(Date initTime) { |
|
|
|
DimDepartmentEntity lastUpdatedDeptDim = dimDepartmentService.getLatestUpdatedDimEntity(); |
|
|
|
if (lastUpdatedDeptDim != null) { |
|
|
|
return departmentService.listDepartmentsByUpdatedTime(lastUpdatedDeptDim.getCreatedTime(), initTime); |
|
|
|
} |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
} |
|
|
|