|  |  | @ -1,14 +1,15 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.screen.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.DateUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.screen.IndexGroupDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.screen.IndexGroupDetailDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.indexcal.CalculateCommonFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.screen.form.IndexCalculateForm; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetCommonServiceOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.redis.IndexCodeFieldReRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.indexcal.CpcIndexCalculateService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.indexcal.GridCorreLationService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.screen.IndexCalculateCommunityService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.screen.IndexCalculateService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.util.DimIdGenerator; | 
			
		
	
		
			
				
					|  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
	
		
			
				
					|  |  | @ -29,45 +30,65 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private GridCorreLationService gridCorreLationService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IndexGroupDao indexGroupDao; | 
			
		
	
		
			
				
					|  |  |  |     private CpcIndexCalculateService cpcIndexCalculateService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IndexCodeFieldReRedis indexCodeFieldReRedis; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IndexGroupDetailDao indexGroupDetailDao; | 
			
		
	
		
			
				
					|  |  |  |     private IndexCalculateCommunityService indexCalculateCommunityService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public Boolean indexCalculate(IndexCalculateForm formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         if (StringUtils.isBlank(formDTO.getMonthId())) { | 
			
		
	
		
			
				
					|  |  |  |             //默认 当前月份-1
 | 
			
		
	
		
			
				
					|  |  |  |             formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //按照客户分组
 | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(formDTO.getCustomerIds())) { | 
			
		
	
		
			
				
					|  |  |  |             Result<List<String>> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); | 
			
		
	
		
			
				
					|  |  |  |             if (!externalCustomerIdsResult.success()) { | 
			
		
	
		
			
				
					|  |  |  |                 log.error("cpcIndexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); | 
			
		
	
		
			
				
					|  |  |  |                 return false; | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             if (StringUtils.isBlank(formDTO.getMonthId())) { | 
			
		
	
		
			
				
					|  |  |  |                 //默认 当前月份-1
 | 
			
		
	
		
			
				
					|  |  |  |                 formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             formDTO.setCustomerIds(externalCustomerIdsResult.getData()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         formDTO.getCustomerIds().forEach(customerId -> { | 
			
		
	
		
			
				
					|  |  |  |             CalculateCommonFormDTO calculateCommonFormDTO=new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); | 
			
		
	
		
			
				
					|  |  |  |             //计算党员
 | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |                 //Map<String, BigDecimal> list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
 | 
			
		
	
		
			
				
					|  |  |  |             } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             //按照客户分组
 | 
			
		
	
		
			
				
					|  |  |  |             if (CollectionUtils.isEmpty(formDTO.getCustomerIds())) { | 
			
		
	
		
			
				
					|  |  |  |                 Result<List<String>> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); | 
			
		
	
		
			
				
					|  |  |  |                 if (!externalCustomerIdsResult.success()) { | 
			
		
	
		
			
				
					|  |  |  |                     log.error("indexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); | 
			
		
	
		
			
				
					|  |  |  |                     return false; | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 formDTO.setCustomerIds(externalCustomerIdsResult.getData()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             formDTO.getCustomerIds().forEach(customerId -> { | 
			
		
	
		
			
				
					|  |  |  |                 CalculateCommonFormDTO calculateCommonFormDTO = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); | 
			
		
	
		
			
				
					|  |  |  |                 //计算党员相关的
 | 
			
		
	
		
			
				
					|  |  |  |                 Boolean flag = false; | 
			
		
	
		
			
				
					|  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |                     CalculateCommonFormDTO param = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); | 
			
		
	
		
			
				
					|  |  |  |                     flag = cpcIndexCalculateService.cpcIndexCalculate(param); | 
			
		
	
		
			
				
					|  |  |  |                     log.info("indexCalculate cpcIndexCalculate return result:{}", flag); | 
			
		
	
		
			
				
					|  |  |  |                 } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                     log.error("indexCalculate cpcIndexCalculate exception", e); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             //计算网格
 | 
			
		
	
		
			
				
					|  |  |  |             //TODO
 | 
			
		
	
		
			
				
					|  |  |  |             gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO); | 
			
		
	
		
			
				
					|  |  |  |             //计算社区
 | 
			
		
	
		
			
				
					|  |  |  |             //TODO
 | 
			
		
	
		
			
				
					|  |  |  |                 //计算网格
 | 
			
		
	
		
			
				
					|  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |                     flag = gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO); | 
			
		
	
		
			
				
					|  |  |  |                     log.info("indexCalculate calculateGridCorreLation return result:{}", flag); | 
			
		
	
		
			
				
					|  |  |  |                 } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                     log.error("indexCalculate calculateGridCorreLation exception", e); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 //计算社区
 | 
			
		
	
		
			
				
					|  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |                     indexCalculateCommunityService.calAll(customerId, formDTO.getMonthId()); | 
			
		
	
		
			
				
					|  |  |  |                     log.info("indexCalculate calAll return result:{}", flag); | 
			
		
	
		
			
				
					|  |  |  |                 } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                     log.error("indexCalculate calAll exception", e); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |             indexCodeFieldReRedis.deleteIndexCodeFromRedis(); | 
			
		
	
		
			
				
					|  |  |  |         } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |             log.error("indexCalculate exception,param:{}", JSON.toJSONString(formDTO)); | 
			
		
	
		
			
				
					|  |  |  |         } finally { | 
			
		
	
		
			
				
					|  |  |  |             //清除缓存
 | 
			
		
	
		
			
				
					|  |  |  |             indexCodeFieldReRedis.deleteIndexCodeFromRedis(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return true; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |