|
|
@ -14,8 +14,9 @@ import com.epmet.service.project.ProjectProcessService; |
|
|
|
import com.epmet.service.project.ProjectService; |
|
|
|
import com.epmet.service.stats.*; |
|
|
|
import com.epmet.util.DimIdGenerator; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
@ -34,6 +35,7 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
@Service |
|
|
|
public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
|
|
|
|
protected static final Logger log = LoggerFactory.getLogger(StatsProjectServiceImpl.class); |
|
|
|
@Autowired |
|
|
|
private DimCustomerService dimCustomerService; |
|
|
|
@Autowired |
|
|
@ -57,10 +59,10 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 数据-项目-机关、网格日(月)统计 |
|
|
|
* @Description 数据-项目-机关日(月)统计 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public void agencyGridProjectStats() { |
|
|
|
public void agencyProjectStats() { |
|
|
|
int pageNo = 1; |
|
|
|
int pageSize = 100; |
|
|
|
List<String> customerIdList = null; |
|
|
@ -68,8 +70,13 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
customerIdList = dimCustomerService.selectCustomerIdPage(pageNo++, pageSize); |
|
|
|
if (!CollectionUtils.isEmpty(customerIdList)) { |
|
|
|
for (String customerId : customerIdList) { |
|
|
|
//遍历统计每一个客户数据
|
|
|
|
customerStats(customerId); |
|
|
|
try { |
|
|
|
//遍历统计每一个客户数据
|
|
|
|
customerAgencyStats(customerId); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("项目-机关-数据统计程序错误,对应客户Id:"+customerId, e); |
|
|
|
log.error("Error creating model JSON", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() == pageSize); |
|
|
@ -77,11 +84,10 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 一个客户一个线程, 分别统计机关/网格日/月数据 |
|
|
|
* @Description 分别统计机关日/月数据 |
|
|
|
**/ |
|
|
|
@Async |
|
|
|
public void customerStats(String customerId) { |
|
|
|
Date date = new Date(); |
|
|
|
public void customerAgencyStats(String customerId) { |
|
|
|
Date date = yesterDay(); |
|
|
|
//1:查询各维度表Id,方便使用
|
|
|
|
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(date); |
|
|
|
|
|
|
@ -90,39 +96,25 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
dimAgencyDTO.setCustomerId(customerId); |
|
|
|
List<DimAgencyDTO> dimAgencyList = dimAgencyService.getDimAgencyList(dimAgencyDTO); |
|
|
|
|
|
|
|
//3:根据客户Id查询网格维度表数据
|
|
|
|
List<DimGridEntity> dimGridList = dimGridService.getGridListByCustomerId(customerId); |
|
|
|
|
|
|
|
//4:根据客户Id查询项目业务表已结案数据(查询传入日期及之前的数据)
|
|
|
|
//3:根据客户Id查询项目业务表已结案数据(查询传入日期及之前的数据)
|
|
|
|
ProjectEntity projectEntity = new ProjectEntity(); |
|
|
|
projectEntity.setCustomerId(customerId); |
|
|
|
projectEntity.setCreatedTime(date); |
|
|
|
projectEntity.setStatus(ProjectConstant.CLOSED); |
|
|
|
List<ProjectEntity> projectList = projectService.getProjectList(projectEntity); |
|
|
|
|
|
|
|
//5:查询项目处理进展表中有效数据(创建日期截取yyyy-mm-dd格式字段值)(查询传入日期及之前的数据)
|
|
|
|
//4:查询项目处理进展表中有效数据(创建日期截取yyyy-mm-dd格式字段值)(查询传入日期及之前的数据)
|
|
|
|
List<ProjectProcessEntity> processList = projectProcessService.getProcessList(projectEntity); |
|
|
|
|
|
|
|
//6:机关层级日月统计
|
|
|
|
//5:机关层级日月统计
|
|
|
|
if (null != dimAgencyList && dimAgencyList.size() > NumConstant.ZERO) { |
|
|
|
//6.1:执行机关日数据统计
|
|
|
|
//5.1:执行机关日数据统计
|
|
|
|
agencyDateProjectStats(customerId, dimId, dimAgencyList, projectList, processList); |
|
|
|
|
|
|
|
//6.2:执行机关月数据统计
|
|
|
|
if (Calendar.getInstance().get(Calendar.DATE) == 1) { |
|
|
|
//5.2:执行机关月数据统计
|
|
|
|
//if (Calendar.getInstance().get(Calendar.DATE) == 1) {
|
|
|
|
agencyMonthProjectStats(customerId, dimId, dimAgencyList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//7:网格层级日月统计
|
|
|
|
if (null != dimGridList && dimGridList.size() > NumConstant.ZERO) { |
|
|
|
//7.1:执行网格日数据统计
|
|
|
|
gridDateProjectStats(customerId, dimId, dimGridList, projectList, processList); |
|
|
|
|
|
|
|
//7.2:执行网格月数据统计
|
|
|
|
if (Calendar.getInstance().get(Calendar.DATE) == 1) { |
|
|
|
gridMonthProjectStats(customerId, dimId, dimGridList); |
|
|
|
} |
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -138,7 +130,7 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
List<FactAgencyProjectDailyEntity> projectDateEntityList = new ArrayList<>(); |
|
|
|
//计算百分比使用,保留小数点后两位
|
|
|
|
NumberFormat numberFormat = NumberFormat.getInstance(); |
|
|
|
numberFormat.setMaximumFractionDigits(2); |
|
|
|
numberFormat.setMaximumFractionDigits(6); |
|
|
|
|
|
|
|
//1:遍历机关维度数据,统计每个机关各项指标数
|
|
|
|
for (DimAgencyDTO agency : dimAgencyList) { |
|
|
@ -232,12 +224,12 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
agencyDailyEntity.setResolvedTotal(resolvedTotal.intValue()); |
|
|
|
agencyDailyEntity.setUnresolvedTotal(unResolvedTotal.intValue()); |
|
|
|
if (projectTotal.intValue() > NumConstant.ZERO) { |
|
|
|
agencyDailyEntity.setPendingRatio(new BigDecimal(numberFormat.format((float) agencyDailyEntity.getPendingTotal() / (float) projectTotal.intValue() * 100))); |
|
|
|
agencyDailyEntity.setClosedRatio(new BigDecimal(numberFormat.format((float) closedTotal.intValue() / (float) projectTotal.intValue() * 100))); |
|
|
|
agencyDailyEntity.setPendingRatio(new BigDecimal(numberFormat.format((float) agencyDailyEntity.getPendingTotal() / (float) projectTotal.intValue()))); |
|
|
|
agencyDailyEntity.setClosedRatio(new BigDecimal(numberFormat.format((float) closedTotal.intValue() / (float) projectTotal.intValue()))); |
|
|
|
} |
|
|
|
if (closedTotal.intValue() > NumConstant.ZERO) { |
|
|
|
agencyDailyEntity.setResolvedRatio(new BigDecimal(numberFormat.format((float) resolvedTotal.intValue() / (float) closedTotal.intValue() * 100))); |
|
|
|
agencyDailyEntity.setUnresolvedRatio(new BigDecimal(numberFormat.format((float) unResolvedTotal.intValue() / (float) closedTotal.intValue() * 100))); |
|
|
|
agencyDailyEntity.setResolvedRatio(new BigDecimal(numberFormat.format((float) resolvedTotal.intValue() / (float) closedTotal.intValue()))); |
|
|
|
agencyDailyEntity.setUnresolvedRatio(new BigDecimal(numberFormat.format((float) unResolvedTotal.intValue() / (float) closedTotal.intValue()))); |
|
|
|
} |
|
|
|
agencyDailyEntity.setProjectIncr(projectIncr.intValue()); |
|
|
|
agencyDailyEntity.setPendingIncr(projectIncr.intValue() - closedIncr.intValue()); |
|
|
@ -276,8 +268,7 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
//1:获取昨天日期所在月份的起始日期和结束日期
|
|
|
|
MonthProjectListFormDTO formDTO = new MonthProjectListFormDTO(); |
|
|
|
formDTO.setCustomerId(customerId); |
|
|
|
formDTO.setStartTime(getMonthBegin(date)); |
|
|
|
formDTO.setEndTime(getMonthEnd(date)); |
|
|
|
formDTO.setMonthId(dimId.getMonthId()); |
|
|
|
|
|
|
|
//2:遍历机关维度数据,分别统计每个组织月数据
|
|
|
|
for (DimAgencyDTO agency : dimAgencyList) { |
|
|
@ -342,6 +333,65 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 数据-项目-机关日(月)统计 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public void gridProjectStats() { |
|
|
|
int pageNo = 1; |
|
|
|
int pageSize = 100; |
|
|
|
List<String> customerIdList = null; |
|
|
|
do { |
|
|
|
customerIdList = dimCustomerService.selectCustomerIdPage(pageNo++, pageSize); |
|
|
|
if (!CollectionUtils.isEmpty(customerIdList)) { |
|
|
|
for (String customerId : customerIdList) { |
|
|
|
try { |
|
|
|
//遍历统计每一个客户数据
|
|
|
|
customerGridStats(customerId); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("项目-网格-数据统计程序错误,对应客户Id:"+customerId, e); |
|
|
|
log.error("Error creating model JSON", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() == pageSize); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 分别统计网格日/月数据 |
|
|
|
**/ |
|
|
|
public void customerGridStats(String customerId) { |
|
|
|
Date date = yesterDay(); |
|
|
|
//1:查询各维度表Id,方便使用
|
|
|
|
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(date); |
|
|
|
|
|
|
|
//2:根据客户Id查询网格维度表数据
|
|
|
|
List<DimGridEntity> dimGridList = dimGridService.getGridListByCustomerId(customerId); |
|
|
|
|
|
|
|
//3:根据客户Id查询项目业务表已结案数据(查询传入日期及之前的数据)
|
|
|
|
ProjectEntity projectEntity = new ProjectEntity(); |
|
|
|
projectEntity.setCustomerId(customerId); |
|
|
|
projectEntity.setCreatedTime(date); |
|
|
|
projectEntity.setStatus(ProjectConstant.CLOSED); |
|
|
|
List<ProjectEntity> projectList = projectService.getProjectList(projectEntity); |
|
|
|
|
|
|
|
//4:查询项目处理进展表中有效数据(创建日期截取yyyy-mm-dd格式字段值)(查询传入日期及之前的数据)
|
|
|
|
List<ProjectProcessEntity> processList = projectProcessService.getProcessList(projectEntity); |
|
|
|
|
|
|
|
//5:网格层级日月统计
|
|
|
|
if (null != dimGridList && dimGridList.size() > NumConstant.ZERO) { |
|
|
|
//5.1:执行网格日数据统计
|
|
|
|
gridDateProjectStats(customerId, dimId, dimGridList, projectList, processList); |
|
|
|
|
|
|
|
//5.2:执行网格月数据统计
|
|
|
|
//if (Calendar.getInstance().get(Calendar.DATE) == 1) {
|
|
|
|
gridMonthProjectStats(customerId, dimId, dimGridList); |
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
* @param customerId |
|
|
|
* @return |
|
|
@ -354,7 +404,7 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
List<FactGridProjectDailyEntity> gridDateEntityList = new ArrayList<>(); |
|
|
|
//计算百分比使用,保留小数点后两位
|
|
|
|
NumberFormat numberFormat = NumberFormat.getInstance(); |
|
|
|
numberFormat.setMaximumFractionDigits(2); |
|
|
|
numberFormat.setMaximumFractionDigits(6); |
|
|
|
|
|
|
|
//1:根据客户Id查询议题库已转项目的网格项目关系数据
|
|
|
|
List<IssueEntity> gridProjectList = issueService.getGridProjectList(customerId); |
|
|
@ -448,12 +498,12 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
gridDailyEntity.setResolvedTotal(resolvedTotal.intValue()); |
|
|
|
gridDailyEntity.setUnresolvedTotal(unResolvedTotal.intValue()); |
|
|
|
if (projectTotal.intValue() > NumConstant.ZERO) { |
|
|
|
gridDailyEntity.setPendingRatio(new BigDecimal(numberFormat.format((float) gridDailyEntity.getPendingTotal() / (float) projectTotal.intValue() * 100))); |
|
|
|
gridDailyEntity.setClosedRatio(new BigDecimal(numberFormat.format((float) closedTotal.intValue() / (float) projectTotal.intValue() * 100))); |
|
|
|
gridDailyEntity.setPendingRatio(new BigDecimal(numberFormat.format((float) gridDailyEntity.getPendingTotal() / (float) projectTotal.intValue()))); |
|
|
|
gridDailyEntity.setClosedRatio(new BigDecimal(numberFormat.format((float) closedTotal.intValue() / (float) projectTotal.intValue()))); |
|
|
|
} |
|
|
|
if (closedTotal.intValue() > NumConstant.ZERO) { |
|
|
|
gridDailyEntity.setResolvedRatio(new BigDecimal(numberFormat.format((float) resolvedTotal.intValue() / (float) closedTotal.intValue() * 100))); |
|
|
|
gridDailyEntity.setUnresolvedRatio(new BigDecimal(numberFormat.format((float) unResolvedTotal.intValue() / (float) closedTotal.intValue() * 100))); |
|
|
|
gridDailyEntity.setResolvedRatio(new BigDecimal(numberFormat.format((float) resolvedTotal.intValue() / (float) closedTotal.intValue()))); |
|
|
|
gridDailyEntity.setUnresolvedRatio(new BigDecimal(numberFormat.format((float) unResolvedTotal.intValue() / (float) closedTotal.intValue()))); |
|
|
|
} |
|
|
|
gridDailyEntity.setProjectIncr(projectIncr.intValue()); |
|
|
|
gridDailyEntity.setPendingIncr(projectIncr.intValue() - closedIncr.intValue()); |
|
|
@ -489,15 +539,14 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
//批量月数据新增对象
|
|
|
|
List<FactGridProjectMonthlyEntity> monthlyEntityList = new ArrayList<>(); |
|
|
|
|
|
|
|
//1:获取昨天日期所在月份的起始日期和结束日期
|
|
|
|
//1:查询客户网格月份内日统计数据
|
|
|
|
MonthProjectListFormDTO formDTO = new MonthProjectListFormDTO(); |
|
|
|
formDTO.setCustomerId(customerId); |
|
|
|
formDTO.setStartTime(getMonthBegin(yesterDay())); |
|
|
|
formDTO.setEndTime(getMonthEnd(yesterDay())); |
|
|
|
formDTO.setMonthId(dimId.getMonthId()); |
|
|
|
|
|
|
|
//2:遍历网格维度数据,分别统计每个网格月数据
|
|
|
|
for (DimGridEntity grid : dimGridList) { |
|
|
|
//2.1:查询上一月网格日统计数据,按时间倒序
|
|
|
|
//2.1:查询当前月网格日统计数据,按时间倒序
|
|
|
|
formDTO.setGridId(grid.getId()); |
|
|
|
List<FactGridProjectDailyEntity> projectDailyList = factGridProjectDailyService.getMonthProjectList(formDTO); |
|
|
|
|
|
|
@ -575,46 +624,4 @@ public class StatsProjectServiceImpl implements StatsProjectService { |
|
|
|
return date; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 获取指定日期所在月份开始的时间 |
|
|
|
**/ |
|
|
|
public Date getMonthBegin(Date date) { |
|
|
|
Calendar c = Calendar.getInstance(); |
|
|
|
c.setTime(date); |
|
|
|
//设置为1号,当前日期既为本月第一天
|
|
|
|
c.set(Calendar.DAY_OF_MONTH, 1); |
|
|
|
//将小时至0
|
|
|
|
c.set(Calendar.HOUR_OF_DAY, 0); |
|
|
|
//将分钟至0
|
|
|
|
c.set(Calendar.MINUTE, 0); |
|
|
|
//将秒至0
|
|
|
|
c.set(Calendar.SECOND, 0); |
|
|
|
//将毫秒至0
|
|
|
|
c.set(Calendar.MILLISECOND, 0); |
|
|
|
//获取本月第一天的时间
|
|
|
|
return c.getTime(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 获取指定日期所在月份结束的时间 |
|
|
|
**/ |
|
|
|
public Date getMonthEnd(Date date) { |
|
|
|
Calendar c = Calendar.getInstance(); |
|
|
|
c.setTime(date); |
|
|
|
//设置为当月最后一天
|
|
|
|
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH)); |
|
|
|
//将小时至23
|
|
|
|
c.set(Calendar.HOUR_OF_DAY, 23); |
|
|
|
//将分钟至59
|
|
|
|
c.set(Calendar.MINUTE, 59); |
|
|
|
//将秒至59
|
|
|
|
c.set(Calendar.SECOND, 59); |
|
|
|
//将毫秒至999
|
|
|
|
c.set(Calendar.MILLISECOND, 999); |
|
|
|
//获取本月最后一天的时间
|
|
|
|
return c.getTime(); |
|
|
|
} |
|
|
|
|
|
|
|
} |