From 9e9776e98b0e634ff18dd64b8b7eb51a485a3192 Mon Sep 17 00:00:00 2001 From: wxz Date: Mon, 24 May 2021 10:11:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E6=A0=BC=E7=9B=B8=E5=85=B3=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E8=AE=A1=E7=AE=97=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=B9=B3?= =?UTF-8?q?=E5=9D=87=E5=80=BC=E7=9A=84=E6=A0=B7=E6=9C=AC=E9=87=8F=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../evaluationindex/indexcal/CpcScoreDao.java | 9 +-- .../indexcal/GridSubScoreEntity.java | 5 ++ .../com/epmet/model/AvgOperationResultVO.java | 21 +++++++ .../impl/GridCorreLationServiceImpl.java | 63 ++++++++++++++----- .../V0.0.14__cpc_subscore_add_samplecount.sql | 1 + .../evaluationindex/indexcal/CpcScoreDao.xml | 10 +-- .../indexcal/GridSubScoreDao.xml | 6 +- 7 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/AvgOperationResultVO.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.14__cpc_subscore_add_samplecount.sql diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcScoreDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcScoreDao.java index c1b8e5b479..b4b6fc8869 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcScoreDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcScoreDao.java @@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.indexcal.CpcScoreResultDTO; import com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity; +import com.epmet.model.AvgOperationResultVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -46,9 +47,9 @@ public interface CpcScoreDao extends BaseDao { * @description 获取网格内党员的联系群众能力考评分(平均值) * @Date 2020/8/31 10:56 **/ - BigDecimal selectGridContactMassesAvgValue(@Param("customerId") String customerId, - @Param("monthId") String monthId, - @Param("gridId") String gridId); + AvgOperationResultVO selectGridContactMassesAvgValue(@Param("customerId") String customerId, + @Param("monthId") String monthId, + @Param("gridId") String gridId); /** * @param formDTO @@ -77,7 +78,7 @@ public interface CpcScoreDao extends BaseDao { * @description 组织内党员的参与议事能力考评分(平均值) * @Date 2020/8/31 15:51 **/ - BigDecimal selectGridJoinIssueAvgValue(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("gridId") String gridId); + AvgOperationResultVO selectGridJoinIssueAvgValue(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("gridId") String gridId); int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("indexCode") String indexCode, @Param("deleteSize") Integer deleteSize, @Param("isTotal") String isTotal); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/indexcal/GridSubScoreEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/indexcal/GridSubScoreEntity.java index fa88df4ba7..f6bf4bb903 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/indexcal/GridSubScoreEntity.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/indexcal/GridSubScoreEntity.java @@ -101,4 +101,9 @@ public class GridSubScoreEntity extends BaseEpmetEntity { * 权重(同一组权重总和=1) */ private BigDecimal weight; + + /** + * 样本总量 + */ + private Integer sampleCount; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/AvgOperationResultVO.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/AvgOperationResultVO.java new file mode 100644 index 0000000000..d97ad2e264 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/AvgOperationResultVO.java @@ -0,0 +1,21 @@ +package com.epmet.model; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 平均值运算结果vo + */ +@Data +public class AvgOperationResultVO { + /** + * 样本量 + */ + private Integer sampleCount; + + /** + * 平均值 + */ + private BigDecimal avgValue; +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java index b785d78b4a..e70200f06a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java @@ -26,6 +26,7 @@ import com.epmet.entity.evaluationindex.indexcal.GridSelfSubScoreEntity; import com.epmet.entity.evaluationindex.indexcal.GridSubScoreEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.eum.IndexCodeEnum; +import com.epmet.model.AvgOperationResultVO; import com.epmet.service.evaluationindex.indexcal.GridCorreLationService; import com.epmet.service.evaluationindex.indexcal.IndexCodeFieldReService; import com.epmet.service.evaluationindex.screen.IndexGroupDetailService; @@ -185,6 +186,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { **/ @Transactional(rollbackFor = Exception.class) public void calculateGridDangJian(CalculateCommonFormDTO formDTO) { + // 该客户下的指标列表及权重 List indexList = indexGroupDetailService.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.WANG_GE_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); @@ -192,7 +194,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { log.error("calculateGridDangJian customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); throw new RenException("客户【网格相关:党建能力】指标权重信息不存在"); } - //查询总记录数 + //查询总记录数(该客户下,该月份,每个网格一条,有多少条) int total = factIndexPartyAblityGridMonthlyDao.selectCount(formDTO); if (NumConstant.ZERO == total) { log.warn(String.format("customerId=%s,monthId=%s,没有上传网格相关-党建能力-五级指标数据", formDTO.getCustomerId(), formDTO.getMonthId())); @@ -210,10 +212,12 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { //指标集合 Map> indexMap = buildGridCorrelationIndexInputVO(formDTO, indexList, minAndMaxMap); List> resultMapList = new ArrayList<>(); + // 平均值计算结果,内含平均值,样本总量 + HashMap gridAvgOpeResultMap = new HashMap<>(); //分页查询采集记录 for (int pageNo = 1; pageNo <= totalPage; pageNo++) { int pageIndex = (pageNo - NumConstant.ONE) * IndexCalConstant.PAGE_SIZE; - //前10条 + //前10条。每个网格的党建能力的数据 List> recordList = queryListPartyAblityGrid(new PageQueryGridFormDTO(formDTO.getCustomerId(), formDTO.getMonthId(), pageIndex, @@ -231,8 +235,10 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { // log.info("组织内党员的联系群众能力考评分(平均值) 单独处理"); //网格内党员的联系群众能力考评分(平均值) String gridId = (String) recordMap.get(IndexCalConstant.GRID_ID); - BigDecimal contactMassesAvgValue = getGridContactMassesAvgValue(formDTO, gridId); - SampleValue contactMassesAblityValue = new SampleValue((String) recordMap.get(IndexCalConstant.GRID_ID), contactMassesAvgValue); + String monthId = (String) recordMap.get(IndexCalConstant.MONTH_ID); + AvgOperationResultVO contactMassesAvgVo = getGridContactMassesAvgValue(formDTO, gridId); + gridAvgOpeResultMap.put(gridId.concat(":").concat(monthId), contactMassesAvgVo); + SampleValue contactMassesAblityValue = new SampleValue((String) recordMap.get(IndexCalConstant.GRID_ID), contactMassesAvgVo.getAvgValue()); value.getIndexValueVOs().add(contactMassesAblityValue); }else if (StringUtils.isNotBlank(indexCodeFieldReService.getFieldNameByIndexCode(key))) { //对应的数值 @@ -251,7 +257,11 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { saveGridCorreLationResult(formDTO, resultMapList, IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(), - NumConstant.ZERO_STR); + NumConstant.ZERO_STR, + gridAvgOpeResultMap); + + // 清理map + gridAvgOpeResultMap.clear(); } /** @@ -312,10 +322,11 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { * @description 获取网格(组织)内党员的联系群众能力考评分(平均值) * @Date 2020/8/31 9:50 **/ - private BigDecimal getGridContactMassesAvgValue(CalculateCommonFormDTO calculateCommonFormDTO, String gridId) { - BigDecimal result = cpcScoreDao.selectGridContactMassesAvgValue(calculateCommonFormDTO.getCustomerId(), calculateCommonFormDTO.getMonthId(), gridId); + private AvgOperationResultVO getGridContactMassesAvgValue(CalculateCommonFormDTO calculateCommonFormDTO, String gridId) { + AvgOperationResultVO result = cpcScoreDao.selectGridContactMassesAvgValue(calculateCommonFormDTO.getCustomerId(), calculateCommonFormDTO.getMonthId(), gridId); if (null == result) { - return new BigDecimal(NumConstant.ZERO_STR); + result.setAvgValue(new BigDecimal(0)); + result.setSampleCount(0); } //FOR TEST /*BigDecimal result=null; @@ -337,10 +348,12 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { * @description 组织内党员的参与议事能力考评分(平均值) * @Date 2020/8/31 15:51 **/ - private BigDecimal getGridJoinIssueAvgValue(CalculateCommonFormDTO formDTO, String gridId) { - BigDecimal result = cpcScoreDao.selectGridJoinIssueAvgValue(formDTO.getCustomerId(), formDTO.getMonthId(), gridId); + private AvgOperationResultVO getGridJoinIssueAvgValue(CalculateCommonFormDTO formDTO, String gridId) { + AvgOperationResultVO result = cpcScoreDao.selectGridJoinIssueAvgValue(formDTO.getCustomerId(), formDTO.getMonthId(), gridId); if (null == result) { - return new BigDecimal(NumConstant.ZERO_STR); + //return new BigDecimal(NumConstant.ZERO_STR); + result.setSampleCount(0); + result.setAvgValue(new BigDecimal(0)); } //FOR TEST /*BigDecimal result=null; @@ -411,7 +424,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { /** * @param formDTO 客户id 月份id: yyyyMM - * @param resultMapList + * @param resultMapList key:网格id,value:该网格各项指标的计算结果 * @param indexCode 指标编码: 党建能力:dangjiannengli;治理能力:zhilinengli;服务能力:fuwunengli; * @param isTotal 1:总分;0不是 * @return void @@ -422,7 +435,8 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { private void saveGridCorreLationResult(CalculateCommonFormDTO formDTO, List> resultMapList, String indexCode, - String isTotal) { + String isTotal, + HashMap avgOpeResultVo) { String quarterId = DateUtils.getQuarterId(formDTO.getMonthId()); String yearId = DateUtils.getYearId(formDTO.getMonthId()); //三大能力结果表 @@ -463,6 +477,14 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { gridSubScoreEntity.setScore(detail.getScore()); gridSubScoreEntity.setWeight(detail.getWeight()); gridSubScoreEntity.setOriginValue(detail.getOriginValue()); + + // 为平均值类型的指标赋值样本总量 + AvgOperationResultVO avgOperationResultVO = avgOpeResultVo.get(gridSubScoreEntity.getGridId().concat(":").concat(gridSubScoreEntity.getMonthId())); + if (avgOperationResultVO != null) { + gridSubScoreEntity.setSampleCount(avgOperationResultVO.getSampleCount()); + } else { + gridSubScoreEntity.setSampleCount(0); + } gridSubScoreList.add(gridSubScoreEntity); } }); @@ -621,6 +643,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { //指标集合 Map> indexMap = buildGridCorrelationIndexInputVO(formDTO, indexList, minAndMaxMap); List> resultMapList = new ArrayList<>(); + HashMap avgOperationResultVo = new HashMap<>(); //分页查询采集记录 for (int pageNo = 1; pageNo <= totalPage; pageNo++) { int pageIndex = (pageNo - NumConstant.ONE) * IndexCalConstant.PAGE_SIZE; @@ -639,8 +662,11 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { if (IndexCodeEnum.ZUZHINEIDANGYDSYYSNLKPFPJZ.getCode().equals(key)) { // log.info("组织内党员的参与议事能力考评分(平均值) 单独处理"); String gridId = (String) recordMap.get(IndexCalConstant.GRID_ID); - BigDecimal joinAvgValue = getGridJoinIssueAvgValue(formDTO, gridId); - SampleValue contactMassesAblityValue = new SampleValue((String) recordMap.get(IndexCalConstant.GRID_ID), joinAvgValue); + String monthId = (String) recordMap.get(IndexCalConstant.MONTH_ID); + AvgOperationResultVO joinAvgValue = getGridJoinIssueAvgValue(formDTO, gridId); + avgOperationResultVo.put(gridId.concat(":").concat(monthId), joinAvgValue); + + SampleValue contactMassesAblityValue = new SampleValue((String) recordMap.get(IndexCalConstant.GRID_ID), joinAvgValue.getAvgValue()); value.getIndexValueVOs().add(contactMassesAblityValue); }else if (StringUtils.isNotBlank(indexCodeFieldReService.getFieldNameByIndexCode(key))) { //对应的数值 @@ -659,7 +685,8 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { saveGridCorreLationResult(formDTO, resultMapList, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(), - NumConstant.ZERO_STR); + NumConstant.ZERO_STR, + avgOperationResultVo); } @@ -696,6 +723,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { //指标集合 Map> indexMap = buildGridCorrelationIndexInputVO(formDTO, indexList, minAndMaxMap); List> resultMapList = new ArrayList<>(); + HashMap avgOperationResultVO = new HashMap<>(); //分页查询采集记录 for (int pageNo = 1; pageNo <= totalPage; pageNo++) { int pageIndex = (pageNo - NumConstant.ONE) * IndexCalConstant.PAGE_SIZE; @@ -730,7 +758,8 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { saveGridCorreLationResult(formDTO, resultMapList, IndexCodeEnum.FU_WU_NENG_LI.getCode(), - NumConstant.ZERO_STR); + NumConstant.ZERO_STR, + avgOperationResultVO); } /** diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.14__cpc_subscore_add_samplecount.sql b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.14__cpc_subscore_add_samplecount.sql new file mode 100644 index 0000000000..af7688ee68 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.14__cpc_subscore_add_samplecount.sql @@ -0,0 +1 @@ +alter table fact_index_grid_sub_score add column SAMPLE_COUNT int(10) comment '样本量' after ORIGIN_VALUE; \ No newline at end of file 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 bf0cfd3d51..b4ad476821 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 @@ -46,9 +46,10 @@ - SELECT - round(AVG( SCORE ),6) AS AVG_CONTACT_MASSES_SCORE + round(AVG( SCORE ),6) AS AVG_VALUE, + count(1) AS SAMPLE_COUNT FROM fact_index_cpc_score m WHERE @@ -90,9 +91,10 @@ - SELECT - round(AVG( SCORE ),6) AS AVG_CONTACT_MASSES_SCORE + round(AVG( SCORE ),6) AS AVG_VALUE, + count(1) AS SAMPLE_COUNT FROM fact_index_cpc_score m WHERE diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSubScoreDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSubScoreDao.xml index 056f92afb2..8d39d8dcc3 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSubScoreDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSubScoreDao.xml @@ -24,7 +24,8 @@ `CREATED_BY`, `CREATED_TIME`, `UPDATED_BY`, - `UPDATED_TIME` + `UPDATED_TIME`, + `SAMPLE_COUNT` ) VALUES @@ -47,7 +48,8 @@ 'APP_USER', now(), 'APP_USER', - now() + now(), + #{item.sampleCount} )