|  |  | @ -24,10 +24,12 @@ import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.constant.CustomerAgencyConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.CustomerAgencyDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.CustomerAgencyDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.CustomerAgencyEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.AgencyService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.CustomerAgencyService; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.slf4j.Logger; | 
			
		
	
		
			
				
					|  |  |  | import org.slf4j.LoggerFactory; | 
			
		
	
	
		
			
				
					|  |  | @ -35,8 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import java.util.Arrays; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | /** | 
			
		
	
		
			
				
					|  |  |  |  * 机关单位信息 | 
			
		
	
	
		
			
				
					|  |  | @ -49,6 +50,8 @@ public class AgencyServiceImpl implements AgencyService { | 
			
		
	
		
			
				
					|  |  |  |     private static final Logger log = LoggerFactory.getLogger(AgencyServiceImpl.class); | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private CustomerAgencyDao customerAgencyDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private CustomerAgencyService customerAgencyService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @param formDTO | 
			
		
	
	
		
			
				
					|  |  | @ -103,10 +106,46 @@ public class AgencyServiceImpl implements AgencyService { | 
			
		
	
		
			
				
					|  |  |  |         CustomerAgencyEntity entity = new CustomerAgencyEntity(); | 
			
		
	
		
			
				
					|  |  |  |         entity.setId(formDTO.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setOrganizationName(formDTO.getAgencyName()); | 
			
		
	
		
			
				
					|  |  |  |         //1:更新当前组织信息
 | 
			
		
	
		
			
				
					|  |  |  |         if (customerAgencyDao.updateById(entity) < NumConstant.ONE) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(CustomerAgencyConstant.UPDATE_EXCEPTION); | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(CustomerAgencyConstant.UPDATE_EXCEPTION); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //2:查询当前组织的所有下级组织列表(查询pids字段值包含该组织id的数据)
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerAgencyDTO agencyDTO = new CustomerAgencyDTO(); | 
			
		
	
		
			
				
					|  |  |  |         agencyDTO.setPids(formDTO.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerAgencyDTO> agencyList = customerAgencyDao.selectFindList(agencyDTO); | 
			
		
	
		
			
				
					|  |  |  |         if (null == agencyList || agencyList.size() < NumConstant.ONE) { | 
			
		
	
		
			
				
					|  |  |  |             return result; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //3:循环组织列表,查询每一个组织的所有上级组织重新拼接所有上级名称(allParentName)字段值
 | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerAgencyEntity> editList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         Date date = new Date(); | 
			
		
	
		
			
				
					|  |  |  |         agencyList.forEach(agency->{ | 
			
		
	
		
			
				
					|  |  |  |             CustomerAgencyEntity customerAgencyEntity = new CustomerAgencyEntity(); | 
			
		
	
		
			
				
					|  |  |  |             //3-1:查询当前组织的所有上级组织
 | 
			
		
	
		
			
				
					|  |  |  |             List<String> listStr = Arrays.asList(agency.getPids().split(":")); | 
			
		
	
		
			
				
					|  |  |  |             List<ParentListResultDTO> parentList = customerAgencyDao.selectPAgencyById(listStr); | 
			
		
	
		
			
				
					|  |  |  |             //3-2:重新拼接当前组织的所有上级名称字段值,将组织Id和拼好的值存入集合
 | 
			
		
	
		
			
				
					|  |  |  |             StringBuffer allParentName = new StringBuffer(); | 
			
		
	
		
			
				
					|  |  |  |             parentList.forEach(parents->{ | 
			
		
	
		
			
				
					|  |  |  |                 if(StringUtils.isBlank(allParentName)){ | 
			
		
	
		
			
				
					|  |  |  |                     allParentName.append(parents.getName()); | 
			
		
	
		
			
				
					|  |  |  |                 }else { | 
			
		
	
		
			
				
					|  |  |  |                     allParentName.append("-").append(parents.getName()); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |             customerAgencyEntity.setId(agency.getId()); | 
			
		
	
		
			
				
					|  |  |  |             customerAgencyEntity.setAllParentName(allParentName.toString()); | 
			
		
	
		
			
				
					|  |  |  |             customerAgencyEntity.setUpdatedBy(formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             customerAgencyEntity.setUpdatedTime(date); | 
			
		
	
		
			
				
					|  |  |  |             editList.add(customerAgencyEntity); | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |         //4:批量更新因一个组织名称变动而引起的其他组织字段值的变动
 | 
			
		
	
		
			
				
					|  |  |  |         if (!customerAgencyService.updateBatchById(editList)) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(CustomerAgencyConstant.UPDATE_EXCEPTION); | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(CustomerAgencyConstant.UPDATE_EXCEPTION); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return result; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -151,9 +190,11 @@ public class AgencyServiceImpl implements AgencyService { | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public Result<AgencysResultDTO> agencyDetail(AgencydetailFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         AgencysResultDTO agencysResultDTO = new AgencysResultDTO(); | 
			
		
	
		
			
				
					|  |  |  |         List<ParentListResultDTO> parentList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         //1:查询本机关详细信息
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerAgencyEntity entity = customerAgencyDao.selectById(formDTO.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == entity) { | 
			
		
	
		
			
				
					|  |  |  |             agencysResultDTO.setParentList(parentList); | 
			
		
	
		
			
				
					|  |  |  |             return new Result<AgencysResultDTO>().ok(agencysResultDTO); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         agencysResultDTO = ConvertUtils.sourceToTarget(entity, AgencysResultDTO.class); | 
			
		
	
	
		
			
				
					|  |  | @ -161,10 +202,11 @@ public class AgencyServiceImpl implements AgencyService { | 
			
		
	
		
			
				
					|  |  |  |         agencysResultDTO.setAgencyName(entity.getOrganizationName()); | 
			
		
	
		
			
				
					|  |  |  |         //2:查询本机关的所有上级机关,按自上而下层级顺序
 | 
			
		
	
		
			
				
					|  |  |  |         if (null == entity.getPids()) { | 
			
		
	
		
			
				
					|  |  |  |             agencysResultDTO.setParentList(parentList); | 
			
		
	
		
			
				
					|  |  |  |             return new Result<AgencysResultDTO>().ok(agencysResultDTO); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         List<String> listStr = Arrays.asList(entity.getPids().split(":")); | 
			
		
	
		
			
				
					|  |  |  |         List<ParentListResultDTO> parentList = customerAgencyDao.selectPAgencyById(listStr); | 
			
		
	
		
			
				
					|  |  |  |         parentList = customerAgencyDao.selectPAgencyById(listStr); | 
			
		
	
		
			
				
					|  |  |  |         agencysResultDTO.setParentList(parentList); | 
			
		
	
		
			
				
					|  |  |  |         return new Result<AgencysResultDTO>().ok(agencysResultDTO); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  | @ -180,7 +222,7 @@ public class AgencyServiceImpl implements AgencyService { | 
			
		
	
		
			
				
					|  |  |  |         SubAgencyResultDTO subAgencyResultDTO = new SubAgencyResultDTO(); | 
			
		
	
		
			
				
					|  |  |  |         //1:根据当前机关Id查询直属下一级机关列表
 | 
			
		
	
		
			
				
					|  |  |  |         List<SubListResultDTO> agencyList = customerAgencyDao.selectSubAgencyById(formDTO.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         subAgencyResultDTO.setAgencyList(agencyList); | 
			
		
	
		
			
				
					|  |  |  |         subAgencyResultDTO.setAgencyList(null == agencyList ? new ArrayList<SubListResultDTO>() : agencyList); | 
			
		
	
		
			
				
					|  |  |  |         //2:统计下一级机关数
 | 
			
		
	
		
			
				
					|  |  |  |         subAgencyResultDTO.setSubAgencyCount(agencyList.size()); | 
			
		
	
		
			
				
					|  |  |  |         return new Result<SubAgencyResultDTO>().ok(subAgencyResultDTO); | 
			
		
	
	
		
			
				
					|  |  | @ -195,7 +237,7 @@ public class AgencyServiceImpl implements AgencyService { | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public Result<List<AgencyListResultDTO>> agencyList(AgencyListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         List<AgencyListResultDTO> agencyList = customerAgencyDao.selectAgencyList(formDTO.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         return new Result<List<AgencyListResultDTO>>().ok(agencyList); | 
			
		
	
		
			
				
					|  |  |  |         return new Result<List<AgencyListResultDTO>>().ok(null == agencyList ? new ArrayList<AgencyListResultDTO>() : agencyList); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
	
		
			
				
					|  |  | 
 |