package com.glxp.api.service.basic; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.dao.basic.UdiRelevanceDao; import com.glxp.api.entity.basic.UdiProductEntity; import com.glxp.api.entity.basic.UdiRelevanceEntity; import com.glxp.api.entity.thrsys.ThrProductsEntity; import com.glxp.api.http.NmpaUdiClient; import com.glxp.api.req.basic.UdiCombineRequest; import com.glxp.api.req.basic.FilterUdiRelRequest; import com.glxp.api.req.thrsys.FilterThrProductsRequest; import com.glxp.api.res.basic.UdiRelevanceResponse; import com.glxp.api.service.thrsys.ThrProductsService; import com.glxp.api.util.CustomUtil; import com.glxp.api.util.DateUtil; import com.glxp.api.util.GennerOrderUtils; import com.glxp.api.util.udi.UdiInfoUtil; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; import java.util.List; /** * 耗材字典对照 */ @Service public class UdiContrastService { @Resource UdiRelevanceDao udiRelevanceDao; @Resource GennerOrderUtils gennerOrderUtils; @Resource ThrProductsService thrProductsService; @Resource UdiRelevanceService udiRelevanceService; @Resource UdiProductService udiProductService; @Resource NmpaUdiClient udiDlHttpClient; public boolean isExit(String originUuid, String mainId, String thirdSys) { if (StrUtil.isNotEmpty(originUuid) && StrUtil.isNotEmpty(mainId) && StrUtil.isBlank(thirdSys)) { List udiRelevanceEntities = findByUnion(originUuid, mainId); if (CollUtil.isNotEmpty(udiRelevanceEntities)) { return true; } else return false; } else if (StrUtil.isNotEmpty(originUuid) && StrUtil.isEmpty(mainId)) { List udiRelevanceEntities = findByOriginUuid(originUuid); if (CollUtil.isNotEmpty(udiRelevanceEntities)) { for (UdiRelevanceResponse udiRelevanceEntity : udiRelevanceEntities) { if (StrUtil.isEmpty(udiRelevanceEntity.getMainId()) && StrUtil.isNotEmpty(udiRelevanceEntity.getOriginUuid())) { return true; } } } return false; } else if (StrUtil.isEmpty(originUuid) && StrUtil.isNotEmpty(mainId)) { List udiRelevanceEntities = findByMainId(mainId); if (CollUtil.isNotEmpty(udiRelevanceEntities)) { for (UdiRelevanceResponse udiRelevanceEntity : udiRelevanceEntities) { if (StrUtil.isEmpty(udiRelevanceEntity.getOriginUuid()) && StrUtil.isNotEmpty(udiRelevanceEntity.getMainId())) { return true; } } } return false; } else if (StrUtil.isNotBlank(originUuid) && StrUtil.isNotBlank(mainId) && StrUtil.isNotBlank(thirdSys)) { List udiRelevanceEntities = findByUnion2(originUuid, mainId, thirdSys); if (CollUtil.isNotEmpty(udiRelevanceEntities)) { return true; } else return false; } return false; } private List findByUnion2(String originUuid, String mainId, String thirdSys) { FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest(); filterUdiRelRequest.setMainId(mainId); filterUdiRelRequest.setOriginUuid(originUuid); filterUdiRelRequest.setThirdSys(thirdSys); List udiRelevanceEntities = udiRelevanceDao.contrastJoinSelect(filterUdiRelRequest); return udiRelevanceEntities; } public List findByUnion(String originUuid, String mainId) { FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest(); filterUdiRelRequest.setMainId(mainId); filterUdiRelRequest.setOriginUuid(originUuid); List udiRelevanceEntities = udiRelevanceDao.contrastJoinSelect(filterUdiRelRequest); return udiRelevanceEntities; } public List findByUuid(String uuid) { FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest(); filterUdiRelRequest.setUuid(uuid); List udiRelevanceEntities = udiRelevanceDao.contrastJoinSelect(filterUdiRelRequest); return udiRelevanceEntities; } public UdiRelevanceResponse findById(Long id) { FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest(); filterUdiRelRequest.setId(id); List udiRelevanceEntities = udiRelevanceDao.contrastJoinSelect(filterUdiRelRequest); if (CollUtil.isNotEmpty(udiRelevanceEntities)) return udiRelevanceEntities.get(0); return null; } public List findByOriginUuid(String originUuid) { FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest(); filterUdiRelRequest.setOriginUuid(originUuid); List udiRelevanceEntities = udiRelevanceDao.contrastJoinSelect(filterUdiRelRequest); return udiRelevanceEntities; } public List findByMainId(String mainId) { FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest(); filterUdiRelRequest.setMainId(mainId); List udiRelevanceEntities = udiRelevanceDao.contrastJoinSelect(filterUdiRelRequest); return udiRelevanceEntities; } public List filterAll(FilterUdiRelRequest filterUdiRelRequest) { List udiRelevanceEntities = udiRelevanceDao.contrastJoinSelect(filterUdiRelRequest); return udiRelevanceEntities; } public void createUnionContrast(UdiCombineRequest udiCombineRequest, String key) { List udiInfoEntities = udiDlHttpClient.getOrUpdateByUuid(key); UdiRelevanceEntity udiRelevanceEntity = new UdiRelevanceEntity(); udiRelevanceEntity.setThirdId(udiCombineRequest.getThirdId()); udiRelevanceEntity.setMainId(udiCombineRequest.getThirdId()); udiRelevanceEntity.setUpdateTime(new Date()); udiRelevanceEntity.setModifyTime(new Date()); udiRelevanceEntity.setUuid(udiInfoEntities.get(0).getUuid()); udiRelevanceEntity.setSupName(udiCombineRequest.getSupName()); udiRelevanceEntity.setId(gennerOrderUtils.getRelId()); udiRelevanceEntity.setIsDisable(false); udiRelevanceService.insertUdiRelevance(udiRelevanceEntity); insertUdiInfos(udiInfoEntities); } public void createOnlyMainId(String mainId) { FilterThrProductsRequest filterThrProductsRequest = new FilterThrProductsRequest(); filterThrProductsRequest.setCode(mainId); ThrProductsEntity thrProductsEntity = thrProductsService.selectByCode(mainId); UdiRelevanceEntity udiRelevanceEntity = new UdiRelevanceEntity(); udiRelevanceEntity.setThirdId(thrProductsEntity.getCode()); udiRelevanceEntity.setMainId(thrProductsEntity.getCode()); udiRelevanceEntity.setUpdateTime(new Date()); udiRelevanceEntity.setModifyTime(new Date()); udiRelevanceEntity.setUuid(CustomUtil.getUUId()); udiRelevanceEntity.setSupName(thrProductsEntity.getSupName()); udiRelevanceEntity.setId(gennerOrderUtils.getRelId()); udiRelevanceEntity.setIsDisable(false); udiRelevanceService.insertUdiRelevance(udiRelevanceEntity); UdiProductEntity udiProductEntity = new UdiProductEntity(); BeanUtils.copyProperties(thrProductsEntity, udiProductEntity); udiProductEntity.setNameCode(thrProductsEntity.getCode()); udiProductEntity.setCpmctymc(thrProductsEntity.getName()); udiProductEntity.setManufactory(thrProductsEntity.getManufactory()); udiProductEntity.setYlqxzcrbarmc(thrProductsEntity.getManufactory()); udiProductEntity.setGgxh(thrProductsEntity.getSpec()); udiProductEntity.setZczbhhzbapzbh(thrProductsEntity.getRegisterNo()); udiProductEntity.setUuid(udiRelevanceEntity.getUuid()); udiProductEntity.setProductType(ConstantStatus.PRODUCT_TYPE_THIRD); udiProductEntity.setDiType(1); udiProductEntity.setScbssfbhph("是"); udiProductEntity.setScbssfbhscrq("是"); udiProductEntity.setScbssfbhsxrq("是"); udiProductEntity.setScbssfbhxlh("否"); udiProductEntity = UdiInfoUtil.initUdiInfoEntity(udiProductEntity); udiProductService.insertUdiInfo(udiProductEntity); } public Long createOnlyUuid(UdiCombineRequest udiCombineRequest, String key) { List udiInfoEntities = udiDlHttpClient.getOrUpdateByUuid(key); if(udiInfoEntities==null || udiInfoEntities.size()==0){ //为了处理审核时的线上问题 int a=9999; return Long.valueOf(a); }else{ UdiRelevanceEntity udiRelevanceEntity = new UdiRelevanceEntity(); udiRelevanceEntity.setUpdateTime(new Date()); udiRelevanceEntity.setModifyTime(new Date()); udiRelevanceEntity.setUuid(udiInfoEntities.get(0).getUuid()); if (StrUtil.isNotBlank(udiCombineRequest.getSupName())) { udiRelevanceEntity.setSupName(udiCombineRequest.getSupName()); } Long relId = gennerOrderUtils.getRelId(); udiRelevanceEntity.setId(relId); udiRelevanceEntity.setIsDisable(false); udiRelevanceService.insertUdiRelevance(udiRelevanceEntity); insertUdiInfos(udiInfoEntities); return relId; } } public void insertUdiInfos(List udiInfoEntities) { if (CollUtil.isNotEmpty(udiInfoEntities)) { UdiProductEntity udiProductEntity = udiProductService.findByUuid(udiInfoEntities.get(0).getUuid()); if (udiProductEntity == null) { for (UdiProductEntity udiInfoEntity : udiInfoEntities) { udiInfoEntity.setId(IdUtil.getSnowflakeNextId()); } udiProductService.insertUdiInfos(UdiInfoUtil.initUdiInfoEntitys(udiInfoEntities)); } } } }