package com.glxp.api.service.inout; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.UUID; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.StrUtil; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.Constant; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.constant.ConstantType; import com.glxp.api.entity.auth.InvWarehouseEntity; import com.glxp.api.entity.basic.BasicBussinessTypeEntity; import com.glxp.api.entity.basic.UdiEntity; import com.glxp.api.entity.inout.*; import com.glxp.api.entity.inv.InvInnerOrderPdfTempEntity; import com.glxp.api.entity.inv.InvPreinDetailEntity; import com.glxp.api.res.inout.IoOrderCheckResultResponse; import com.glxp.api.res.inout.IoOrderDetailBizResponse; import com.glxp.api.res.inout.IoOrderDetailCodeResponse; import com.glxp.api.service.auth.InvWarehouseService; 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.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; import java.util.*; /** * 校验出入库服务 */ @Service @Transactional(rollbackFor = Exception.class) public class IoCheckInoutService { @Resource IoOrderService orderService; @Resource IoCodeService codeService; @Resource IoCodeTempService codeTempService; @Resource IBasicBussinessTypeService basicBussinessTypeService; @Resource IoOrderDetailCodeService orderDetailCodeService; @Resource IoOrderDetailBizService orderDetailBizService; @Resource IoOrderDetailResultService orderDetailResultService; @Resource InvPreinDetailService invPreinDetailService; @Resource IoGenInvService genInvService; @Resource IoAddInoutService addInoutService; //判断是否需要手动校验 public boolean checkManual(String billNo) { IoOrderEntity orderEntity = orderService.findByBillNo(billNo); BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction()); if (!bussinessTypeEntity.isCheckEnable()) { return false; } else { if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDIMS) { if (!bussinessTypeEntity.isCheckUdims()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_WEBNEW) { if (!bussinessTypeEntity.isCheckWebNew()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAED) { if (!bussinessTypeEntity.isCheckPdaEd()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAUN) { if (!bussinessTypeEntity.isCheckPdaUn()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PC) { if (!bussinessTypeEntity.isCheckPc()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_CHANGE) { if (!bussinessTypeEntity.isCheckChange()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PEACE_CHANGE) { if (!bussinessTypeEntity.isCheckBalance()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDISP) { if (!bussinessTypeEntity.isCheckSp()) { return false; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_COPY) { if (!bussinessTypeEntity.isCheckCopy()) { return false; } } return true; } } //校验流程 //一次校验 public void check(String orderId) { IoOrderEntity orderEntity = orderService.findByBillNo(orderId); //过滤非未校验或校验异常 if (orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_CHECK && orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_CHECK_FAIL) return; BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction()); if (!bussinessTypeEntity.isCheckEnable()) { unCheckFirstFinish(orderEntity); } else { if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDIMS) { if (!bussinessTypeEntity.isCheckUdims()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_WEBNEW) { if (!bussinessTypeEntity.isCheckWebNew()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAED) { if (!bussinessTypeEntity.isCheckPdaEd()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAUN) { if (!bussinessTypeEntity.isCheckPdaUn()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PC) { if (!bussinessTypeEntity.isCheckPc()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_CHANGE) { if (!bussinessTypeEntity.isCheckChange()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PEACE_CHANGE) { if (!bussinessTypeEntity.isCheckBalance()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDISP) { if (!bussinessTypeEntity.isCheckSp()) { unCheckFirstFinish(orderEntity); return; } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_COPY) { if (!bussinessTypeEntity.isCheckCopy()) { unCheckFirstFinish(orderEntity); return; } } checkFirstFinish(orderEntity); } } @Resource IoCodeLostService codeLostService; @Async public void genLostCode(String orderId) { List ioCodeEntities = codeService.findByOrderId(orderId); for (IoCodeEntity codeEntity : ioCodeEntities) { UdiEntity udiEntity = FilterUdiUtils.getUdi(codeEntity.getCode()); IoCodeLostEntity codeLostEntity = codeLostService.findByCode(codeEntity.getCode()); if (codeLostEntity == null) codeLostEntity = new IoCodeLostEntity(); //校验是否写入缺失表 boolean isTrue = false; if (udiEntity != null) { if (!StrUtil.trimToEmpty(codeEntity.getBatchNo()).equals(StrUtil.trimToEmpty(udiEntity.getBatchNo()))) { if (StrUtil.isNotEmpty(codeEntity.getBatchNo())) { codeLostEntity.setBatchNo(codeEntity.getBatchNo()); isTrue = true; } } if (!StrUtil.trimToEmpty(codeEntity.getProduceDate()).equals(StrUtil.trimToEmpty(udiEntity.getProduceDate()))) { if (StrUtil.isNotEmpty(codeEntity.getProduceDate())) { codeLostEntity.setProduceDate(codeEntity.getProduceDate()); isTrue = true; } } if (!StrUtil.trimToEmpty(codeEntity.getExpireDate()).equals(StrUtil.trimToEmpty(udiEntity.getExpireDate()))) { if (StrUtil.isNotEmpty(codeEntity.getExpireDate())) { codeLostEntity.setExpireDate(codeEntity.getExpireDate()); isTrue = true; } } if (isTrue) { codeLostEntity.setCreateTime(new Date()); codeLostService.insertOrUpdate(codeLostEntity); } } } } public String checkCode(IoCodeTempEntity codeEntity) { boolean isBillExit = orderDetailBizService.isExit(codeEntity.getOrderId()); if (!isBillExit) { return "请先录入业务详情"; } IoOrderDetailBizEntity bizEntity = orderDetailBizService.findByUnique(codeEntity.getOrderId(), codeEntity.getRelId(), codeEntity.getBatchNo(), codeEntity.getProduceDate(), codeEntity.getExpireDate()); if (bizEntity == null) { return "非此单产品!"; } IoOrderDetailCodeEntity orderDetailCodeEntity = orderDetailCodeService.findByUnique(codeEntity.getOrderId(), codeEntity.getRelId(), codeEntity.getBatchNo()); int curCount = 0; if (orderDetailCodeEntity != null) { curCount = orderDetailCodeEntity.getReCount() + codeEntity.getMyReCount(); } else { curCount = codeEntity.getMyReCount(); } if (curCount > bizEntity.getCount()) { return "当前产品数量超出!"; } return null; } //一次校验(无需校验)完成 public void unCheckFirstFinish(IoOrderEntity orderEntity) { List orderDetailCodeEntities = orderDetailCodeService.findByOrderId(orderEntity.getBillNo()); if (CollUtil.isEmpty(orderDetailCodeEntities)) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_FAIL); orderEntity.setUpdateTime(new Date()); orderEntity.setErrMsg("校验失败,扫码详情为空!"); orderService.update(orderEntity); return; } orderDetailBizService.deleteByOrderId(orderEntity.getBillNo()); orderDetailResultService.deleteByOrderId(orderEntity.getBillNo()); orderDetailCodeEntities.forEach(orderDetailCodeEntity -> { //生成业务单据 IoOrderDetailBizEntity orderDetailBizEntity = new IoOrderDetailBizEntity(); BeanUtils.copyProperties(orderDetailCodeEntity, orderDetailBizEntity); orderDetailBizEntity.setCount(orderDetailCodeEntity.getReCount()); orderDetailBizEntity.setId(null); orderDetailBizService.insert(orderDetailBizEntity); //生成单据结果 IoOrderDetailResultEntity orderDetailResultEntity = new IoOrderDetailResultEntity(); BeanUtils.copyProperties(orderDetailCodeEntity, orderDetailResultEntity); orderDetailResultEntity.setCount(orderDetailCodeEntity.getReCount()); orderDetailResultEntity.setReCount(orderDetailCodeEntity.getReCount()); orderDetailResultEntity.setId(null); orderDetailResultService.insert(orderDetailResultEntity); }); //临时表转正式表 List codeTempEntities = codeTempService.findByOrderId(orderEntity.getBillNo()); for (IoCodeTempEntity codeTempEntity : codeTempEntities) { IoCodeEntity codeEnttity = new IoCodeEntity(); BeanUtils.copyProperties(codeTempEntity, codeEnttity); codeEnttity.setId(null); codeService.insert(codeEnttity); } codeTempService.deleteByBillNo(orderEntity.getBillNo()); orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_SUCCESS); orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_POST); orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); genLostCode(orderEntity.getBillNo()); checkThird(orderEntity); } //一次校验完成 public void checkFirstFinish(IoOrderEntity orderEntity) { List orderDetailCodeEntities = orderDetailCodeService.findByOrderId(orderEntity.getBillNo()); List orderDetailBizEntities = orderDetailBizService.findByOrderId(orderEntity.getBillNo()); if (CollUtil.isEmpty(orderDetailCodeEntities)) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK); orderEntity.setUpdateTime(new Date()); orderEntity.setErrMsg("校验失败,扫码详情为空!"); orderService.update(orderEntity); return; } if (CollUtil.isEmpty(orderDetailBizEntities)) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK); orderEntity.setUpdateTime(new Date()); orderEntity.setErrMsg("校验失败,业务详情为空!"); orderService.update(orderEntity); return; } String errMsg = ""; //正向校验 for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { String msg = ""; for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { if (!bizEntity.isCheckSuccess() && !codeEntity.isCheckSuccess() && checkId(bizEntity, codeEntity) == null && checkBatchNo(bizEntity, codeEntity) == null && checkProductDate(bizEntity, codeEntity) == null && checkExpireDate(bizEntity, codeEntity) == null ) { if (checkCount(bizEntity, codeEntity) == null) { bizEntity.setCheckSuccess(true); bizEntity.setScanCount(codeEntity.getReCount()); codeEntity.setCheckSuccess(true); } else { bizEntity.setScanCount(codeEntity.getReCount()); bizEntity.setCheckSuccess(false); msg = "数量不匹配"; } break; } } if (StrUtil.isEmpty(msg) && !bizEntity.isCheckSuccess()) { msg = "三期不匹配"; } bizEntity.setErrMsg(msg); } for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { if (!bizEntity.isCheckSuccess()) { errMsg = errMsg + bizEntity.getCoName() + bizEntity.getErrMsg() + ";"; } } //反向校验 for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { if (!bizEntity.isCheckSuccess() && !codeEntity.isCheckSuccess() && checkId(bizEntity, codeEntity) == null && checkBatchNo(bizEntity, codeEntity) == null && checkProductDate(bizEntity, codeEntity) == null && checkExpireDate(bizEntity, codeEntity) == null ) { if (checkCount(bizEntity, codeEntity) == null) { bizEntity.setCheckSuccess(true); codeEntity.setCheckSuccess(true); } break; } } } for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { if (!codeEntity.isCheckSuccess()) { errMsg = errMsg + codeEntity.getCoName() + ";"; } } if (StrUtil.isNotEmpty(errMsg)) { orderEntity.setErrMsg(errMsg + "校验失败"); orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_FAIL); orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); } else { //生成单据结果 orderDetailResultService.deleteByOrderId(orderEntity.getBillNo()); for (IoOrderDetailBizEntity orderDetailBizEntity : orderDetailBizEntities) { IoOrderDetailResultEntity orderDetailResultEntity = new IoOrderDetailResultEntity(); BeanUtils.copyProperties(orderDetailBizEntity, orderDetailResultEntity); orderDetailResultEntity.setId(null); orderDetailResultEntity.setReCount(orderDetailBizEntity.getScanCount()); orderDetailResultService.insert(orderDetailResultEntity); } //临时表转正式表 List codeTempEntities = codeTempService.findByOrderId(orderEntity.getBillNo()); for (IoCodeTempEntity codeTempEntity : codeTempEntities) { IoCodeEntity codeEnttity = new IoCodeEntity(); BeanUtils.copyProperties(codeTempEntity, codeEnttity); codeService.insert(codeEnttity); } codeTempService.deleteByBillNo(orderEntity.getBillNo()); orderEntity.setErrMsg("校验成功!"); orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_SUCCESS); orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_POST); orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); //生成缺失码 genLostCode(orderEntity.getBillNo()); checkThird(orderEntity); } } //业务单正向校验 public String bizOrderCheck(List orderDetailBizEntities, List orderDetailCodeEntities) { String errMsg = ""; //初始化默认值 for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { codeEntity.setCheckSuccess(false); } for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { bizEntity.setCheckSuccess(false); } for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { String msg = ""; for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { if (!bizEntity.isCheckSuccess() && !codeEntity.isCheckSuccess() && checkId(bizEntity, codeEntity) == null && checkBatchNo(bizEntity, codeEntity) == null && checkProductDate(bizEntity, codeEntity) == null && checkExpireDate(bizEntity, codeEntity) == null ) { if (checkCount(bizEntity, codeEntity) == null) { bizEntity.setCheckSuccess(true); codeEntity.setCheckSuccess(true); bizEntity.setScanCount(codeEntity.getReCount()); } else { msg = "数量不匹配"; bizEntity.setScanCount(codeEntity.getReCount()); bizEntity.setCheckSuccess(false); } break; } } if (StrUtil.isEmpty(msg) && !bizEntity.isCheckSuccess()) { msg = "三期不匹配"; } bizEntity.setErrMsg(msg); } for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { if (!bizEntity.isCheckSuccess()) { errMsg = errMsg + bizEntity.getCoName() + bizEntity.getErrMsg() + ";"; } } return errMsg; } //业务单正向校验 public String bizOrderCheck2(List orderDetailBizEntities, List orderDetailCodeEntities) { String errMsg = ""; //初始化默认值 for (IoOrderDetailBizResponse bizResponse : orderDetailBizEntities) { IoOrderDetailBizEntity bizEntity = new IoOrderDetailBizEntity(); BeanUtils.copyProperties(bizResponse, bizEntity); for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { if (!bizEntity.isCheckSuccess() && !codeEntity.isCheckSuccess() && checkId(bizEntity, codeEntity) == null && checkBatchNo(bizEntity, codeEntity) == null ) { if (checkCount(bizEntity, codeEntity) == null) { bizResponse.setCheckSuccess(true); codeEntity.setCheckSuccess(true); bizResponse.setScanCount(codeEntity.getReCount()); } else { bizResponse.setScanCount(codeEntity.getReCount()); bizResponse.setCheckSuccess(false); } break; } } } for (IoOrderDetailBizResponse bizEntity : orderDetailBizEntities) { if (!bizEntity.isCheckSuccess()) { errMsg = errMsg + bizEntity.getCoName() + ";"; } } return errMsg; } //单据合并校验 public List combineCheck(List orderDetailBizEntities, List orderDetailCodeEntities) { List orderCheckResultResponses = new ArrayList<>(); for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { boolean isPass = false; for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { if (!codeEntity.isCheckSuccess() && checkId(bizEntity, codeEntity) == null && checkBatchNo(bizEntity, codeEntity) == null ) { //将产品ID,批次号匹配的合并,添加到列表 IoOrderCheckResultResponse ioOrderCheckResultResponse = new IoOrderCheckResultResponse(); BeanUtils.copyProperties(bizEntity, ioOrderCheckResultResponse); ioOrderCheckResultResponse.setBBatchNo(bizEntity.getBatchNo()); ioOrderCheckResultResponse.setBProductDate(bizEntity.getProductDate()); ioOrderCheckResultResponse.setBExpireDate(bizEntity.getExpireDate()); ioOrderCheckResultResponse.setSBatchNo(codeEntity.getBatchNo()); ioOrderCheckResultResponse.setSProductDate(codeEntity.getProductDate()); ioOrderCheckResultResponse.setSExpireDate(codeEntity.getExpireDate()); bizEntity.setCheckSuccess(true); codeEntity.setCheckSuccess(true); bizEntity.setScanCount(codeEntity.getReCount()); ioOrderCheckResultResponse.setScanCount(bizEntity.getScanCount()); ioOrderCheckResultResponse.setCheckSuccess(true); isPass = true; orderCheckResultResponses.add(ioOrderCheckResultResponse); break; } } if (!isPass) { //将未与扫码单 IoOrderCheckResultResponse ioOrderCheckResultResponse = new IoOrderCheckResultResponse(); BeanUtils.copyProperties(bizEntity, ioOrderCheckResultResponse); ioOrderCheckResultResponse.setBBatchNo(bizEntity.getBatchNo()); ioOrderCheckResultResponse.setBProductDate(bizEntity.getProductDate()); ioOrderCheckResultResponse.setBExpireDate(bizEntity.getExpireDate()); bizEntity.setScanCount(0); ioOrderCheckResultResponse.setCheckSuccess(false); orderCheckResultResponses.add(ioOrderCheckResultResponse); } } for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { if (!codeEntity.isCheckSuccess()) { IoOrderCheckResultResponse ioOrderCheckResultResponse = new IoOrderCheckResultResponse(); BeanUtils.copyProperties(codeEntity, ioOrderCheckResultResponse); ioOrderCheckResultResponse.setSBatchNo(codeEntity.getBatchNo()); ioOrderCheckResultResponse.setSProductDate(codeEntity.getProductDate()); ioOrderCheckResultResponse.setSExpireDate(codeEntity.getExpireDate()); ioOrderCheckResultResponse.setCount(0); ioOrderCheckResultResponse.setScanCount(codeEntity.getReCount()); orderCheckResultResponses.add(ioOrderCheckResultResponse); } } return orderCheckResultResponses; } //扫码单反向校验 public String codeOrderCheck(List orderDetailCodeEntities, List orderDetailBizEntities) { //初始化默认值 for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { codeEntity.setCheckSuccess(false); } for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { bizEntity.setCheckSuccess(false); } for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { String msg = ""; for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { if (!bizEntity.isCheckSuccess() && !codeEntity.isCheckSuccess() && checkId(bizEntity, codeEntity) == null && checkBatchNo(bizEntity, codeEntity) == null && checkProductDate(bizEntity, codeEntity) == null && checkExpireDate(bizEntity, codeEntity) == null ) { if (checkCount(bizEntity, codeEntity) == null) { bizEntity.setCheckSuccess(true); codeEntity.setCheckSuccess(true); codeEntity.setOrderCount(bizEntity.getCount()); } else { msg = "数量不匹配"; codeEntity.setCheckSuccess(false); codeEntity.setOrderCount(bizEntity.getCount()); } break; } else { codeEntity.setCheckSuccess(false); } } if (StrUtil.isEmpty(msg) && !codeEntity.isCheckSuccess()) { msg = "三期不匹配"; } codeEntity.setErrMsg(msg); } String errMsg = ""; for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { if (!codeEntity.isCheckSuccess()) { errMsg = errMsg + codeEntity.getCoName() + codeEntity.getErrMsg() + ";"; } } return errMsg; } public void codeOrderCheck2(List orderDetailCodeEntities, List orderDetailBizEntities) { for (IoOrderDetailCodeResponse codeResponse : orderDetailCodeEntities) { IoOrderDetailCodeEntity codeEntity = new IoOrderDetailCodeEntity(); BeanUtils.copyProperties(codeResponse, codeEntity); for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { if (!bizEntity.isCheckSuccess() && !codeEntity.isCheckSuccess() && checkId(bizEntity, codeEntity) == null && checkBatchNo(bizEntity, codeEntity) == null ) { if (checkCount(bizEntity, codeEntity) == null) { bizEntity.setCheckSuccess(true); codeResponse.setCheckSuccess(true); codeResponse.setOrderCount(bizEntity.getCount()); } else { codeResponse.setCheckSuccess(false); codeResponse.setOrderCount(bizEntity.getCount()); } break; } else { codeResponse.setCheckSuccess(false); } } } } //三次校验(中间层) public void checkThird(IoOrderEntity orderEntity) { BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction()); if (orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_AUDITED && orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_CHECK_REW) { if (bussinessTypeEntity.isThrCheckEnable()) { if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDIMS) { if (!bussinessTypeEntity.isThrCheckUdims()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_WEBNEW) { if (!bussinessTypeEntity.isThrCheckWebNew()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAED) { if (!bussinessTypeEntity.isThrCheckPdaEd()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAUN) { if (!bussinessTypeEntity.isThrCheckPdaUn()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PC) { if (!bussinessTypeEntity.isThrCheckPc()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_CHANGE) { if (!bussinessTypeEntity.isThrCheckChange()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PEACE_CHANGE) { if (!bussinessTypeEntity.isThrCheckBalance()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_COPY) { if (!bussinessTypeEntity.isThrCheckCopy()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } } else { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW); } } if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_CHECK_REW) { orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_REW); orderEntity.setUpdateTime(new Date()); orderEntity.setCheckTime(new Date()); orderService.update(orderEntity); checkSecond(orderEntity); } } //二次校验 public void checkSecond(IoOrderEntity orderEntity) { BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction()); if (orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_AUDITED) { if (bussinessTypeEntity.isSecCheckEnable()) { if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDIMS) { if (!bussinessTypeEntity.isSecCheckUdims()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_WEBNEW) { if (!bussinessTypeEntity.isSecCheckWebNew()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAED) { if (!bussinessTypeEntity.isSecCheckPdaEd()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAUN) { if (!bussinessTypeEntity.isSecCheckPdaUn()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PC) { if (!bussinessTypeEntity.isSecCheckPc()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_CHANGE) { if (!bussinessTypeEntity.isSecCheckChange()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PEACE_CHANGE) { if (!bussinessTypeEntity.isSecCheckBalance()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_COPY) { if (!bussinessTypeEntity.isSecCheckCopy()) { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } } else { orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED); } } if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_AUDITED) { orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_CHECK); orderEntity.setUpdateTime(new Date()); orderEntity.setAuditTime(new Date()); orderService.update(orderEntity); List codeEntities = codeService.findByOrderId(orderEntity.getBillNo()); genInv(orderEntity, bussinessTypeEntity); } } @Resource IoChangeInoutService changeInoutService; @Resource InvPreinProductDetailService invPreinProductDetailService; @Resource UdiCalCountUtil udiCalCountUtil; //校验完成后生成库存 public void genInv(IoOrderEntity orderEntity, BasicBussinessTypeEntity bussinessTypeEntity) { if (bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT) && bussinessTypeEntity.isScanPreIn()) { // ThreadUtil.execAsync(() -> { if (StrUtil.isNotEmpty(bussinessTypeEntity.getPreInBackAction())) { if (bussinessTypeEntity.getBackPreinType() == 1) { //按单退货 String orderIds = orderEntity.getCheckPreInOrders(); if (StrUtil.isNotEmpty(orderIds)) { String[] orderIdArray = orderIds.split(","); List orderList = CollUtil.toList(orderIdArray); List outCodeEntitys = codeService.findByOrderId(orderEntity.getBillNo()); List preInCodeEntities = codeService.findByOrderIds(orderList, null); // 扣减数量 for (IoCodeEntity preInCodeEntity : preInCodeEntities) { for (IoCodeEntity codeEntity : outCodeEntitys) { if (preInCodeEntity.getCode().equals(codeEntity.getCode())) { int count = preInCodeEntity.getMyCount() - codeEntity.getMyCount(); int reCount = preInCodeEntity.getMyReCount() - codeEntity.getMyReCount(); if (count > 0) { preInCodeEntity.setCount(count); preInCodeEntity.setReCount(reCount); codeEntity.setCount(0); codeEntity.setReCount(0); } else if (count < 0) { preInCodeEntity.setCount(0); preInCodeEntity.setReCount(0); codeEntity.setCount(-count); codeEntity.setReCount(-reCount); } else { preInCodeEntity.setCount(0); preInCodeEntity.setReCount(0); codeEntity.setCount(0); codeEntity.setReCount(0); } } } } List backCodeList = new ArrayList<>(); for (IoCodeEntity codeEntity : preInCodeEntities) { if (codeEntity.getMyCount() > 0) { backCodeList.add(codeEntity); } } genBackOrder(orderEntity, backCodeList); } } else { //按仓库货位退货 List backCodeList = new ArrayList<>(); List codeList = codeService.findByOrderId(orderEntity.getBillNo()); 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); genBackOrder(orderEntity, backCodeList); } } } } // }); } //校验是否是不入库存单据 if (bussinessTypeEntity.isInStock()) { //生成库存 if (bussinessTypeEntity.getActionType() == ConstantStatus.ACTION_TYPE_PREIN) { genInvService.genPreInInv(orderEntity.getBillNo()); } else if (bussinessTypeEntity.getActionType() == ConstantStatus.ACTION_TYPE_ADVANCE) { genInvService.genPreInv(orderEntity.getBillNo()); } else { genInvService.genNorInv(orderEntity.getBillNo()); } } else { //不入库存,直接进行单据流转 changeInoutService.changeOrder(orderEntity); } } @Resource InvWarehouseService invWarehouseService; public void genBackOrder(IoOrderEntity orderEntity, List backCodeList) { if (CollUtil.isEmpty(backCodeList)) return; BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction()); if (StrUtil.isNotEmpty(basicBussinessTypeEntity.getPreInBackAction())) { IoOrderEntity outOrder = new IoOrderEntity(); IoCodeEntity codeEntity = backCodeList.get(0); outOrder.setId(null); outOrder.setMainAction(ConstantType.TYPE_OUT); outOrder.setAction(basicBussinessTypeEntity.getPreInBackAction()); InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(Constant.INV_PRE_IN_CODE); outOrder.setInvCode(invWarehouseEntity.getCode()); outOrder.setDeptCode(invWarehouseEntity.getParentId()); outOrder.setFromCorp(codeEntity.getSupId()); outOrder.setCreateTime(new Date()); outOrder.setFromType(ConstantStatus.FROM_BACK); 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 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.带回时生成退货出库单 @Resource GennerOrderUtils gennerOrderUtils; public String checkId(IoOrderDetailBizEntity bizEntity, IoOrderDetailCodeEntity codeEntity) { if (bizEntity.getBindRlFk().longValue() == codeEntity.getBindRlFk().longValue()) { return null; } else { return "产品ID不匹配"; } } public String checkBatchNo(IoOrderDetailBizEntity bizEntity, IoOrderDetailCodeEntity codeEntity) { if (StrUtil.nullToEmpty(bizEntity.getBatchNo()).equals(StrUtil.nullToEmpty(codeEntity.getBatchNo()))) { return null; } else { return bizEntity.getCoName() + "批次号不匹配"; } } public String checkProductDate(IoOrderDetailBizEntity bizEntity, IoOrderDetailCodeEntity codeEntity) { if (StrUtil.nullToEmpty(bizEntity.getProductDate()).equals(StrUtil.nullToEmpty(codeEntity.getProductDate()))) { return null; } else { return bizEntity.getCoName() + "生产日期不匹配"; } } public String checkExpireDate(IoOrderDetailBizEntity bizEntity, IoOrderDetailCodeEntity codeEntity) { if (StrUtil.nullToEmpty(bizEntity.getExpireDate()).equals(StrUtil.nullToEmpty(codeEntity.getExpireDate()))) { return null; } else { return bizEntity.getCoName() + "失效日期不匹配"; } } public String checkCount(IoOrderDetailBizEntity bizEntity, IoOrderDetailCodeEntity codeEntity) { if (bizEntity.getCount() == codeEntity.getReCount()) { return null; } return bizEntity.getCoName() + "数量不匹配!"; } }