|
|
|
@ -1,16 +1,21 @@
|
|
|
|
|
package com.glxp.api.service.inv.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.common.enums.ResultEnum;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
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.basic.BasicBusTypeChangeDao;
|
|
|
|
|
import com.glxp.api.dao.basic.BasicBussinessTypeDao;
|
|
|
|
|
import com.glxp.api.dao.basic.BasicCorpDao;
|
|
|
|
|
import com.glxp.api.dao.basic.UdiRlSupDao;
|
|
|
|
|
import com.glxp.api.dao.inout.IoCodeDao;
|
|
|
|
|
import com.glxp.api.dao.inout.IoCodeTempDao;
|
|
|
|
|
import com.glxp.api.dao.inout.IoOrderDao;
|
|
|
|
@ -19,26 +24,36 @@ import com.glxp.api.dao.inv.InvCountOrderDao;
|
|
|
|
|
import com.glxp.api.dao.inv.InvCountOrderDetailDao;
|
|
|
|
|
import com.glxp.api.dao.inv.InvProductDetailDao;
|
|
|
|
|
import com.glxp.api.entity.auth.AuthAdmin;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicBusTypeChangeEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoCodeTempEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoOrderEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.InvCountCodesEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.InvCountOrderDetailEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.InvCountOrderEntity;
|
|
|
|
|
import com.glxp.api.req.inv.AddInvCountOrderSaveRequest;
|
|
|
|
|
import com.glxp.api.req.inv.FilterInvCountOrderRequest;
|
|
|
|
|
import com.glxp.api.entity.inv.InvProductDetailEntity;
|
|
|
|
|
import com.glxp.api.req.inv.*;
|
|
|
|
|
import com.glxp.api.res.inv.InvCountOrderResponse;
|
|
|
|
|
import com.glxp.api.service.auth.CustomerService;
|
|
|
|
|
import com.glxp.api.service.basic.CompanyProductsRelService;
|
|
|
|
|
import com.glxp.api.service.inv.InvCountCodesService;
|
|
|
|
|
import com.glxp.api.service.inv.InvCountOrderService;
|
|
|
|
|
import com.glxp.api.util.CustomUtil;
|
|
|
|
|
import com.glxp.api.util.DateUtil;
|
|
|
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
|
|
|
import com.glxp.api.util.OrderNoTypeBean;
|
|
|
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
|
|
|
import com.glxp.api.util.udi.UdiCalCountUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
@ -72,7 +87,9 @@ public class InvCountOrderServiceImpl implements InvCountOrderService {
|
|
|
|
|
@Resource
|
|
|
|
|
private IoCodeDao codesDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private CompanyProductsRelService companyProductsRelService;
|
|
|
|
|
private UdiRlSupDao udiRlSupDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private UdiCalCountUtil udiCalCountUtil;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<InvCountOrderResponse> filterList(FilterInvCountOrderRequest filterInvCountOrderRequest) {
|
|
|
|
@ -101,15 +118,14 @@ public class InvCountOrderServiceImpl implements InvCountOrderService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse saveCountOrder(InvCountOrderEntity invCountOrder) {
|
|
|
|
|
//TODO 确认一下盘点单据的部门是由前端选入还是后端获取
|
|
|
|
|
if (invCountOrder.getCountType() == 0 || invCountOrder.getCountType() == 2) {
|
|
|
|
|
//整库盘点
|
|
|
|
|
if (StrUtil.isBlank(invCountOrder.getInvCode())) {
|
|
|
|
|
if (StrUtil.isNotBlank(invCountOrder.getDeptCode()) || StrUtil.isBlank(invCountOrder.getInvCode())) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "请选择仓库信息!");
|
|
|
|
|
}
|
|
|
|
|
} else if (invCountOrder.getCountType() == 1) {
|
|
|
|
|
//货位盘点
|
|
|
|
|
if (StrUtil.isBlank(invCountOrder.getInvCode()) || StrUtil.isBlank(invCountOrder.getInvCode()) || StrUtil.isBlank(invCountOrder.getInvSpaceCode())) {
|
|
|
|
|
if (StrUtil.isBlank(invCountOrder.getDeptCode()) || StrUtil.isBlank(invCountOrder.getInvCode()) || StrUtil.isBlank(invCountOrder.getInvSpaceCode())) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "请选择仓库和货位信息!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -183,6 +199,26 @@ public class InvCountOrderServiceImpl implements InvCountOrderService {
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse saveCountOrderForPDA(AddInvCountOrderSaveRequest addInvCountOrderSaveRequest) {
|
|
|
|
|
InvCountOrderEntity invCountOrder = invCountOrderDao.selectByOrderId(addInvCountOrderSaveRequest.getOrderId());
|
|
|
|
|
if (null == invCountOrder) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此单据不存在");
|
|
|
|
|
}
|
|
|
|
|
if (invCountOrder.getStatus() != 0) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此单据不可编辑");
|
|
|
|
|
}
|
|
|
|
|
//解析条码,修改单据详情,修改单据状态为待审核
|
|
|
|
|
invCountOrder.setStatus(1);
|
|
|
|
|
invCountOrder.setUpdateTime(new Date());
|
|
|
|
|
List<InvCountCodesEntity> countCodeList = addInvCountOrderSaveRequest.getCountCodeList();
|
|
|
|
|
for (InvCountCodesEntity invCountCodes : countCodeList) {
|
|
|
|
|
invCountCodesService.addCode(invCountCodes);
|
|
|
|
|
}
|
|
|
|
|
submitAudit(invCountOrder.getId().toString());
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse updateCountOrderStatus(String id, Integer status) {
|
|
|
|
|
InvCountOrderEntity invCountOrder = invCountOrderDao.selectById(Integer.valueOf(id));
|
|
|
|
@ -206,28 +242,318 @@ public class InvCountOrderServiceImpl implements InvCountOrderService {
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO 盘点单据转单逻辑,待完善
|
|
|
|
|
/**
|
|
|
|
|
* 盘点单据转扫码单据
|
|
|
|
|
*
|
|
|
|
|
* @param invCountOrder 盘点单据
|
|
|
|
|
*/
|
|
|
|
|
private void countOrderTransfer(InvCountOrderEntity invCountOrder) {
|
|
|
|
|
//查询单据生成设置,是否已经配置对应单据类型,若未配置则结束转单流程
|
|
|
|
|
List<BasicBussinessTypeEntity> transferOrderSettings = getOrderSettings();
|
|
|
|
|
if (CollUtil.isEmpty(transferOrderSettings)) {
|
|
|
|
|
log.error("未配置盘点转单设置,无法转单!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成盘盈和盘亏单据逻辑
|
|
|
|
|
* 盘盈单据:1、找出盘点单据码详情比库存码详情多的产品
|
|
|
|
|
* 2、判断条码是否包含批次号和序列号,如果不包含,根据 盘盈数量 / 实际数量 = 多出的条码数量 ,计算出盘盈单据此条码的扫码数量
|
|
|
|
|
* 3、生成条码,保存单据
|
|
|
|
|
*
|
|
|
|
|
* 盘亏单据:1、找出库存有,而盘点不存在的条码
|
|
|
|
|
* 2、判断此库存详情是否包含批次号,如果不包含,盘亏数量 / 实际数量 = 少的条码数量,计算出盘亏单据扫码数量
|
|
|
|
|
* 3、生成条码,保存单据
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//获取出入库码明细
|
|
|
|
|
List<IoCodeTempEntity> inCodes = getOrderCodes(invCountOrder, "in");
|
|
|
|
|
List<IoCodeTempEntity> outCodes = getOrderCodes(invCountOrder, "out");
|
|
|
|
|
|
|
|
|
|
//生成盘盈/盘亏单据
|
|
|
|
|
createNewOrder(invCountOrder, inCodes, outCodes, transferOrderSettings);
|
|
|
|
|
log.info("盘点转单完成");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse saveCountOrderForPDA(AddInvCountOrderSaveRequest addInvCountOrderSaveRequest) {
|
|
|
|
|
InvCountOrderEntity invCountOrder = invCountOrderDao.selectByOrderId(addInvCountOrderSaveRequest.getOrderId());
|
|
|
|
|
if (null == invCountOrder) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此单据不存在");
|
|
|
|
|
/**
|
|
|
|
|
* 生成盘盈/盘亏单据
|
|
|
|
|
*
|
|
|
|
|
* @param invCountOrder 盘点单据
|
|
|
|
|
* @param inCodes 盘盈单据码明细
|
|
|
|
|
* @param outCodes 盘亏单据码明细
|
|
|
|
|
* @param transferOrderSettings 单据转换单据类型
|
|
|
|
|
*/
|
|
|
|
|
private void createNewOrder(InvCountOrderEntity invCountOrder, List<IoCodeTempEntity> inCodes, List<IoCodeTempEntity> outCodes, List<BasicBussinessTypeEntity> transferOrderSettings) {
|
|
|
|
|
BasicBussinessTypeEntity inBusType = new BasicBussinessTypeEntity();
|
|
|
|
|
BasicBussinessTypeEntity outBusType = new BasicBussinessTypeEntity();
|
|
|
|
|
for (BasicBussinessTypeEntity basicBussinessTypeEntity : transferOrderSettings) {
|
|
|
|
|
if (basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
|
|
|
|
|
inBusType = basicBussinessTypeEntity;
|
|
|
|
|
} else if (basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
|
|
outBusType = basicBussinessTypeEntity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (invCountOrder.getStatus() != 0) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此单据不可编辑");
|
|
|
|
|
|
|
|
|
|
log.info("开始生成盘盈单据");
|
|
|
|
|
//开始生成盘盈单据
|
|
|
|
|
String inOrderId = buildOrder(invCountOrder, inCodes, inBusType);
|
|
|
|
|
invCountOrder.setInOrderIds(inOrderId);
|
|
|
|
|
log.info("盘盈单据生成成功");
|
|
|
|
|
|
|
|
|
|
//开始生成盘亏单据
|
|
|
|
|
log.info("开始生成盘亏单据");
|
|
|
|
|
String outOrderId = buildOrder(invCountOrder, outCodes, outBusType);
|
|
|
|
|
invCountOrder.setOrderId(outOrderId);
|
|
|
|
|
log.info("盘亏单据生成成功");
|
|
|
|
|
|
|
|
|
|
//更新盘点单据的出入库单据信息
|
|
|
|
|
invCountOrderDao.updateById(invCountOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成单据逻辑
|
|
|
|
|
*
|
|
|
|
|
* @param invCountOrder 盘点单据
|
|
|
|
|
* @param codeTempList 单据码明细
|
|
|
|
|
* @param inBusType 单据类型
|
|
|
|
|
*/
|
|
|
|
|
private String buildOrder(InvCountOrderEntity invCountOrder, List<IoCodeTempEntity> codeTempList, BasicBussinessTypeEntity inBusType) {
|
|
|
|
|
if (CollUtil.isNotEmpty(codeTempList)) {
|
|
|
|
|
//构造单据数据
|
|
|
|
|
IoOrderEntity order = new IoOrderEntity();
|
|
|
|
|
order.setMainAction(inBusType.getMainAction());
|
|
|
|
|
order.setAction(inBusType.getAction());
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
order.setCreateTime(date);
|
|
|
|
|
order.setUpdateTime(date);
|
|
|
|
|
order.setDeptCode(invCountOrder.getDeptCode());
|
|
|
|
|
order.setInvCode(invCountOrder.getInvCode());
|
|
|
|
|
//查询单据往来单位信息
|
|
|
|
|
order.setFromCorp(inBusType.getDefaultUnit());
|
|
|
|
|
order.setFromType(ConstantStatus.FROM_COUNT);
|
|
|
|
|
order.setCorpOrderId(CustomUtil.getId() + "x");
|
|
|
|
|
//设置为草稿状态
|
|
|
|
|
order.setStatus(1);
|
|
|
|
|
order.setDealStatus(1);
|
|
|
|
|
//生成单据号
|
|
|
|
|
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trim(inBusType.getPrefix()), "yyyyMMdd"));
|
|
|
|
|
order.setBillNo(orderNo);
|
|
|
|
|
//对条码统一设置创建时间,单号等信息
|
|
|
|
|
codeTempList.forEach(codeTemp -> {
|
|
|
|
|
codeTemp.setCreateTime(date);
|
|
|
|
|
codeTemp.setOrderId(orderNo);
|
|
|
|
|
codeTemp.setAction(order.getAction());
|
|
|
|
|
codeTemp.setCorpOrderId(order.getCorpOrderId());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
orderDao.insert(order);
|
|
|
|
|
codesTempDao.insertBatch(codeTempList);
|
|
|
|
|
return orderNo;
|
|
|
|
|
}
|
|
|
|
|
//解析条码,修改单据详情,修改单据状态为待审核
|
|
|
|
|
invCountOrder.setStatus(1);
|
|
|
|
|
invCountOrder.setUpdateTime(new Date());
|
|
|
|
|
List<InvCountCodesEntity> countCodeList = addInvCountOrderSaveRequest.getCountCodeList();
|
|
|
|
|
for (InvCountCodesEntity invCountCodes : countCodeList) {
|
|
|
|
|
invCountCodesService.addCode(invCountCodes);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取入库或出库的条码列表
|
|
|
|
|
*
|
|
|
|
|
* @param invCountOrder 盘点单据
|
|
|
|
|
* @param type 出入库类型 in/out
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<IoCodeTempEntity> getOrderCodes(InvCountOrderEntity invCountOrder, String type) {
|
|
|
|
|
//构造库存详情查询参数
|
|
|
|
|
FilterInvProductDetailRequest invProductDetailRequest = new FilterInvProductDetailRequest();
|
|
|
|
|
invProductDetailRequest.setDeptCode(invCountOrder.getDeptCode());
|
|
|
|
|
invProductDetailRequest.setInvCode(invCountOrder.getInvCode());
|
|
|
|
|
//锁库存,查询库存更新时间早于或等于盘点单创建时间的数据
|
|
|
|
|
invProductDetailRequest.setUpdateTime(DateUtil.toDateStr(invCountOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
//判断是否是按货位盘点的单据,如果是,则查询库存详情的参数需要添加货位
|
|
|
|
|
invProductDetailRequest.setInvSpaceCode(invCountOrder.getInvSpaceCode());
|
|
|
|
|
|
|
|
|
|
//查询盘点单据详情
|
|
|
|
|
FilterInvCountOrderDetailRequest countOrderDetailRequest = new FilterInvCountOrderDetailRequest();
|
|
|
|
|
countOrderDetailRequest.setOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
countOrderDetailRequest.setStatus(type.equals("in") ? 1 : 0);
|
|
|
|
|
List<InvCountOrderDetailEntity> detailList = invCountOrderDetailDao.filterList(countOrderDetailRequest);
|
|
|
|
|
|
|
|
|
|
List<IoCodeTempEntity> codeList = new ArrayList<>();
|
|
|
|
|
//查找条码列表
|
|
|
|
|
if (type.equals("in")) {
|
|
|
|
|
log.info("开始生成盘盈单据码明细");
|
|
|
|
|
//查找盘盈条码列表
|
|
|
|
|
detailList.forEach(invCountOrderDetailEntity -> {
|
|
|
|
|
invProductDetailRequest.setRelId(String.valueOf(invCountOrderDetailEntity.getRelId()));
|
|
|
|
|
invProductDetailRequest.setBatchNo(invProductDetailRequest.getBatchNo());
|
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetailList(invProductDetailRequest);
|
|
|
|
|
//查询盘点码明细
|
|
|
|
|
FilterInvCountCodesRequest countCodesRequest = new FilterInvCountCodesRequest();
|
|
|
|
|
countCodesRequest.setOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
countCodesRequest.setRelId(String.valueOf(invCountOrderDetailEntity.getRelId()));
|
|
|
|
|
countCodesRequest.setBatchNo(invCountOrderDetailEntity.getBatchNo());
|
|
|
|
|
List<String> countCodeList = invCountCodesDao.selectCodes(countCodesRequest);
|
|
|
|
|
List<String> invProductDetailCodes = invProductDetailEntities.stream().map(InvProductDetailEntity::getCode).collect(Collectors.toList());
|
|
|
|
|
List<String> profitCodes = CollUtil.subtractToList(countCodeList, invProductDetailCodes);
|
|
|
|
|
if (CollUtil.isNotEmpty(invProductDetailCodes) && CollUtil.isEmpty(profitCodes)) {
|
|
|
|
|
/**
|
|
|
|
|
* 盘点条码不为空,且库存条码也不为空,但是计算的条码差集为空
|
|
|
|
|
* 说明盘点的条码和库存的条码是相同的条码,直接根据盘盈数量计算出扫码数量,生成一个条码即可
|
|
|
|
|
*/
|
|
|
|
|
IoCodeTempEntity codeTempEntity = buildCodeTempEntity(invCountOrder, countCodeList.get(0), invCountOrderDetailEntity);
|
|
|
|
|
codeList.add(codeTempEntity);
|
|
|
|
|
} else {
|
|
|
|
|
for (String code : profitCodes) {
|
|
|
|
|
if (!verifyCodeExist(codeList, code)) {
|
|
|
|
|
//生成码明细
|
|
|
|
|
IoCodeTempEntity codeTempEntity = buildCodeTempEntity(invCountOrder, code, invCountOrderDetailEntity);
|
|
|
|
|
codeList.add(codeTempEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
log.info("盘盈单据码明细生成成功");
|
|
|
|
|
} else {
|
|
|
|
|
log.info("开始生成盘亏单据码明细");
|
|
|
|
|
|
|
|
|
|
detailList.forEach(invCountOrderDetailEntity -> {
|
|
|
|
|
invProductDetailRequest.setRelId(String.valueOf(invCountOrderDetailEntity.getRelId()));
|
|
|
|
|
invProductDetailRequest.setBatchNo(invCountOrderDetailEntity.getBatchNo());
|
|
|
|
|
//查询库存详情
|
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetailList(invProductDetailRequest);
|
|
|
|
|
//查询盘点码明细
|
|
|
|
|
FilterInvCountCodesRequest countCodesRequest = new FilterInvCountCodesRequest();
|
|
|
|
|
countCodesRequest.setOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
countCodesRequest.setRelId(String.valueOf(invCountOrderDetailEntity.getRelId()));
|
|
|
|
|
countCodesRequest.setBatchNo(invCountOrderDetailEntity.getBatchNo());
|
|
|
|
|
List<String> countCodeList = invCountCodesDao.selectCodes(countCodesRequest);
|
|
|
|
|
List<String> invProductDetailCodes = invProductDetailEntities.stream().map(InvProductDetailEntity::getCode).collect(Collectors.toList());
|
|
|
|
|
List<String> lossCodes = CollUtil.subtractToList(invProductDetailCodes, countCodeList);
|
|
|
|
|
if (CollUtil.isNotEmpty(countCodeList) && CollUtil.isEmpty(lossCodes)) {
|
|
|
|
|
//盘点的码不为空,但是盘点数量和库存数量不一样,比对差集结果为空,说明是同一个条码,数量不同,直接根据盘亏数量计算生成一个扫码单据的码明细
|
|
|
|
|
//生成码详情
|
|
|
|
|
IoCodeTempEntity codeTempEntity = buildCodeTempEntity(invCountOrder, countCodeList.get(0), invCountOrderDetailEntity);
|
|
|
|
|
codeList.add(codeTempEntity);
|
|
|
|
|
} else {
|
|
|
|
|
for (InvProductDetailEntity invProductDetailEntity : invProductDetailEntities) {
|
|
|
|
|
if (!countCodeList.contains(invProductDetailEntity.getCode()) && !verifyCodeExist(codeList, invProductDetailEntity.getCode())) {
|
|
|
|
|
InvCountOrderDetailEntity orderDetailEntity = new InvCountOrderDetailEntity();
|
|
|
|
|
orderDetailEntity.setRelId(invCountOrderDetailEntity.getRelId());
|
|
|
|
|
orderDetailEntity.setStatus(0);
|
|
|
|
|
IoCodeTempEntity codeTempEntity = buildCodeTempEntity(invCountOrder, invProductDetailEntity.getCode(), orderDetailEntity);
|
|
|
|
|
codeList.add(codeTempEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
log.info("盘亏单据码名称生成成功");
|
|
|
|
|
}
|
|
|
|
|
submitAudit(invCountOrder.getId().toString());
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
return codeList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 比对码在集合中是否存在
|
|
|
|
|
*
|
|
|
|
|
* @param codeList
|
|
|
|
|
* @param code
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean verifyCodeExist(List<IoCodeTempEntity> codeList, String code) {
|
|
|
|
|
for (IoCodeTempEntity codeTempEntity : codeList) {
|
|
|
|
|
if (codeTempEntity.getCode().equals(code)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造扫码单据码明细数据
|
|
|
|
|
*
|
|
|
|
|
* @param invCountOrder 盘点单据
|
|
|
|
|
* @param code 码
|
|
|
|
|
* @param invCountOrderDetailEntity 盘点单据详情
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private IoCodeTempEntity buildCodeTempEntity(InvCountOrderEntity invCountOrder, String code, InvCountOrderDetailEntity invCountOrderDetailEntity) {
|
|
|
|
|
IoCodeTempEntity codeTemp = new IoCodeTempEntity();
|
|
|
|
|
codeTemp.setCode(code);
|
|
|
|
|
codeTemp.setRelId(invCountOrderDetailEntity.getRelId());
|
|
|
|
|
codeTemp.setMainAction(invCountOrderDetailEntity.getStatus() == 0 ? ConstantType.TYPE_OUT : ConstantType.TYPE_PUT);
|
|
|
|
|
codeTemp.setDeptCode(invCountOrder.getDeptCode());
|
|
|
|
|
codeTemp.setInvCode(invCountOrder.getInvCode());
|
|
|
|
|
UdiEntity udi = FilterUdiUtils.getUdi(code);
|
|
|
|
|
codeTemp.setBatchNo(udi.getBatchNo());
|
|
|
|
|
codeTemp.setNameCode(udi.getUdi());
|
|
|
|
|
codeTemp.setProduceDate(udi.getProduceDate());
|
|
|
|
|
codeTemp.setExpireDate(udi.getExpireDate());
|
|
|
|
|
codeTemp.setSerialNo(udi.getSerialNo());
|
|
|
|
|
//计算码数量
|
|
|
|
|
int actCount = udiCalCountUtil.getActCount(codeTemp.getNameCode());
|
|
|
|
|
//判断此码有无批次号和序列号
|
|
|
|
|
if ((StrUtil.isBlank(codeTemp.getBatchNo()) && StrUtil.isBlank(codeTemp.getSerialNo())) || (StrUtil.isBlank(codeTemp.getSerialNo()) && StrUtil.isNotBlank(codeTemp.getBatchNo()))) {
|
|
|
|
|
//根据盘点盈亏状态取盘点数量值
|
|
|
|
|
int countNum = invCountOrderDetailEntity.getStatus() == 0 ? invCountOrderDetailEntity.getLossNum() : invCountOrderDetailEntity.getProfitNum();
|
|
|
|
|
int codeNum = countNum / actCount;
|
|
|
|
|
codeTemp.setCount(codeNum);
|
|
|
|
|
codeTemp.setReCount(codeNum);
|
|
|
|
|
} else {
|
|
|
|
|
codeTemp.setCount(actCount);
|
|
|
|
|
codeTemp.setReCount(actCount);
|
|
|
|
|
}
|
|
|
|
|
//获取盘点盈亏状态值
|
|
|
|
|
String countStatus = invCountOrderDetailEntity.getStatus() == 0 ? "loss" : "profit";
|
|
|
|
|
//设置供应商信息
|
|
|
|
|
setSupInfo(codeTemp, countStatus);
|
|
|
|
|
return codeTemp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置条码供应商信息
|
|
|
|
|
*
|
|
|
|
|
* @param codeTemp 条码数据
|
|
|
|
|
* @param countStatus 盈亏状态
|
|
|
|
|
*/
|
|
|
|
|
private void setSupInfo(IoCodeTempEntity codeTemp, String countStatus) {
|
|
|
|
|
/**
|
|
|
|
|
* 根据此码明细的盈亏状态,使用不同的逻辑生成供应商信息
|
|
|
|
|
* 盘盈:此条码不存在于库存详情中,需要从供应商产品信息表查询供应商信息
|
|
|
|
|
* 盘亏:此条码在库存中存在,但是盘点中没有此条码,直接查询库存详情表中的供应商ID
|
|
|
|
|
*
|
|
|
|
|
* 若查询出的供应商信息多余1条,则表明此产品被多个供应商绑定,在此处不进行绑定,单据生成之后会进入异常单据页面,在异常单据页面手动指定供应商
|
|
|
|
|
*/
|
|
|
|
|
if (countStatus.equals("loss")) {
|
|
|
|
|
log.info("生成盘亏单据条码供应商信息,条码信息:{}", codeTemp.getCode());
|
|
|
|
|
List<String> supIds = invProductDetailDao.selectSupIdByCode(codeTemp.getCode());
|
|
|
|
|
if (CollUtil.isNotEmpty(supIds) && supIds.size() == 1) {
|
|
|
|
|
//此产品在库存中存在且只绑定了一个供应商,若绑定了多个供应商,则不填供应商ID字段,生成单据之后会进入异常单据页面,由操作人员手动指定供应商
|
|
|
|
|
codeTemp.setSupId(supIds.get(0));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("生成盘盈单据条码供应商详情,条码信息:{}", codeTemp.getCode());
|
|
|
|
|
List<String> unitFkList = udiRlSupDao.selectUnitFkByRelId(codeTemp.getRelId());
|
|
|
|
|
if (CollUtil.isNotEmpty(unitFkList) && unitFkList.size() == 1) {
|
|
|
|
|
//此产品只绑定了一个供应商,若绑定了多个供应商,则不填供应商ID字段,生成单据之后会进入异常单据页面,手动指定供应商
|
|
|
|
|
codeTemp.setSupId(unitFkList.get(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询单据生成中配置的关联扫码单据类型
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<BasicBussinessTypeEntity> getOrderSettings() {
|
|
|
|
|
//查询类型为盘点转单的配置
|
|
|
|
|
List<BasicBusTypeChangeEntity> list = busTypeChangeDao.selectList(new QueryWrapper<BasicBusTypeChangeEntity>().eq("type", 4));
|
|
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
List<BasicBussinessTypeEntity> busTypes = new ArrayList<>(2);
|
|
|
|
|
for (BasicBusTypeChangeEntity basicBusTypeChangeEntity : list) {
|
|
|
|
|
if ("PDRK".equals(basicBusTypeChangeEntity.getOriginAction()) || "PDCK".equals(basicBusTypeChangeEntity.getOriginAction())) {
|
|
|
|
|
busTypes.add(bussinessTypeDao.selectOne(new QueryWrapper<BasicBussinessTypeEntity>().eq("action", basicBusTypeChangeEntity.getTargetAction())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|