|  |  | @ -20,29 +20,39 @@ package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.StrConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.CustomerStaffRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcResiUserDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcUserChangeRecordDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcResiCategoryWarnConfigDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcUserChangeRecordDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.IcResiUserChangeRecordFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.IcUserChangeRecordInitFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.IcUsercategoryAnalysisFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.AllGridsByUserIdResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.BuildingResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.IcUserChangeRecordResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.IcUsercategoryAnalysisResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcUserChangeDetailedEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcUserChangeRecordEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.GovOrgOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.OperCustomizeOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcUserChangeDetailedService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcUserChangeRecordService; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageHelper; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageInfo; | 
			
		
	
		
			
				
					|  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.util.CollectionUtils; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import java.util.ArrayList; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Set; | 
			
		
	
		
			
				
					|  |  |  | import java.text.ParseException; | 
			
		
	
		
			
				
					|  |  |  | import java.text.SimpleDateFormat; | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  | import java.util.function.Function; | 
			
		
	
		
			
				
					|  |  |  | import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -53,9 +63,18 @@ import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  |  * @since v1.0.0 2022-01-14 | 
			
		
	
		
			
				
					|  |  |  |  */ | 
			
		
	
		
			
				
					|  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  | public class IcUserChangeRecordServiceImpl extends BaseServiceImpl<IcUserChangeRecordDao, IcUserChangeRecordEntity> implements IcUserChangeRecordService { | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private GovOrgOpenFeignClient govOrgOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcResiUserDao icResiUserDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcUserChangeRecordService icUserChangeRecordService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcUserChangeDetailedService icUserChangeDetailedService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -118,4 +137,119 @@ public class IcUserChangeRecordServiceImpl extends BaseServiceImpl<IcUserChangeR | 
			
		
	
		
			
				
					|  |  |  |         return new PageData<>(list, pageInfo.getTotal()); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 历史居民数据生成变更记录和变更明细数据 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void icUserChangeRecordInit(IcUserChangeRecordInitFormDTO formDTO) throws ParseException { | 
			
		
	
		
			
				
					|  |  |  |         //1.有客户id按客户执行,没有的按ic_resi_user表有效客户执行
 | 
			
		
	
		
			
				
					|  |  |  |         //入参有客户Id的则按客户Id执行,没有的则全部客户都执行
 | 
			
		
	
		
			
				
					|  |  |  |         if (null != formDTO && StringUtils.isNotBlank(formDTO.getCustomerId())) { | 
			
		
	
		
			
				
					|  |  |  |             initIcUserChange(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |             List<String> customerIdList = icResiUserDao.icUserCustomerIds(); | 
			
		
	
		
			
				
					|  |  |  |             for (String customerId : customerIdList) { | 
			
		
	
		
			
				
					|  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |                     //遍历统计每一个客户数据
 | 
			
		
	
		
			
				
					|  |  |  |                     initIcUserChange(customerId); | 
			
		
	
		
			
				
					|  |  |  |                 } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                     log.error("初始客户居民变更记录数据失败,对应客户Id:" + customerId, e); | 
			
		
	
		
			
				
					|  |  |  |                     log.error("Error creating model JSON", e); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 按客户初始化客户下居民的变更记录、变更明细数据 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void initIcUserChange(String customerId) throws ParseException { | 
			
		
	
		
			
				
					|  |  |  |         log.info("开始初始客户下居民的变更记录和变更明细数据,客户Id->"+customerId); | 
			
		
	
		
			
				
					|  |  |  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
			
		
	
		
			
				
					|  |  |  |         //1.获取客户居民类别预警配置表数据
 | 
			
		
	
		
			
				
					|  |  |  |         Result<List<IcResiCategoryWarnConfigDTO>> resultList = operCustomizeOpenFeignClient.categoryWarnConfigList(customerId); | 
			
		
	
		
			
				
					|  |  |  |         if (!resultList.success()) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RuntimeException("居民信息修改,获取客户居民类别预警配置表数据失败"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         List<IcUserChangeRecordEntity> changeList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         IcUserChangeRecordEntity change = null; | 
			
		
	
		
			
				
					|  |  |  |         List<IcUserChangeDetailedEntity> detailedList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         IcUserChangeDetailedEntity detailed = null; | 
			
		
	
		
			
				
					|  |  |  |         //存放工作人员姓名
 | 
			
		
	
		
			
				
					|  |  |  |         Map<String, String> hash = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         //2.分批处理客户下居民数据
 | 
			
		
	
		
			
				
					|  |  |  |         int pageNo = NumConstant.ONE; | 
			
		
	
		
			
				
					|  |  |  |         List<Map<String, String>> icUserList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         do { | 
			
		
	
		
			
				
					|  |  |  |             //一千条一循环查询客户下居民数据
 | 
			
		
	
		
			
				
					|  |  |  |             PageHelper.startPage(pageNo, NumConstant.ONE_THOUSAND); | 
			
		
	
		
			
				
					|  |  |  |             icUserList = icResiUserDao.getIcUserList(customerId); | 
			
		
	
		
			
				
					|  |  |  |             pageNo++; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             //3.遍历封装数据
 | 
			
		
	
		
			
				
					|  |  |  |             for (Map<String,String> map : icUserList){ | 
			
		
	
		
			
				
					|  |  |  |                 //存放一个人的类别为是的变更明细数据
 | 
			
		
	
		
			
				
					|  |  |  |                 List<IcUserChangeDetailedEntity> subList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                 String changeId = UUID.randomUUID().toString().replaceAll("-", ""); | 
			
		
	
		
			
				
					|  |  |  |                 for (IcResiCategoryWarnConfigDTO dto : resultList.getData()){ | 
			
		
	
		
			
				
					|  |  |  |                     if(map.containsKey(dto.getColumnName())&&"1".equals(map.get(dto.getColumnName()))){ | 
			
		
	
		
			
				
					|  |  |  |                         detailed = new IcUserChangeDetailedEntity(); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setIcUserChangeRecordId(changeId); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setPids(map.get("PIDS")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setAgencyId(map.get("AGENCY_ID")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setGridId(map.get("GRID_ID")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setNeighborHoodId(map.get("VILLAGE_ID")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setBuildingId(map.get("BUILD_ID")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setBuildingUnitId(map.get("UNIT_ID")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setHouseId(map.get("HOME_ID")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setIcUserId(map.get("HOME_ID")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setType("add"); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setTypeName("新增"); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setFieldName(dto.getColumnName()); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setValue(1); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setCreatedBy(map.get("CREATED_BY")); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setCreatedTime(sdf.parse(map.get("CREATED_TIME"))); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setUpdatedBy("APP_USER"); | 
			
		
	
		
			
				
					|  |  |  |                         detailed.setUpdatedTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |                         subList.add(detailed); | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 if (subList.size() > NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |                     detailedList.addAll(subList); | 
			
		
	
		
			
				
					|  |  |  |                     if (!hash.containsKey(map.get("CREATED_BY"))) { | 
			
		
	
		
			
				
					|  |  |  |                         CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, map.get("CREATED_BY")); | 
			
		
	
		
			
				
					|  |  |  |                         //被删除或被移除的工作人员,名字为空
 | 
			
		
	
		
			
				
					|  |  |  |                         hash.put(map.get("CREATED_BY"), null != staffInfoCache ? staffInfoCache.getRealName() : ""); | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                     change = new IcUserChangeRecordEntity(); | 
			
		
	
		
			
				
					|  |  |  |                     change.setId(changeId); | 
			
		
	
		
			
				
					|  |  |  |                     change.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |                     change.setOperatorId(map.get("CREATED_BY")); | 
			
		
	
		
			
				
					|  |  |  |                     change.setIcUserId(map.get("ID")); | 
			
		
	
		
			
				
					|  |  |  |                     change.setOperatorName(hash.get(map.get("CREATED_BY"))); | 
			
		
	
		
			
				
					|  |  |  |                     change.setIcUserName(map.get("NAME")); | 
			
		
	
		
			
				
					|  |  |  |                     change.setType("add"); | 
			
		
	
		
			
				
					|  |  |  |                     change.setTypeName("新增"); | 
			
		
	
		
			
				
					|  |  |  |                     change.setBeforeChangeName("-"); | 
			
		
	
		
			
				
					|  |  |  |                     change.setAfterChangeName("-"); | 
			
		
	
		
			
				
					|  |  |  |                     change.setChangeTime(sdf.parse(map.get("CREATED_TIME"))); | 
			
		
	
		
			
				
					|  |  |  |                     change.setCreatedBy(map.get("CREATED_BY")); | 
			
		
	
		
			
				
					|  |  |  |                     change.setCreatedTime(sdf.parse(map.get("CREATED_TIME"))); | 
			
		
	
		
			
				
					|  |  |  |                     change.setUpdatedBy("APP_USER"); | 
			
		
	
		
			
				
					|  |  |  |                     change.setUpdatedTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |                     changeList.add(change); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } while (icUserList.size() == NumConstant.ONE_THOUSAND); | 
			
		
	
		
			
				
					|  |  |  |         //4.批量新增数据,先删后增【只删除新增节点的历史数据】
 | 
			
		
	
		
			
				
					|  |  |  |         baseDao.delByCustomerId(customerId, "add"); | 
			
		
	
		
			
				
					|  |  |  |         icUserChangeDetailedService.delByCustomerId(customerId, "add"); | 
			
		
	
		
			
				
					|  |  |  |         icUserChangeRecordService.insertBatch(changeList); | 
			
		
	
		
			
				
					|  |  |  |         icUserChangeDetailedService.insertBatch(detailedList); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } |