|  |  | @ -17,6 +17,7 @@ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.StrConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; | 
			
		
	
	
		
			
				
					|  |  | @ -39,14 +40,11 @@ import com.epmet.dto.CustomerStaffDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.CustomerStaffDepartmentDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.CustomerAgencyEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.CustomerDepartmentEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.CustomerStaffDepartmentEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetHeartOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetUserFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetUserOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.CustomerDepartmentService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.CustomerStaffDepartmentService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.DepartmentService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.util.ModuleConstant; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.slf4j.Logger; | 
			
		
	
	
		
			
				
					|  |  | @ -55,6 +53,7 @@ import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.util.CollectionUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import java.util.ArrayList; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
	
		
			
				
					|  |  | @ -86,6 +85,15 @@ public class DepartmentServiceImpl implements DepartmentService { | 
			
		
	
		
			
				
					|  |  |  |     private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private StaffOrgRelationDao staffOrgRelationDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private CustomerStaffAgencyService customerStaffAgencyService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private CustomerAgencyService customerAgencyService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private StaffOrgRelationService staffOrgRelationService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private EpmetHeartOpenFeignClient epmetHeartOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @param formDTO | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
	
		
			
				
					|  |  | @ -294,6 +302,13 @@ public class DepartmentServiceImpl implements DepartmentService { | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public CheckStaffInfoResultDTO checkStaffInfo(CheckStaffInfoFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         CheckStaffInfoResultDTO resultDTO = new CheckStaffInfoResultDTO(); | 
			
		
	
		
			
				
					|  |  |  |         resultDTO.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         resultDTO.setUserId(formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         //座机号的直接返回
 | 
			
		
	
		
			
				
					|  |  |  |         if(formDTO.getMobile().startsWith("0")){ | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setMsg("座机账号无法创建账号,建议使用填写手机号,否则将无法获取通知信息"); | 
			
		
	
		
			
				
					|  |  |  |             return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //1.根据手机号查询客户下工作人员信息
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffFormDTO user = new CustomerStaffFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |         user.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
	
		
			
				
					|  |  | @ -314,29 +329,29 @@ public class DepartmentServiceImpl implements DepartmentService { | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(list)) { | 
			
		
	
		
			
				
					|  |  |  |             return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         resultDTO.setOrgId(list.get(0).getOrgId()); | 
			
		
	
		
			
				
					|  |  |  |         resultDTO.setOrgType(list.get(0).getOrgType()); | 
			
		
	
		
			
				
					|  |  |  |         resultDTO.setStaffId(list.get(0).getStaffId()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //3.校验工作人员的注册关系【从哪里新增进来的工作人员】
 | 
			
		
	
		
			
				
					|  |  |  |         //获取当前操作人员缓存信息
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getStaffId()); | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == staffInfo) { | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getStaffId())); | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getUserId())); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //所属组织信息不同的给提示【所属组织不同时则不新增部门、不新增工作人员】
 | 
			
		
	
		
			
				
					|  |  |  |         if (!list.get(0).getAgencyId().equals(staffInfo.getAgencyId())) { | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setMsg("联系电话已存在其他组织工作账号中,请使用其他手机号,否则将无法获取通知信息"); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setKey(false); | 
			
		
	
		
			
				
					|  |  |  |             return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //从网格下添加的人给提示【网格下加的人时则不新增部门、不新增工作人员】
 | 
			
		
	
		
			
				
					|  |  |  |         if ("gridId".equals(list.get(0).getOrgType())) { | 
			
		
	
		
			
				
					|  |  |  |         if (!"agency".equals(list.get(0).getOrgType())) { | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setMsg("联系电话已存在其他部门工作账号中,请先将该工作人员调动至本组织下,再次添加"); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setKey(false); | 
			
		
	
		
			
				
					|  |  |  |             return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //账号被禁用的给提示【人员被禁用的则不新增部门、不新增工作人员】
 | 
			
		
	
		
			
				
					|  |  |  |         if ("disabled".equals(userResult.getData().getEnableFlag())) { | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setMsg("该工作人员账号已被禁用,请使用其他联系电话,否则将无法获取通知信息"); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setKey(false); | 
			
		
	
		
			
				
					|  |  |  |             return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //姓名不一样的给反馈
 | 
			
		
	
	
		
			
				
					|  |  | @ -348,5 +363,116 @@ public class DepartmentServiceImpl implements DepartmentService { | 
			
		
	
		
			
				
					|  |  |  |         return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public CheckStaffInfoResultDTO addOrEditDeptOrStaff(CheckStaffInfoFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == staffInfo) { | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getUserId())); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //1.校验当前数据是否允许操作
 | 
			
		
	
		
			
				
					|  |  |  |         CheckStaffInfoResultDTO resultDTO = checkStaffInfo(formDTO); | 
			
		
	
		
			
				
					|  |  |  |         if(!resultDTO.getType()){ | 
			
		
	
		
			
				
					|  |  |  |             return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //2.根据校验结果操作数据
 | 
			
		
	
		
			
				
					|  |  |  |         //2-1.没查到人的直接新增部门、人员
 | 
			
		
	
		
			
				
					|  |  |  |         if(StringUtils.isBlank(resultDTO.getOrgType())){ | 
			
		
	
		
			
				
					|  |  |  |             //一、新增工作人员
 | 
			
		
	
		
			
				
					|  |  |  |             StaffSubmitFromDTO submitDTO = ConvertUtils.sourceToTarget(formDTO, StaffSubmitFromDTO.class); | 
			
		
	
		
			
				
					|  |  |  |             submitDTO.setName(formDTO.getPersonName()); | 
			
		
	
		
			
				
					|  |  |  |             submitDTO.setAgencyId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             submitDTO.setGender(0); | 
			
		
	
		
			
				
					|  |  |  |             submitDTO.setWorkType("fulltime"); | 
			
		
	
		
			
				
					|  |  |  |             Result<CustomerStaffDTO> staffResult = epmetUserOpenFeignClient.deptToAddStaff(submitDTO); | 
			
		
	
		
			
				
					|  |  |  |             if (!staffResult.success()) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("人员添加失败" + staffResult.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             //二、新增部门
 | 
			
		
	
		
			
				
					|  |  |  |             AddDepartmentFormDTO deptDTO = new AddDepartmentFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setAgencyId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setDepartmentDuty(""); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setDepartmentName(formDTO.getDeptName()); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setTotalUser(1); | 
			
		
	
		
			
				
					|  |  |  |             Result<AddDepartmentResultDTO> deptResult = addDepartment(deptDTO); | 
			
		
	
		
			
				
					|  |  |  |             //三、新增组织人员关系数据
 | 
			
		
	
		
			
				
					|  |  |  |             //人员机关关系表
 | 
			
		
	
		
			
				
					|  |  |  |             CustomerStaffAgencyEntity customerStaffAgencyEntity = new CustomerStaffAgencyEntity(); | 
			
		
	
		
			
				
					|  |  |  |             customerStaffAgencyEntity.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             customerStaffAgencyEntity.setUserId(staffResult.getData().getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             customerStaffAgencyEntity.setAgencyId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             customerStaffAgencyService.insert(customerStaffAgencyEntity); | 
			
		
	
		
			
				
					|  |  |  |             //机关总人数加一
 | 
			
		
	
		
			
				
					|  |  |  |             OrgResultDTO orgDTO = customerAgencyDao.selectAgencyDetail(staffInfo.getAgencyId(), "agency"); | 
			
		
	
		
			
				
					|  |  |  |             CustomerAgencyEntity agencyEntity = new CustomerAgencyEntity(); | 
			
		
	
		
			
				
					|  |  |  |             agencyEntity.setId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             agencyEntity.setTotalUser(orgDTO.getTotalUser() + 1); | 
			
		
	
		
			
				
					|  |  |  |             customerAgencyService.updateById(agencyEntity); | 
			
		
	
		
			
				
					|  |  |  |             //工作人员注册组织关系表新增数据
 | 
			
		
	
		
			
				
					|  |  |  |             StaffOrgRelationEntity staffOrgRelationEntity = new StaffOrgRelationEntity(); | 
			
		
	
		
			
				
					|  |  |  |             staffOrgRelationEntity.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             staffOrgRelationEntity.setPids(("".equals(orgDTO.getPids()) ? "" : orgDTO.getPids())); | 
			
		
	
		
			
				
					|  |  |  |             staffOrgRelationEntity.setStaffId(staffResult.getData().getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             staffOrgRelationEntity.setOrgId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             staffOrgRelationEntity.setOrgType("agency"); | 
			
		
	
		
			
				
					|  |  |  |             staffOrgRelationService.insert(staffOrgRelationEntity); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             //四、部门下新增人员关系数据
 | 
			
		
	
		
			
				
					|  |  |  |             CustomerStaffDepartmentEntity dept = new CustomerStaffDepartmentEntity(); | 
			
		
	
		
			
				
					|  |  |  |             dept.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             dept.setUserId(staffResult.getData().getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             dept.setDepartmentId(deptResult.getData().getDepartmentId()); | 
			
		
	
		
			
				
					|  |  |  |             customerStaffDepartmentService.insert(dept); | 
			
		
	
		
			
				
					|  |  |  |             //修改联建单位/社会自组织业务数据
 | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setId(formDTO.getId()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setDeptId(deptResult.getData().getDepartmentId()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setDeptType(formDTO.getDeptType()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setDeptStaffId(staffResult.getData().getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setSyncType("sync"); | 
			
		
	
		
			
				
					|  |  |  |             Result heartResult = epmetHeartOpenFeignClient.editPartyOrCommunity(resultDTO); | 
			
		
	
		
			
				
					|  |  |  |             if (!heartResult.success()) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("修改联建单位/社会自组织业务数据失败" + heartResult.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //2-2.查到是组织下的人,新增部门,绑定部门人员关系
 | 
			
		
	
		
			
				
					|  |  |  |         if(("agency".equals(resultDTO.getOrgType()))){ | 
			
		
	
		
			
				
					|  |  |  |             //一、更新人员基础数据[姓名 手机号信息]
 | 
			
		
	
		
			
				
					|  |  |  |             CustomerStaffDTO staffDTO = new CustomerStaffDTO(); | 
			
		
	
		
			
				
					|  |  |  |             staffDTO.setUserId(resultDTO.getStaffId()); | 
			
		
	
		
			
				
					|  |  |  |             staffDTO.setRealName(formDTO.getPersonName()); | 
			
		
	
		
			
				
					|  |  |  |             staffDTO.setMobile(formDTO.getMobile()); | 
			
		
	
		
			
				
					|  |  |  |             staffDTO.setUpdatedBy(resultDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             Result result = epmetUserOpenFeignClient.editToStaff(staffDTO); | 
			
		
	
		
			
				
					|  |  |  |             if (!result.success()) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("更新工作人员基础信息失败" + result.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             //二、新增部门数据
 | 
			
		
	
		
			
				
					|  |  |  |             AddDepartmentFormDTO deptDTO = new AddDepartmentFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setAgencyId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setDepartmentDuty(""); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setDepartmentName(formDTO.getDeptName()); | 
			
		
	
		
			
				
					|  |  |  |             deptDTO.setTotalUser(1); | 
			
		
	
		
			
				
					|  |  |  |             Result<AddDepartmentResultDTO> deptResult = addDepartment(deptDTO); | 
			
		
	
		
			
				
					|  |  |  |             //三、部门下新增人员关系数据
 | 
			
		
	
		
			
				
					|  |  |  |             CustomerStaffDepartmentEntity dept = new CustomerStaffDepartmentEntity(); | 
			
		
	
		
			
				
					|  |  |  |             dept.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             dept.setUserId(resultDTO.getStaffId()); | 
			
		
	
		
			
				
					|  |  |  |             dept.setDepartmentId(deptResult.getData().getDepartmentId()); | 
			
		
	
		
			
				
					|  |  |  |             customerStaffDepartmentService.insert(dept); | 
			
		
	
		
			
				
					|  |  |  |             //修改联建单位/社会自组织业务数据
 | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setId(formDTO.getId()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setDeptId(deptResult.getData().getDepartmentId()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setDeptType(formDTO.getDeptType()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setDeptStaffId(resultDTO.getStaffId()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setSyncType("sync"); | 
			
		
	
		
			
				
					|  |  |  |             Result heartResult = epmetHeartOpenFeignClient.editPartyOrCommunity(resultDTO); | 
			
		
	
		
			
				
					|  |  |  |             if (!heartResult.success()) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("修改联建单位/社会自组织业务数据失败" + heartResult.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } |