|  |  |  | @ -267,19 +267,21 @@ public class UdiProductService { | 
			
		
	
		
			
				
					|  |  |  |  |                     udiProductEntity.setDiType(1); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |                 udiProductDao.updateUdiInfo(udiProductEntity); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                 //修改关联表
 | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setUseLeverCount(addProductRequest.getUseLeverCount()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setSplitEnable(addProductRequest.getSplitEnable()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setUseLevelDi(addProductRequest.getUseLevelDi()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setUseLevelUnit(addProductRequest.getUseLevelUnit()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setDistributeLevelDi(addProductRequest.getDistributeLevelDi()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setDistributeLevelUnit(addProductRequest.getDistributeLevelUnit()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setDistributeLevelCount(addProductRequest.getDistributeLevelCount()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setPayFeeCode(addProductRequest.getPayFeeCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceDao.updateById(udiRelevanceEntity); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             //修改关联表
 | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setUseLeverCount(addProductRequest.getUseLeverCount()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setSplitEnable(addProductRequest.getSplitEnable()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setUseLevelDi(addProductRequest.getUseLevelDi()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setUseLevelUnit(addProductRequest.getUseLevelUnit()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setUseLevel(addProductRequest.getUseLevel()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setDistributeLevelDi(addProductRequest.getDistributeLevelDi()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setDistributeLevelUnit(addProductRequest.getDistributeLevelUnit()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setDistributeLevelCount(addProductRequest.getDistributeLevelCount()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setDistributeLevel(addProductRequest.getDistributeLevel()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setPayFeeCode(addProductRequest.getPayFeeCode()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceDao.updateById(udiRelevanceEntity); | 
			
		
	
		
			
				
					|  |  |  |  |             updateLevelCount(udiRelevanceEntity); | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity = new UdiRelevanceEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setId(IdUtil.getSnowflakeNextId()); | 
			
		
	
	
		
			
				
					|  |  |  | @ -293,25 +295,31 @@ public class UdiProductService { | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setAttributeType(addProductRequest.getAttributeType()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setHcType(addProductRequest.getHcType()); | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceEntity.setPayFeeCode(addProductRequest.getPayFeeCode()); | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getDistributeLevelDi() != null){ | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getDistributeLevelDi() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setDistributeLevelDi(addProductRequest.getDistributeLevelDi()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getDistributeLevelCount() != null){ | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getDistributeLevelCount() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setDistributeLevelCount(addProductRequest.getDistributeLevelCount()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getDistributeLevelUnit() != null){ | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getDistributeLevelUnit() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setDistributeLevelUnit(addProductRequest.getDistributeLevelUnit()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getUseLevelDi() != null){ | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getUseLevelDi() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setUseLevelDi(addProductRequest.getUseLevelDi()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getUseLevelUnit() != null){ | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getUseLevelUnit() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setUseLevelUnit(addProductRequest.getUseLevelUnit()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getUseLeverCount() != null){ | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getUseLeverCount() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setUseLeverCount(addProductRequest.getUseLeverCount()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getDistributeLevel() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setDistributeLevel(addProductRequest.getDistributeLevel()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (addProductRequest.getUseLevel() != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 udiRelevanceEntity.setUseLevel(addProductRequest.getUseLevel()); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (CollUtil.isNotEmpty(addProductRequest.getDrugLevelLists())) { | 
			
		
	
		
			
				
					|  |  |  |  |                 for (UpdateLevelDrugRequest updateLevelDrugRequest : addProductRequest.getDrugLevelLists()) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -349,10 +357,94 @@ public class UdiProductService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             udiRelevanceDao.insertUdiRelevance(udiRelevanceEntity); | 
			
		
	
		
			
				
					|  |  |  |  |             updateLevelCount(udiRelevanceEntity); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return addProductRequest; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * 更新各个层级数量换算 | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @param udiRelevanceEntity | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     public void updateLevelCount(UdiRelevanceEntity udiRelevanceEntity) { | 
			
		
	
		
			
				
					|  |  |  |  |         List<UdiProductEntity> udiProductEntities = udiProductDao.findByUuids(udiRelevanceEntity.getUuid()); | 
			
		
	
		
			
				
					|  |  |  |  |         Integer curLevel = udiRelevanceEntity.getDistributeLevelCount(); | 
			
		
	
		
			
				
					|  |  |  |  |         //更新各个层级流通时包含计量单元数量
 | 
			
		
	
		
			
				
					|  |  |  |  |         if (CollUtil.isNotEmpty(udiProductEntities)) { | 
			
		
	
		
			
				
					|  |  |  |  |             for (UdiProductEntity udiProductEntity : udiProductEntities) { | 
			
		
	
		
			
				
					|  |  |  |  |                 if (IntUtil.value(udiProductEntity.getPackLevel()) > IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                     UdiProductEntity nextLevelProduct1 = getNextLevelProduct(udiProductEntity, udiProductEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (nextLevelProduct1 != null && IntUtil.value(nextLevelProduct1.getPackLevel()) > IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         UdiProductEntity nextLevelProduct2 = getNextLevelProduct(nextLevelProduct1, udiProductEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                         if (nextLevelProduct2 != null && IntUtil.value(nextLevelProduct2.getPackLevel()) > IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                             UdiProductEntity nextLevelProduct3 = getNextLevelProduct(nextLevelProduct2, udiProductEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                             if (nextLevelProduct3 != null && IntUtil.value(nextLevelProduct3.getPackLevel()) == IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 udiProductEntity.setBhltcjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(nextLevelProduct1.getBhxjsl()) * IntUtil.value(nextLevelProduct2.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getDistributeLevelCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                 udiProductEntity.setBhltcjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(nextLevelProduct1.getBhxjsl()) * IntUtil.value(nextLevelProduct2.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getDistributeLevelCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                         } else { | 
			
		
	
		
			
				
					|  |  |  |  |                             udiProductEntity.setBhltcjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(nextLevelProduct1.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getDistributeLevelCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         if (nextLevelProduct1 != null && IntUtil.value(nextLevelProduct1.getPackLevel()) == IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                             udiProductEntity.setBhltcjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getDistributeLevelCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |  |                     if (udiProductEntity != null && IntUtil.value(udiProductEntity.getPackLevel()) == IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         udiProductEntity.setBhltcjsl(IntUtil.value(udiRelevanceEntity.getDistributeLevelCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         //更新各个层级使用时包含计量单元数量
 | 
			
		
	
		
			
				
					|  |  |  |  |         if (CollUtil.isNotEmpty(udiProductEntities)) { | 
			
		
	
		
			
				
					|  |  |  |  |             for (UdiProductEntity udiProductEntity : udiProductEntities) { | 
			
		
	
		
			
				
					|  |  |  |  |                 if (IntUtil.value(udiProductEntity.getPackLevel()) > IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                     UdiProductEntity nextLevelProduct1 = getNextLevelProduct(udiProductEntity, udiProductEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (nextLevelProduct1 != null && IntUtil.value(nextLevelProduct1.getPackLevel()) > IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         UdiProductEntity nextLevelProduct2 = getNextLevelProduct(nextLevelProduct1, udiProductEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                         if (nextLevelProduct2 != null && IntUtil.value(nextLevelProduct2.getPackLevel()) > IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                             UdiProductEntity nextLevelProduct3 = getNextLevelProduct(nextLevelProduct2, udiProductEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                             if (nextLevelProduct3 != null && IntUtil.value(nextLevelProduct3.getPackLevel()) == IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 udiProductEntity.setBhsycjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(nextLevelProduct1.getBhxjsl()) * IntUtil.value(nextLevelProduct2.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getUseLeverCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                 udiProductEntity.setBhsycjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(nextLevelProduct1.getBhxjsl()) * IntUtil.value(nextLevelProduct2.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getUseLeverCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                         } else { | 
			
		
	
		
			
				
					|  |  |  |  |                             udiProductEntity.setBhsycjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(nextLevelProduct1.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getUseLeverCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         if (nextLevelProduct1 != null && IntUtil.value(nextLevelProduct1.getPackLevel()) == IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                             udiProductEntity.setBhsycjsl(IntUtil.value(udiProductEntity.getBhxjsl()) * IntUtil.value(udiRelevanceEntity.getUseLeverCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |  |                     if (udiProductEntity != null && IntUtil.value(udiProductEntity.getPackLevel()) == IntUtil.value(curLevel)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         udiProductEntity.setBhsycjsl(IntUtil.value(udiRelevanceEntity.getUseLeverCount())); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         udiProductDao.updateBatchById(udiProductEntities); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     public UdiProductEntity getNextLevelProduct(UdiProductEntity curProductEntity, List<UdiProductEntity> udiProductEntities) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         for (UdiProductEntity udiProductEntity : udiProductEntities) { | 
			
		
	
		
			
				
					|  |  |  |  |             if (StrUtil.emptyIfNull(curProductEntity.getBhxjcpbm()).equals(udiProductEntity.getNameCode())) { | 
			
		
	
		
			
				
					|  |  |  |  |                 return udiProductEntity; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return null; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * 添加或更新层级药品信息 | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
	
		
			
				
					|  |  |  | @ -419,7 +511,7 @@ public class UdiProductService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     public UdiProductEntity findUltimateEntity(UdiProductEntity udiProductEntity, List<UdiProductEntity> udiProductEntities, CountWrapper xjCountWrapper) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (StrUtil.isEmpty(udiProductEntity.getBhxjcpbm())) { | 
			
		
	
		
			
				
					|  |  |  |  |             xjCountWrapper.addCount(udiProductEntity.getBhxjsl()); | 
			
		
	
		
			
				
					|  |  |  |  |             xjCountWrapper.addCount(IntUtil.value(udiProductEntity.getBhxjsl())); | 
			
		
	
		
			
				
					|  |  |  |  |             return udiProductEntity; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -427,7 +519,7 @@ public class UdiProductService { | 
			
		
	
		
			
				
					|  |  |  |  |                 .filter(item -> item.getNameCode().equals(udiProductEntity.getBhxjcpbm())) | 
			
		
	
		
			
				
					|  |  |  |  |                 .findFirst(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         nextEntityOptional.ifPresent(entity -> xjCountWrapper.addCount(udiProductEntity.getBhxjsl())); | 
			
		
	
		
			
				
					|  |  |  |  |         nextEntityOptional.ifPresent(entity -> xjCountWrapper.addCount(IntUtil.value(udiProductEntity.getBhxjsl()))); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         return nextEntityOptional | 
			
		
	
		
			
				
					|  |  |  |  |                 .map(entity -> findUltimateEntity(entity, udiProductEntities, xjCountWrapper)) | 
			
		
	
	
		
			
				
					|  |  |  | 
 |