|  |  | @ -36,6 +36,7 @@ import com.epmet.dto.screen.ScreenProjectCategoryOrgDailyDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.screen.result.CategoryProjectResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.screencoll.ScreenCollFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.crm.CustomerRelationEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.evaluationindex.screen.ScreenProjectCategoryOrgDailyEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.crm.CustomerRelationService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.evaluationindex.extract.todata.FactOriginProjectCategoryDailyService; | 
			
		
	
	
		
			
				
					|  |  | @ -179,6 +180,12 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |              * 1.查自己客户分类标签统计 | 
			
		
	
		
			
				
					|  |  |  |              * 2.查询子级客户分类标签【分为 epmet_category_code is null 和 is not null】,pid = '0',跟父客户对比,同类标签项目数累加,不同直接添加到父客户 | 
			
		
	
		
			
				
					|  |  |  |              * 注:加入直属网格 | 
			
		
	
		
			
				
					|  |  |  |              * | 
			
		
	
		
			
				
					|  |  |  |              * 2021-05-21新注释 | 
			
		
	
		
			
				
					|  |  |  |              * 1.查询客户自己的分类标签 | 
			
		
	
		
			
				
					|  |  |  |              * 2.查询子客户的分类标签,把子客户分类标签一样的累加 | 
			
		
	
		
			
				
					|  |  |  |              * 3.子客户累加后的跟父客户对比 categoryCode,一样累加到父客户,不一样直接添加到父客户,agencyId一并改为父客户的 | 
			
		
	
		
			
				
					|  |  |  |              * 4.父客户数据处理好,在存储一套子客户数据 | 
			
		
	
		
			
				
					|  |  |  |              */ | 
			
		
	
		
			
				
					|  |  |  |             disposeMoreCustomer(customerId,dateId,relationInfo); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
	
		
			
				
					|  |  | @ -254,16 +261,19 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                     Map<Boolean, List<CategoryProjectResultDTO>> groupByStatus = categoryProjectGrid.stream().collect(Collectors.groupingBy(CategoryProjectResultDTO::getStatus)); | 
			
		
	
		
			
				
					|  |  |  |                     List<CategoryProjectResultDTO> categoryProjectResultDTOS1 = groupByStatus.get(false); | 
			
		
	
		
			
				
					|  |  |  |                     if (!CollectionUtils.isEmpty(categoryProjectResultDTOS1)) categoryProjectResultDTOS.addAll(categoryProjectResultDTOS1); | 
			
		
	
		
			
				
					|  |  |  |                     if (!CollectionUtils.isEmpty(categoryProjectResultDTOS1)) { | 
			
		
	
		
			
				
					|  |  |  |                         categoryProjectResultDTOS.addAll(categoryProjectResultDTOS1); | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             result = ConvertUtils.sourceToTarget(categoryProjectResultDTOS,ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         // 组织项目分类 项目数
 | 
			
		
	
		
			
				
					|  |  |  |         List<String> orgIds = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<CustomerAgencyInfoResultDTO>> groupByLevel = agencyIdList.stream().collect(Collectors.groupingBy(CustomerAgencyInfoResultDTO::getLevel)); | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerAgencyInfoResultDTO> levelAgencyInfo = groupByLevel.get(level); | 
			
		
	
		
			
				
					|  |  |  |         if (!CollectionUtils.isEmpty(levelAgencyInfo)){ | 
			
		
	
		
			
				
					|  |  |  |             List<String> orgIds = levelAgencyInfo.stream().map(m -> m.getAgencyId()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |             orgIds = levelAgencyInfo.stream().map(m -> m.getAgencyId()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |             List<ScreenProjectCategoryGridDailyDTO> screenProjectCategory = factOriginProjectCategoryDailyService.selectListProjectCategoryByOrg(orgIds,customerId); | 
			
		
	
		
			
				
					|  |  |  |             if (!CollectionUtils.isEmpty(result)){ | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(screenProjectCategory)){ | 
			
		
	
	
		
			
				
					|  |  | @ -291,7 +301,7 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                 result.forEach(r -> {r.setOrgType(level);r.setDateId(dateId);}); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         deleteAndInsert(customerId,dateId,result); | 
			
		
	
		
			
				
					|  |  |  |         deleteAndInsert(customerId,dateId,result,orgIds); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -349,15 +359,18 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                 result = ConvertUtils.sourceToTarget(categoryInfos, ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         }else { | 
			
		
	
		
			
				
					|  |  |  |             // 根据客户ID,时间,组织级别查询 分类标签
 | 
			
		
	
		
			
				
					|  |  |  |             List<CategoryProjectResultDTO> categoryProjectResultDTOS = baseDao.selectOrgCategoryInfo(customerId, dateId, level); | 
			
		
	
		
			
				
					|  |  |  |             List<ScreenCustomerGridDTO> belongGridInfos = gridService.selectBelongGridInfo(customerId, level); | 
			
		
	
		
			
				
					|  |  |  |             if (!CollectionUtils.isEmpty(belongGridInfos)){ | 
			
		
	
		
			
				
					|  |  |  |                 // 存在直属网格
 | 
			
		
	
		
			
				
					|  |  |  |                 List<String> gridIds = belongGridInfos.stream().map(m -> m.getGridId()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |                 // 根据网格ID查询分类标签
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> categoryProjectGrid = gridDailyDao.selectCategoryInfo(customerId, dateId, level, gridIds); | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectGrid)){ | 
			
		
	
		
			
				
					|  |  |  |                     categoryProjectResultDTOS.forEach(agency -> { | 
			
		
	
		
			
				
					|  |  |  |                         categoryProjectGrid.forEach(grid -> { | 
			
		
	
		
			
				
					|  |  |  |                             // 组织ID 和 分类标签code一样时,项目数累加
 | 
			
		
	
		
			
				
					|  |  |  |                             if (agency.getOrgId().equals(grid.getOrgId()) && agency.getCategoryCode().equals(grid.getCategoryCode())){ | 
			
		
	
		
			
				
					|  |  |  |                                 agency.setProjectTotal(agency.getProjectTotal() + grid.getProjectTotal()); | 
			
		
	
		
			
				
					|  |  |  |                                 grid.setStatus(true); | 
			
		
	
	
		
			
				
					|  |  | @ -365,17 +378,57 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                     Map<Boolean, List<CategoryProjectResultDTO>> groupByStatus = categoryProjectGrid.stream().collect(Collectors.groupingBy(CategoryProjectResultDTO::getStatus)); | 
			
		
	
		
			
				
					|  |  |  |                     // 取出分类标签code同agency级别不一样的数据
 | 
			
		
	
		
			
				
					|  |  |  |                     List<CategoryProjectResultDTO> categoryProjectResultDTOS1 = groupByStatus.get(false); | 
			
		
	
		
			
				
					|  |  |  |                     categoryProjectResultDTOS.addAll(categoryProjectResultDTOS1); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             result = ConvertUtils.sourceToTarget(categoryProjectResultDTOS,ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |             /** | 
			
		
	
		
			
				
					|  |  |  |              * 查询父子客户所有的分类,根据分类分组,然后把agencyId统一换成父客户的 | 
			
		
	
		
			
				
					|  |  |  |              * 在保存一份子客户自己agencyId的 | 
			
		
	
		
			
				
					|  |  |  |              */ | 
			
		
	
		
			
				
					|  |  |  |             if (ScreenConstant.DISTRICT.equals(level)){ | 
			
		
	
		
			
				
					|  |  |  |                 // 查询 平阴的agencyId
 | 
			
		
	
		
			
				
					|  |  |  |                 ScreenCustomerAgencyEntity entity = agencyService.selectTopAgency(customerId); | 
			
		
	
		
			
				
					|  |  |  |                 // 子级客户ID
 | 
			
		
	
		
			
				
					|  |  |  |                 List<String> customerIds = relationInfo.stream().map(m -> m.getCustomerId()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |                 // 父客户存在的分类
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> categoryProjectExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, true); | 
			
		
	
		
			
				
					|  |  |  |                 // 父客户不存在的分类
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> categoryProjectNotExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, false); | 
			
		
	
		
			
				
					|  |  |  |                 // 子级客户的分类标签数据
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> sonResult = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     categoryProjectResultDTOS.addAll(categoryProjectExists); | 
			
		
	
		
			
				
					|  |  |  |                     sonResult.addAll(categoryProjectExists); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectNotExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     categoryProjectResultDTOS.addAll(categoryProjectNotExists); | 
			
		
	
		
			
				
					|  |  |  |                     sonResult.addAll(categoryProjectNotExists); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 // 此时的 'categoryProjectResultDTOS' 等于 父子客户所有的分类标签
 | 
			
		
	
		
			
				
					|  |  |  |                 Map<String, List<CategoryProjectResultDTO>> groupByCategoryCode = categoryProjectResultDTOS.stream().collect(Collectors.groupingBy(CategoryProjectResultDTO::getCategoryCode)); | 
			
		
	
		
			
				
					|  |  |  |                 // 这时的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.setCategoryCode(code); | 
			
		
	
		
			
				
					|  |  |  |                     e.setOrgId(entity.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |                     e.setProjectTotal(CollectionUtils.isEmpty(list) ? NumConstant.ZERO : list.stream().collect(Collectors.summingInt(CategoryProjectResultDTO::getProjectTotal))); | 
			
		
	
		
			
				
					|  |  |  |                     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); | 
			
		
	
		
			
				
					|  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(sonResult)){ | 
			
		
	
		
			
				
					|  |  |  |                     List<ScreenProjectCategoryOrgDailyEntity> entities = ConvertUtils.sourceToTarget(sonResult, ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |                     result.addAll(entities); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 /*if (!CollectionUtils.isEmpty(categoryProjectExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     result.forEach(r -> { | 
			
		
	
		
			
				
					|  |  |  |                         categoryProjectExists.forEach(c -> { | 
			
		
	
		
			
				
					|  |  |  |                             if (r.getCategoryCode().equals(c.getCategoryCode())){ | 
			
		
	
	
		
			
				
					|  |  | @ -391,19 +444,19 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                         result.addAll(f); | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 // 父客户不存在的分类
 | 
			
		
	
		
			
				
					|  |  |  |                 List<CategoryProjectResultDTO> categoryProjectNotExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, false); | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(categoryProjectNotExists)){ | 
			
		
	
		
			
				
					|  |  |  |                     List<ScreenProjectCategoryOrgDailyEntity> notExists = ConvertUtils.sourceToTarget(categoryProjectNotExists, ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  |                     result.addAll(notExists); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 }*/ | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         // 目前不考虑计算子客户组织直接创建的项目,只算内部客户
 | 
			
		
	
		
			
				
					|  |  |  |         List<String> orgIds = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<CustomerAgencyInfoResultDTO>> groupByLevel = agencyIdList.stream().collect(Collectors.groupingBy(CustomerAgencyInfoResultDTO::getLevel)); | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerAgencyInfoResultDTO> levelAgencyInfo = groupByLevel.get(level); | 
			
		
	
		
			
				
					|  |  |  |         if (!CollectionUtils.isEmpty(levelAgencyInfo)) { | 
			
		
	
		
			
				
					|  |  |  |             List<String> orgIds = levelAgencyInfo.stream().map(m -> m.getAgencyId()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |             orgIds = levelAgencyInfo.stream().map(m -> m.getAgencyId()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |             // 查询客户下,组织直接立项的,各项目分类下的项目数量【筛选组织创建的项目,fact_origin_project_main_daily表gridId为空】
 | 
			
		
	
		
			
				
					|  |  |  |             List<ScreenProjectCategoryGridDailyDTO> screenProjectCategory = factOriginProjectCategoryDailyService.selectListProjectCategoryByOrg(orgIds, customerId); | 
			
		
	
		
			
				
					|  |  |  |             if (!CollectionUtils.isEmpty(result)) { | 
			
		
	
		
			
				
					|  |  |  |                 if (!CollectionUtils.isEmpty(screenProjectCategory)) { | 
			
		
	
	
		
			
				
					|  |  | @ -416,6 +469,7 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                     Map<Boolean, List<ScreenProjectCategoryGridDailyDTO>> groupByStatus = screenProjectCategory.stream().collect(Collectors.groupingBy(ScreenProjectCategoryGridDailyDTO::getStatus)); | 
			
		
	
		
			
				
					|  |  |  |                     // 取出没有累加过的数据
 | 
			
		
	
		
			
				
					|  |  |  |                     List<ScreenProjectCategoryGridDailyDTO> screenProjectCategoryNoCal = groupByStatus.get(false); | 
			
		
	
		
			
				
					|  |  |  |                     if (!CollectionUtils.isEmpty(screenProjectCategoryNoCal)) { | 
			
		
	
		
			
				
					|  |  |  |                         List<ScreenProjectCategoryOrgDailyEntity> noCalCategory = ConvertUtils.sourceToTarget(screenProjectCategoryNoCal, ScreenProjectCategoryOrgDailyEntity.class); | 
			
		
	
	
		
			
				
					|  |  | @ -434,7 +488,7 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         deleteAndInsert(customerId,dateId,result); | 
			
		
	
		
			
				
					|  |  |  |         deleteAndInsert(customerId,dateId,result,orgIds); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -445,13 +499,16 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc | 
			
		
	
		
			
				
					|  |  |  |      * @date 2021/3/23 上午10:52 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void deleteAndInsert(String customerId, String dateId, List<ScreenProjectCategoryOrgDailyEntity> needInsert){ | 
			
		
	
		
			
				
					|  |  |  |     public void deleteAndInsert(String customerId, String dateId, List<ScreenProjectCategoryOrgDailyEntity> needInsert,List<String> orgIds){ | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(needInsert)){ | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(orgIds)){ | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         Integer row = NumConstant.ZERO; | 
			
		
	
		
			
				
					|  |  |  |         do { | 
			
		
	
		
			
				
					|  |  |  |             row = baseDao.deleteByDateIdAndCustomerId(customerId, dateId); | 
			
		
	
		
			
				
					|  |  |  |             row = baseDao.deleteAppointData(customerId, dateId,orgIds); | 
			
		
	
		
			
				
					|  |  |  |         }while (row > NumConstant.ZERO && row == NumConstant.ONE_THOUSAND); | 
			
		
	
		
			
				
					|  |  |  |         List<List<ScreenProjectCategoryOrgDailyEntity>> partition = ListUtils.partition(needInsert, NumConstant.ONE_HUNDRED); | 
			
		
	
		
			
				
					|  |  |  |         partition.forEach(p -> { | 
			
		
	
	
		
			
				
					|  |  | 
 |