| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -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<String, Object> 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<CpcScoreEntity> values) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        cpcScoreDao.deleteByMonthId(customerId, monthId, indexCode); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * desc:根据客户id和月份Id 指标code 非必填 删除数据 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param formDTO | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param indexCode 指标code 非必填 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param values | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private void deleteAndInsertBatch(CalculateCommonFormDTO formDTO, Collection<CpcScoreEntity> 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<Map<String, Object>> list = null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        do { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (!CollectionUtils.isEmpty(list)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                //遍历指标分组 计算分数
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                List<Map<String, Object>> finalList = list; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                groupIndexDetailsMap.forEach((parentIndexCode, details) -> { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    calculateScore(formDTO, details, finalList, minAndMaxMap, parentIndexCode); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                //如果是第一页且仅有一条数据 则直接给50分
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (pageNo == NumConstant.ONE && list.size() == NumConstant.ONE) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    List<CpcScoreEntity> 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<String, List<IndexGroupDetailEntity>> entry : groupIndexDetailsMap.entrySet()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        String parentIndexCode = entry.getKey(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        List<IndexGroupDetailEntity> 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(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //分值计算器
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |