| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -18,6 +18,7 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					package com.epmet.service.impl; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import cn.hutool.core.bean.BeanUtil; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.alibaba.fastjson.JSON; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -28,12 +29,14 @@ import com.epmet.commons.tools.constant.NumConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.constant.StrConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.dto.result.OptionResultDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.enums.DictTypeEnum; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.enums.OrgTypeEnum; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.exception.EpmetErrorCode; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.exception.EpmetException; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.exception.RenException; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.page.PageData; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.redis.RedisKeys; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.redis.RedisUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.redis.common.CustomerOrgRedis; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.redis.common.CustomerStaffRedis; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.security.dto.TokenDto; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.ConvertUtils; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -41,10 +44,13 @@ import com.epmet.commons.tools.utils.Result; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.constant.CustomerGridConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dao.CustomerGridDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dao.CustomerStaffGridDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dao.StaffOrgRelationDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.*; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.*; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.result.*; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.entity.CustomerGridEntity; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.entity.CustomerStaffGridEntity; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.entity.StaffOrgRelationEntity; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.feign.*; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.resi.partymember.feign.ResiPartyMemberOpenFeignClient; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.service.CustomerAgencyService; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -86,6 +92,8 @@ public class CustomerGridServiceImpl extends BaseServiceImpl<CustomerGridDao, Cu | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private CustomerGridDao customerGridDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private StaffOrgRelationDao staffOrgRelationDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private RedisUtils redisUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private EpmetAdminOpenFeignClient adminOpenFeignClient; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -983,7 +991,7 @@ public class CustomerGridServiceImpl extends BaseServiceImpl<CustomerGridDao, Cu | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //可以弃用、处理数据 todo
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // ....
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // ....
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.abandonGridForDealBizData(formDTO.getGridId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //处理成功,隐藏网格
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        LambdaUpdateWrapper<CustomerGridEntity> updateGrid=new LambdaUpdateWrapper<>(); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -992,4 +1000,60 @@ public class CustomerGridServiceImpl extends BaseServiceImpl<CustomerGridDao, Cu | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        baseDao.update(null,updateGrid); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Override | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void abandonGridForDealBizData(String gridId) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        try { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //根据网格id 获取网格内工作人员及其添加关系
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            List<StaffOrgRelationDTO> staffList = customerStaffGridDao.getGridStaffList(gridId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (CollectionUtils.isEmpty(staffList)){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                log.info("abandonGridForDealBizData gridId:{} have any staff", gridId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                return; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.debug("abandonGridForDealBizData staffList:{}", JSON.toJSONString(staffList)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            List<StaffOrgRelationEntity> updateList = new ArrayList<>(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            staffList.forEach(staffOrg->{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if(OrgTypeEnum.GRID.getCode().equals(staffOrg.getOrgType())){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    StaffOrgRelationEntity entity = new StaffOrgRelationEntity(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    entity.setId(staffOrg.getId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    entity.setOrgType(OrgTypeEnum.AGENCY.getCode()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    String pid = CustomerOrgRedis.getGridInfo(staffOrg.getStaffId()).getPid(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if (StringUtils.isBlank(pid)){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        log.error("abandonGridForDealBizData agencyId:{} is not exist",pid); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        return; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    entity.setOrgId(pid); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    updateList.add(entity); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //更新工作人员组织关系
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String customerId = staffList.get(NumConstant.ZERO).getCustomerId(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            updateGridStaff2Agency(customerId,gridId, staffList, updateList); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //清空工作人员缓存
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            staffList.forEach(staff->CustomerStaffRedis.delStaffInfoFormCache(customerId,staff.getStaffId())); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } catch (Exception e) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            log.error("abandonGridForDealBizData exception", e); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            throw e; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Transactional | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void updateGridStaff2Agency(String customerId, String gridId, List<StaffOrgRelationDTO> staffList, List<StaffOrgRelationEntity> updateList) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //1.删除工作人员与网格的关系
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        LambdaQueryWrapper<CustomerStaffGridEntity> updateWrapper = new LambdaQueryWrapper<>(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        updateWrapper.eq(CustomerStaffGridEntity::getGridId,gridId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        customerStaffGridDao.delete(updateWrapper); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //2.修改 网格内添加工作人员改为组织
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        updateList.forEach(e->{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            staffOrgRelationDao.update(e,null); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //网格对应的人数减少
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        long reduceCount = NumConstant.ZERO - staffList.stream().map(StaffOrgRelationDTO::getStaffId).distinct().count(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        log.debug("updateGridStaff2Agency gridId:{} reduceCount:{}",gridId, reduceCount); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        int effectRow = customerGridDao.updateTotalUser(gridId, reduceCount); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        Result<Integer> badgeResult = epmetUserFeignClient.deleteBadgeCertificateAuditing(customerId,gridId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (badgeResult == null || !badgeResult.success()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"删除未审核徽章失败,请稍后重试"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |