From b70ef58633550d3584f5b8f5e42c8f7cba662ca3 Mon Sep 17 00:00:00 2001 From: jianjun Date: Wed, 23 Sep 2020 21:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8B=E7=BA=A7=E5=8F=8A?= =?UTF-8?q?=E8=87=AA=E8=BA=AB=E5=88=86=E6=95=B0=20=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indexcal/AgencySelfSubScoreDao.java | 4 +- .../indexcal/AgencySubScoreDao.java | 5 +- .../indexcal/CommunitySelfSubScoreDao.java | 6 ++ .../indexcal/CommunitySubScoreDao.java | 4 +- .../impl/GridCorreLationServiceImpl.java | 1 - .../IndexCalculateCommunityServiceImpl.java | 86 ++++++++++++++++++ .../IndexCalculateDistrictServiceImpl.java | 87 ++++++++++++++++++- .../impl/IndexCalculateStreetServiceImpl.java | 87 ++++++++++++++++++- .../indexcal/AgencySelfSubScoreDao.xml | 9 +- .../indexcal/AgencySubScoreDao.xml | 11 +++ .../indexcal/CommunitySelfSubScoreDao.xml | 75 +++++++++++----- .../indexcal/CommunitySubScoreDao.xml | 12 +++ 12 files changed, 356 insertions(+), 31 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySelfSubScoreDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySelfSubScoreDao.java index 6d7cd81e19..9adf9fc179 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySelfSubScoreDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySelfSubScoreDao.java @@ -33,7 +33,7 @@ import java.util.List; @Mapper public interface AgencySelfSubScoreDao extends BaseDao { - int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId); - int insertBatch(@Param("list") List list); + + int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @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/dao/evaluationindex/indexcal/AgencySubScoreDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySubScoreDao.java index 970b671a7f..3a28e2d908 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySubScoreDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySubScoreDao.java @@ -19,8 +19,8 @@ package com.epmet.dao.evaluationindex.indexcal; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.indexcal.AgencyScoreDTO; -import com.epmet.dto.indexcal.SubAgencyScoreAvgResultDTO; import com.epmet.entity.evaluationindex.indexcal.AgencyScoreEntity; +import com.epmet.entity.evaluationindex.indexcal.AgencySubScoreEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -50,6 +50,7 @@ public interface AgencySubScoreDao extends BaseDao { * @author zxc * @date 2020/9/2 15:47 */ - Integer deleteOldRecord(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("dataType") String dataType,@Param("delNum")Integer delNum); + Integer deleteOldRecord(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("dataType") String dataType, @Param("delNum") Integer delNum); + List selectSubListByPath(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("levelIndexPath") String levelIndexPath); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySelfSubScoreDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySelfSubScoreDao.java index 02323576b9..9827dbaa64 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySelfSubScoreDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySelfSubScoreDao.java @@ -20,6 +20,9 @@ package com.epmet.dao.evaluationindex.indexcal; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.entity.evaluationindex.indexcal.CommunitySelfSubScoreEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 社区相关 自身/下级分数表 @@ -30,4 +33,7 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface CommunitySelfSubScoreDao extends BaseDao { + int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("indexCode") String indexCode); + + int insertBatch(@Param("list") List communitySelfSubScoreEntities); } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySubScoreDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySubScoreDao.java index a8d5971cc7..ac850fc317 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySubScoreDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySubScoreDao.java @@ -49,6 +49,8 @@ public interface CommunitySubScoreDao extends BaseDao selectSubListByPath(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("levelIndexPath") String levelIndexPath); } 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 798809e2bf..96a20fa266 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 @@ -160,7 +160,6 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); } log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getGridId(), score.getScore(), score.getWeight(), partScore); - System.out.println("=====grid:" + score.getGridId() + ",originScore:" + score.getScore() + ",weight:" + score.getWeight() + ",finalScore:" + partScore + " ,selftotal:" + scoreEntity.getSelfScore() + ",subScore:" + scoreEntity.getSubScore()); }); deleteAndInsertSelfSubScore(formDTO, index.getIndexCode(), insertMap); }); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java index 03e10c7748..9fee142586 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java @@ -6,19 +6,25 @@ import com.epmet.commons.dynamic.datasource.annotation.DataSource; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.constant.DataSourceConstant; import com.epmet.constant.IndexCalConstant; import com.epmet.dao.evaluationindex.indexcal.CommunityScoreDao; +import com.epmet.dao.evaluationindex.indexcal.CommunitySelfSubScoreDao; import com.epmet.dao.evaluationindex.indexcal.CommunitySubScoreDao; import com.epmet.dao.evaluationindex.indexcal.GridScoreDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityOrgMonthlyDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityOrgMonthlyDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexServiceAblityOrgMonthlyDao; +import com.epmet.dao.evaluationindex.screen.IndexGroupDetailDao; +import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.indexcal.CommunityCalResultDTO; import com.epmet.dto.screen.FactIndexCommunityScoreDTO; import com.epmet.dto.screen.result.MaxAndMinBigDecimalResultDTO; import com.epmet.dto.screen.result.SubGridAvgResultDTO; +import com.epmet.entity.evaluationindex.indexcal.CommunitySelfSubScoreEntity; +import com.epmet.entity.evaluationindex.indexcal.FactIndexCommunitySubScoreEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.eum.IndexCodeEnum; import com.epmet.service.evaluationindex.indexcal.IndexCalculateCommunityService; @@ -68,6 +74,10 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni private GridScoreDao factIndexGridScoreDao; @Autowired private CommunitySubScoreDao communitySubScoreDao; + @Autowired + private IndexGroupDetailDao indexGroupDetailDao; + @Autowired + private CommunitySelfSubScoreDao communitySelfSubScoreDao; /** * @param customerId @@ -76,6 +86,7 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni * @author zxc * @date 2020/9/1 4:12 下午 */ + @Override public Boolean calCommunityAll(String customerId, String monthId) { Boolean aBoolean = communityPartyCalculate(customerId, monthId);//党建能力 if (!aBoolean.equals(true)) { @@ -93,9 +104,84 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni if (!dBoolean.equals(true)) { throw new RenException("calculate community-all insert failure ......"); } + //计算自身和下级 + CalculateCommonFormDTO formDTO = new CalculateCommonFormDTO(); + formDTO.setMonthId(monthId); + formDTO.setCustomerId(customerId); + calculateSelfSubScore(formDTO); return true; } + private void calculateSelfSubScore(CalculateCommonFormDTO formDTO) { + //todo 指标添加缓存 + List indexList = indexGroupDetailService.getDetailListByParentCode(formDTO.getCustomerId(), + IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode()); + if (CollectionUtils.isEmpty(indexList)) { + log.error("calculateSelfSubScore customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); + throw new RenException("客户【网格相关】指标权重信息不存在"); + } + indexList.forEach(index -> { + String levelIndexPath = index.getAllParentIndexCode().concat(StrConstant.COLON).concat(index.getIndexCode()); + //获取出指标之间的关系 + List selfSubIndexList = indexGroupDetailDao.selectSelfSubIndex(formDTO.getCustomerId(), levelIndexPath); + if (CollectionUtils.isEmpty(selfSubIndexList)) { + log.error("calculateSelfSubScore indexGroupDetailDao.selectSelfSubIndex return empty,customerId:{}", formDTO.getCustomerId()); + return; + } + //获取该能力下的分数 + List subScore = communitySubScoreDao.selectSubListByPath(formDTO.getCustomerId(), formDTO.getMonthId(), levelIndexPath); + if (CollectionUtils.isEmpty(subScore)) { + log.error("calculateSelfSubScore communitySubScoreDao.selectSubListByPath return empty,customerId:{} ", formDTO.getCustomerId()); + return; + } + Map> selfSubParentMap = new HashMap<>(); + selfSubParentMap.put("zishen", new HashSet<>()); + selfSubParentMap.put("xiaji", new HashSet<>()); + selfSubIndexList.forEach(o -> { + //找出自身 和下级的指标 + if (o.getAllIndexCodePath().indexOf("xiaji") > -1) { + selfSubParentMap.get("xiaji").add(o.getIndexCode()); + } else { + selfSubParentMap.get("zishen").add(o.getIndexCode()); + } + }); + Map insertMap = new HashMap<>(); + subScore.forEach(score -> { + String key = score.getAgencyId().concat(index.getIndexCode()); + CommunitySelfSubScoreEntity scoreEntity = insertMap.get(key); + if (scoreEntity == null) { + scoreEntity = ConvertUtils.sourceToTarget(score, CommunitySelfSubScoreEntity.class); + insertMap.put(key, scoreEntity); + scoreEntity.setSelfScore(new BigDecimal(0)); + scoreEntity.setSubScore(new BigDecimal(0)); + scoreEntity.setParentIndexCode(index.getIndexCode()); + scoreEntity.setSelfWeight(new BigDecimal(0)); + scoreEntity.setSubWeight(new BigDecimal(0)); + } + BigDecimal partScore = score.getScore().multiply(score.getWeight()); + if (selfSubParentMap.get("xiaji").contains(score.getIndexCode())) { + scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore)); + scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight())); + } else { + scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); + scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); + } + log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore); + }); + deleteAndInsertSelfSubScore(formDTO, index.getIndexCode(), insertMap); + }); + } + + @Transactional(rollbackFor = Exception.class) + public void deleteAndInsertSelfSubScore(CalculateCommonFormDTO formDTO, String indexCode, Map insertMap) { + int effectRow = 0; + do { + communitySelfSubScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode); + } while (effectRow > 0); + + communitySelfSubScoreDao.insertBatch(new ArrayList<>(insertMap.values())); + } + /** * @param customerId * @Description 社区名义发文数量计算【党建能力】 diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java index d170c73df4..0c5ecca06c 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java @@ -6,18 +6,24 @@ import com.epmet.commons.dynamic.datasource.annotation.DataSource; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.constant.DataSourceConstant; import com.epmet.constant.IndexCalConstant; import com.epmet.dao.evaluationindex.indexcal.AgencyScoreDao; +import com.epmet.dao.evaluationindex.indexcal.AgencySelfSubScoreDao; import com.epmet.dao.evaluationindex.indexcal.AgencySubScoreDao; import com.epmet.dao.evaluationindex.indexcal.DeptScoreDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityOrgMonthlyDao; +import com.epmet.dao.evaluationindex.screen.IndexGroupDetailDao; import com.epmet.dao.evaluationindex.screen.ScreenCustomerAgencyDao; import com.epmet.dto.indexcal.AgencyCalResultDTO; import com.epmet.dto.indexcal.AgencyScoreDTO; +import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.indexcal.SubAgencyScoreAvgResultDTO; import com.epmet.dto.screen.result.MaxAndMinBigDecimalResultDTO; +import com.epmet.entity.evaluationindex.indexcal.AgencySelfSubScoreEntity; +import com.epmet.entity.evaluationindex.indexcal.AgencySubScoreEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.eum.IndexCodeEnum; import com.epmet.service.evaluationindex.indexcal.IndexCalculateDistrictService; @@ -65,11 +71,15 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict private ScreenCustomerAgencyDao customerAgencyDao; @Autowired private AgencySubScoreDao agencySubScoreDao; + @Autowired + private IndexGroupDetailDao indexGroupDetailDao; + @Autowired + private AgencySelfSubScoreDao agencySelfSubScoreDao; /** - * @Description 计算全区相关总分 * @param customerId * @param monthId + * @Description 计算全区相关总分 * @author zxc * @date 2020/9/2 3:12 下午 */ @@ -91,9 +101,84 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict if (!dBoolean.equals(true)) { throw new RenException("calculate district-all insert failure ......"); } + //计算自身和下级 + CalculateCommonFormDTO formDTO = new CalculateCommonFormDTO(); + formDTO.setMonthId(monthId); + formDTO.setCustomerId(customerId); + calculateSelfSubScore(formDTO); return true; } + private void calculateSelfSubScore(CalculateCommonFormDTO formDTO) { + //todo 指标添加缓存 + List indexList = indexGroupDetailService.getDetailListByParentCode(formDTO.getCustomerId(), + IndexCodeEnum.QU_ZHI_BU_MEN.getCode()); + if (CollectionUtils.isEmpty(indexList)) { + log.error("calculateSelfSubScore customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); + throw new RenException("客户【网格相关】指标权重信息不存在"); + } + indexList.forEach(index -> { + String levelIndexPath = index.getAllParentIndexCode().concat(StrConstant.COLON).concat(index.getIndexCode()); + //获取出指标之间的关系 + List selfSubIndexList = indexGroupDetailDao.selectSelfSubIndex(formDTO.getCustomerId(), levelIndexPath); + if (CollectionUtils.isEmpty(selfSubIndexList)) { + log.error("calculateSelfSubScore indexGroupDetailDao.selectSelfSubIndex return empty,customerId:{}", formDTO.getCustomerId()); + return; + } + //获取该能力下的分数 + List subScore = agencySubScoreDao.selectSubListByPath(formDTO.getCustomerId(), formDTO.getMonthId(), levelIndexPath); + if (CollectionUtils.isEmpty(subScore)) { + log.error("calculateSelfSubScore communitySubScoreDao.selectSubListByPath return empty,customerId:{} ", formDTO.getCustomerId()); + return; + } + Map> selfSubParentMap = new HashMap<>(); + selfSubParentMap.put("zishen", new HashSet<>()); + selfSubParentMap.put("xiaji", new HashSet<>()); + selfSubIndexList.forEach(o -> { + //找出自身 和下级的指标 + if (o.getAllIndexCodePath().indexOf("xiaji") > -1) { + selfSubParentMap.get("xiaji").add(o.getIndexCode()); + } else { + selfSubParentMap.get("zishen").add(o.getIndexCode()); + } + }); + Map insertMap = new HashMap<>(); + subScore.forEach(score -> { + String key = score.getAgencyId().concat(index.getIndexCode()); + AgencySelfSubScoreEntity scoreEntity = insertMap.get(key); + if (scoreEntity == null) { + scoreEntity = ConvertUtils.sourceToTarget(score, AgencySelfSubScoreEntity.class); + insertMap.put(key, scoreEntity); + scoreEntity.setSelfScore(new BigDecimal(0)); + scoreEntity.setSubScore(new BigDecimal(0)); + scoreEntity.setParentIndexCode(index.getIndexCode()); + scoreEntity.setSelfWeight(new BigDecimal(0)); + scoreEntity.setSubWeight(new BigDecimal(0)); + } + BigDecimal partScore = score.getScore().multiply(score.getWeight()); + if (selfSubParentMap.get("xiaji").contains(score.getIndexCode())) { + scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore)); + scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight())); + } else { + scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); + scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); + } + log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore); + }); + deleteAndInsertSelfSubScore(formDTO, index.getIndexCode(), insertMap); + }); + } + + @Transactional(rollbackFor = Exception.class) + public void deleteAndInsertSelfSubScore(CalculateCommonFormDTO formDTO, String indexCode, Map insertMap) { + int effectRow = 0; + do { + agencySelfSubScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode); + } while (effectRow > 0); + + agencySelfSubScoreDao.insertBatch(new ArrayList<>(insertMap.values())); + } + /** * @param customerId * @Description 全区名义发文数量计算【党建能力】 diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java index 59920d55fa..c5099fe557 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java @@ -6,19 +6,25 @@ import com.epmet.commons.dynamic.datasource.annotation.DataSource; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.constant.DataSourceConstant; import com.epmet.constant.IndexCalConstant; import com.epmet.dao.evaluationindex.indexcal.AgencyScoreDao; +import com.epmet.dao.evaluationindex.indexcal.AgencySelfSubScoreDao; import com.epmet.dao.evaluationindex.indexcal.AgencySubScoreDao; import com.epmet.dao.evaluationindex.indexcal.CommunityScoreDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityOrgMonthlyDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityOrgMonthlyDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexServiceAblityOrgMonthlyDao; +import com.epmet.dao.evaluationindex.screen.IndexGroupDetailDao; import com.epmet.dto.indexcal.AgencyCalResultDTO; import com.epmet.dto.indexcal.AgencyScoreDTO; +import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.indexcal.SubCommunityAvgResultDTO; import com.epmet.dto.screen.result.MaxAndMinBigDecimalResultDTO; +import com.epmet.entity.evaluationindex.indexcal.AgencySelfSubScoreEntity; +import com.epmet.entity.evaluationindex.indexcal.AgencySubScoreEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.eum.IndexCodeEnum; import com.epmet.service.evaluationindex.indexcal.IndexCalculateStreetService; @@ -68,11 +74,15 @@ public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetServ private AgencyScoreDao agencyScoreDao; @Autowired private AgencySubScoreDao agencySubScoreDao; + @Autowired + private IndexGroupDetailDao indexGroupDetailDao; + @Autowired + private AgencySelfSubScoreDao agencySelfSubScoreDao; /** - * @Description 计算街道相关总分 * @param customerId * @param monthId + * @Description 计算街道相关总分 * @author zxc * @date 2020/9/2 3:12 下午 */ @@ -94,9 +104,84 @@ public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetServ if (!dBoolean.equals(true)) { throw new RenException("calculate street-all insert failure ......"); } + //计算自身和下级 + CalculateCommonFormDTO formDTO = new CalculateCommonFormDTO(); + formDTO.setMonthId(monthId); + formDTO.setCustomerId(customerId); + calculateSelfSubScore(formDTO); return true; } + private void calculateSelfSubScore(CalculateCommonFormDTO formDTO) { + //todo 指标添加缓存 + List indexList = indexGroupDetailService.getDetailListByParentCode(formDTO.getCustomerId(), + IndexCodeEnum.JIE_DAO_XIANG_GUAN.getCode()); + if (CollectionUtils.isEmpty(indexList)) { + log.error("calculateSelfSubScore customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); + throw new RenException("客户【网格相关】指标权重信息不存在"); + } + indexList.forEach(index -> { + String levelIndexPath = index.getAllParentIndexCode().concat(StrConstant.COLON).concat(index.getIndexCode()); + //获取出指标之间的关系 + List selfSubIndexList = indexGroupDetailDao.selectSelfSubIndex(formDTO.getCustomerId(), levelIndexPath); + if (CollectionUtils.isEmpty(selfSubIndexList)) { + log.error("calculateSelfSubScore indexGroupDetailDao.selectSelfSubIndex return empty,customerId:{}", formDTO.getCustomerId()); + return; + } + //获取该能力下的分数 + List subScore = agencySubScoreDao.selectSubListByPath(formDTO.getCustomerId(), formDTO.getMonthId(), levelIndexPath); + if (CollectionUtils.isEmpty(subScore)) { + log.error("calculateSelfSubScore communitySubScoreDao.selectSubListByPath return empty,customerId:{} ", formDTO.getCustomerId()); + return; + } + Map> selfSubParentMap = new HashMap<>(); + selfSubParentMap.put("zishen", new HashSet<>()); + selfSubParentMap.put("xiaji", new HashSet<>()); + selfSubIndexList.forEach(o -> { + //找出自身 和下级的指标 + if (o.getAllIndexCodePath().indexOf("xiaji") > -1) { + selfSubParentMap.get("xiaji").add(o.getIndexCode()); + } else { + selfSubParentMap.get("zishen").add(o.getIndexCode()); + } + }); + Map insertMap = new HashMap<>(); + subScore.forEach(score -> { + String key = score.getAgencyId().concat(index.getIndexCode()); + AgencySelfSubScoreEntity scoreEntity = insertMap.get(key); + if (scoreEntity == null) { + scoreEntity = ConvertUtils.sourceToTarget(score, AgencySelfSubScoreEntity.class); + insertMap.put(key, scoreEntity); + scoreEntity.setSelfScore(new BigDecimal(0)); + scoreEntity.setSubScore(new BigDecimal(0)); + scoreEntity.setParentIndexCode(index.getIndexCode()); + scoreEntity.setSelfWeight(new BigDecimal(0)); + scoreEntity.setSubWeight(new BigDecimal(0)); + } + BigDecimal partScore = score.getScore().multiply(score.getWeight()); + if (selfSubParentMap.get("xiaji").contains(score.getIndexCode())) { + scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore)); + scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight())); + } else { + scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); + scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); + } + log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore); + }); + deleteAndInsertSelfSubScore(formDTO, index.getIndexCode(), insertMap); + }); + } + + @Transactional(rollbackFor = Exception.class) + public void deleteAndInsertSelfSubScore(CalculateCommonFormDTO formDTO, String indexCode, Map insertMap) { + int effectRow = 0; + do { + agencySelfSubScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode); + } while (effectRow > 0); + + agencySelfSubScoreDao.insertBatch(new ArrayList<>(insertMap.values())); + } + /** * @param customerId * @Description 社区名义发文数量计算【党建能力】 diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySelfSubScoreDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySelfSubScoreDao.xml index 9df88e8cd4..6ae6d742ef 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySelfSubScoreDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySelfSubScoreDao.xml @@ -4,11 +4,16 @@ - delete from fact_index_agency_self_sub_score limit 1000 + delete from fact_index_agency_self_sub_score + where CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} + and MONTH_ID = #{monthId,jdbcType=VARCHAR} + and PARENT_INDEX_CODE = #{parentIndexCode,jdbcType=VARCHAR} + limit 1000 - INSERT INTO fact_index_agency_self_sub_score (ID, CUSTOMER_ID, AGENCY_ID, PARENT_AGENCY_ID, YEAR_ID, QUARTER_ID, MONTH_ID, + INSERT INTO fact_index_agency_self_sub_score + (ID, CUSTOMER_ID, AGENCY_ID, PARENT_AGENCY_ID, YEAR_ID, QUARTER_ID, MONTH_ID, DATA_TYPE, SELF_SCORE, SUB_SCORE, PARENT_INDEX_CODE,ALL_PARENT_INDEX_CODE, SELF_WEIGHT,SUB_WEIGHT,DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) VALUES diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySubScoreDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySubScoreDao.xml index 42e77b47a2..bc3f151ff8 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySubScoreDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySubScoreDao.xml @@ -46,4 +46,15 @@ LIMIT #{delNum} + diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySelfSubScoreDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySelfSubScoreDao.xml index ec000e7116..f077cb0f13 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySelfSubScoreDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySelfSubScoreDao.xml @@ -3,26 +3,59 @@ - - - - - - - - - - - - - - - - - - - - - + + delete from fact_index_community_self_sub_score + where CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} + AND MONTH_ID = #{monthId,jdbcType=VARCHAR} + AND PARENT_INDEX_CODE = #{parentIndexCode,jdbcType=VARCHAR} + limit 1000 + + + INSERT INTO `fact_index_grid_self_sub_score` ( + `ID`, + `CUSTOMER_ID`, + `AGENCY_ID`, + `PARENT_AGENCY_ID`, + `QUARTER_ID`, + `YEAR_ID`, + `MONTH_ID`, + `SELF_SCORE`, + `SUB_SCORE`, + `PARENT_INDEX_CODE`, + `ALL_PARENT_INDEX_CODE`, + `SELF_WEIGHT`, + `SUB_WEIGHT`, + `DEL_FLAG`, + `REVISION`, + `CREATED_BY`, + `CREATED_TIME`, + `UPDATED_BY`, + `UPDATED_TIME` + ) + VALUES + + ( + (SELECT REPLACE(UUID(), '-', '') AS id), + #{item.customerId}, + #{item.agencyId}, + #{item.parentAgencyId}, + #{item.quarterId}, + #{item.yearId}, + #{item.monthId}, + #{item.selfScore}, + #{item.subScore}, + #{item.parentIndexCode}, + #{item.allParentIndexCode}, + #{item.selfWeight}, + #{item.subWeight}, + 0, + 0, + 'APP_USER', + now(), + 'APP_USER', + now() + ) + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySubScoreDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySubScoreDao.xml index 6a3b2da17f..b4a245a758 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySubScoreDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySubScoreDao.xml @@ -44,4 +44,16 @@ LIMIT #{delNum} +