|  |  | @ -22,6 +22,7 @@ import com.glxp.api.service.collect.*; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.service.inout.impl.IoCodeService; |  |  |  | import com.glxp.api.service.inout.impl.IoCodeService; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.service.inv.impl.InvProductServiceNew; |  |  |  | import com.glxp.api.service.inv.impl.InvProductServiceNew; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.vo.basic.InvProductNewVo; |  |  |  | import com.glxp.api.vo.basic.InvProductNewVo; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import org.apache.xpath.operations.Bool; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.aspectj.weaver.ast.Var; |  |  |  | import org.aspectj.weaver.ast.Var; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.springframework.beans.BeanUtils; |  |  |  | import org.springframework.beans.BeanUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | import cn.hutool.core.collection.CollUtil; |  |  |  | import cn.hutool.core.collection.CollUtil; | 
			
		
	
	
		
		
			
				
					|  |  | @ -487,6 +488,7 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); |  |  |  |             return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         AddCodeResult addCodeResult = new AddCodeResult(); |  |  |  |         AddCodeResult addCodeResult = new AddCodeResult(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 获取用户提交的追溯码列表
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         List<String> codeList = addOrderCodeRequest.getCodeList(); |  |  |  |         List<String> codeList = addOrderCodeRequest.getCodeList(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (CollUtil.isEmpty(codeList)) |  |  |  |         if (CollUtil.isEmpty(codeList)) | 
			
		
	
		
		
			
				
					
					|  |  |  |             return ResultVOUtils.error(500, "追溯码不能为空"); |  |  |  |             return ResultVOUtils.error(500, "追溯码不能为空"); | 
			
		
	
	
		
		
			
				
					|  |  | @ -501,12 +503,14 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (code.endsWith("\u001D")) { |  |  |  |             if (code.endsWith("\u001D")) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 code = code.replace("\u001D", ""); |  |  |  |                 code = code.replace("\u001D", ""); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 根据追溯码获取 udi 实体类
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             UdiEntity udiEntity = FilterUdiUtils.getUdi(code); |  |  |  |             UdiEntity udiEntity = FilterUdiUtils.getUdi(code); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (udiEntity == null) { |  |  |  |             if (udiEntity == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 vailCodeResultResponse.setCode(code); |  |  |  |                 vailCodeResultResponse.setCode(code); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 vailCodeResultResponse.setStatus(2); |  |  |  |                 vailCodeResultResponse.setStatus(2); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 vailCodeResultResponse.setErrMsg("无效条码"); |  |  |  |                 vailCodeResultResponse.setErrMsg("无效条码"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 如果请求中有生产日期,过期日期等数据,赋给 udi 实体类
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (StrUtil.isNotEmpty(addOrderRequest.getBatchNo())) { |  |  |  |             if (StrUtil.isNotEmpty(addOrderRequest.getBatchNo())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 udiEntity.setBatchNo(addOrderRequest.getBatchNo()); |  |  |  |                 udiEntity.setBatchNo(addOrderRequest.getBatchNo()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
	
		
		
			
				
					|  |  | @ -523,6 +527,7 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |             AuthAdmin authAdmin = getUser(); |  |  |  |             AuthAdmin authAdmin = getUser(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             addOrderRequest.setInvCode(authAdmin.getLocInvCode()); |  |  |  |             addOrderRequest.setInvCode(authAdmin.getLocInvCode()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (IntUtil.value(addOrderCodeRequest.getInoutType()) == 2) { |  |  |  |             if (IntUtil.value(addOrderCodeRequest.getInoutType()) == 2) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 退货
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 addOrderRequest.setAction(ConstantType.SPLIT_RETURN); |  |  |  |                 addOrderRequest.setAction(ConstantType.SPLIT_RETURN); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else { |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 addOrderRequest.setAction(ConstantType.SPLIT_OUT); |  |  |  |                 addOrderRequest.setAction(ConstantType.SPLIT_OUT); | 
			
		
	
	
		
		
			
				
					|  |  | @ -531,8 +536,10 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             BaseResponse baseResponse = null; |  |  |  |             BaseResponse baseResponse = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |             addOrderRequest.setCode(code); |  |  |  |             addOrderRequest.setCode(code); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 根据本地订单号获取 IoOrder 实体
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             IoOrderEntity ioOrderEntity = orderService.findCorpOrderId(addOrderCodeRequest.getCorpOrderId()); |  |  |  |             IoOrderEntity ioOrderEntity = orderService.findCorpOrderId(addOrderCodeRequest.getCorpOrderId()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (ioOrderEntity != null) { |  |  |  |             if (ioOrderEntity != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 设置单据号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 addOrderRequest.setBillNo(ioOrderEntity.getBillNo()); |  |  |  |                 addOrderRequest.setBillNo(ioOrderEntity.getBillNo()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (IntUtil.value(udiEntity.getProductType()) == 2) { |  |  |  |             if (IntUtil.value(udiEntity.getProductType()) == 2) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -1286,19 +1293,25 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |     @Resource |  |  |  |     @Resource | 
			
		
	
		
		
			
				
					
					|  |  |  |     RelCodeBatchService relCodeBatchService; |  |  |  |     RelCodeBatchService relCodeBatchService; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     @Transactional(rollbackFor = Exception.class) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public BaseResponse addDrugOrder(AddOrderRequest addOrderRequest, UdiEntity udiEntity, String code) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         AddCodeResult addCodeResult = new AddCodeResult(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderRequest.getAction()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderRequest.getInvCode()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 校验批次号 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param addOrderRequest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiEntity | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return true->通过校验, false->不通过 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public Boolean validationUdiBatchNo(AddOrderRequest addOrderRequest, UdiEntity udiEntity) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 批次号校验
 |  |  |  |         // 批次号校验
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 判断此产品是否开启允许无批次号
 |  |  |  |         // 判断此产品是否开启允许无批次号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         UdiProductEntity udiInfoEntity = udiProductService.findByNameCode(udiEntity.getUdi()); |  |  |  |         UdiProductEntity udiInfoEntity = udiProductService.findByNameCode(udiEntity.getUdi()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (udiInfoEntity == null) { |  |  |  |         if (udiInfoEntity == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return ResultVOUtils.error(500, "药品字典不存在此产品!"); |  |  |  |             return false; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 如果批次号为空
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (StrUtil.isEmpty(udiEntity.getBatchNo())) { |  |  |  |         if (StrUtil.isEmpty(udiEntity.getBatchNo())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 扫码缺失字段信息补齐实体 如果有批次号,生产日期,过期日期,可以给 udi 实体
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             IoCodeLostEntity codeLostEntity = codeLostService.findByCode(addOrderRequest.getCode()); |  |  |  |             IoCodeLostEntity codeLostEntity = codeLostService.findByCode(addOrderRequest.getCode()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (codeLostEntity != null) { |  |  |  |             if (codeLostEntity != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 udiEntity.setBatchNo(codeLostEntity.getBatchNo()); |  |  |  |                 udiEntity.setBatchNo(codeLostEntity.getBatchNo()); | 
			
		
	
	
		
		
			
				
					|  |  | @ -1306,15 +1319,26 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 udiEntity.setExpireDate(codeLostEntity.getExpireDate()); |  |  |  |                 udiEntity.setExpireDate(codeLostEntity.getExpireDate()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         String orderId = addOrderRequest.getBillNo(); |  |  |  |         return true; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 校验 udi 的药品有效期 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param bussinessTypeEntity  单据类型 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiEntity | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param addOrderRequest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return true->通过校验, false->不通过 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public Boolean validationUdiExpireDate(BasicBussinessTypeEntity bussinessTypeEntity, UdiEntity udiEntity, AddOrderRequest addOrderRequest) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         //过期提醒:
 |  |  |  |         //过期提醒:
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 检查有效期,不可以忽视过期
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 1 && !addOrderRequest.isIgnoreExpire()) { |  |  |  |         if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 1 && !addOrderRequest.isIgnoreExpire()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { |  |  |  |             if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); |  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); |  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (expireTime - System.currentTimeMillis() < 0) { |  |  |  |                 if (expireTime - System.currentTimeMillis() < 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(504, "当前产品已过期,是否确定继续添加?"); |  |  |  |                     return false; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
	
		
		
			
				
					|  |  | @ -1323,46 +1347,79 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); |  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); |  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (expireTime - System.currentTimeMillis() < 0) { |  |  |  |                 if (expireTime - System.currentTimeMillis() < 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(604, "当前产品已过期,无法添加!"); |  |  |  |                     return false; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi()); |  |  |  |         return true; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 校验 udi 包装层级 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param bussinessTypeEntity  单据类型 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiRelevanceResponse udi 相关响应对象 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return true->通过校验, false->不通过 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public Boolean validationUdiPackLevel(BasicBussinessTypeEntity bussinessTypeEntity, UdiRelevanceResponse udiRelevanceResponse) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 判断层级标识是否正确
 |  |  |  |         // 判断层级标识是否正确
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (bussinessTypeEntity.isUse()) { |  |  |  |         if (bussinessTypeEntity.isUse()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 如果最大层级小于包装层级
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) { |  |  |  |             if (IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!"); |  |  |  |                 return false; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 如果包装层级小于使用层级
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) { |  |  |  |             if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!"); |  |  |  |                 return false; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) { |  |  |  |             if (IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!"); |  |  |  |                 return false; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getDistributeLevel())) { |  |  |  |             if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getDistributeLevel())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!"); |  |  |  |                 return false; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return true; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     /** | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 近效期提醒,近效期是指药品、食品或其他有保质期限的产品接近其标明的有效期或保质期 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param bussinessTypeEntity | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiRelevanceResponse | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiEntity | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param addOrderRequest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiDrugExpireTime udi 药品过期时间(单位小时) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return true->需要提醒,false->不需要 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public Boolean remindUdiNearExpirationDate(BasicBussinessTypeEntity bussinessTypeEntity, UdiRelevanceResponse udiRelevanceResponse, UdiEntity udiEntity, AddOrderRequest addOrderRequest, Long udiDrugExpireTime) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 近效期提醒
 |  |  |  |         // 近效期提醒
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         long recent = 0; |  |  |  |         long recent = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (udiRelevanceResponse.getRecentDateTime() != null) |  |  |  |         if (udiRelevanceResponse.getRecentDateTime() != null) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 获取近效期预警时间(小时)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             recent = udiRelevanceResponse.getRecentDateTime().longValue(); |  |  |  |             recent = udiRelevanceResponse.getRecentDateTime().longValue(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // udiRelevanceResponse.getIsDateBy() 时间预警类型填写类型
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire() && udiRelevanceResponse.getIsDateBy() == 2) { |  |  |  |         if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire() && udiRelevanceResponse.getIsDateBy() == 2) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { |  |  |  |             if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); |  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); |  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 近效期预警时间从小时转为毫秒
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000); |  |  |  |                 long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 距离过期还有多久,时间单位是毫秒
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long resultTime = expireTime - System.currentTimeMillis(); |  |  |  |                 long resultTime = expireTime - System.currentTimeMillis(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // resultTime 大于 0,说明还没过期
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (resultTime > 0) { |  |  |  |                 if (resultTime > 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     long time = resultTime / (60 * 60 * 1000); |  |  |  |                     // 距离过期还有多久,时间单位是小时
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     udiDrugExpireTime = resultTime / (60 * 60 * 1000); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 距离过期时间在近效期预警时间内部,说明要提醒
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 比如还有 24 小时过期,近效期是 36 小时,那么就需要提醒
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (resultTime < recentTieme) { |  |  |  |                     if (resultTime < recentTieme) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "时,是否确定继续添加?"); |  |  |  |                         return true; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         // return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "时,是否确定继续添加?");
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
	
		
		
			
				
					|  |  | @ -1372,90 +1429,205 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { |  |  |  |             if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); |  |  |  |                 String expireDate = "20" + udiEntity.getExpireDate(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); |  |  |  |                 long expireTime = MsDateUtil.parseDateExpire(expireDate); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 计算近效期提醒时间(单位为毫秒)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000); |  |  |  |                 long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 计算产品到期时间与当前时间的差值(单位为毫秒)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long resultTime = expireTime - System.currentTimeMillis(); |  |  |  |                 long resultTime = expireTime - System.currentTimeMillis(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (resultTime > 0) { |  |  |  |                 if (resultTime > 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     long time = resultTime / (24 * 60 * 60 * 1000); |  |  |  |                     // 还剩几天过期
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     udiDrugExpireTime = resultTime / (24 * 60 * 60 * 1000); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (resultTime < recentTieme) { |  |  |  |                     if (resultTime < recentTieme) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "天,是否确定继续添加?"); |  |  |  |                         return true; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return false; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 校验库存 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param bussinessTypeEntity | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiRelevanceResponse | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param invRes | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param genDetaiEntity | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public BaseResponse validationUdiInv(BasicBussinessTypeEntity bussinessTypeEntity, UdiRelevanceResponse udiRelevanceResponse, BaseResponse invRes, IoCodeTempEntity genDetaiEntity) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 出库模式为:科室集合使用出库
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 只采集预验收产品并且出库模式是预验收库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 2)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 校验预验收库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 3)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 校验寄售库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (bussinessTypeEntity.isVailInv() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 1)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 访问库存,校验入账库
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 物资使用出库模式为正常或者物资多次使用出库模式
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (bussinessTypeEntity.isScanPreIn()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 校验预验收库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } else if (bussinessTypeEntity.isAdvancePreIn()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 校验寄售库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (invRes != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return invRes; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 添加药品单据 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param addOrderRequest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param udiEntity | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param code | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public BaseResponse addDrugOrder(AddOrderRequest addOrderRequest, UdiEntity udiEntity, String code) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         AddCodeResult addCodeResult = new AddCodeResult(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 获取单据类型
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderRequest.getAction()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderRequest.getInvCode()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 校验批次号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (!validationUdiBatchNo(addOrderRequest, udiEntity)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return ResultVOUtils.error(500, "药品字典不存在此产品!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 校验药品有效期
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (!validationUdiExpireDate(bussinessTypeEntity, udiEntity, addOrderRequest)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 1 && !addOrderRequest.isIgnoreExpire()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 return ResultVOUtils.error(504, "当前产品已过期,是否确定继续添加?"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } else if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 2){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 return ResultVOUtils.error(604, "当前产品已过期,无法添加!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 校验药品包装层级
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (!validationUdiPackLevel(bussinessTypeEntity, udiRelevanceResponse)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Long udiDrugExpireTime = 0L; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 近效期提醒
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Boolean isNeedRemind = remindUdiNearExpirationDate(bussinessTypeEntity, udiRelevanceResponse, udiEntity, addOrderRequest, udiDrugExpireTime); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (isNeedRemind) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // udiDrugExpireTime 对象传递,获取 remindUdiNearExpirationDate 方法中修改后的
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + udiDrugExpireTime + "时,是否确定继续添加?"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         // ------工位上货相关-----校验工位存量是否存在----
 |  |  |  |         // ------工位上货相关-----校验工位存量是否存在----
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT)) { |  |  |  |         if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 工位上货(以前是拆零出库)的情况
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 1. 检查预出库队列 表 io_split_fifo_code 是否存在这个追溯码
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null); |  |  |  |             IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (fifoCodeEntity != null && StrUtil.isNotEmpty(fifoCodeEntity.getSerialNo())) { |  |  |  |             if (fifoCodeEntity != null && StrUtil.isNotEmpty(fifoCodeEntity.getSerialNo())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(533, "当前追溯码已存在!"); |  |  |  |                 return ResultVOUtils.error(533, "当前追溯码已存在!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 2. 检查科室出库码拆零表 io_split_code 是否存在这个追溯码
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             IoSplitCodeEntity splitCodeEntity = splitCodeService.findByCode(code); |  |  |  |             IoSplitCodeEntity splitCodeEntity = splitCodeService.findByCode(code); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (splitCodeEntity != null) {//&& StrUtil.isNotEmpty(splitCodeEntity.getSerialNo())
 |  |  |  |             if (splitCodeEntity != null) {//&& StrUtil.isNotEmpty(splitCodeEntity.getSerialNo())
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(533, "当前追溯码已存在拆零库存!"); |  |  |  |                 return ResultVOUtils.error(533, "当前追溯码已存在拆零库存!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             //校验码表是否已经存在追溯码 io_code_temp
 |  |  |  |             // 3. 校验临时码表是否已经存在追溯码 io_code_temp
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             IoCodeTempEntity codeTempEntity = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction()); |  |  |  |             IoCodeTempEntity codeTempEntity = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (codeTempEntity != null) { |  |  |  |             if (codeTempEntity != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!"); |  |  |  |                 return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN)) { |  |  |  |         } else if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 工位退货(以前是拆零退货)的情况
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 1. 检查预出库队列是否存在追溯码
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null); |  |  |  |             IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (fifoCodeEntity == null) { |  |  |  |             if (fifoCodeEntity == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(500, "当前追溯码未上货!"); |  |  |  |                 return ResultVOUtils.error(500, "当前追溯码未上货!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 2. 检查科室出库码拆零表 io_split_code 是否存在这个追溯码
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             IoSplitCodeEntity splitCodeEntity = splitCodeService.findByCode(code); |  |  |  |             IoSplitCodeEntity splitCodeEntity = splitCodeService.findByCode(code); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (splitCodeEntity != null) {//&& StrUtil.isNotEmpty(splitCodeEntity.getSerialNo())
 |  |  |  |             if (splitCodeEntity != null) {//&& StrUtil.isNotEmpty(splitCodeEntity.getSerialNo())
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 拆零了,就无法退货了,毕竟不是完整的了
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(533, "当前追溯码已经拆零,无法退货!"); |  |  |  |                 return ResultVOUtils.error(533, "当前追溯码已经拆零,无法退货!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             //校验码表是否已经存在追溯码 io_code_temp
 |  |  |  |             // 3. 校验码表是否已经存在追溯码 io_code_temp
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             IoCodeTempEntity codeTempEntity = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction()); |  |  |  |             IoCodeTempEntity codeTempEntity = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (codeTempEntity != null) { |  |  |  |             if (codeTempEntity != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!"); |  |  |  |                 return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (addOrderRequest.getFromCorp() == null || StrUtil.isNotEmpty(addOrderRequest.getSickerAdNum())) { |  |  |  |         if (addOrderRequest.getFromCorp() == null || StrUtil.isNotEmpty(addOrderRequest.getSickerAdNum())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 出库时更新往来单位信息
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             String fromCorp = ioAddInoutService.updateCorp(bussinessTypeEntity, addOrderRequest.getFromCorp(), addOrderRequest.getSickerAdNum()); |  |  |  |             String fromCorp = ioAddInoutService.updateCorp(bussinessTypeEntity, addOrderRequest.getFromCorp(), addOrderRequest.getSickerAdNum()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             addOrderRequest.setFromCorp(fromCorp); |  |  |  |             addOrderRequest.setFromCorp(fromCorp); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         //先生成扫码单据
 |  |  |  |         // 首先生成扫码单据,如果事先没有业务单,需要自动生产业务单
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         String orderId = addOrderRequest.getBillNo(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 根据单据 id 获取单据实体
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         IoOrderEntity orderEntity = orderService.findByBillNo(orderId); |  |  |  |         IoOrderEntity orderEntity = orderService.findByBillNo(orderId); | 
			
		
	
		
		
			
				
					
					|  |  |  |         String inBatch = ""; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (StringUtils.isBlank(orderId) || orderEntity == null) { |  |  |  |         if (StringUtils.isBlank(orderId) || orderEntity == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 基于 redis 生成单据编号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd")); |  |  |  |             String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd")); | 
			
		
	
		
		
			
				
					
					|  |  |  |             orderId = orderNo; |  |  |  |             orderId = orderNo; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |         String inBatch = ""; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 从 orderId 中提取一个子字符串
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         inBatch = orderId.substring((Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix())).length()); |  |  |  |         inBatch = orderId.substring((Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix())).length()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 根据新的单据编号来查询临时码表
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         List<IoCodeTempEntity> codeEnttitys = codeTempService.findByOrderId(orderId); |  |  |  |         List<IoCodeTempEntity> codeEnttitys = codeTempService.findByOrderId(orderId); | 
			
		
	
		
		
			
				
					
					|  |  |  |         IoCodeTempEntity exitLocalEntity = null; |  |  |  |         IoCodeTempEntity exitLocalEntity = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |         IoCodeTempEntity genDetaiEntity = new IoCodeTempEntity(); |  |  |  |         IoCodeTempEntity genDetaiEntity = new IoCodeTempEntity(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         List<UdiRelevanceResponse> udiRelevanceResponses = null; |  |  |  |         List<UdiRelevanceResponse> udiRelevanceResponses = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (codeEnttitys.size() > 0) { |  |  |  |         if (codeEnttitys.size() > 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 临时码表中存在
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             exitLocalEntity = isExitLocal(code, codeEnttitys); |  |  |  |             exitLocalEntity = isExitLocal(code, codeEnttitys); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (exitLocalEntity != null) { |  |  |  |             if (exitLocalEntity != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 如果当前药品追溯码已经在 io_code_temp 表中
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (StrUtil.isEmpty(exitLocalEntity.getSupId()) || exitLocalEntity.getRelId() == null) { |  |  |  |                 if (StrUtil.isEmpty(exitLocalEntity.getSupId()) || exitLocalEntity.getRelId() == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 供应商 id 为空,或者耗材 id 为空
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, "当前药品追溯码已存在,且存在异常未处理!"); |  |  |  |                     return ResultVOUtils.error(500, "当前药品追溯码已存在,且存在异常未处理!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 根据 di 标识找到 udi 关联响应实体列表
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(exitLocalEntity.getNameCode(), null); |  |  |  |                 udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(exitLocalEntity.getNameCode(), null); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 BeanUtils.copyProperties(exitLocalEntity, genDetaiEntity); |  |  |  |                 BeanUtils.copyProperties(exitLocalEntity, genDetaiEntity); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 设置扫码数量
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 genDetaiEntity.setCount(1); |  |  |  |                 genDetaiEntity.setCount(1); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (bussinessTypeEntity.isUse()) { |  |  |  |                 if (bussinessTypeEntity.isUse()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 单据已使用,设置实际数量
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     genDetaiEntity.setReCount(udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0))); |  |  |  |                     genDetaiEntity.setReCount(udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0))); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else { |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 单据未使用,实际数量是流通数量
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     genDetaiEntity.setReCount(udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0))); |  |  |  |                     genDetaiEntity.setReCount(udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0))); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 设置扫码数量
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1); |  |  |  |                 exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (bussinessTypeEntity.isUse()) { |  |  |  |                 if (bussinessTypeEntity.isUse()) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -1464,36 +1636,20 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0))); |  |  |  |                     exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0))); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (!StringUtils.isBlank(exitLocalEntity.getSerialNo())) { |  |  |  |                 if (!StringUtils.isBlank(exitLocalEntity.getSerialNo())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 序列号存在,不为空,说明重复扫码
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, "重复扫码!"); |  |  |  |                     return ResultVOUtils.error(500, "重复扫码!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // 校验库存
 |  |  |  |                 // 校验库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 BaseResponse invRes = null; |  |  |  |                 BaseResponse invRes = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) { |  |  |  |                 invRes = validationUdiInv(bussinessTypeEntity, udiRelevanceResponse, invRes, genDetaiEntity); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 2)) {    //校验预验收库存
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 3)) {  //校验寄售库存
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (bussinessTypeEntity.isVailInv() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 1)) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (bussinessTypeEntity.isScanPreIn()) {    //校验预验收库存
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } else if (bussinessTypeEntity.isAdvancePreIn()) {  //校验寄售库存
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } else { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (invRes != null) { |  |  |  |                 if (invRes != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return invRes; |  |  |  |                     return invRes; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) { |  |  |  |                 if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 有三期业务单配/拣货 且 根据业务单据校验
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     String errMsg = ioCheckInoutService.checkCode(genDetaiEntity); |  |  |  |                     String errMsg = ioCheckInoutService.checkCode(genDetaiEntity); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (errMsg != null) { |  |  |  |                     if (errMsg != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         return ResultVOUtils.error(500, errMsg); |  |  |  |                         return ResultVOUtils.error(500, errMsg); | 
			
		
	
	
		
		
			
				
					|  |  | @ -1507,6 +1663,7 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         codeTempService.updateById(exitLocalEntity); |  |  |  |                         codeTempService.updateById(exitLocalEntity); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else { |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     boolean update = true; |  |  |  |                     boolean update = true; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 是否启用价格先进先出策略,值是 "1"
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     String priceFifo = systemParamConfigService.selectValueByParamKey("price_fifo"); |  |  |  |                     String priceFifo = systemParamConfigService.selectValueByParamKey("price_fifo"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (IntUtil.value(priceFifo) > 0) { |  |  |  |                     if (IntUtil.value(priceFifo) > 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) { |  |  |  |                         if (bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -1514,9 +1671,13 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                             Integer outCount = invProductServiceNew.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_OUT); |  |  |  |                             Integer outCount = invProductServiceNew.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_OUT); | 
			
		
	
		
		
			
				
					
					|  |  |  |                             //2.获取当前批次入库数量
 |  |  |  |                             //2.获取当前批次入库数量
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                             Integer inCount = invProductServiceNew.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT); |  |  |  |                             Integer inCount = invProductServiceNew.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             // reCount 当前操作中需要出库的数量
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             // 当前批次的可用库存数量小于 0,要去下一批次的库存中获取
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                             if ((IntUtil.value(inCount) - IntUtil.value(outCount) - IntUtil.value(exitLocalEntity.getReCount())) < 0) { |  |  |  |                             if ((IntUtil.value(inCount) - IntUtil.value(outCount) - IntUtil.value(exitLocalEntity.getReCount())) < 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                 // 从下一个批次中获取库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                                 InvProductNewVo nextInvProduct = invProductServiceNew.selectNextInBatch(bussinessTypeEntity, exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT, exitLocalEntity.getInBatchNo()); |  |  |  |                                 InvProductNewVo nextInvProduct = invProductServiceNew.selectNextInBatch(bussinessTypeEntity, exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT, exitLocalEntity.getInBatchNo()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                                 if (nextInvProduct != null) { |  |  |  |                                 if (nextInvProduct != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                     // 更新 genDetaiEntity 的价格和入库批次号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     genDetaiEntity.setPrice(nextInvProduct.getPrice()); |  |  |  |                                     genDetaiEntity.setPrice(nextInvProduct.getPrice()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     genDetaiEntity.setInBatchNo(nextInvProduct.getInBatchNo()); |  |  |  |                                     genDetaiEntity.setInBatchNo(nextInvProduct.getInBatchNo()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     codeTempService.insert(genDetaiEntity); |  |  |  |                                     codeTempService.insert(genDetaiEntity); | 
			
		
	
	
		
		
			
				
					|  |  | @ -1530,17 +1691,21 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (update) { |  |  |  |                     if (update) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         codeTempService.updateById(exitLocalEntity); |  |  |  |                         codeTempService.updateById(exitLocalEntity); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (exitLocalEntity == null) { |  |  |  |         if (exitLocalEntity == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 临时码表中不存在
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             IoCodeTempEntity codeEnttity = new IoCodeTempEntity(); |  |  |  |             IoCodeTempEntity codeEnttity = new IoCodeTempEntity(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setCode(code); |  |  |  |             codeEnttity.setCode(code); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setOrderId(orderId); |  |  |  |             codeEnttity.setOrderId(orderId); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 设置手持订单号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setCorpOrderId(addOrderRequest.getCorpOrderId()); |  |  |  |             codeEnttity.setCorpOrderId(addOrderRequest.getCorpOrderId()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setCreateTime(new Date()); |  |  |  |             codeEnttity.setCreateTime(new Date()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setUpdateTime(new Date()); |  |  |  |             codeEnttity.setUpdateTime(new Date()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 设置主单据类型
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setMainAction(bussinessTypeEntity.getMainAction()); |  |  |  |             codeEnttity.setMainAction(bussinessTypeEntity.getMainAction()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setAction(bussinessTypeEntity.getAction()); |  |  |  |             codeEnttity.setAction(bussinessTypeEntity.getAction()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setNameCode(udiEntity.getUdi()); |  |  |  |             codeEnttity.setNameCode(udiEntity.getUdi()); | 
			
		
	
	
		
		
			
				
					|  |  | @ -1555,6 +1720,7 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setPreInSpaceCode(addOrderRequest.getCheckPreInSpaceCode()); |  |  |  |             codeEnttity.setPreInSpaceCode(addOrderRequest.getCheckPreInSpaceCode()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setRelId(addOrderRequest.getRelId()); |  |  |  |             codeEnttity.setRelId(addOrderRequest.getRelId()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setFifoSplit(addOrderRequest.getFifoSplit()); |  |  |  |             codeEnttity.setFifoSplit(addOrderRequest.getFifoSplit()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 单据产品类型  1:器械;2:药品
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setProductType(2); |  |  |  |             codeEnttity.setProductType(2); | 
			
		
	
		
		
			
				
					
					|  |  |  |             codeEnttity.setCount(1); |  |  |  |             codeEnttity.setCount(1); | 
			
		
	
		
		
			
				
					
					|  |  |  |             String unitFk = null; |  |  |  |             String unitFk = null; | 
			
		
	
	
		
		
			
				
					|  |  | @ -1563,14 +1729,16 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else if (StrUtil.isNotEmpty(addOrderRequest.getSelectSupId())) { |  |  |  |             } else if (StrUtil.isNotEmpty(addOrderRequest.getSelectSupId())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 unitFk = addOrderRequest.getSelectSupId(); |  |  |  |                 unitFk = addOrderRequest.getSelectSupId(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             //产品是否禁用
 |  |  |  |             // 产品是否禁用,获取没有禁用的产品列表
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeEnttity.getNameCode(), false); |  |  |  |             udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeEnttity.getNameCode(), false); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT)) { |  |  |  |             if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 存在上货货位
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (orderEntity != null && StrUtil.isNotEmpty(orderEntity.getWorkPlaceQueueCode()) && CollUtil.isNotEmpty(codeEnttitys)) { |  |  |  |                 if (orderEntity != null && StrUtil.isNotEmpty(orderEntity.getWorkPlaceQueueCode()) && CollUtil.isNotEmpty(codeEnttitys)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     boolean isSame = false; |  |  |  |                     boolean isSame = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     for (IoCodeTempEntity ioOrderDetailCodeEntity : codeEnttitys) { |  |  |  |                     for (IoCodeTempEntity ioOrderDetailCodeEntity : codeEnttitys) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (ioOrderDetailCodeEntity.getRelId().equals(udiRelevanceResponse.getId())) { |  |  |  |                         if (ioOrderDetailCodeEntity.getRelId().equals(udiRelevanceResponse.getId())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             // 存在一个相等
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                             isSame = true; |  |  |  |                             isSame = true; | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |                         } | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
	
		
		
			
				
					|  |  | @ -1583,6 +1751,7 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (udiRelevanceResponse == null) { |  |  |  |                 if (udiRelevanceResponse == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, "该产品信息未维护!"); |  |  |  |                     return ResultVOUtils.error(500, "该产品信息未维护!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else if (!udiRelevanceResponse.getUseDy() && udiRelevanceResponse.getDiType() == ConstantStatus.DITYPE_SYDY) { |  |  |  |                 } else if (!udiRelevanceResponse.getUseDy() && udiRelevanceResponse.getDiType() == ConstantStatus.DITYPE_SYDY) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 某些产品可能要求必须以整箱或整批的形式入库,而不是单个使用单元
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, "该产品不允许以使用单元入库!"); |  |  |  |                     return ResultVOUtils.error(500, "该产品不允许以使用单元入库!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -1590,6 +1759,7 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, "该产品不可配送,请联系院方!"); |  |  |  |                     return ResultVOUtils.error(500, "该产品不可配送,请联系院方!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 不匹配
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (bussinessTypeEntity.getVailGroupBuy() == 1 && !udiRelevanceResponse.isGroupBuy()) {       //只采集集采产品
 |  |  |  |                 if (bussinessTypeEntity.getVailGroupBuy() == 1 && !udiRelevanceResponse.isGroupBuy()) {       //只采集集采产品
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "单只允许录入集采产品!"); |  |  |  |                     return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "单只允许录入集采产品!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
	
		
		
			
				
					|  |  | @ -1664,32 +1834,33 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 boolean isBillExit = orderDetailBizService.isExit(orderEntity.getBillNo()); |  |  |  |                 boolean isBillExit = orderDetailBizService.isExit(orderEntity.getBillNo()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (!isBillExit) { |  |  |  |                 if (!isBillExit) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 业务详情表不存在这个单据,那么删除
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     orderService.deleteByBillNo(orderEntity.getBillNo()); |  |  |  |                     orderService.deleteByBillNo(orderEntity.getBillNo()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, "请先录入业务详情"); |  |  |  |                     return ResultVOUtils.error(500, "请先录入业务详情"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |             // 检验药品 id 唯一性
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             BaseResponse baseResponse = checkDrugRelId(codeEnttity, unitFk); |  |  |  |             BaseResponse baseResponse = checkDrugRelId(codeEnttity, unitFk); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (baseResponse != null) { |  |  |  |             if (baseResponse != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 deleteEmptyBillNo(orderEntity); |  |  |  |                 deleteEmptyBillNo(orderEntity); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             genDetaiEntity = codeEnttity; |  |  |  |             genDetaiEntity = codeEnttity; | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (baseResponse == null) { |  |  |  |             if (baseResponse == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 校验供应商的唯一性
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 baseResponse = checkSupId(bussinessTypeEntity, codeEnttity, unitFk); |  |  |  |                 baseResponse = checkSupId(bussinessTypeEntity, codeEnttity, unitFk); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (baseResponse != null) |  |  |  |                 if (baseResponse != null) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     return baseResponse; |  |  |  |                     return baseResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else { |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (baseResponse.getCode() == 501) { |  |  |  |                 if (baseResponse.getCode() == 501 || baseResponse.getCode() == 502) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     return baseResponse; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else if (baseResponse.getCode() == 502) { |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     return baseResponse; |  |  |  |                     return baseResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 checkSupId(bussinessTypeEntity, codeEnttity, unitFk); |  |  |  |                 checkSupId(bussinessTypeEntity, codeEnttity, unitFk); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return baseResponse; |  |  |  |                 return baseResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |             // 校验库存
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) { |  |  |  |             if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 2)) {    //校验预验收库存
 |  |  |  |                 if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 2)) {    //校验预验收库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false); |  |  |  |                     BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false); | 
			
		
	
	
		
		
			
				
					|  |  | @ -1713,13 +1884,15 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else { |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (bussinessTypeEntity.isScanPreIn()) {    //校验预验收库存
 |  |  |  |                 if (bussinessTypeEntity.isScanPreIn()) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 校验预验收库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false); |  |  |  |                     BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (invRes != null) { |  |  |  |                     if (invRes != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         deleteEmptyBillNo(orderEntity); |  |  |  |                         deleteEmptyBillNo(orderEntity); | 
			
		
	
		
		
			
				
					
					|  |  |  |                         return invRes; |  |  |  |                         return invRes; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else if (bussinessTypeEntity.isAdvancePreIn()) {  //校验寄售库存
 |  |  |  |                 } else if (bussinessTypeEntity.isAdvancePreIn()) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 校验寄售库存
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     BaseResponse invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeEnttity, false); |  |  |  |                     BaseResponse invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeEnttity, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (invRes != null) { |  |  |  |                     if (invRes != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         deleteEmptyBillNo(orderEntity); |  |  |  |                         deleteEmptyBillNo(orderEntity); | 
			
		
	
	
		
		
			
				
					|  |  | @ -1968,6 +2141,7 @@ public class IoCodeTempController extends BaseController { | 
			
		
	
		
		
			
				
					
					|  |  |  |      * @return |  |  |  |      * @return | 
			
		
	
		
		
			
				
					
					|  |  |  |      */ |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public IoCodeTempEntity isExitLocal(String code, List<IoCodeTempEntity> codeEnttityList) { |  |  |  |     public IoCodeTempEntity isExitLocal(String code, List<IoCodeTempEntity> codeEnttityList) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 返回匹配的 IoCodeTempEntity 对象
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         List<IoCodeTempEntity> codeTempEntities = isExitLocalList(code, codeEnttityList); |  |  |  |         List<IoCodeTempEntity> codeTempEntities = isExitLocalList(code, codeEnttityList); | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (CollUtil.isNotEmpty(codeTempEntities)) { |  |  |  |         if (CollUtil.isNotEmpty(codeTempEntities)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return codeTempEntities.get(0); |  |  |  |             return codeTempEntities.get(0); | 
			
		
	
	
		
		
			
				
					|  |  | 
 |