diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java index 978181b3a4..003813df2b 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java @@ -1,9 +1,10 @@ package com.epmet.controller; +import com.epmet.commons.extappauth.annotation.ExternalAppRequestAuth; +import com.epmet.commons.extappauth.bean.ExternalAppRequestParam; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.indexcal.CalculateCommonFormDTO; -import com.epmet.dto.screen.form.IndexCalculateForm; import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService; import com.epmet.service.evaluationindex.indexcal.IndexCalculateService; import com.epmet.util.DimIdGenerator; @@ -40,10 +41,21 @@ public class IndexCalculateController { * @Author zhangyong * @Date 10:52 2020-08-20 **/ + @ExternalAppRequestAuth @PostMapping("all") - public Result indexCalculate(@RequestBody IndexCalculateForm formDTO) { + public Result indexCalculate(ExternalAppRequestParam externalAppRequestParam, @RequestBody CalculateCommonFormDTO formDTO) { + formDTO.setCustomerId(externalAppRequestParam.getCustomerId()); + Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); + if (aBoolean) { + return new Result().ok(true); + } + return new Result().error("指标计算失败"); + } + + @PostMapping("reAll") + public Result calculateAll(@RequestBody CalculateCommonFormDTO formDTO) { Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); - if (aBoolean){ + if (aBoolean) { return new Result().ok(true); } return new Result().error("指标计算失败"); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java index a1ab0ad1bf..7866473d6f 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java @@ -1,6 +1,6 @@ package com.epmet.service.evaluationindex.indexcal; -import com.epmet.dto.screen.form.IndexCalculateForm; +import com.epmet.dto.indexcal.CalculateCommonFormDTO; /** * 指标计算service @@ -11,8 +11,9 @@ import com.epmet.dto.screen.form.IndexCalculateForm; public interface IndexCalculateService { /** * desc:按照客户计算所有指标(按照月份) + * * @param formDTO * @return */ - Boolean indexCalculate(IndexCalculateForm formDTO); + Boolean indexCalculate(CalculateCommonFormDTO formDTO); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java index 9385c1f121..5ab74faadf 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java @@ -2,21 +2,22 @@ package com.epmet.service.evaluationindex.indexcal.impl; import com.alibaba.fastjson.JSON; import com.epmet.commons.dynamic.datasource.annotation.DataSource; +import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.DataSourceConstant; import com.epmet.dto.indexcal.CalculateCommonFormDTO; -import com.epmet.dto.screen.form.IndexCalculateForm; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.redis.IndexCodeFieldReRedis; import com.epmet.service.evaluationindex.indexcal.*; +import com.epmet.service.evaluationindex.indexcoll.FactIndexCollectService; import com.epmet.util.DimIdGenerator; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; 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; @@ -44,78 +45,98 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { private IndexCalculateDistrictService indexCalculateDistrictService; @Autowired private DeptScoreService deptScoreService; + @Autowired + private FactIndexCollectService factIndexCollectService; + @Override - public Boolean indexCalculate(IndexCalculateForm formDTO) { + public Boolean indexCalculate(CalculateCommonFormDTO formDTO) { try { if (StringUtils.isBlank(formDTO.getMonthId())) { //默认 当前月份-1 formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); } //按照客户分组 - if (CollectionUtils.isEmpty(formDTO.getCustomerIds())) { + List customerIds = new ArrayList<>(); + if (StringUtils.isBlank(formDTO.getCustomerId())) { Result> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); if (!externalCustomerIdsResult.success()) { log.error("indexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); return false; } - formDTO.setCustomerIds(externalCustomerIdsResult.getData()); + customerIds = externalCustomerIdsResult.getData(); + } else { + customerIds.add(formDTO.getCustomerId()); } Boolean flag = false; - for (String customerId : formDTO.getCustomerIds()) { + for (String customerId : customerIds) { CalculateCommonFormDTO calculateCommonFormDTO = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); - //计算党员相关的 try { - CalculateCommonFormDTO param = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); - flag = cpcIndexCalculateService.cpcIndexCalculate(param); - log.info("indexCalculate cpcIndexCalculate return result:{}", flag); - } catch (Exception e) { - log.error("indexCalculate cpcIndexCalculate exception", e); - break; - } + //计算党员相关的 + try { + CalculateCommonFormDTO param = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); + flag = cpcIndexCalculateService.cpcIndexCalculate(param); + log.info("indexCalculate cpcIndexCalculate return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate cpcIndexCalculate exception", e); + throw new RenException("indexCalculate cpcIndexCalculate exception", e); + } - //计算网格 - try { - flag = gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO); - log.info("indexCalculate calculateGridCorreLation return result:{}", flag); - } catch (Exception e) { - log.error("indexCalculate calculateGridCorreLation exception", e); - break; - } - //计算社区 - try { - indexCalculateCommunityService.calCommunityAll(customerId, formDTO.getMonthId()); - log.info("indexCalculate calAll return result:{}", flag); - } catch (Exception e) { - log.error("indexCalculate calAll exception", e); - break; - } + //计算网格 + try { + flag = gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO); + log.info("indexCalculate calculateGridCorreLation return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate calculateGridCorreLation exception", e); + throw new RenException("indexCalculate calculateGridCorreLation exception", e); + } + //计算社区 + try { + flag = indexCalculateCommunityService.calCommunityAll(customerId, formDTO.getMonthId()); + log.info("indexCalculate calCommunityAll return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate calCommunityAll exception", e); + throw new RenException("indexCalculate calAll exception", e); + } - //计算街道 - try { - indexCalculateStreetService.calStreetAll(customerId,formDTO.getMonthId()); - log.info("indexCalculate calAll return result:{}", flag); - } catch (Exception e) { - log.error("indexCalculate calAll exception", e); - break; - } + //计算街道 + try { + flag = indexCalculateStreetService.calStreetAll(customerId, formDTO.getMonthId()); + log.info("indexCalculate calStreetAll return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate calStreetAll exception", e); + throw new RenException("indexCalculate calStreetAll exception", e); + } - //计算区直属 - try { - deptScoreService.calculateDeptCorreLation(calculateCommonFormDTO); - log.info("indexCalculate calAll return result:{}", flag); - } catch (Exception e) { - log.error("indexCalculate calAll exception", e); - break; + //计算区直属 + try { + flag = deptScoreService.calculateDeptCorreLation(calculateCommonFormDTO); + log.info("indexCalculate calculateDeptCorreLation return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate calculateDeptCorreLation exception", e); + throw new RenException("indexCalculate calculateDeptCorreLation exception", e); + } + + //计算全区 + try { + indexCalculateDistrictService.calDistrictAll(customerId, formDTO.getMonthId()); + log.info("indexCalculate calDistrictAll return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate calDistrictAll exception", e); + throw new RenException("indexCalculate calDistrictAll exception", e); + } + } catch (RenException e) { + flag = false; } - //计算全区 - try { - indexCalculateDistrictService.calDistrictAll(customerId,formDTO.getMonthId()); - log.info("indexCalculate calAll return result:{}", flag); - } catch (Exception e) { - log.error("indexCalculate calAll exception", e); - break; + //计算完毕后 将结果插入大屏相关数据表 + if (flag) { + try { + factIndexCollectService.insertScreenIndexDataMonthlyAndYearly(formDTO.getMonthId(), formDTO.getCustomerId()); + } catch (Exception e) { + log.error("indexCalculate insertScreenIndexDataMonthlyAndYearly exception", e); + flag = false; + } } } return flag;