Browse Source

定时任务添加入参,date和customerId,可以执行任意时间任意客户数据统计

master
sunyuchao 5 years ago
parent
commit
a19c03277e
  1. 25
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/project/form/ProjectStatsFormDTO.java
  2. 10
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/StatsProjectController.java
  3. 6
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsProjectService.java
  4. 104
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsProjectServiceImpl.java
  5. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactAgencyProjectDailyDao.xml
  6. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactGridProjectDailyDao.xml

25
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/project/form/ProjectStatsFormDTO.java

@ -0,0 +1,25 @@
package com.epmet.dto.project.form;
import lombok.Data;
import java.io.Serializable;
/**
* @Author sun
* 项目数据统计接口入参方便后期可以手动调用
*/
@Data
public class ProjectStatsFormDTO implements Serializable {
private static final long serialVersionUID = -3634745091993094743L;
/**
* 客户Id
*/
private String customerId;
/**
* 需要执行的日期格式yyyy-MM-dd2020-01-01
*/
private String date;
}

10
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/StatsProjectController.java

@ -1,9 +1,11 @@
package com.epmet.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.project.form.ProjectStatsFormDTO;
import com.epmet.service.StatsProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -23,8 +25,8 @@ public class StatsProjectController {
* @Description 数据-项目-机关日()统计
**/
@PostMapping("agencyprojectstats")
public Result agencyProjectStats() {
statsProjectService.agencyProjectStats();
public Result agencyProjectStats(@RequestBody ProjectStatsFormDTO formDTO) {
statsProjectService.agencyProjectStats(formDTO);
return new Result();
}
@ -33,8 +35,8 @@ public class StatsProjectController {
* @Description 数据-项目-网格日()统计
**/
@PostMapping("gridprojectstats")
public Result gridProjectStats() {
statsProjectService.gridProjectStats();
public Result gridProjectStats(@RequestBody ProjectStatsFormDTO formDTO) {
statsProjectService.gridProjectStats(formDTO);
return new Result();
}

6
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsProjectService.java

@ -1,5 +1,7 @@
package com.epmet.service;
import com.epmet.dto.project.form.ProjectStatsFormDTO;
/**
* 数据统计-项目
* @author sun
@ -10,11 +12,11 @@ public interface StatsProjectService {
* @Author sun
* @Description 数据-项目-机关日()统计
**/
void agencyProjectStats();
void agencyProjectStats(ProjectStatsFormDTO formDTO);
/**
* @Author sun
* @Description 数据-项目-网格日()统计
**/
void gridProjectStats();
void gridProjectStats(ProjectStatsFormDTO formDTO);
}

104
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsProjectServiceImpl.java

@ -1,8 +1,10 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.ProjectConstant;
import com.epmet.dto.project.form.MonthProjectListFormDTO;
import com.epmet.dto.project.form.ProjectStatsFormDTO;
import com.epmet.dto.stats.DimAgencyDTO;
import com.epmet.entity.issue.IssueEntity;
import com.epmet.entity.project.ProjectEntity;
@ -19,6 +21,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.text.DateFormat;
@ -62,33 +65,40 @@ public class StatsProjectServiceImpl implements StatsProjectService {
* @Description 数据-项目-机关日()统计
**/
@Override
public void agencyProjectStats() {
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 {
log.info("for循环统计机关-项目-日月数据,当前统计的客户Id:" + customerId);
//遍历统计每一个客户数据
customerAgencyStats(customerId);
} catch (Exception e) {
log.error("项目-机关-数据统计程序错误,对应客户Id:" + customerId, e);
log.error("Error creating model JSON", e);
public void agencyProjectStats(ProjectStatsFormDTO formDTO) {
Date date = yesterDay();
if (null != formDTO.getDate() && StringUtils.isNotBlank(formDTO.getDate())) {
date = DateUtils.parse(formDTO.getDate(), DateUtils.DATE_PATTERN);
}
if (null != formDTO.getCustomerId() && StringUtils.isNotBlank(formDTO.getCustomerId())) {
customerAgencyStats(formDTO.getCustomerId(), date);
} else {
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 {
log.info("for循环统计机关-项目-日月数据,当前统计的客户Id:" + customerId);
//遍历统计每一个客户数据
customerAgencyStats(customerId, date);
} catch (Exception e) {
log.error("项目-机关-数据统计程序错误,对应客户Id:" + customerId, e);
log.error("Error creating model JSON", e);
}
}
}
}
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() == pageSize);
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() == pageSize);
}
}
/**
* @Author sun
* @Description 分别统计机关日/月数据
**/
public void customerAgencyStats(String customerId) {
Date date = yesterDay();
public void customerAgencyStats(String customerId, Date date) {
//1:查询各维度表Id,方便使用
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(date);
@ -115,7 +125,7 @@ public class StatsProjectServiceImpl implements StatsProjectService {
//5.1:执行机关日数据统计
try {
log.info("StatsProjectServiceImpl.customerAgencyStats-开始执行机关日统计方法,方法名:agencyDateProjectStats,客户Id:" + customerId);
agencyDateProjectStats(customerId, dimId, dimAgencyList, projectList, processList);
agencyDateProjectStats(customerId, dimId, date, dimAgencyList, projectList, processList);
} catch (Exception e) {
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, "agencyDateProjectStats", customerId, dimId.getDateId()), e);
}
@ -138,8 +148,7 @@ public class StatsProjectServiceImpl implements StatsProjectService {
* @Author sun
* @Description 数据-项目-机关日统计
**/
private String agencyDateProjectStats(String customerId, DimIdGenerator.DimIdBean dimId, List<DimAgencyDTO> dimAgencyList, List<ProjectEntity> projectList, List<ProjectProcessEntity> processList) {
Date date = yesterDay();
private String agencyDateProjectStats(String customerId, DimIdGenerator.DimIdBean dimId, Date date, List<DimAgencyDTO> dimAgencyList, List<ProjectEntity> projectList, List<ProjectProcessEntity> processList) {
//批量机关日统计新增对象
List<FactAgencyProjectDailyEntity> projectDateEntityList = new ArrayList<>();
//计算百分比使用,保留小数点后两位
@ -277,7 +286,6 @@ public class StatsProjectServiceImpl implements StatsProjectService {
* @Description 数据-项目-机关月统计
**/
private String agencyMonthProjectStats(String customerId, DimIdGenerator.DimIdBean dimId, List<DimAgencyDTO> dimAgencyList) {
Date date = yesterDay();
//批量月数据新增对象
List<FactAgencyProjectMonthlyEntity> monthlyEntityList = new ArrayList<>();
@ -356,33 +364,40 @@ public class StatsProjectServiceImpl implements StatsProjectService {
* @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 {
log.info("for循环统计网格-项目-日月数据,当前统计的客户Id:" + customerId);
//遍历统计每一个客户数据
customerGridStats(customerId);
} catch (Exception e) {
log.error("项目-网格-数据统计程序错误,对应客户Id:" + customerId, e);
log.error("Error creating model JSON", e);
public void gridProjectStats(ProjectStatsFormDTO formDTO) {
Date date = yesterDay();
if (null != formDTO.getDate() && StringUtils.isNotBlank(formDTO.getDate())) {
date = DateUtils.parse(formDTO.getDate(), DateUtils.DATE_PATTERN);
}
if (null != formDTO.getCustomerId() && StringUtils.isNotBlank(formDTO.getCustomerId())) {
customerGridStats(formDTO.getCustomerId(), date);
} else {
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 {
log.info("for循环统计网格-项目-日月数据,当前统计的客户Id:" + customerId);
//遍历统计每一个客户数据
customerGridStats(customerId, date);
} catch (Exception e) {
log.error("项目-网格-数据统计程序错误,对应客户Id:" + customerId, e);
log.error("Error creating model JSON", e);
}
}
}
}
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() == pageSize);
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() == pageSize);
}
}
/**
* @Author sun
* @Description 分别统计网格日/月数据
**/
public void customerGridStats(String customerId) {
Date date = yesterDay();
public void customerGridStats(String customerId, Date date) {
//1:查询各维度表Id,方便使用
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(date);
@ -407,7 +422,7 @@ public class StatsProjectServiceImpl implements StatsProjectService {
//5.1:执行网格日数据统计
try {
log.info("StatsProjectServiceImpl.customerGridStats-开始执行机关日统计方法,方法名:gridDateProjectStats,客户Id:" + customerId);
gridDateProjectStats(customerId, dimId, dimGridList, projectList, processList);
gridDateProjectStats(customerId, dimId, date, dimGridList, projectList, processList);
} catch (Exception e) {
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, "gridDateProjectStats", customerId, dimId.getDateId()), e);
}
@ -431,8 +446,7 @@ public class StatsProjectServiceImpl implements StatsProjectService {
* @Author sun
* @Description 数据-项目-网格日统计
**/
private String gridDateProjectStats(String customerId, DimIdGenerator.DimIdBean dimId, List<DimGridEntity> dimGridList, List<ProjectEntity> projectList, List<ProjectProcessEntity> processList) {
Date date = yesterDay();
private String gridDateProjectStats(String customerId, DimIdGenerator.DimIdBean dimId, Date date, List<DimGridEntity> dimGridList, List<ProjectEntity> projectList, List<ProjectProcessEntity> processList) {
//批量网格日统计新增对象
List<FactGridProjectDailyEntity> gridDateEntityList = new ArrayList<>();
//计算百分比使用,保留小数点后两位

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

@ -13,7 +13,7 @@
AND customer_id = #{customerId}
AND agency_id = #{agencyId}
AND month_id = #{monthId}
ORDER BY created_time DESC,project_total DESC
ORDER BY date_id DESC,project_total DESC
</select>
<delete id="delDateProject">

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

@ -13,7 +13,7 @@
AND customer_id = #{customerId}
AND grid_id = #{gridId}
AND month_id = #{monthId}
ORDER BY created_time DESC,project_total DESC
ORDER BY date_id DESC,project_total DESC
</select>
<delete id="delDateProject">

Loading…
Cancel
Save