|  |  |  | @ -19,11 +19,13 @@ import com.glxp.api.res.inout.IoOrderDetailCodeResponse; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.service.basic.IBasicBussinessTypeService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.service.inv.InvPreinDetailService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.service.inv.InvPreinOrderService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.service.inv.InvPreinProductDetailService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.CustomUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.GennerOrderUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.JasperUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.OrderNoTypeBean; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.udi.FilterUdiUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.udi.UdiCalCountUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import net.sf.jasperreports.engine.JRException; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.beans.BeanUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.scheduling.annotation.Async; | 
			
		
	
	
		
			
				
					|  |  |  | @ -731,6 +733,10 @@ public class IoCheckInoutService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     IoChangeInoutService changeInoutService; | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     InvPreinProductDetailService invPreinProductDetailService; | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     UdiCalCountUtil udiCalCountUtil; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     //校验完成后生成库存
 | 
			
		
	
		
			
				
					|  |  |  |  |     public void genInv(IoOrderEntity orderEntity, BasicBussinessTypeEntity bussinessTypeEntity) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -738,163 +744,175 @@ public class IoCheckInoutService { | 
			
		
	
		
			
				
					|  |  |  |  |         if (bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT) && bussinessTypeEntity.isScanPreIn()) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             ThreadUtil.execAsync(() -> { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                 List<IoCodeEntity> backCodeList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                 List<IoCodeEntity> codeList = codeService.findByOrderId(orderEntity.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                 //找出UDI码对应的预验收入库单号
 | 
			
		
	
		
			
				
					|  |  |  |  |                 Map<String, String> preInOrder = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                 for (IoCodeEntity warehouseEntity : codeList) { | 
			
		
	
		
			
				
					|  |  |  |  |                     List<InvPreinDetailEntity> invProductDetailEntities = invPreinDetailService.findByCode(warehouseEntity.getCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (invProductDetailEntities.size() > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                         for (InvPreinDetailEntity invPreinDetailEntity : invProductDetailEntities) | 
			
		
	
		
			
				
					|  |  |  |  |                             preInOrder.put(invPreinDetailEntity.getOrderId(), invPreinDetailEntity.getOrderId()); | 
			
		
	
		
			
				
					|  |  |  |  |                 for (IoCodeEntity codeEntity : codeList) { | 
			
		
	
		
			
				
					|  |  |  |  |                     int count = invPreinProductDetailService.findCountByCode(codeEntity.getCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (count > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                         codeEntity.setCount(count); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeEntity.setReCount(udiCalCountUtil.getActCount(codeEntity.getNameCode())); | 
			
		
	
		
			
				
					|  |  |  |  |                         backCodeList.add(codeEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |                 if (preInOrder.size() > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                     String preInBillNo = ""; | 
			
		
	
		
			
				
					|  |  |  |  |                     boolean isBreak = false; | 
			
		
	
		
			
				
					|  |  |  |  |                     List<IoCodeEntity> backCodeList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                     for (String key : preInOrder.keySet()) { | 
			
		
	
		
			
				
					|  |  |  |  |                         if (!isBreak) { | 
			
		
	
		
			
				
					|  |  |  |  |                             preInBillNo = preInBillNo + "," + key; | 
			
		
	
		
			
				
					|  |  |  |  |                             IoOrderEntity preInEntity = orderService.findByBillNo(key); | 
			
		
	
		
			
				
					|  |  |  |  |                             preInEntity.setPreOutBillNo(orderEntity.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                             orderService.update(preInEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                             BasicBussinessTypeEntity preBusType = basicBussinessTypeService.findByAction(preInEntity.getAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                             //预验收不删除单号,方便后续查询
 | 
			
		
	
		
			
				
					|  |  |  |  |                             if (preBusType.isPreInBack()) {            //预验收如果带回,则清空相关预验收库存;
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 invPreinDetailService.deleteByOrderId(preInEntity.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 //剩余UDI码生成退货单 todo
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 List<IoCodeEntity> codeEntities = codeService.findByOrderId(preInBillNo); | 
			
		
	
		
			
				
					|  |  |  |  |                                 backCodeList.addAll(codeEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                             } else {            //预验收如果不带回,则清除已出库相关库存
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 for (IoCodeEntity codeEntity : codeList) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     if (StrUtil.isEmpty(codeEntity.getSerialNo())) { | 
			
		
	
		
			
				
					|  |  |  |  |                                         InvPreinDetailEntity invPreinDetailEntity = invPreinDetailService.findByCode(key, codeEntity.getCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                                         if (invPreinDetailEntity != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                                             int count = 0; | 
			
		
	
		
			
				
					|  |  |  |  |                                             if (invPreinDetailEntity.getCount() < codeEntity.getCount()) { | 
			
		
	
		
			
				
					|  |  |  |  |                                                 count = 0; | 
			
		
	
		
			
				
					|  |  |  |  |                                             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                                 count = invPreinDetailEntity.getCount() - codeEntity.getCount(); | 
			
		
	
		
			
				
					|  |  |  |  |                                             } | 
			
		
	
		
			
				
					|  |  |  |  |                                             if (count >= 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                                                 isBreak = true; | 
			
		
	
		
			
				
					|  |  |  |  |                                                 if (count == 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                                                     invPreinDetailService.deleteByCode(key, codeEntity.getCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                                                 } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                                     invPreinDetailEntity.setCount(count); | 
			
		
	
		
			
				
					|  |  |  |  |                                                     invPreinDetailService.update(invPreinDetailEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                                                 int reCount = invPreinDetailEntity.getReCount() - codeEntity.getMyReCount(); | 
			
		
	
		
			
				
					|  |  |  |  |                                                 if (reCount == 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                                                     invPreinDetailService.deleteByCode(key, codeEntity.getCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                                                 } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                                     invPreinDetailEntity.setReCount(reCount); | 
			
		
	
		
			
				
					|  |  |  |  |                                                     invPreinDetailService.update(invPreinDetailEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                                             } | 
			
		
	
		
			
				
					|  |  |  |  |                                         } | 
			
		
	
		
			
				
					|  |  |  |  |                                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                         invPreinDetailService.deleteByCode(key, codeEntity.getCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     } | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                     orderEntity.setPreInBillNo(preInBillNo.substring(1)); | 
			
		
	
		
			
				
					|  |  |  |  |                 BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                 if (StrUtil.isNotEmpty(basicBussinessTypeEntity.getPreInBackAction())) { | 
			
		
	
		
			
				
					|  |  |  |  |                     IoOrderEntity outOrder = new IoOrderEntity(); | 
			
		
	
		
			
				
					|  |  |  |  | //                    BeanUtils.copyProperties(orderEntity, outOrder);
 | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setId(null); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setMainAction(ConstantType.TYPE_OUT); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setAction(basicBussinessTypeEntity.getAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setCreateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setFromType(ConstantStatus.FROM_CHANGE); | 
			
		
	
		
			
				
					|  |  |  |  |                     String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(basicBussinessTypeEntity.getPrefix()), "yyyyMMdd")); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setBillNo(orderNo); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setCustomerId(Constant.SYSTEM_CUSTOMER_ID); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setCorpOrderId(CustomUtil.getId() + "x"); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setStatus(ConstantStatus.ORDER_STATUS_PROCESS); | 
			
		
	
		
			
				
					|  |  |  |  |                     orderEntity.setUllageSupNo(outOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                     orderEntity.setUpdateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                     orderService.update(orderEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setOriginUllageSupNo(orderEntity.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setCreateUser(null); | 
			
		
	
		
			
				
					|  |  |  |  |                     outOrder.setReviewUser(null); | 
			
		
	
		
			
				
					|  |  |  |  |                     orderService.insertOrder(outOrder); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                     //生成条码
 | 
			
		
	
		
			
				
					|  |  |  |  |                     List<IoCodeTempEntity> codeTempEntities = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                     for (IoCodeEntity warehouseEntity : backCodeList) { | 
			
		
	
		
			
				
					|  |  |  |  |                         IoCodeTempEntity codeTempEntity = new IoCodeTempEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |                         BeanUtils.copyProperties(warehouseEntity, codeTempEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeTempEntity.setId(null); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeTempEntity.setOrderId(outOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeTempEntity.setAction(outOrder.getAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeTempEntity.setMainAction(outOrder.getMainAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeTempEntity.setCreateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeTempEntity.setUpdateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                         codeTempEntities.add(codeTempEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                     codeTempService.insertBatch(codeTempEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                     addInoutService.dealProcess(outOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (!checkManual(outOrder.getBillNo())) { | 
			
		
	
		
			
				
					|  |  |  |  |                         check(outOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                     //生成退货单 1.查出所有关联的单据条码,2.扣减当前出库数量;3.生成单据类型对应绑定的出库单
 | 
			
		
	
		
			
				
					|  |  |  |  |                     if (CollUtil.isNotEmpty(backCodeList)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         List<IoCodeEntity> realBackCodeList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                         for (IoCodeEntity backCodeEntity : backCodeList) { | 
			
		
	
		
			
				
					|  |  |  |  |                             for (IoCodeEntity codeEntity : codeList) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 if (codeEntity.getCount() != 0 && backCodeEntity.getCode().equals(codeEntity.getCode())) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     int count = backCodeEntity.getCount() - codeEntity.getCount(); | 
			
		
	
		
			
				
					|  |  |  |  |                                     int reCount = backCodeEntity.getReCount() - codeEntity.getReCount(); | 
			
		
	
		
			
				
					|  |  |  |  |                                     if (count > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeEntity.setCount(0); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeEntity.setReCount(0); | 
			
		
	
		
			
				
					|  |  |  |  |                                         backCodeEntity.setCount(count); | 
			
		
	
		
			
				
					|  |  |  |  |                                         backCodeEntity.setReCount(reCount); | 
			
		
	
		
			
				
					|  |  |  |  |                                         realBackCodeList.add(backCodeEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                                     } else if (count == 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeEntity.setCount(0); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeEntity.setReCount(0); | 
			
		
	
		
			
				
					|  |  |  |  |                                     } else if (count < 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeEntity.setCount(-count); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeEntity.setReCount(-reCount); | 
			
		
	
		
			
				
					|  |  |  |  |                                     } | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                         if (CollUtil.isNotEmpty(realBackCodeList)) { | 
			
		
	
		
			
				
					|  |  |  |  |                             Map<String, List<IoCodeEntity>> backPreInOrder = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                             for (IoCodeEntity codeEntity : codeList) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 List<IoCodeEntity> codeEntities = backPreInOrder.get(codeEntity.getOrderId()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 if (CollUtil.isEmpty(codeEntities)) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     codeEntities = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                                 codeEntities.add(codeEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                                 backPreInOrder.put(codeEntity.getOrderId(), codeEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                             for (String key : backPreInOrder.keySet()) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 IoOrderEntity originOrder = orderService.findByBillNo(key); | 
			
		
	
		
			
				
					|  |  |  |  |                                 BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeService.findByAction(originOrder.getAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 if (StrUtil.isNotEmpty(basicBussinessTypeEntity.getPreInBackAction())) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     IoOrderEntity outOrder = new IoOrderEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |                                     BeanUtils.copyProperties(originOrder, outOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setId(null); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setMainAction(ConstantType.TYPE_OUT); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setAction(basicBussinessTypeEntity.getAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setCreateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setFromType(ConstantStatus.FROM_CHANGE); | 
			
		
	
		
			
				
					|  |  |  |  |                                     String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(basicBussinessTypeEntity.getPrefix()), "yyyyMMdd")); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setBillNo(orderNo); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setCustomerId(Constant.SYSTEM_CUSTOMER_ID); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setCorpOrderId(CustomUtil.getId() + "x"); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setStatus(ConstantStatus.ORDER_STATUS_PROCESS); | 
			
		
	
		
			
				
					|  |  |  |  |                                     originOrder.setUllageSupNo(outOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     originOrder.setUpdateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     orderService.update(originOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setOriginUllageSupNo(originOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setCreateUser(null); | 
			
		
	
		
			
				
					|  |  |  |  |                                     outOrder.setReviewUser(null); | 
			
		
	
		
			
				
					|  |  |  |  |                                     orderService.insertOrder(outOrder); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                                     //生成条码
 | 
			
		
	
		
			
				
					|  |  |  |  |                                     List<IoCodeTempEntity> codeTempEntities = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                                     for (IoCodeEntity warehouseEntity : backPreInOrder.get(key)) { | 
			
		
	
		
			
				
					|  |  |  |  |                                         IoCodeTempEntity codeTempEntity = new IoCodeTempEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |                                         BeanUtils.copyProperties(warehouseEntity, codeTempEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeTempEntity.setId(null); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeTempEntity.setOrderId(outOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeTempEntity.setAction(outOrder.getAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeTempEntity.setMainAction(outOrder.getMainAction()); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeTempEntity.setCreateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeTempEntity.setUpdateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                                         codeTempEntities.add(codeTempEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                                     } | 
			
		
	
		
			
				
					|  |  |  |  |                                     codeTempService.insertBatch(codeTempEntities); | 
			
		
	
		
			
				
					|  |  |  |  |                                     addInoutService.dealProcess(outOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                                     if (!checkManual(outOrder.getBillNo())) { | 
			
		
	
		
			
				
					|  |  |  |  |                                         check(outOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //                //找出UDI码对应的预验收入库单号
 | 
			
		
	
		
			
				
					|  |  |  |  | //                Map<String, String> preInOrder = new HashMap<>();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                for (IoCodeEntity warehouseEntity : codeList) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    List<InvPreinDetailEntity> invProductDetailEntities = invPreinDetailService.findByCode(warehouseEntity.getCode());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    if (invProductDetailEntities.size() > 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        for (InvPreinDetailEntity invPreinDetailEntity : invProductDetailEntities)
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            preInOrder.put(invPreinDetailEntity.getOrderId(), invPreinDetailEntity.getOrderId());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                if (preInOrder.size() > 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    String preInBillNo = "";
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    boolean isBreak = false;
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    for (String key : preInOrder.keySet()) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        if (!isBreak) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            preInBillNo = preInBillNo + "," + key;
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            IoOrderEntity preInEntity = orderService.findByBillNo(key);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            preInEntity.setPreOutBillNo(orderEntity.getBillNo());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            orderService.update(preInEntity);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            BasicBussinessTypeEntity preBusType = basicBussinessTypeService.findByAction(preInEntity.getAction());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            //预验收不删除单号,方便后续查询
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            if (preBusType.isPreInBack()) {            //预验收如果带回,则清空相关预验收库存;
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                invPreinDetailService.deleteByOrderId(preInEntity.getBillNo());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                //剩余UDI码生成退货单 todo
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                List<IoCodeEntity> codeEntities = codeService.findByOrderId(key);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                backCodeList.addAll(codeEntities);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            } else {            //预验收如果不带回,则清除已出库相关库存
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                for (IoCodeEntity codeEntity : codeList) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    if (StrUtil.isEmpty(codeEntity.getSerialNo())) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                        InvPreinDetailEntity invPreinDetailEntity = invPreinDetailService.findByCode(key, codeEntity.getCode());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                        if (invPreinDetailEntity != null) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                            int count = 0;
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                            if (invPreinDetailEntity.getCount() < codeEntity.getCount()) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                count = 0;
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                            } else {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                count = invPreinDetailEntity.getCount() - codeEntity.getCount();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                            }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                            if (count >= 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                isBreak = true;
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                if (count == 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                    invPreinDetailService.deleteByCode(key, codeEntity.getCode());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                } else {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                    invPreinDetailEntity.setCount(count);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                    invPreinDetailService.update(invPreinDetailEntity);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                int reCount = invPreinDetailEntity.getReCount() - codeEntity.getMyReCount();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                if (reCount == 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                    invPreinDetailService.deleteByCode(key, codeEntity.getCode());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                } else {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                    invPreinDetailEntity.setReCount(reCount);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                    invPreinDetailService.update(invPreinDetailEntity);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                                }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                            }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                        }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    } else {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                        invPreinDetailService.deleteByCode(key, codeEntity.getCode());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                }
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        }
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                orderEntity.setPreInBillNo(preInBillNo.substring(1));
 | 
			
		
	
		
			
				
					|  |  |  |  | //                orderService.update(orderEntity);
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //                //生成退货单 1.查出所有关联的单据条码,2.扣减当前出库数量;3.生成单据类型对应绑定的出库单
 | 
			
		
	
		
			
				
					|  |  |  |  | //                if (CollUtil.isNotEmpty(backCodeList)) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    List<IoCodeEntity> realBackCodeList = new ArrayList<>();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    for (IoCodeEntity backCodeEntity : backCodeList) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        for (IoCodeEntity codeEntity : codeList) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            if (codeEntity.getCount() != 0 && backCodeEntity.getCode().equals(codeEntity.getCode())) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                int count = backCodeEntity.getCount() - codeEntity.getCount();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                int reCount = backCodeEntity.getReCount() - codeEntity.getReCount();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                if (count > 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    codeEntity.setCount(0);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    codeEntity.setReCount(0);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    backCodeEntity.setCount(count);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    backCodeEntity.setReCount(reCount);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    realBackCodeList.add(backCodeEntity);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                } else if (count == 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    codeEntity.setCount(0);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    codeEntity.setReCount(0);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                } else if (count < 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    codeEntity.setCount(-count);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    codeEntity.setReCount(-reCount);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        }
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    if (CollUtil.isNotEmpty(realBackCodeList)) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        Map<String, List<IoCodeEntity>> backPreInOrder = new HashMap<>();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        for (IoCodeEntity codeEntity : codeList) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            List<IoCodeEntity> codeEntities = backPreInOrder.get(codeEntity.getOrderId());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            if (CollUtil.isEmpty(codeEntities)) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                codeEntities = new ArrayList<>();
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            codeEntities.add(codeEntity);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            backPreInOrder.put(codeEntity.getOrderId(), codeEntities);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        }
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        for (String key : backPreInOrder.keySet()) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            IoOrderEntity originOrder = orderService.findByBillNo(key);
 | 
			
		
	
		
			
				
					|  |  |  |  | //                            BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeService.findByAction(originOrder.getAction());
 | 
			
		
	
		
			
				
					|  |  |  |  | //
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    }
 | 
			
		
	
		
			
				
					|  |  |  |  | //                }
 | 
			
		
	
		
			
				
					|  |  |  |  | //            }
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |