From 6b2730e4aa5fda6edfb5ada0289c1effc241e7e1 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Thu, 3 Sep 2020 16:00:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E7=9B=B4=E9=83=A8=E9=97=A8=E6=9A=82?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/constant/IndexCalConstant.java | 2 + .../com/epmet/controller/DemoController.java | 4 + .../FactIndexGovrnAblityDeptMonthlyDao.java | 35 +++++ .../indexcal/impl/DeptScoreServiceImpl.java | 146 +++++++++++++++++- .../FactIndexGovrnAblityDeptMonthlyDao.xml | 61 ++++++++ 5 files changed, 244 insertions(+), 4 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java index a2064455a4..b232ea7635 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java @@ -12,6 +12,8 @@ public interface IndexCalConstant { String GRID_ID="GRID_ID"; + String DEPT_ID="DEPT_ID"; + String AGENCY_ID="AGENCY_ID"; String PARENT_AGENCY_ID = "parentAgencyId"; diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java index 58d08b8120..380b2f3b86 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java @@ -17,6 +17,7 @@ import com.epmet.entity.evaluationindex.indexcoll.FactIndexServiceAblityGridMont import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity; import com.epmet.entity.stats.DimAgencyEntity; import com.epmet.service.StatsDemoService; +import com.epmet.service.evaluationindex.indexcal.DeptScoreService; import com.epmet.service.evaluationindex.indexcal.GridCorreLationService; import com.epmet.service.evaluationindex.indexcal.IndexCalculateCommunityService; import com.epmet.service.evaluationindex.indexcal.IndexCalculateStreetService; @@ -53,6 +54,8 @@ public class DemoController { private GridCorreLationService gridCorreLationService; @Autowired private IndexCalculateStreetService indexCalculateStreetService; + @Autowired + private DeptScoreService deptScoreService; @GetMapping("testAlarm") public void testAlarm() { @@ -162,6 +165,7 @@ public class DemoController { // List gridScoreDTOList=gridScoreDao.selectList(formDTO); // return new Result>().ok(gridScoreDTOList); gridCorreLationService.calculateGridCorreLation(formDTO); +// deptScoreService.calculateDeptCorreLation(formDTO); return new Result(); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.java index 5db8adb014..20abf945b7 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.java @@ -17,12 +17,14 @@ package com.epmet.dao.evaluationindex.indexcoll; /** import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.indexcollect.form.DeptGovrnAbilityFormDTO; import com.epmet.entity.evaluationindex.indexcoll.FactIndexGovrnAblityDeptMonthlyEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Map; /** * 治理能力-部门相关数据 @@ -63,4 +65,37 @@ public interface FactIndexGovrnAblityDeptMonthlyDao extends BaseDao list, @Param("customerId")String customerId); + + /** + * @return java.lang.Integer + * @param calculateCommonFormDTO + * @author yinzuomei + * @description 查询(fact_index_govrn_ablity_dept_monthly治理能力-区直部门相关数据 )当前月共上传了多少条记录 + * @Date 2020/9/3 9:31 + **/ + Integer selectCount(CalculateCommonFormDTO calculateCommonFormDTO); + + /** + * @return java.util.Map + * @param calculateCommonFormDTO + * @author yinzuomei + * @description 计算最大最小值 + * @Date 2020/9/3 9:36 + **/ + Map selectExtremeValue(CalculateCommonFormDTO calculateCommonFormDTO); + + /** + * @return java.util.List> + * @param customerId 客户id + * @param monthId yyyyMM + * @param offset + * @param pageSize + * @author yinzuomei + * @description + * @Date 2020/9/3 11:00 + **/ + List> selectListByMonthId(@Param("customerId") String customerId, + @Param("monthId") String monthId, + @Param("offset") Integer offset, + @Param("pageSize") Integer pageSize); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java index d999757956..20360baa29 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java @@ -19,7 +19,10 @@ package com.epmet.service.evaluationindex.indexcal.impl; import com.alibaba.fastjson.JSON; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.RenException; +import com.epmet.constant.IndexCalConstant; import com.epmet.dao.evaluationindex.indexcal.DeptScoreDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityDeptMonthlyDao; import com.epmet.dto.indexcal.CalculateCommonFormDTO; @@ -27,13 +30,26 @@ import com.epmet.entity.evaluationindex.indexcal.DeptScoreEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.eum.IndexCodeEnum; import com.epmet.service.evaluationindex.indexcal.DeptScoreService; +import com.epmet.service.evaluationindex.indexcal.IndexCodeFieldReService; import com.epmet.service.evaluationindex.screen.IndexGroupDetailService; +import com.epmet.support.normalizing.BigDecimalScoreCalculator; +import com.epmet.support.normalizing.Correlation; +import com.epmet.support.normalizing.ScoreCalculator; +import com.epmet.support.normalizing.ScoreConstants; +import com.epmet.support.normalizing.batch.IndexInputVO; +import com.epmet.support.normalizing.batch.SampleValue; 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.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** @@ -49,6 +65,8 @@ public class DeptScoreServiceImpl extends BaseServiceImpl parentIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), + List indexGroupDetailEntityList = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.QU_ZHI_BU_MEN.getCode(), IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); - if (CollectionUtils.isEmpty(parentIndexDetails)) { + if (CollectionUtils.isEmpty(indexGroupDetailEntityList)) { log.warn("calculateDeptCorreLation customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); throw new RenException("客户【区直部门:治理能力】指标权重信息不存在"); } - log.info(JSON.toJSONString(parentIndexDetails)); - return null; + log.info(JSON.toJSONString(indexGroupDetailEntityList)); + + //1、查询总记录数 + int total = factIndexGovrnAblityDeptMonthlyDao.selectCount(formDTO); + if (NumConstant.ZERO == total) { + log.warn(String.format("customerId=%s,monthId=%s,fact_index_govrn_ablity_dept_monthly have not any fact record", formDTO.getCustomerId(), formDTO.getMonthId())); + return Boolean.FALSE; + } else if (NumConstant.ONE == total) { + //只有一个网格时 + log.warn(String.format("customerId:%s,monthId:%s,only one fact_index_party_ablity_grid_monthly record", formDTO.getCustomerId(), formDTO.getMonthId())); + this.handleOneGridScene(formDTO); + return Boolean.TRUE; + } + + //2、计算最大最小值 + Map minAndMaxMap = factIndexGovrnAblityDeptMonthlyDao.selectExtremeValue(formDTO); + if (CollectionUtils.isEmpty(minAndMaxMap)) { + log.warn("calculateDeptCorreLation getExtremeValue customerId:{} fact_index_govrn_ablity_dept_monthly have not any fact record", formDTO.getCustomerId()); + throw new RenException("【区直部门:治理能力】指标原始数据记录不存在"); + } + //3、构造入参 指标集合 + Map> indexMap = buildDeptCorrelationIndexInputVO(indexGroupDetailEntityList, minAndMaxMap); + //4、分批计算 + int pageNo = NumConstant.ONE; + int pageSize = IndexCalConstant.PAGE_SIZE; + //分页查询 要计算的原始数据 + List> list = null; + do { + list = factIndexGovrnAblityDeptMonthlyDao.selectListByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); + if (!CollectionUtils.isEmpty(list)) { + //遍历指标分组 计算分数 + List> crrentFactRecordList = list; + calculateScore(formDTO,indexMap,crrentFactRecordList); + } + } while (!CollectionUtils.isEmpty(list) && pageNo++ > 0); + return true; + } + + /** + * @return void + * @param formDTO + * @param indexMap + * @author yinzuomei + * @description 计算分值并保存结果 + * @Date 2020/9/3 11:14 + **/ + private void calculateScore(CalculateCommonFormDTO formDTO, Map> indexMap,List> recordList) { + //遍历每一个网格的记录 + recordList.forEach(recordMap -> { + //遍历所有的指标 + indexMap.forEach((key, indexInputVO) -> { + if (StringUtils.isNotBlank(indexCodeFieldReService.getFieldNameByIndexCode(key))) { + //对应的数值 + String sampleValueStr = (String) recordMap.get(indexCodeFieldReService.getFieldNameByIndexCode(key)); + //构造样本值对象 + SampleValue currentGridIndexValue = new SampleValue((String) recordMap.get(IndexCalConstant.DEPT_ID), new BigDecimal(sampleValueStr)); + indexInputVO.getIndexValueVOs().add(currentGridIndexValue); + + } + }); + + + }); + //保存中间表记录 TODO + + } + + /** + * @param formDTO + * @return void + * @author yinzuomei + * @description TODO + * @Date 2020/9/3 9:35 + **/ + private void handleOneGridScene(CalculateCommonFormDTO formDTO) { + + } + + /** + * @param indexList + * @param minAndMaxMap + * @return java.util.Map> + * @author yinzuomei + * @description + * @Date 2020/9/3 9:31 + **/ + private Map> buildDeptCorrelationIndexInputVO(List indexList, + Map minAndMaxMap) { + Map> map = new HashMap<>(); + for (IndexGroupDetailEntity index : indexList) { + //获取指标对应的列名 + String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(index.getIndexCode()); + if (StringUtils.isBlank(fieldName)) { + log.error("index_code:{} not find field_name", index.getIndexCode()); + continue; + } + String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN); + String maxValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MAX); + BigDecimal minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey))); + BigDecimal maxValue = new BigDecimal(String.valueOf(minAndMaxMap.get(maxValueKey))); + //有阈值,且最大值>阈值,则最大值赋值为阈值 + if (new BigDecimal(NumConstant.ONE_NEG_STR).compareTo(index.getThreshold()) != NumConstant.ZERO + && maxValue.compareTo(index.getThreshold()) == NumConstant.ONE) { + maxValue = index.getThreshold(); + } + //分值计算器 + ScoreCalculator scoreCalculator = new BigDecimalScoreCalculator(minValue, + maxValue, + ScoreConstants.MIN_SCORE, + ScoreConstants.MAX_SCORE, + Correlation.getCorrelation(index.getCorrelation()) + ); + List> sampleValueList = new ArrayList<>(); + IndexInputVO indexInputVO1 = new IndexInputVO(index.getIndexCode(), + sampleValueList, + index.getThreshold(), +// new BigDecimal("-1"), //FOR TEST + index.getWeight(), + scoreCalculator); + map.put(index.getIndexCode(), indexInputVO1); + } + return map; } } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.xml index acacf4211e..bf9647c67f 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.xml @@ -79,4 +79,65 @@ + + + + + + + +