|  |  | @ -3,20 +3,31 @@ package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.AppClientConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.FieldConstant; | 
			
		
	
		
			
				
					|  |  |  | 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.exception.EpmetException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.CustomerOrgRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.CustomerStaffRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.EpmetRequestHolder; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcExportTemplateDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcFormItemDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcExportTemplateDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.IcExportItemListFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.IcExportTemplateQueryFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.IcExportTemplateSaveFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.ConditionResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.IcCustomExportResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.IcExportTemplateForExportResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcExportTemplateConfigEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcExportTemplateEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcExportTemplateConfigService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcExportTemplateService; | 
			
		
	
		
			
				
					|  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
	
		
			
				
					|  |  | @ -42,6 +53,8 @@ public class IcExportTemplateServiceImpl extends BaseServiceImpl<IcExportTemplat | 
			
		
	
		
			
				
					|  |  |  |     private IcExportTemplateDao icExportTemplateDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcFormItemDao icFormItemDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcExportTemplateConfigService icExportTemplateConfigService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<IcExportTemplateDTO> page(Map<String, Object> params) { | 
			
		
	
	
		
			
				
					|  |  | @ -76,9 +89,83 @@ public class IcExportTemplateServiceImpl extends BaseServiceImpl<IcExportTemplat | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void save(IcExportTemplateSaveFormDTO dto) { | 
			
		
	
		
			
				
					|  |  |  |         //TODO
 | 
			
		
	
		
			
				
					|  |  |  |     public List<IcExportTemplateForExportResultDTO> save(IcExportTemplateSaveFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         List<IcExportTemplateForExportResultDTO> resultList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         IcExportTemplateEntity tempEntity = new IcExportTemplateEntity(); | 
			
		
	
		
			
				
					|  |  |  |         List<IcExportTemplateConfigEntity> itemList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         String customerId = EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID); | 
			
		
	
		
			
				
					|  |  |  |         String staffId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); | 
			
		
	
		
			
				
					|  |  |  |         //1.获取工作人员所属组织缓存信息
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, staffId); | 
			
		
	
		
			
				
					|  |  |  |         if (null == staffInfo) { | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", EpmetRequestHolder.getHeader(AppClientConstant.USER_ID))); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == agencyInfo) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(String.format("获取组织缓存信息失败%s", staffInfo.getAgencyId())); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //2.根据是否保存判断查询当前组织已存在模板的最大sort值
 | 
			
		
	
		
			
				
					|  |  |  |         int sort = 1; | 
			
		
	
		
			
				
					|  |  |  |         String tempId = ""; | 
			
		
	
		
			
				
					|  |  |  |         if (formDTO.getIsTemp()) { | 
			
		
	
		
			
				
					|  |  |  |             List<IcExportTemplateDTO> templist = baseDao.selectByAgencyId(agencyInfo.getId()); | 
			
		
	
		
			
				
					|  |  |  |             if (!CollectionUtils.isEmpty(templist)) { | 
			
		
	
		
			
				
					|  |  |  |                 sort = templist.get(NumConstant.ZERO).getSort() + NumConstant.ONE; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             tempId = UUID.randomUUID().toString().replace("-", ""); | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setId(tempId); | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setAgencyId(agencyInfo.getId()); | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setPids(StringUtils.isEmpty(agencyInfo.getPids()) ? agencyInfo.getId() : agencyInfo.getPids() + ":" + agencyInfo.getId()); | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setFormCode(formDTO.getFormCode()); | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setName(formDTO.getName()); | 
			
		
	
		
			
				
					|  |  |  |             /*tempEntity.setType(); | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setUrl();*/ | 
			
		
	
		
			
				
					|  |  |  |             tempEntity.setSort(sort); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //3.组装待保存和待返回数据对象
 | 
			
		
	
		
			
				
					|  |  |  |         int num = 0; | 
			
		
	
		
			
				
					|  |  |  |         for (IcExportItemListFormDTO dto : formDTO.getItemList()) { | 
			
		
	
		
			
				
					|  |  |  |             IcExportTemplateConfigEntity itemEntity = ConvertUtils.sourceToTarget(dto, IcExportTemplateConfigEntity.class); | 
			
		
	
		
			
				
					|  |  |  |             itemEntity.setId(UUID.randomUUID().toString().replace("-", "")); | 
			
		
	
		
			
				
					|  |  |  |             itemEntity.setPid("0"); | 
			
		
	
		
			
				
					|  |  |  |             itemEntity.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |             itemEntity.setTempId(tempId); | 
			
		
	
		
			
				
					|  |  |  |             num += 1; | 
			
		
	
		
			
				
					|  |  |  |             itemEntity.setSort(num); | 
			
		
	
		
			
				
					|  |  |  |             itemList.add(itemEntity); | 
			
		
	
		
			
				
					|  |  |  |             IcExportTemplateForExportResultDTO resultDTO = ConvertUtils.sourceToTarget(dto, IcExportTemplateForExportResultDTO.class); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setId(itemEntity.getId()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setPid(itemEntity.getPid()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setSort(itemEntity.getSort()); | 
			
		
	
		
			
				
					|  |  |  |             resultList.add(resultDTO); | 
			
		
	
		
			
				
					|  |  |  |             int subNum = 0; | 
			
		
	
		
			
				
					|  |  |  |             for (IcExportItemListFormDTO subDTO : dto.getChildren()) { | 
			
		
	
		
			
				
					|  |  |  |                 IcExportTemplateConfigEntity subItem = ConvertUtils.sourceToTarget(subDTO, IcExportTemplateConfigEntity.class); | 
			
		
	
		
			
				
					|  |  |  |                 subItem.setId(UUID.randomUUID().toString().replace("-", "")); | 
			
		
	
		
			
				
					|  |  |  |                 subItem.setPid(itemEntity.getId()); | 
			
		
	
		
			
				
					|  |  |  |                 subItem.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |                 subItem.setTempId(tempId); | 
			
		
	
		
			
				
					|  |  |  |                 subNum += 1; | 
			
		
	
		
			
				
					|  |  |  |                 subItem.setSort(subNum); | 
			
		
	
		
			
				
					|  |  |  |                 itemList.add(subItem); | 
			
		
	
		
			
				
					|  |  |  |                 IcExportTemplateForExportResultDTO subResultDTO = ConvertUtils.sourceToTarget(subDTO, IcExportTemplateForExportResultDTO.class); | 
			
		
	
		
			
				
					|  |  |  |                 subResultDTO.setId(subItem.getId()); | 
			
		
	
		
			
				
					|  |  |  |                 subResultDTO.setPid(subItem.getPid()); | 
			
		
	
		
			
				
					|  |  |  |                 subResultDTO.setSort(subItem.getSort()); | 
			
		
	
		
			
				
					|  |  |  |                 resultList.add(subResultDTO); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //4.执行数据保存
 | 
			
		
	
		
			
				
					|  |  |  |         if (formDTO.getIsTemp()) { | 
			
		
	
		
			
				
					|  |  |  |             baseDao.insert(tempEntity); | 
			
		
	
		
			
				
					|  |  |  |             icExportTemplateConfigService.insertBatch(itemList); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //5.返回组装数据对象
 | 
			
		
	
		
			
				
					|  |  |  |         return resultList; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | 
 |