From 00324ad1c760545e702120b5cc170539fde9a423 Mon Sep 17 00:00:00 2001 From: jianjun Date: Mon, 31 Aug 2020 13:33:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/dao/screen/IndexGroupDetailDao.java | 2 + .../impl/CpcIndexCalculateServiceImpl.java | 79 ++++++++++--------- .../screen/IndexGroupDetailService.java | 8 ++ .../impl/IndexCalculateServiceImpl.java | 4 +- .../impl/IndexGroupDetailServiceImpl.java | 5 ++ .../mapper/screen/IndexGroupDetailDao.xml | 9 +++ 6 files changed, 66 insertions(+), 41 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java index 8c7a4e82fb..8982bc5f29 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java @@ -34,4 +34,6 @@ import java.util.List; public interface IndexGroupDetailDao extends BaseDao { List getDetailListByParentCode(@Param("customerId") String customerId, @Param("indexCode") String indexCode); + + List getDetailListLikeParentCode(@Param("customerId") String customerId, @Param("parentIndexCode") String parentIndexCode); } \ No newline at end of file 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 c427a81eb9..521c9dd631 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,5 +1,6 @@ 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; @@ -14,7 +15,9 @@ 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 com.epmet.support.normalizing.batch.BatchScoreCalculator; +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; @@ -45,7 +48,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { public Boolean cpcIndexCalculate(CalculateCommonFormDTO formDTO) { //获取指标权重信息 -参与议事 - List indexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.CAN_YU_YI_SHI.getCode()); + List indexDetails = getDetailListByParentCode.getDetailListLikeParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); if (CollectionUtils.isEmpty(indexDetails)) { log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); return false; @@ -53,7 +56,6 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { canyuyishi(formDTO, indexDetails); - //log.info(JSON.toJSONString(minAndMaxList)); return null; } @@ -71,54 +73,55 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { return; } //指标集合 - Map> indexMap = getIndexInputVO(indexDetails, minAndMaxMap); + //对指标进行分组 + Map> groupIndexDetailsMap = indexDetails.stream().collect(Collectors.groupingBy(IndexGroupDetailEntity::getAllParentIndexCode)); + + + 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); - } - - } - } - List result = calculate(indexMap); - // TODO 处理结果 - saveGridCorreLationDangJian(formDTO, indexDetails, result); + //遍历指标分组 计算分数 + List> finalList = list; + groupIndexDetailsMap.forEach((parentIndex, indexDetailList)->{ + Map> indexMap = getIndexInputVO(indexDetailList, minAndMaxMap); + //遍历指标 进行计算 + for (Map.Entry> entry : indexMap.entrySet()) { + String indexCode = entry.getKey(); + IndexInputVO value = entry.getValue(); + String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode); + if (StringUtils.isBlank(fieldName)) { + log.error("cpcIndexCalculate fieldName error"); + continue; + } + for (Map cpcIndex : finalList) { + //对应的数值 + 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); + } + } + HashMap 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())); + try { + System.out.println( JSON.toJSONString(result)); + } catch (Exception e) { } - } - } catch (Exception e) { + }); } - } while (!CollectionUtils.isEmpty(list) && pageNo++ > 0); } @Transactional(rollbackFor = Exception.class) - public void saveGridCorreLationDangJian(CalculateCommonFormDTO formDTO, List indexDetails, List result) { + public void saveGridCorreLationDangJian(CalculateCommonFormDTO formDTO, List indexDetails, HashMap result) { } @@ -129,11 +132,11 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { * @description * @Date 2020/8/30 21:40 **/ - private List calculate(Map> indexMap) { + private HashMap calculate(Map> indexMap) { //构造入参 List indexInputVOS = indexMap.values().stream().collect(Collectors.toList()); BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); - return batchScoreCalculator.getScoreDetailOfIndexId(indexInputVOS); + return batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); } /** diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java index aa69cba8e7..888b36725d 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java @@ -35,4 +35,12 @@ public interface IndexGroupDetailService extends BaseService getDetailListByParentCode(String customerId,String... indexCode); + + /** + * desc:获取所有 包含该指标code的 + * @param customerId + * @param parentIndexCode + * @return + */ + List getDetailListLikeParentCode(String customerId, String parentIndexCode); } \ No newline at end of file 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 fa6c520c96..611ad18f4e 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 @@ -17,10 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; -import java.math.BigDecimal; import java.util.Date; import java.util.List; -import java.util.Map; /** * @author liujianjun @@ -58,7 +56,7 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { CalculateCommonFormDTO calculateCommonFormDTO=new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); //计算党员 try { - Map list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); + //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/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java index 0225c956c5..1135b023c8 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java @@ -48,4 +48,9 @@ public class IndexGroupDetailServiceImpl extends BaseServiceImpl getDetailListLikeParentCode(String customerId, String parentIndexCode) { + return baseDao.getDetailListLikeParentCode(customerId,parentIndexCode); + } } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml index 6038ecbfeb..bb4e5636ae 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml @@ -12,4 +12,13 @@ CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and STATUS = 'enable' and DEL_FLAG = '0' and ALL_PARENT_INDEX_CODE = #{indexCode,jdbcType=VARCHAR} + + \ No newline at end of file