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 0cfcdcc2a7..aff436ff3d 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 @@ -15,4 +15,6 @@ public interface IndexCalConstant { String CUSTOMER_ID="CUSTOMER_ID"; String MONTH_ID="MONTH_ID"; + + String USER_ID="USER_ID"; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexcoll/FactIndexPartyAblityCpcMonthlyDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexcoll/FactIndexPartyAblityCpcMonthlyDao.java index f9c0ad1af2..cdecd48f51 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexcoll/FactIndexPartyAblityCpcMonthlyDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexcoll/FactIndexPartyAblityCpcMonthlyDao.java @@ -23,7 +23,6 @@ import com.epmet.entity.indexcoll.FactIndexPartyAblityCpcMonthlyEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -70,7 +69,7 @@ public interface FactIndexPartyAblityCpcMonthlyDao extends BaseDao list, @Param("customerId") String customerId); - Map getCountByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId); + List> getCountByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize); - Map getExtremeValue(@Param("customerId") String customerId); + Map getExtremeValue(@Param("customerId") String customerId); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java index 0367e90137..c427a81eb9 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java @@ -1,6 +1,7 @@ package com.epmet.service.indexcal.impl; -import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.constant.IndexCalConstant; import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao; import com.epmet.dao.screen.IndexCodeFieldReDao; import com.epmet.dto.indexcal.CalculateCommonFormDTO; @@ -9,14 +10,24 @@ import com.epmet.eum.IndexCodeEnum; import com.epmet.service.indexcal.CpcIndexCalculateService; import com.epmet.service.indexcal.IndexCodeFieldReService; import com.epmet.service.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.*; 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.transaction.annotation.Transactional; 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; @Slf4j @Service @@ -29,35 +40,144 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { private IndexGroupDetailService getDetailListByParentCode; @Autowired private IndexCodeFieldReService indexCodeFieldReService; + @Override public Boolean cpcIndexCalculate(CalculateCommonFormDTO formDTO) { - //计算最大最小值 - Map minAndMaxList = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId()); - if (CollectionUtils.isEmpty(minAndMaxList)){ - log.warn("cpcIndexCalculate customerId:{} have not any fact record",formDTO.getCustomerId()); - return false; - } - //获取指标权重信息 - List indexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(),IndexCodeEnum.CAN_YU_YI_SHI.getCode()); - if (CollectionUtils.isEmpty(indexDetails)){ - log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail",formDTO.getCustomerId()); + + //获取指标权重信息 -参与议事 + List indexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.CAN_YU_YI_SHI.getCode()); + if (CollectionUtils.isEmpty(indexDetails)) { + log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); return false; } + + canyuyishi(formDTO, indexDetails); + + + //log.info(JSON.toJSONString(minAndMaxList)); + return null; + } + + private void canyuyishi(CalculateCommonFormDTO formDTO, List indexDetails) { Map indexCodeFieldReList = indexCodeFieldReService.getIndexCodeFieldReMap(); - if (CollectionUtils.isEmpty(indexCodeFieldReList)){ - log.warn("cpcIndexCalculate have any indexcodefieldre"); - return false; + if (CollectionUtils.isEmpty(indexCodeFieldReList)) { + log.error("cpcIndexCalculate have any indexcodefieldre"); + return; } - String indexCode = null; - String fieldName = null; - for (IndexGroupDetailEntity indexDetail : indexDetails) { - indexCode = indexDetail.getIndexCode(); - fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode); - + //计算最大最小值 + Map minAndMaxMap = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId()); + if (CollectionUtils.isEmpty(minAndMaxMap)) { + log.warn("cpcIndexCalculate getExtremeValue customerId:{} have not any fact record", formDTO.getCustomerId()); + return; } + //指标集合 + Map> indexMap = getIndexInputVO(indexDetails, minAndMaxMap); + List> list = null; + int pageNo = 1; + int pageSize = 10; + do { + String fieldName = null; + list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); + if (!CollectionUtils.isEmpty(list)) { + //遍历指标 进行计算 + for (Map.Entry> entry : indexMap.entrySet()) { + String indexCode = entry.getKey(); + IndexInputVO value = entry.getValue(); + fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode); + if (StringUtils.isBlank(fieldName)) { + log.error("cpcIndexCalculate fieldName error"); + continue; + } + for (Map cpcIndex : list) { + //对应的数值 + String sampleValueStr = String.valueOf(cpcIndex.get(indexCodeFieldReService.getFieldNameByIndexCode(fieldName))); + //构造样本值对象 + SampleValue currentGridIndexValue = new SampleValue((String) cpcIndex.get(IndexCalConstant.USER_ID), new BigDecimal(sampleValueStr)); + value.getIndexValueVOs().add(currentGridIndexValue); + } - log.info(JSON.toJSONString(minAndMaxList)); - Map list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId()); - return null; + } + } + + List result = calculate(indexMap); + // TODO 处理结果 + saveGridCorreLationDangJian(formDTO, indexDetails, result); + + try { + for (IndexOutputVO m : result) { + log.info("indexId=" + m.getIndexId()); + for (SampleScore sampleScore : m.getIndexScoreVOs()) { + log.info(String.format("网格id:%s,得分:%s", sampleScore.getSampleId(), sampleScore.getSampleScore())); + } + } + } catch (Exception e) { + } + + } while (!CollectionUtils.isEmpty(list) && pageNo++ > 0); + + } + + @Transactional(rollbackFor = Exception.class) + public void saveGridCorreLationDangJian(CalculateCommonFormDTO formDTO, List indexDetails, List result) { + + } + + /** + * @param indexMap + * @return java.util.List + * @author yinzuomei + * @description + * @Date 2020/8/30 21:40 + **/ + private List calculate(Map> indexMap) { + //构造入参 + List indexInputVOS = indexMap.values().stream().collect(Collectors.toList()); + BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); + return batchScoreCalculator.getScoreDetailOfIndexId(indexInputVOS); + } + + /** + * @param indexList 指标集合 + * @param minAndMaxMap 最大值最小值集合 + * @return java.util.Map + * @author yinzuomei + * @description + * @Date 2020/8/30 15:56 + **/ + private Map> getIndexInputVO(List indexList, Map minAndMaxMap) { + Map> map = new HashMap<>(); + for (int indexNum = 0; indexNum < indexList.size(); indexNum++) { + IndexGroupDetailEntity index = indexList.get(indexNum); + IndexInputVO indexInputVO = new IndexInputVO(); + // 指标code + indexInputVO.setIndexId(index.getIndexCode()); + //权重 + indexInputVO.setWeight(index.getWeight()); + BigDecimal minValue = null; + BigDecimal maxValue = null; + + //获取指标对应的列名 + String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(index.getIndexCode()); + //最小值key + String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN); + //最大值key + String maxValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MAX); + minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey))); + maxValue = new BigDecimal(String.valueOf(minAndMaxMap.get(maxValueKey))); + + //分值计算器 + ScoreCalculator scoreCalculator = new BigDecimalScoreCalculator(minValue, + maxValue, + ScoreConstants.MIN_SCORE, + ScoreConstants.MAX_SCORE, + Correlation.getCorrelation(index.getCorrelation()) + ); + indexInputVO.setScoreCalculator(scoreCalculator); + List> sampleValueList = new ArrayList<>(); + indexInputVO.setIndexValueVOs(sampleValueList); + + map.put(index.getIndexCode(), indexInputVO); + } + return map; } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java index 4163ea074c..fa6c520c96 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java @@ -58,7 +58,7 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { CalculateCommonFormDTO calculateCommonFormDTO=new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); //计算党员 try { - Map list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId()); + Map list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); } catch (Exception e) { } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml index 41946192dd..beb5b42a4e 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml @@ -3,33 +3,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - delete from fact_index_party_ablity_cpc_monthly where CUSTOMER_ID = #{customerId} AND AGENCY_ID = #{agencyId} AND GRID_ID = #{gridId} AND USER_ID = #{userId} @@ -94,27 +67,7 @@ - + + + +