From 9fbb8136e44552e5ce2205757cce444036f5f13d Mon Sep 17 00:00:00 2001 From: jianjun Date: Thu, 3 Sep 2020 22:15:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=9A=E5=91=98=E7=9B=B8=E5=85=B3=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=8F=AA=E6=9C=89=E4=B8=80=E6=9D=A1=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=88=99=E7=BB=9950=E5=88=86=EF=BC=9B=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=AF=BC=E5=85=A5=E6=8C=87=E6=A0=87=E7=9A=84=E6=AD=A3?= =?UTF-8?q?=E8=B4=9F=E7=9B=B8=E5=85=B3=E5=8F=8A=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/model/IndexExcelDataListener.java | 28 +++++-- .../main/java/com/epmet/model/IndexModel.java | 1 + .../impl/CpcIndexCalculateServiceImpl.java | 77 +++++++++++++++---- .../evaluationindex/indexcal/CpcScoreDao.xml | 18 +++-- 4 files changed, 91 insertions(+), 33 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java index eef2856684..3fec1a9132 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java @@ -11,6 +11,7 @@ import com.epmet.entity.evaluationindex.screen.IndexGroupTemplateEntity; import com.epmet.service.evaluationindex.screen.IndexDictService; import com.epmet.service.evaluationindex.screen.IndexGroupDetailTemplateService; import com.epmet.service.evaluationindex.screen.IndexGroupTemplateService; +import com.epmet.support.normalizing.Correlation; import com.epmet.util.Pinyin4jUtil; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -29,7 +30,6 @@ import java.util.stream.Collectors; */ public class IndexExcelDataListener extends AnalysisEventListener { private static final Logger LOGGER = LoggerFactory.getLogger(IndexExcelDataListener.class); - private String POSITIVE = "positive"; /** * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 */ @@ -86,8 +86,23 @@ public class IndexExcelDataListener extends AnalysisEventListener { data.setWeight(preWheight); } LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); - //TODO 默认正相关 - data.setCorrelation(POSITIVE); + if (StringUtils.isNotBlank(data.getThreshold())) { + String threshold = data.getThreshold(); + if ("无".equals(data.getThreshold())) { + threshold = "-1"; + } else if (data.getThreshold().contains("%")) { + String thresholdStr = data.getThreshold().replace("%", ""); + threshold = new BigDecimal(thresholdStr).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP).toString(); + } + data.setThreshold(threshold); + } + if (StringUtils.isNotBlank(data.getCorrelation())) { + if (Correlation.NEGATIVE.getDesc().equals(data.getCorrelation())) { + data.setCorrelation(Correlation.NEGATIVE.getCode()); + } else { + data.setCorrelation(Correlation.POSITIVE.getCode()); + } + } IndexDictEntity entity = new IndexDictEntity(); IndexDictEntity entity2 = new IndexDictEntity(); @@ -240,11 +255,8 @@ public class IndexExcelDataListener extends AnalysisEventListener { templateEntity.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), false, 4)); templateEntity.setWeight(new BigDecimal(index.getWeight()).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP)); } - - if (StringUtils.isNotBlank(index.getThreshold())) { - String thresholdStr = index.getThreshold().replace("%", ""); - templateEntity.setThreshold(new BigDecimal(thresholdStr).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP)); - } + templateEntity.setThreshold(new BigDecimal(index.getThreshold())); + templateEntity.setCorrelation(index.getCorrelation()); } private void buildIndexDicEntity(IndexModel data, IndexDictEntity entity, IndexDictEntity entity2, IndexDictEntity entity3, IndexDictEntity entity4, IndexDictEntity entity5) { diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java index 5ff0b19267..77a0fd3138 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java @@ -21,6 +21,7 @@ public class IndexModel { private String weight; @ExcelProperty(value = "五级权重") private String level5Weight; + //没有阈值:无,有就是百分数 @ExcelProperty(value = "阈值") private String threshold; /** diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java index 7876c2158e..52cb4e3fc6 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java @@ -10,9 +10,9 @@ import com.epmet.constant.DataSourceConstant; import com.epmet.constant.IndexCalConstant; import com.epmet.dao.evaluationindex.indexcal.CpcScoreDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityCpcMonthlyDao; -import com.epmet.dao.evaluationindex.screen.IndexCodeFieldReDao; import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity; +import com.epmet.entity.evaluationindex.indexcoll.FactIndexPartyAblityCpcMonthlyEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.eum.IndexCodeEnum; import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService; @@ -43,8 +43,6 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { @Autowired private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao; @Autowired - private IndexCodeFieldReDao indexCodeFieldReDao; - @Autowired private IndexGroupDetailService getDetailListByParentCode; @Autowired private IndexCodeFieldReService indexCodeFieldReService; @@ -97,11 +95,43 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { totalEntity.setScore(totalEntity.getScore().add(total)); } }); - deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(),cpcScoreTotalMap.values().stream().collect(Collectors.toList())); + deleteAndInsertBatch(formDTO, cpcScoreTotalMap.values().stream().collect(Collectors.toList()), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); + } + + /** + * @param formDTO + * @param indexCode + * @param stringObjectMap + * @return void + * @author yinzuomei + * @description 只有一条事实记录时,分值默认赋50 + * @Date 2020/9/2 14:35 + **/ + private CpcScoreEntity handleOneGridScene(CalculateCommonFormDTO formDTO, String indexCode, Map stringObjectMap) { + FactIndexPartyAblityCpcMonthlyEntity factCpc = JSON.parseObject(JSON.toJSONString(stringObjectMap), FactIndexPartyAblityCpcMonthlyEntity.class); + // 保存中间表 + CpcScoreEntity cpcScoreEntity = new CpcScoreEntity(); + cpcScoreEntity.setCustomerId(factCpc.getCustomerId()); + cpcScoreEntity.setAgencyId(factCpc.getAgencyId()); + cpcScoreEntity.setGridId(factCpc.getGridId()); + cpcScoreEntity.setYearId(factCpc.getYearId()); + cpcScoreEntity.setMonthId(factCpc.getMonthId()); + cpcScoreEntity.setUserId(factCpc.getUserId()); + cpcScoreEntity.setScore(new BigDecimal(NumConstant.FIFTY_STR)); + cpcScoreEntity.setIndexCode(indexCode); + cpcScoreEntity.setIsTotal(NumConstant.ZERO_STR); + return cpcScoreEntity; } - private void deleteAndInsertBatch(String customerId, String monthId, String indexCode, Collection values) { - cpcScoreDao.deleteByMonthId(customerId, monthId, indexCode); + /** + * desc:根据客户id和月份Id 指标code 非必填 删除数据 + * + * @param formDTO + * @param indexCode 指标code 非必填 + * @param values + */ + private void deleteAndInsertBatch(CalculateCommonFormDTO formDTO, Collection values, String indexCode) { + cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode); cpcScoreDao.insertBatch(values); } @@ -119,20 +149,33 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { return; } - int pageNo = 1; - int pageSize = 10; + int pageNo = NumConstant.ONE; + int pageSize = NumConstant.ONE_THOUSAND; //分页查询 要计算的原始数据 List> list = null; do { list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); if (!CollectionUtils.isEmpty(list)) { - //遍历指标分组 计算分数 - List> finalList = list; - groupIndexDetailsMap.forEach((parentIndexCode, details) -> { - calculateScore(formDTO, details, finalList, minAndMaxMap, parentIndexCode); - }); + //如果是第一页且仅有一条数据 则直接给50分 + if (pageNo == NumConstant.ONE && list.size() == NumConstant.ONE) { + List insertList = new ArrayList<>(); + for (String parentIndexCode : groupIndexDetailsMap.keySet()) { + insertList.add(handleOneGridScene(formDTO, parentIndexCode, list.get(0))); + } + if (CollectionUtils.isEmpty(insertList)) { + deleteAndInsertBatch(formDTO, insertList, null); + } + } else { + //遍历指标分组 计算分数 + for (Map.Entry> entry : groupIndexDetailsMap.entrySet()) { + String parentIndexCode = entry.getKey(); + List details = entry.getValue(); + calculateScore(formDTO, details, list, minAndMaxMap, parentIndexCode); + } + } } - } while (!CollectionUtils.isEmpty(list) && pageNo++ > 0); + pageNo++; + } while (!CollectionUtils.isEmpty(list) && list.size() == pageSize); } /** @@ -185,7 +228,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { log.info("计算的结果:{}", result); //处理结果 - if (CollectionUtils.isEmpty(result)){ + if (CollectionUtils.isEmpty(result)) { log.error("calculateScore calculateScore return empty"); return; } @@ -209,7 +252,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { cpcScoreEntity.setScore(score); list.add(cpcScoreEntity); }); - this.deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),parentIndexCode,list); + this.deleteAndInsertBatch(formDTO, list, parentIndexCode); } @@ -242,7 +285,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey))); //如果最大值超过阈值 则最大值为阈值 if (new BigDecimal(NumConstant.ONE_NEG).compareTo(index.getThreshold()) != NumConstant.ZERO - && maxValue.compareTo(new BigDecimal(NumConstant.ONE_NEG)) == NumConstant.ONE){ + && maxValue.compareTo(new BigDecimal(NumConstant.ONE_NEG)) == NumConstant.ONE) { maxValue = index.getThreshold(); } //分值计算器 diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcScoreDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcScoreDao.xml index 3f38b0dbbc..3c6fb2ea55 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcScoreDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcScoreDao.xml @@ -3,6 +3,16 @@ + + delete from fact_index_cpc_score + where + CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} + and MONTH_ID = #{monthId,jdbcType=VARCHAR} + + and INDEX_CODE = #{indexCode,jdbcType=VARCHAR} + + + @@ -18,14 +28,6 @@ - - delete from fact_index_cpc_score - where - CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} - and MONTH_ID = #{monthId,jdbcType=VARCHAR} - and INDEX_CODE = #{indexCode,jdbcType=VARCHAR} - -