You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1117 lines
51 KiB
Java
1117 lines
51 KiB
Java
package com.glxp.api.service.inout;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.lang.UUID;
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
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.dao.inout.IoOrderDetailCodeDao;
|
|
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.entity.system.SystemParamConfigEntity;
|
|
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.inout.impl.IoCodeService;
|
|
import com.glxp.api.service.inout.impl.IoOrderInvoiceService;
|
|
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.service.system.SystemParamConfigService;
|
|
import com.glxp.api.util.*;
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
import com.glxp.api.util.udi.UdiCalCountUtil;
|
|
import lombok.RequiredArgsConstructor;
|
|
import net.sf.jasperreports.engine.JRException;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.context.annotation.Lazy;
|
|
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.*;
|
|
|
|
import static com.glxp.api.constant.ConstantStatus.ORDER_STATUS_CHECK_PROCESS;
|
|
|
|
/**
|
|
* 校验出入库服务
|
|
*/
|
|
@Service
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@RequiredArgsConstructor
|
|
public class IoCheckInoutService {
|
|
|
|
@Resource
|
|
IoOrderService orderService;
|
|
@Resource
|
|
IoCodeService codeService;
|
|
@Resource
|
|
IoCodeTempService codeTempService;
|
|
@Resource
|
|
IBasicBussinessTypeService basicBussinessTypeService;
|
|
|
|
@Lazy
|
|
private final IoOrderDetailCodeService orderDetailCodeService;
|
|
|
|
@Lazy
|
|
private final IoOrderDetailBizService orderDetailBizService;
|
|
@Resource
|
|
IoOrderDetailResultService orderDetailResultService;
|
|
@Resource
|
|
IoOrderDetailCodeDao orderDetailCodeDao;
|
|
|
|
@Resource
|
|
InvPreinDetailService invPreinDetailService;
|
|
@Resource
|
|
IoGenInvService genInvService;
|
|
@Resource
|
|
IoAddInoutService addInoutService;
|
|
@Resource
|
|
SystemParamConfigService systemParamConfigService;
|
|
|
|
/**
|
|
* 判断是否需要手动校验
|
|
*
|
|
* @param billNo
|
|
* @return
|
|
*/
|
|
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.getCheckUdims() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_WEBNEW) {
|
|
if (bussinessTypeEntity.getCheckWebNew() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAED) {
|
|
if (bussinessTypeEntity.getCheckPdaEd() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAUN) {
|
|
if (bussinessTypeEntity.getCheckPdaUn() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PC) {
|
|
if (bussinessTypeEntity.getCheckPc() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_CHANGE) {
|
|
if (bussinessTypeEntity.getCheckChange() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PEACE_CHANGE) {
|
|
if (bussinessTypeEntity.getCheckBalance() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDISP) {
|
|
if (bussinessTypeEntity.getCheckSp() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_COPY) {
|
|
if (bussinessTypeEntity.getCheckCopy() == 0) {
|
|
return false;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_REVIEW) {
|
|
if (bussinessTypeEntity.getCheckReview() == 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 校验流程 | 一次校验
|
|
*
|
|
* @param orderId
|
|
*/
|
|
public void check(String orderId) {
|
|
IoOrderEntity orderEntity = orderService.findByBillNo(orderId);
|
|
//过滤非未校验或校验异常
|
|
if (orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_CHECK_PROCESS &&
|
|
orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_CHECK && orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_CHECK_FAIL)
|
|
return;
|
|
|
|
orderEntity.setStatus(ORDER_STATUS_CHECK_PROCESS);
|
|
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_POST);
|
|
orderService.update(orderEntity);
|
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
|
|
if (!bussinessTypeEntity.isCheckEnable()) {
|
|
unCheckFirstFinish(orderEntity);
|
|
} else {
|
|
if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDIMS) {
|
|
if (bussinessTypeEntity.getCheckUdims() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_WEBNEW) {
|
|
if (bussinessTypeEntity.getCheckWebNew() == 0 || bussinessTypeEntity.getCheckWebNew() == 4) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAED) {
|
|
if (bussinessTypeEntity.getCheckPdaEd() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PDAUN) {
|
|
if (bussinessTypeEntity.getCheckPdaUn() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PC) {
|
|
if (bussinessTypeEntity.getCheckPc() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_CHANGE) {
|
|
if (bussinessTypeEntity.getCheckChange() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_PEACE_CHANGE) {
|
|
if (bussinessTypeEntity.getCheckBalance() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDISP) {
|
|
if (bussinessTypeEntity.getCheckSp() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_COPY) {
|
|
if (bussinessTypeEntity.getCheckCopy() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_REVIEW) {
|
|
if (bussinessTypeEntity.getCheckReview() == 0) {
|
|
unCheckFirstFinish(orderEntity);
|
|
return;
|
|
}
|
|
}
|
|
checkFirstFinish(orderEntity);
|
|
}
|
|
}
|
|
|
|
@Resource
|
|
IoCodeLostService codeLostService;
|
|
|
|
@Async
|
|
public void genLostCode(String orderId) {
|
|
List<IoCodeEntity> 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();
|
|
codeLostEntity.setId(IdUtil.getSnowflakeNextId());
|
|
codeLostEntity.setNameCode(udiEntity.getUdi());
|
|
codeLostEntity.setCode(codeEntity.getCode());
|
|
codeLostEntity.setBatchNo(codeEntity.getBatchNo());
|
|
codeLostEntity.setProduceDate(codeEntity.getProduceDate());
|
|
codeLostEntity.setExpireDate(codeEntity.getExpireDate());
|
|
codeLostEntity.setSerialNo(codeEntity.getSerialNo());
|
|
}
|
|
//校验是否写入缺失表
|
|
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) {
|
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("only_vail_batch");
|
|
boolean vailBatchNo = false;
|
|
if (systemParamConfigEntity != null) {
|
|
if (systemParamConfigEntity.getParamValue().equals("1")) {
|
|
vailBatchNo = true;
|
|
}
|
|
}
|
|
|
|
boolean isBillExit = orderDetailBizService.isExit(codeEntity.getOrderId());
|
|
if (!isBillExit) {
|
|
return "请先录入业务详情";
|
|
}
|
|
IoOrderDetailBizEntity bizEntity;
|
|
if (vailBatchNo) {
|
|
bizEntity = orderDetailBizService.findByUnique(codeEntity.getOrderId(), codeEntity.getRelId(), codeEntity.getBatchNo());
|
|
} else {
|
|
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 "当前产品数量超出!";
|
|
}
|
|
if (bizEntity.getPrice() != null)
|
|
codeEntity.setPrice(bizEntity.getPrice());
|
|
return null;
|
|
}
|
|
|
|
|
|
// 无三期拣货校验
|
|
public String checkNoPiCode(IoCodeTempEntity codeTempEntity) {
|
|
boolean isBillExit = orderDetailBizService.isExit(codeTempEntity.getOrderId());
|
|
if (!isBillExit) {
|
|
return "请先录入业务详情";
|
|
}
|
|
IoOrderDetailBizEntity bizEntity = orderDetailBizService.findByRelId(codeTempEntity.getOrderId(), codeTempEntity.getRelId());
|
|
if (bizEntity == null) {
|
|
return "非此单产品!";
|
|
}
|
|
Integer detailCount = orderDetailCodeService.findByRelIdCount(codeTempEntity.getOrderId(), codeTempEntity.getRelId());
|
|
int curCount = 0;
|
|
if (detailCount != null) {
|
|
curCount = detailCount + codeTempEntity.getMyReCount();
|
|
} else {
|
|
curCount = codeTempEntity.getMyReCount();
|
|
}
|
|
if (curCount > bizEntity.getCount()) {
|
|
return "当前产品数量超出!";
|
|
}
|
|
if (bizEntity.getPrice() != null)
|
|
codeTempEntity.setPrice(bizEntity.getPrice());
|
|
return null;
|
|
}
|
|
|
|
|
|
//一次校验(无需校验)完成
|
|
public void unCheckFirstFinish(IoOrderEntity orderEntity) {
|
|
|
|
List<IoOrderDetailCodeEntity> 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;
|
|
}
|
|
|
|
|
|
if (orderEntity.getFromType() != ConstantStatus.FROM_UDISP
|
|
&& orderEntity.getFromType() != ConstantStatus.FROM_UDIMS) {
|
|
if (orderEntity.getFromType() != ConstantStatus.FROM_COPY
|
|
&& orderEntity.getFromType() != ConstantStatus.FROM_CHANGE) {
|
|
orderDetailBizService.deleteByOrderId(orderEntity.getBillNo());
|
|
}
|
|
orderDetailResultService.deleteByOrderId(orderEntity.getBillNo());
|
|
if (!orderDetailBizService.isExit(orderEntity.getBillNo())) {
|
|
orderDetailCodeEntities.forEach(orderDetailCodeEntity ->
|
|
{
|
|
//生成业务单据
|
|
IoOrderDetailBizEntity orderDetailBizEntity = new IoOrderDetailBizEntity();
|
|
BeanUtils.copyProperties(orderDetailCodeEntity, orderDetailBizEntity);
|
|
orderDetailBizEntity.setCount(orderDetailCodeEntity.getReCount());
|
|
orderDetailBizEntity.setId(null);
|
|
orderDetailBizService.insert(orderDetailBizEntity);
|
|
});
|
|
}
|
|
orderDetailCodeEntities.forEach(orderDetailCodeEntity ->
|
|
{
|
|
//生成单据结果
|
|
IoOrderDetailResultEntity orderDetailResultEntity = new IoOrderDetailResultEntity();
|
|
BeanUtils.copyProperties(orderDetailCodeEntity, orderDetailResultEntity);
|
|
orderDetailResultEntity.setCount(orderDetailCodeEntity.getReCount());
|
|
orderDetailResultEntity.setReCount(orderDetailCodeEntity.getReCount());
|
|
orderDetailResultEntity.setId(null);
|
|
orderDetailResultService.insert(orderDetailResultEntity);
|
|
|
|
});
|
|
}
|
|
|
|
|
|
//临时表转正式表
|
|
List<IoCodeTempEntity> 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);
|
|
}
|
|
|
|
@Resource
|
|
IoOrderInvoiceService orderInvoiceService;
|
|
|
|
|
|
//一次校验完成
|
|
public void checkFirstFinish(IoOrderEntity orderEntity) {
|
|
List<IoOrderDetailCodeEntity> orderDetailCodeEntities = orderDetailCodeService.findByOrderId(orderEntity.getBillNo());
|
|
List<IoOrderDetailBizEntity> 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);
|
|
codeEntity.setPrice(bizEntity.getPrice());
|
|
} 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);
|
|
codeEntity.setPrice(bizEntity.getPrice());
|
|
}
|
|
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);
|
|
}
|
|
|
|
// orderDetailCodeDao.updateBatchById(orderDetailCodeEntities);
|
|
|
|
//临时表转正式表
|
|
List<IoCodeTempEntity> codeTempEntities = codeTempService.findByOrderId(orderEntity.getBillNo());
|
|
for (IoCodeTempEntity codeTempEntity : codeTempEntities) {
|
|
IoCodeEntity codeEnttity = new IoCodeEntity();
|
|
BeanUtils.copyProperties(codeTempEntity, codeEnttity);
|
|
codeService.insert(codeEnttity);
|
|
}
|
|
//更新扫码详情表
|
|
orderDetailCodeDao.updateBatchById(orderDetailCodeEntities);
|
|
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 bizNoPiCheck(List<IoOrderDetailBizEntity> orderDetailBizEntities, IoOrderEntity orderEntity) {
|
|
|
|
String errMsg = "";
|
|
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
|
|
bizEntity.setCheckSuccess(false);
|
|
}
|
|
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
|
|
String msg = "";
|
|
int count = orderDetailCodeService.findByRelIdCount(orderEntity.getBillNo(), bizEntity.getBindRlFk());
|
|
if (bizEntity.getCount() == count) {
|
|
bizEntity.setCheckSuccess(true);
|
|
bizEntity.setScanCount(count);
|
|
} else {
|
|
msg = "数量不匹配";
|
|
bizEntity.setScanCount(count);
|
|
bizEntity.setCheckSuccess(false);
|
|
}
|
|
bizEntity.setErrMsg(msg);
|
|
}
|
|
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
|
|
if (!bizEntity.isCheckSuccess()) {
|
|
errMsg = errMsg + bizEntity.getCoName() + bizEntity.getErrMsg() + ";";
|
|
}
|
|
}
|
|
return errMsg;
|
|
}
|
|
|
|
|
|
//业务单正向校验
|
|
public String bizOrderCheck(List<IoOrderDetailBizEntity> orderDetailBizEntities, List<IoOrderDetailCodeEntity> 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<IoOrderDetailBizResponse> orderDetailBizEntities, List<IoOrderDetailCodeEntity> 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<IoOrderCheckResultResponse> combineCheck(List<IoOrderDetailBizEntity> orderDetailBizEntities, List<IoOrderDetailCodeEntity> orderDetailCodeEntities) {
|
|
|
|
List<IoOrderCheckResultResponse> 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<IoOrderDetailCodeEntity> orderDetailCodeEntities, List<IoOrderDetailBizEntity> 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<IoOrderDetailCodeResponse> orderDetailCodeEntities, List<IoOrderDetailBizEntity> 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 if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDISP) {
|
|
if (!bussinessTypeEntity.isThrCheckSp()) {
|
|
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW);
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_REVIEW) {
|
|
if (!bussinessTypeEntity.isThrCheckReview()) {
|
|
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW);
|
|
}
|
|
}
|
|
} else {
|
|
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW);
|
|
}
|
|
}
|
|
if (StrUtil.isEmpty(orderEntity.getCheckUser())) {
|
|
orderEntity.setCheckUser(orderEntity.getCreateUser());
|
|
}
|
|
if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_CHECK_REW) {
|
|
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_REW);
|
|
orderEntity.setUpdateTime(new Date());
|
|
if (IntUtil.value(orderEntity.getFromType()) != ConstantStatus.FROM_UDISP)
|
|
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 if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_UDISP) {
|
|
if (!bussinessTypeEntity.isSecCheckSp()) {
|
|
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_AUDITED);
|
|
}
|
|
} else if (orderEntity.getFromType().intValue() == ConstantStatus.FROM_REVIEW) {
|
|
if (!bussinessTypeEntity.isSeccheckReview()) {
|
|
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());
|
|
if (IntUtil.value(orderEntity.getFromType()) != ConstantStatus.FROM_UDISP)
|
|
orderEntity.setAuditTime(new Date());
|
|
if (StrUtil.isEmpty(orderEntity.getReviewUser())) {
|
|
orderEntity.setReviewUser(orderEntity.getReviewUser());
|
|
}
|
|
orderService.update(orderEntity);
|
|
genInv(orderEntity, bussinessTypeEntity);
|
|
}
|
|
}
|
|
|
|
@Resource
|
|
IoChangeInoutService changeInoutService;
|
|
@Resource
|
|
InvPreinProductDetailService invPreinProductDetailService;
|
|
@Resource
|
|
UdiCalCountUtil udiCalCountUtil;
|
|
|
|
//校验完成后生成库存
|
|
public void genInv(IoOrderEntity orderEntity, BasicBussinessTypeEntity bussinessTypeEntity) {
|
|
|
|
if (
|
|
IntUtil.value(orderEntity.getFromType()) != ConstantStatus.FROM_UDISP &&
|
|
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<String> orderList = CollUtil.toList(orderIdArray);
|
|
List<IoCodeEntity> outCodeEntitys = codeService.findByOrderId(orderEntity.getBillNo());
|
|
List<IoCodeEntity> 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<IoCodeEntity> backCodeList = new ArrayList<>();
|
|
for (IoCodeEntity codeEntity : preInCodeEntities) {
|
|
if (codeEntity.getMyCount() > 0) {
|
|
backCodeList.add(codeEntity);
|
|
}
|
|
}
|
|
genBackOrder(orderEntity, backCodeList);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else { //按仓库货位退货
|
|
List<IoCodeEntity> backCodeList = new ArrayList<>();
|
|
List<IoCodeEntity> 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<IoCodeEntity> 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<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.带回时生成退货出库单
|
|
@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) {
|
|
|
|
String value = systemParamConfigService.selectValueByParamKey("only_vail_batch");
|
|
if (StrUtil.isNotEmpty(value) && value.equals("1")) {
|
|
return null;
|
|
}
|
|
|
|
if (StrUtil.nullToEmpty(bizEntity.getProductDate()).equals(StrUtil.nullToEmpty(codeEntity.getProductDate()))) {
|
|
return null;
|
|
} else {
|
|
return bizEntity.getCoName() + "生产日期不匹配";
|
|
}
|
|
}
|
|
|
|
public String checkExpireDate(IoOrderDetailBizEntity bizEntity, IoOrderDetailCodeEntity codeEntity) {
|
|
|
|
String value = systemParamConfigService.selectValueByParamKey("only_vail_batch");
|
|
if (StrUtil.isNotEmpty(value) && value.equals("1")) {
|
|
return null;
|
|
}
|
|
|
|
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() + "数量不匹配!";
|
|
}
|
|
|
|
|
|
}
|