diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screencoll/form/IndexDataMonthlyFormDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screencoll/form/IndexDataMonthlyFormDTO.java index 4adf142a12..5c730099e4 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screencoll/form/IndexDataMonthlyFormDTO.java +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screencoll/form/IndexDataMonthlyFormDTO.java @@ -41,6 +41,11 @@ public class IndexDataMonthlyFormDTO implements Serializable { */ private String parentId; + /** + * 所有上级ID,用英文逗号分开 + */ + private String allParentIds; + /** * 组织名称 */ diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java index 0732ac80c5..e21d0055d6 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java @@ -2,6 +2,7 @@ package com.epmet.service.evaluationindex.indexcoll.impl; 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.utils.ConvertUtils; import com.epmet.constant.DataSourceConstant; import com.epmet.constant.OrgTypeConstant; @@ -23,16 +24,20 @@ import com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity; import com.epmet.entity.evaluationindex.screen.ScreenCustomerDeptEntity; import com.epmet.eum.IndexCodeEnum; import com.epmet.service.evaluationindex.indexcoll.FactIndexCollectService; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -43,6 +48,7 @@ import java.util.stream.Collectors; @Service @DataSource(DataSourceConstant.EVALUATION_INDEX) public class FactIndexCollectServiceImpl implements FactIndexCollectService { + Cache allParentIds = CacheBuilder.newBuilder().expireAfterWrite(2, TimeUnit.HOURS).build(); @Autowired private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao; @@ -219,6 +225,7 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { // 根据年,汇总今年各项得到,计算平均值后 插入年表 screen_index_data_yearly this.insertIndexDataYear(monthId, customerId); + allParentIds.invalidateAll(); } /** @@ -283,6 +290,7 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { // 补充表中其他字段 monthlyDTO = this.supplementIndexDataMonthlyTable(monthId, OrgTypeConstant.GRID, gridScoreDTOS.get(i).getGridId(), gridScoreDTOS.get(i).getParentAgencyId(), gridScoreDTOS.get(i).getGridName(), monthlyDTO); + monthlyDTO.setAllParentIds(gridScoreDTOS.get(i).getAllParentIds()); monthlyFormDTOList.add(monthlyDTO); } screenIndexDataMonthlyDao.batchInsertIndexDataMonthly(monthlyFormDTOList, customerId); @@ -298,21 +306,26 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { * @Author zhangyong * @Date 14:17 2020-09-03 **/ - private void insertIndexDataMonthlyByGridScore(String monthId, String customerId, List gridScoreDTOS){ + private void insertIndexDataMonthlyByGridScore(String monthId, String customerId, List gridScoreDTOS) { List monthlyFormDTOList = new ArrayList<>(); // 根据网格id进行分组,最后组装一条数据 一个网格 对应 4条数据 Map> collect = gridScoreDTOS.stream().collect(Collectors.groupingBy(FactIndexGridScoreDTO::getGridId)); // 查询网格的 上级组织id 和 组织名称 List parentGridList = screenCustomerGridDao.selectListGridInfo(customerId); - for(Map.Entry> gridScore : collect.entrySet()){ + if (!CollectionUtils.isEmpty(parentGridList)) { + parentGridList.forEach(o -> { + allParentIds.put(o.getGridId(), o.getGridId()); + }); + } + for (Map.Entry> gridScore : collect.entrySet()) { IndexDataMonthlyFormDTO monthlyFormDTO = new IndexDataMonthlyFormDTO(); // 给4个指数 赋默认值 monthlyFormDTO = this.setIndexDefaultValueFor(monthlyFormDTO); - for ( int i = 0; i < gridScore.getValue().size(); i++){ - if (NumConstant.ONE_STR.equals(gridScore.getValue().get(i).getIsTotal())){ + for (int i = 0; i < gridScore.getValue().size(); i++) { + if (NumConstant.ONE_STR.equals(gridScore.getValue().get(i).getIsTotal())) { // 是总分 - if (IndexCodeEnum.WANG_GE_XIANG_GUAN.getCode().equals(gridScore.getValue().get(i).getIndexCode())){ + if (IndexCodeEnum.WANG_GE_XIANG_GUAN.getCode().equals(gridScore.getValue().get(i).getIndexCode())) { // 总指数 = 网格相关 monthlyFormDTO.setIndexTotal(gridScore.getValue().get(i).getScore()); } @@ -339,6 +352,7 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { // 补充表中其他字段 monthlyFormDTO = this.supplementIndexDataMonthlyTable(monthId, OrgTypeConstant.GRID, gridScore.getKey(), parentAgencyId, gridName, monthlyFormDTO); + monthlyFormDTO.setAllParentIds(allParentIds.getIfPresent(monthlyFormDTO.getOrgId())); monthlyFormDTOList.add(monthlyFormDTO); } if (monthlyFormDTOList.size() > NumConstant.ZERO){ @@ -409,6 +423,7 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { // 补充表中其他字段 monthlyDTO = this.supplementIndexDataMonthlyTable(monthId, OrgTypeConstant.AGENCY, communityScoreDTOS.get(i).getAgencyId(), communityScoreDTOS.get(i).getPid(), communityScoreDTOS.get(i).getAgencyName(), monthlyDTO); + monthlyDTO.setAllParentIds(communityScoreDTOS.get(i).getPids()); monthlyFormDTOList.add(monthlyDTO); } screenIndexDataMonthlyDao.batchInsertIndexDataMonthly(monthlyFormDTOList, customerId); @@ -424,20 +439,25 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { * @Author zhangyong * @Date 14:17 2020-09-03 **/ - private void insertIndexDataMonthlyByCommunityScore(String monthId, String customerId, List communityScoreDTOS){ + private void insertIndexDataMonthlyByCommunityScore(String monthId, String customerId, List communityScoreDTOS) { List monthlyFormDTOList = new ArrayList<>(); // 根据组织id 进行分组,最后组装一条数据 一个组织id 对应 4条数据 Map> collect = communityScoreDTOS.stream().collect(Collectors.groupingBy(FactIndexCommunityScoreDTO::getAgencyId)); // 根据客户id,查询区/街道 组织名称、id List parentAgencyList = screenCustomerAgencyDao.selectListAgencyInfo(customerId); - for(Map.Entry> communityScore : collect.entrySet()){ + if (!CollectionUtils.isEmpty(parentAgencyList)) { + parentAgencyList.forEach(o -> { + allParentIds.put(o.getAgencyId(), o.getPids()); + }); + } + for (Map.Entry> communityScore : collect.entrySet()) { IndexDataMonthlyFormDTO monthlyFormDTO = new IndexDataMonthlyFormDTO(); // 给4个指数 赋默认值 monthlyFormDTO = this.setIndexDefaultValueFor(monthlyFormDTO); - for ( int i = 0; i < communityScore.getValue().size(); i++){ - if (NumConstant.ONE_STR.equals(communityScore.getValue().get(i).getIsTotal())){ + for (int i = 0; i < communityScore.getValue().size(); i++) { + if (NumConstant.ONE_STR.equals(communityScore.getValue().get(i).getIsTotal())) { // 是总分 - if (IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode().equals(communityScore.getValue().get(i).getIndexCode())){ + if (IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode().equals(communityScore.getValue().get(i).getIndexCode())) { // 总指数 = 社区相关 monthlyFormDTO.setIndexTotal(communityScore.getValue().get(i).getScore()); } @@ -465,6 +485,7 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { // 补充表中其他字段 monthlyFormDTO = this.supplementIndexDataMonthlyTable(monthId, OrgTypeConstant.AGENCY, communityScore.getKey(), parentAgencyId, agencyName, monthlyFormDTO); + monthlyFormDTO.setAllParentIds(allParentIds.getIfPresent(monthlyFormDTO.getOrgId())); // 补充表中其他字段 monthlyFormDTOList.add(monthlyFormDTO); } @@ -497,7 +518,13 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { mismatchDeptList = screenCustomerDeptDao.selectListMismatchDeptInfo(customerId, null); } - if (!CollectionUtils.isEmpty(mismatchDeptList)){ + if (!CollectionUtils.isEmpty(mismatchDeptList)) { + mismatchDeptList.forEach(o -> { + String pids = allParentIds.getIfPresent(o.getParentAgencyId()); + if (!StringUtils.isEmpty(pids)) { + allParentIds.put(o.getDeptId(), pids.concat(StrConstant.COLON).concat(o.getParentAgencyId())); + } + }); // 如果进行不匹配查询,查到了其他部门信息,一律赋默认值 this.insertIndexMonthlyByDeptDefaultScore(monthId, customerId, mismatchDeptList); } @@ -534,6 +561,7 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { // 补充表中其他字段 monthlyDTO = this.supplementIndexDataMonthlyTable(monthId, OrgTypeConstant.DEPARTMENT, deptScoreDTOS.get(i).getDeptId(), deptScoreDTOS.get(i).getParentAgencyId(), deptScoreDTOS.get(i).getDeptName(), monthlyDTO); + monthlyDTO.setAllParentIds(allParentIds.getIfPresent(monthlyDTO.getOrgId())); monthlyFormDTOList.add(monthlyDTO); } screenIndexDataMonthlyDao.batchInsertIndexDataMonthly(monthlyFormDTOList, customerId); @@ -579,12 +607,17 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { deptName = deptEntity.getDeptName(); } } - if ("".equals(parentAgencyId)){ + if ("".equals(parentAgencyId)) { throw new RuntimeException("在screen_customer_dept表中未查询到该客户下的父级信息:customerId =" + customerId + ", deptId = " + deptScore.getKey()); } // 补充表中其他字段 monthlyFormDTO = this.supplementIndexDataMonthlyTable(monthId, OrgTypeConstant.DEPARTMENT, deptScore.getKey(), parentAgencyId, deptName, monthlyFormDTO); + //部门表没有 allParentIds 所以直接获取 然后拼接 + String ppIds = allParentIds.getIfPresent(monthlyFormDTO.getParentId()); + if (!StringUtils.isEmpty(ppIds)) { + monthlyFormDTO.setAllParentIds(ppIds.concat(StrConstant.COLON).concat(monthlyFormDTO.getParentId())); + } monthlyFormDTOList.add(monthlyFormDTO); } if (monthlyFormDTOList.size() > NumConstant.ZERO){ @@ -634,13 +667,18 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { * @Author zhangyong * @Date 14:17 2020-09-03 **/ - private void insertIndexDataMonthlyByAgencyScore(String monthId, String customerId, List agencyScoreDTOS){ + private void insertIndexDataMonthlyByAgencyScore(String monthId, String customerId, List agencyScoreDTOS) { List monthlyFormDTOList = new ArrayList<>(); // 根据组织id(eg:社区或者街道id) 进行分组,最后组装一条数据 一个组织id 对应 4条数据 Map> collect = agencyScoreDTOS.stream().collect(Collectors.groupingBy(AgencyScoreDTO::getAgencyId)); List parentAgencyList = screenCustomerAgencyDao.selectListAgencyInfo(customerId); int j = 0; - for(Map.Entry> agencyScore : collect.entrySet()){ + if (!CollectionUtils.isEmpty(parentAgencyList)) { + parentAgencyList.forEach(o -> { + allParentIds.put(o.getAgencyId(), o.getPids()); + }); + } + for (Map.Entry> agencyScore : collect.entrySet()) { if (NumConstant.ZERO_STR.equals(agencyScore.getKey())) { log.warn("insertIndexDataMonthlyByAgencyScore agencyyId is 0"); continue; @@ -669,12 +707,16 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { agencyName = agencyScoreDTO.getAgencyName(); } } - if ("".equals(agencyName)){ + if ("".equals(agencyName)) { throw new RuntimeException("在screen_customer_agency表中未查询到该客户下的组织名称:customerId =" + customerId + ", agencyId = " + agencyScore.getKey()); } // 补充表中其他字段 monthlyFormDTO = this.supplementIndexDataMonthlyTable(monthId, OrgTypeConstant.AGENCY, agencyScore.getKey(), parentAgencyId, agencyName, monthlyFormDTO); + if ("S2-C1".equals(monthlyFormDTO.getOrgId())) { + System.out.println("======" + allParentIds.getIfPresent(monthlyFormDTO.getOrgId())); + } + monthlyFormDTO.setAllParentIds(allParentIds.getIfPresent(monthlyFormDTO.getOrgId())); monthlyFormDTOList.add(monthlyFormDTO); } if (monthlyFormDTOList.size() > NumConstant.ZERO){ diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml index 1c1907e4a7..83a948ed38 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml @@ -81,7 +81,8 @@