|  |  | @ -17,6 +17,7 @@ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.evaluationindex.screen.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.dynamic.datasource.annotation.DataSource; | 
			
		
	
	
		
			
				
					|  |  | @ -365,7 +366,7 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |             orgIds.add(PingYinConstant.KONG_CUN_AGENCY_ID); | 
			
		
	
		
			
				
					|  |  |  |             orgIds.add(PingYinConstant.YU_SHAN_AGENCY_ID); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         log.info("groupByLevel:"+groupByLevel+"orgIds:"+orgIds); | 
			
		
	
		
			
				
					|  |  |  |         log.info("groupByLevel:{}"+JSON.toJSONString(groupByLevel)+"orgIds:{}"+JSON.toJSONString(orgIds)); | 
			
		
	
		
			
				
					|  |  |  |         del(customerId,dateId,orgIds); | 
			
		
	
		
			
				
					|  |  |  |         if (isGrid){ | 
			
		
	
		
			
				
					|  |  |  |             // community级别走这
 | 
			
		
	
	
		
			
				
					|  |  | @ -376,7 +377,7 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |         }else { | 
			
		
	
		
			
				
					|  |  |  |             // 根据客户ID,时间,组织级别查询 分类标签
 | 
			
		
	
		
			
				
					|  |  |  |             List<CategoryProjectResultDTO> categoryProjectResultDTOS = baseDao.selectOrgCategoryInfo(customerId, dateId, level); | 
			
		
	
		
			
				
					|  |  |  |             log.info("分类标签:"+categoryProjectResultDTOS); | 
			
		
	
		
			
				
					|  |  |  |             log.info("分类标签:{}"+JSON.toJSONString(categoryProjectResultDTOS)); | 
			
		
	
		
			
				
					|  |  |  |             List<ScreenCustomerGridDTO> belongGridInfos = gridService.selectBelongGridInfo(customerId, level); | 
			
		
	
		
			
				
					|  |  |  |             if (!CollectionUtils.isEmpty(belongGridInfos)){ | 
			
		
	
		
			
				
					|  |  |  |                 // 存在直属网格
 | 
			
		
	
	
		
			
				
					|  |  | @ -405,29 +406,38 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |              * 在保存一份子客户自己agencyId的 | 
			
		
	
		
			
				
					|  |  |  |              */ | 
			
		
	
		
			
				
					|  |  |  |             if (ScreenConstant.DISTRICT.equals(level)){ | 
			
		
	
		
			
				
					|  |  |  |                 // 这时的result集合要清空,因为被上边使用 【result = ConvertUtils.sourceToTarget(categoryProjectResultDTOS,ScreenProjectCategoryOrgDailyEntity.class);】
 | 
			
		
	
		
			
				
					|  |  |  |                 result.clear(); | 
			
		
	
		
			
				
					|  |  |  |                 // 查询 平阴的agencyId
 | 
			
		
	
		
			
				
					|  |  |  |                 ScreenCustomerAgencyEntity entity = agencyService.selectTopAgency(customerId); | 
			
		
	
		
			
				
					|  |  |  |                 // 子级客户ID
 | 
			
		
	
		
			
				
					|  |  |  |                 List<String> customerIds = relationInfo.stream().map(m -> m.getCustomerId()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |                 // 子客户单独存一份【三个街道的】
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> sonCustomerList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                 // 父客户存在的分类
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> categoryProjectExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, true); | 
			
		
	
		
			
				
					|  |  |  |                 log.info("父客户存在的分类"+categoryProjectExists); | 
			
		
	
		
			
				
					|  |  |  |                 // 这时的result集合要清空,因为被上边使用 【result = ConvertUtils.sourceToTarget(categoryProjectResultDTOS,ScreenProjectCategoryOrgDailyEntity.class);】
 | 
			
		
	
		
			
				
					|  |  |  |                 result.clear(); | 
			
		
	
		
			
				
					|  |  |  | /*                List<ScreenProjectCategoryOrgDailyEntity> finalResult = result; | 
			
		
	
		
			
				
					|  |  |  |                 groupByCategoryCode.forEach((code, list) -> { | 
			
		
	
		
			
				
					|  |  |  |                     ScreenProjectCategoryOrgDailyEntity e = new ScreenProjectCategoryOrgDailyEntity(); | 
			
		
	
		
			
				
					|  |  |  |                     e.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |                     e.setCategoryOriginCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |                     e.setCategoryCode(code); | 
			
		
	
		
			
				
					|  |  |  |                     e.setOrgId(entity.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |                     e.setProjectTotal(CollectionUtils.isEmpty(list) ? NumConstant.ZERO : list.stream().collect(Collectors.summingInt(CategoryProjectResultDTO::getProjectTotal))); | 
			
		
	
		
			
				
					|  |  |  |                 log.info("父客户存在的分类{}"+ JSON.toJSONString(categoryProjectExists)); | 
			
		
	
		
			
				
					|  |  |  |                 // 父客户不存在的分类
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> categoryProjectNotExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, false); | 
			
		
	
		
			
				
					|  |  |  |                 log.info("父客户不存在的分类{}"+ JSON.toJSONString(categoryProjectNotExists)); | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     sonCustomerList.addAll(categoryProjectExists); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectNotExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     sonCustomerList.addAll(categoryProjectNotExists); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(sonCustomerList)){ | 
			
		
	
		
			
				
					|  |  |  |                     List<ScreenProjectCategoryOrgDailyEntity> finalSonResult = result; | 
			
		
	
		
			
				
					|  |  |  |                     sonCustomerList.forEach(s -> { | 
			
		
	
		
			
				
					|  |  |  |                         ScreenProjectCategoryOrgDailyEntity e = ConvertUtils.sourceToTarget(s, ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |                         e.setOrgType(ScreenConstant.STREET); | 
			
		
	
		
			
				
					|  |  |  |                         e.setDateId(dateId); | 
			
		
	
		
			
				
					|  |  |  |                         e.setPid(entity.getPid()); | 
			
		
	
		
			
				
					|  |  |  |                     e.setPids(StringUtils.isEmpty(entity.getPids()) ? NumConstant.ZERO_STR : entity.getPids()); | 
			
		
	
		
			
				
					|  |  |  |                     // 因为根据categoryCode分组,所以level都一样,取第一条的
 | 
			
		
	
		
			
				
					|  |  |  |                     e.setLevel(list.get(NumConstant.ZERO).getLevel()); | 
			
		
	
		
			
				
					|  |  |  |                     finalResult.add(e); | 
			
		
	
		
			
				
					|  |  |  |                 });*/ | 
			
		
	
		
			
				
					|  |  |  |                         e.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |                         finalSonResult.add(e); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                     result.addAll(finalSonResult); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 // 内部客户与外部客户 相同的分类累加
 | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     categoryProjectResultDTOS.forEach(f -> { | 
			
		
	
	
		
			
				
					|  |  | @ -449,22 +459,23 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                     e.setPids(StringUtils.isEmpty(entity.getPids()) ? NumConstant.ZERO_STR : entity.getPids()); | 
			
		
	
		
			
				
					|  |  |  |                     finalResult.add(e); | 
			
		
	
		
			
				
					|  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |                 log.info("组合后的数据:"+finalResult); | 
			
		
	
		
			
				
					|  |  |  |                 log.info("组合后的数据{}:"+JSON.toJSONString(finalResult)); | 
			
		
	
		
			
				
					|  |  |  |                 // 父客户存在分类,但是父客户没有使用过此分类
 | 
			
		
	
		
			
				
					|  |  |  |                 Map<Boolean, List<CategoryProjectResultDTO>> groupByStatus = categoryProjectExists.stream().collect(Collectors.groupingBy(CategoryProjectResultDTO::getStatus)); | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(groupByStatus.get(false))){ | 
			
		
	
		
			
				
					|  |  |  |                     List<ScreenProjectCategoryOrgDailyEntity> entities = ConvertUtils.sourceToTarget(groupByStatus.get(false), ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |                     entities.forEach(e -> { | 
			
		
	
		
			
				
					|  |  |  |                         e.setOrgId(entity.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                     result.addAll(entities); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 log.info("父客户存在的分类,但是未使用的分类:"+groupByStatus.get(false)); | 
			
		
	
		
			
				
					|  |  |  |                 log.info("父客户存在的分类,但是未使用的分类,组合后:"+result); | 
			
		
	
		
			
				
					|  |  |  |                 // 父客户不存在的分类
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> categoryProjectNotExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, false); | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectNotExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     List<ScreenProjectCategoryOrgDailyEntity> entities = ConvertUtils.sourceToTarget(categoryProjectNotExists, ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |                     entities.forEach(e -> { | 
			
		
	
		
			
				
					|  |  |  |                         e.setOrgId(entity.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                     result.addAll(entities); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 log.info("父客户不存在的分类:"+categoryProjectNotExists); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         // 目前不考虑计算子客户组织直接创建的项目,只算内部客户
 | 
			
		
	
	
		
			
				
					|  |  | @ -509,7 +520,7 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         log.info("插入总结果:"+result); | 
			
		
	
		
			
				
					|  |  |  |         log.info("插入总结果:{}"+JSON.toJSONString(result)); | 
			
		
	
		
			
				
					|  |  |  |         insert(result); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | 
 |