|
|
|
@ -0,0 +1,669 @@
|
|
|
|
|
package com.glxp.api.service.inv;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
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.BasicBussinessTypeDao;
|
|
|
|
|
import com.glxp.api.dao.basic.BasicCorpDao;
|
|
|
|
|
import com.glxp.api.dao.basic.CompanyProductRelevanceDao;
|
|
|
|
|
import com.glxp.api.dao.basic.UdiRelevanceDao;
|
|
|
|
|
import com.glxp.api.dao.inout.IoCodeDao;
|
|
|
|
|
import com.glxp.api.dao.inout.IoCodeTempDao;
|
|
|
|
|
import com.glxp.api.dao.inout.IoOrderDao;
|
|
|
|
|
import com.glxp.api.dao.inv.*;
|
|
|
|
|
import com.glxp.api.entity.auth.AuthAdmin;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicCorpEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoCodeEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoCodeTempEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoOrderEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.*;
|
|
|
|
|
import com.glxp.api.req.basic.FilterUdiRelRequest;
|
|
|
|
|
import com.glxp.api.req.inv.*;
|
|
|
|
|
import com.glxp.api.res.basic.UdiRelevanceResponse;
|
|
|
|
|
import com.glxp.api.res.inv.InvCountOrderResponse;
|
|
|
|
|
import com.glxp.api.service.auth.CustomerService;
|
|
|
|
|
import com.glxp.api.service.basic.IBasicBussinessTypeService;
|
|
|
|
|
import com.glxp.api.service.basic.UdiRelevanceService;
|
|
|
|
|
import com.glxp.api.util.CustomUtil;
|
|
|
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
|
|
|
import com.glxp.api.util.IntUtil;
|
|
|
|
|
import com.glxp.api.util.OrderNoTypeBean;
|
|
|
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
public class InvCountOrderService extends ServiceImpl<InvCountOrderMapper, InvCountOrderEntity> {
|
|
|
|
|
@Resource
|
|
|
|
|
private InvCountOrderMapper invCountOrderDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvCountOrderDetailMapper invCountOrderDetailDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvCountCodesMapper invCountCodesDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private GennerOrderUtils gennerOrderUtils;
|
|
|
|
|
@Resource
|
|
|
|
|
private CustomerService customerService;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvProductDetailDao invProductDetailDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvCountSettingMapper invCountSettingDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private BasicBussinessTypeDao bussinessTypeDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private BasicCorpDao unitMaintainDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private IoOrderDao orderDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private IoCodeTempDao codesTempDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvCountCodesService invCountCodesService;
|
|
|
|
|
@Resource
|
|
|
|
|
private IoCodeDao codesDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private CompanyProductRelevanceDao companyProductRelevanceDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private UdiRelevanceDao udiRelevanceDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private UdiRelevanceService udiRelevanceService;
|
|
|
|
|
@Resource
|
|
|
|
|
private IBasicBussinessTypeService basicBussinessTypeService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<InvCountOrderResponse> filterList(FilterInvCountOrderRequest filterInvCountOrderRequest) {
|
|
|
|
|
if (null == filterInvCountOrderRequest) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
if (null != filterInvCountOrderRequest.getPage() && null != filterInvCountOrderRequest.getLimit()) {
|
|
|
|
|
PageHelper.offsetPage((filterInvCountOrderRequest.getPage() - 1) * filterInvCountOrderRequest.getLimit(), filterInvCountOrderRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
return invCountOrderDao.selectList(filterInvCountOrderRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteOrder(String id) {
|
|
|
|
|
String orderId = invCountOrderDao.selectOrderIdById(id);
|
|
|
|
|
log.info("开始删除盘点单据,盘点单号: {}", orderId);
|
|
|
|
|
invCountOrderDao.deleteByOrderId(orderId);
|
|
|
|
|
if (invCountOrderDetailDao.countByOrderIdFk(orderId) > 0) {
|
|
|
|
|
invCountOrderDetailDao.deleteByOrderId(orderId);
|
|
|
|
|
}
|
|
|
|
|
if (invCountCodesDao.countByOrderIdFk(orderId) > 0) {
|
|
|
|
|
invCountCodesDao.deleteByOrderId(orderId);
|
|
|
|
|
}
|
|
|
|
|
log.info("盘点单据删除完成");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseResponse saveCountOrder(InvCountOrderEntity invCountOrder) {
|
|
|
|
|
if (invCountOrder.getCountType() == 0 || invCountOrder.getCountType() == 2) {
|
|
|
|
|
//整库盘点
|
|
|
|
|
if (StrUtil.isBlank(invCountOrder.getInvStorageCode()) || StrUtil.isBlank(invCountOrder.getInvWarehouseCode())) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "请选择仓库信息!");
|
|
|
|
|
}
|
|
|
|
|
} else if (invCountOrder.getCountType() == 1) {
|
|
|
|
|
//货位盘点
|
|
|
|
|
if (StrUtil.isBlank(invCountOrder.getInvStorageCode()) || StrUtil.isBlank(invCountOrder.getInvWarehouseCode()) || StrUtil.isBlank(invCountOrder.getInvSpaceCode())) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "请选择仓库和货位信息!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//封装相关数据
|
|
|
|
|
//未提交
|
|
|
|
|
invCountOrder.setStatus(0);
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isBlank(invCountOrder.getOrderId())) {
|
|
|
|
|
//生成单据号
|
|
|
|
|
String orderId = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.COUNT_ORDER, "yyyyMMdd"));
|
|
|
|
|
//盘点单号
|
|
|
|
|
invCountOrder.setOrderId(orderId);
|
|
|
|
|
AuthAdmin user = customerService.getUserBean();
|
|
|
|
|
invCountOrder.setCreateUser(user.getUserName());
|
|
|
|
|
invCountOrder.setCreateTime(new Date());
|
|
|
|
|
invCountOrder.setUpdateTime(new Date());
|
|
|
|
|
invCountOrderDao.insert(invCountOrder);
|
|
|
|
|
} else {
|
|
|
|
|
InvCountOrderEntity oldData = invCountOrderDao.selectByOrderId(invCountOrder.getOrderId());
|
|
|
|
|
BeanUtil.copyProperties(invCountOrder, oldData, "id", "createTime", "createUser");
|
|
|
|
|
oldData.setUpdateTime(new Date());
|
|
|
|
|
invCountOrderDao.updateByOrderId(oldData);
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success(invCountOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseResponse submitAudit(String id) {
|
|
|
|
|
InvCountOrderEntity invCountOrder = invCountOrderDao.selectById(id);
|
|
|
|
|
if (null == invCountOrder) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "单据不存在");
|
|
|
|
|
}
|
|
|
|
|
if (invCountOrder.getStatus() != 0) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "单据已提交,请勿重复提交");
|
|
|
|
|
}
|
|
|
|
|
//查询单据详情和码表是否存在,如果无单据详情和条码,不允许提交
|
|
|
|
|
Long detailCount = invCountOrderDetailDao.countByOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
if (detailCount == 0) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "请先选择盘点产品");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long codesCount = invCountCodesDao.countByOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
if (codesCount == 0) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.DATA_ERROR, "请扫描需要盘点的产品");
|
|
|
|
|
}
|
|
|
|
|
//更新状态
|
|
|
|
|
invCountOrder.setStatus(1);
|
|
|
|
|
invCountOrder.setUpdateTime(new Date());
|
|
|
|
|
//查询单据详情,计算盘点盈亏状态
|
|
|
|
|
List<InvCountOrderDetailEntity> detailList = invCountOrderDetailDao.selectByOrderId(invCountOrder.getOrderId());
|
|
|
|
|
for (InvCountOrderDetailEntity invCountOrderDetail : detailList) {
|
|
|
|
|
int diff = invCountOrderDetail.getInvNum() - invCountOrderDetail.getCountNum();
|
|
|
|
|
if (diff > 0) {
|
|
|
|
|
invCountOrderDetail.setLossNum(Math.abs(diff));
|
|
|
|
|
//盘亏
|
|
|
|
|
invCountOrderDetail.setStatus(0);
|
|
|
|
|
} else if (diff < 0) {
|
|
|
|
|
invCountOrderDetail.setProfitNum(Math.abs(diff));
|
|
|
|
|
//盘盈
|
|
|
|
|
invCountOrderDetail.setStatus(1);
|
|
|
|
|
} else {
|
|
|
|
|
//平衡
|
|
|
|
|
invCountOrderDetail.setStatus(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//更新单据信息
|
|
|
|
|
invCountOrderDao.updateByOrderId(invCountOrder);
|
|
|
|
|
//更新单据详情
|
|
|
|
|
invCountOrderDetailDao.updateBatchById(detailList);
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseResponse updateCountOrderStatus(String id, Integer status) {
|
|
|
|
|
InvCountOrderEntity invCountOrder = invCountOrderDao.selectById(id);
|
|
|
|
|
invCountOrder.setStatus(status);
|
|
|
|
|
invCountOrder.setAuditUser(customerService.getUserBean().getUserName());
|
|
|
|
|
invCountOrder.setAuditTime(new Date());
|
|
|
|
|
invCountOrder.setUpdateTime(new Date());
|
|
|
|
|
if (status == 0) {
|
|
|
|
|
//审核不通过
|
|
|
|
|
//查询盘点单据详情,清空盘盈/盘亏数值
|
|
|
|
|
invCountOrderDetailDao.resetCountFiledValue(invCountOrder.getOrderId());
|
|
|
|
|
} else {
|
|
|
|
|
//审核通过
|
|
|
|
|
//根据单据详情生成相关单据
|
|
|
|
|
log.info("单据审核通过后将会生成对应盘盈盘亏单是否继续?,开始生成扫码单据");
|
|
|
|
|
// ThreadUtil.execAsync(() -> {
|
|
|
|
|
//
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
countTransferOrder(invCountOrder);
|
|
|
|
|
}
|
|
|
|
|
invCountOrderDao.updateById(invCountOrder);
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseResponse saveCountOrderForPDA(FilterInvCountOrderSaveRequest filterInvCountOrderSaveRequest) {
|
|
|
|
|
InvCountOrderEntity invCountOrder = invCountOrderDao.selectByOrderId(filterInvCountOrderSaveRequest.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 = filterInvCountOrderSaveRequest.getCountCodeList();
|
|
|
|
|
for (InvCountCodesEntity invCountCodes : countCodeList) {
|
|
|
|
|
invCountCodesService.addCode(invCountCodes);
|
|
|
|
|
}
|
|
|
|
|
submitAudit(invCountOrder.getId().toString());
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 盘点单据转扫码单
|
|
|
|
|
*/
|
|
|
|
|
private void countOrderTransfer(InvCountOrderEntity invCountOrder) {
|
|
|
|
|
List<InvCountSettingEntity> list = invCountSettingDao.filterList(null);
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
log.error("未配置盘点单据设置参数,无法转单");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//出入库码明细列表
|
|
|
|
|
List<IoCodeTempEntity> inOrderCodes = new ArrayList<>();
|
|
|
|
|
List<IoCodeTempEntity> outOrderCodes = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成盘盈和盘亏单据逻辑
|
|
|
|
|
* 盘盈单据:1、找出盘点单据码详情比库存码详情多的产品
|
|
|
|
|
* 2、判断条码是否包含批次号和序列号,如果不包含,根据 盘盈数量 / 实际数量 = 多出的条码数量 ,计算出盘盈单据此条码的扫码数量
|
|
|
|
|
* 3、生成条码,保存单据
|
|
|
|
|
*
|
|
|
|
|
* 盘亏单据:1、找出库存有,而盘点不存在的条码
|
|
|
|
|
* 2、判断此库存详情是否包含批次号,如果不包含,盘亏数量 / 实际数量 = 少的条码数量,计算出盘亏单据扫码数量
|
|
|
|
|
* 3、生成条码,保存单据
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//构造库存详情查询参数
|
|
|
|
|
FilterInvProductDetailRequest invProductDetailRequest = new FilterInvProductDetailRequest();
|
|
|
|
|
invProductDetailRequest.setInvCode(invCountOrder.getInvStorageCode());
|
|
|
|
|
invProductDetailRequest.setInvSpaceCode(invCountOrder.getInvWarehouseCode());
|
|
|
|
|
//库存早于或等于盘点时间的库存数据,锁库存
|
|
|
|
|
invProductDetailRequest.setUpdateTime(invCountOrder.getCreateTime());
|
|
|
|
|
|
|
|
|
|
if (invCountOrder.getCountType() == 1) {
|
|
|
|
|
//按照货位盘点,查询库存详情添加货位条件
|
|
|
|
|
invProductDetailRequest.setInvSpaceCode(invCountOrder.getInvSpaceCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FilterInvCountOrderDetailRequest detailRequest = new FilterInvCountOrderDetailRequest();
|
|
|
|
|
detailRequest.setOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
//查询亏损单据详情
|
|
|
|
|
detailRequest.setStatus(0);
|
|
|
|
|
List<InvCountOrderDetailEntity> lossDetailList = invCountOrderDetailDao.selectDetailList(detailRequest);
|
|
|
|
|
if (CollUtil.isNotEmpty(lossDetailList)) {
|
|
|
|
|
log.info("开始生成盘亏单据码明细");
|
|
|
|
|
log.info("查询盘亏产品码详情");
|
|
|
|
|
|
|
|
|
|
for (InvCountOrderDetailEntity invCountOrderDetail : lossDetailList) {
|
|
|
|
|
//查询库存详情
|
|
|
|
|
invProductDetailRequest.setRelId(invCountOrderDetail.getProductId());
|
|
|
|
|
invProductDetailRequest.setBatchNo(invCountOrderDetail.getBatchNo());
|
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetailList(invProductDetailRequest);
|
|
|
|
|
//查询盘点码明细
|
|
|
|
|
FilterInvCountCodesRequest codesRequest = new FilterInvCountCodesRequest();
|
|
|
|
|
codesRequest.setOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
codesRequest.setProductId(invCountOrderDetail.getProductId());
|
|
|
|
|
codesRequest.setBatchNo(invCountOrderDetail.getBatchNo());
|
|
|
|
|
List<String> countCodesList = invCountCodesDao.selectCodes(codesRequest);
|
|
|
|
|
List<String> invProductCodes = invProductDetailEntities.stream().map(InvProductDetailEntity::getCode).collect(Collectors.toList());
|
|
|
|
|
List<String> lossCodes = CollUtil.subtractToList(invProductCodes, countCodesList);
|
|
|
|
|
if (CollUtil.isNotEmpty(countCodesList) && CollUtil.isEmpty(lossCodes)) {
|
|
|
|
|
//盘点的码不为空,但是盘点数量和库存数量不一样,比对差集结果为空,说明是同一个条码,数量不同,直接根据盘亏数量计算生成一个扫码单据的码明细
|
|
|
|
|
//生成码详情
|
|
|
|
|
IoCodeTempEntity warehouseEntity = buildWarehouse(invCountOrder, invProductDetailEntities.get(0).getCode(), invProductDetailEntities.get(0).getRelId());
|
|
|
|
|
//判断此条码,是否有批次号和序列号
|
|
|
|
|
UdiEntity udi = FilterUdiUtils.getUdi(invProductDetailEntities.get(0).getCode());
|
|
|
|
|
//修改码数量
|
|
|
|
|
int actCount = invCountCodesService.getActCount(udi.getUdi());
|
|
|
|
|
//使用此盘点单据详情的盘亏数量 / 实际数量,计算得出扫码数量
|
|
|
|
|
int codeNum = invCountOrderDetail.getLossNum() / actCount;
|
|
|
|
|
warehouseEntity.setCount(codeNum);
|
|
|
|
|
warehouseEntity.setReCount(codeNum);
|
|
|
|
|
|
|
|
|
|
//设置供应商信息
|
|
|
|
|
setSupInfo(warehouseEntity, "loss");
|
|
|
|
|
outOrderCodes.add(warehouseEntity);
|
|
|
|
|
} else {
|
|
|
|
|
for (InvProductDetailEntity invProductDetailEntity : invProductDetailEntities) {
|
|
|
|
|
if (!countCodesList.contains(invProductDetailEntity.getCode()) && !verifyCodeExist(outOrderCodes, invProductDetailEntity.getCode())) {
|
|
|
|
|
//生成码详情
|
|
|
|
|
IoCodeTempEntity warehouseEntity = buildWarehouse(invCountOrder, invProductDetailEntity.getCode(), invProductDetailEntity.getRelId());
|
|
|
|
|
//判断此条码,是否有批次号和序列号
|
|
|
|
|
UdiEntity udi = FilterUdiUtils.getUdi(invProductDetailEntity.getCode());
|
|
|
|
|
if ((StrUtil.isBlank(udi.getBatchNo()) && StrUtil.isBlank(udi.getSerialNo())) || (StrUtil.isBlank(udi.getSerialNo()) && StrUtil.isNotBlank(udi.getBatchNo()))) {
|
|
|
|
|
//修改码数量
|
|
|
|
|
int actCount = invCountCodesService.getActCount(udi.getUdi());
|
|
|
|
|
//使用此盘点单据详情的盘亏数量 / 实际数量,计算得出扫码数量
|
|
|
|
|
int codeNum = invCountOrderDetail.getLossNum() / actCount;
|
|
|
|
|
warehouseEntity.setCount(codeNum);
|
|
|
|
|
warehouseEntity.setReCount(codeNum);
|
|
|
|
|
} else {
|
|
|
|
|
//修改实际数量
|
|
|
|
|
int actCount = invCountCodesService.getActCount(udi.getUdi());
|
|
|
|
|
warehouseEntity.setCount(actCount);
|
|
|
|
|
warehouseEntity.setReCount(actCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设置供应商信息
|
|
|
|
|
setSupInfo(warehouseEntity, "loss");
|
|
|
|
|
outOrderCodes.add(warehouseEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("盘亏单据码明细生成完毕");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生成盘盈单据的条码
|
|
|
|
|
//查询盘盈的单据详情
|
|
|
|
|
detailRequest.setStatus(1);
|
|
|
|
|
List<InvCountOrderDetailEntity> profitDetailList = invCountOrderDetailDao.selectDetailList(detailRequest);
|
|
|
|
|
if (CollUtil.isNotEmpty(profitDetailList)) {
|
|
|
|
|
log.info("开始生成盘盈单据码.明细");
|
|
|
|
|
//查询盘盈产品的库存详情
|
|
|
|
|
for (InvCountOrderDetailEntity invCountOrderDetail : profitDetailList) {
|
|
|
|
|
//查询库存详情
|
|
|
|
|
invProductDetailRequest.setRelId(invCountOrderDetail.getProductId());
|
|
|
|
|
invProductDetailRequest.setBatchNo(invCountOrderDetail.getBatchNo());
|
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetailList(invProductDetailRequest);
|
|
|
|
|
//查询盘点码明细
|
|
|
|
|
FilterInvCountCodesRequest codesRequest = new FilterInvCountCodesRequest();
|
|
|
|
|
codesRequest.setOrderIdFk(invCountOrder.getOrderId());
|
|
|
|
|
codesRequest.setProductId(invCountOrderDetail.getProductId());
|
|
|
|
|
codesRequest.setBatchNo(invCountOrderDetail.getBatchNo());
|
|
|
|
|
List<String> countCodesList = invCountCodesDao.selectCodes(codesRequest);
|
|
|
|
|
List<String> invProductCodeList = invProductDetailEntities.stream().map(InvProductDetailEntity::getCode).collect(Collectors.toList());
|
|
|
|
|
List<String> profitCodes = CollUtil.subtractToList(countCodesList, invProductCodeList); //计算盘盈的条码
|
|
|
|
|
log.info("查询盘盈产品的库存详情");
|
|
|
|
|
if (CollUtil.isNotEmpty(invProductCodeList) && CollUtil.isEmpty(profitCodes)) {
|
|
|
|
|
/**
|
|
|
|
|
* 盘点条码不为空,且库存条码也不为空,但是计算的条码差集为空
|
|
|
|
|
* 说明盘点的条码和库存的条码是相同的条码,直接根据盘盈数量计算出扫码数量,生成一个条码即可
|
|
|
|
|
*/
|
|
|
|
|
String code = null;
|
|
|
|
|
if (CollUtil.isNotEmpty(countCodesList)) {
|
|
|
|
|
code = countCodesList.get(0);
|
|
|
|
|
} else {
|
|
|
|
|
code = invProductCodeList.get(0);
|
|
|
|
|
}
|
|
|
|
|
IoCodeTempEntity warehouseEntity = buildWarehouse(invCountOrder, code, Long.parseLong(invCountOrderDetail.getProductId()));
|
|
|
|
|
//判断此条码,是否有批次号和序列号
|
|
|
|
|
UdiEntity udi = FilterUdiUtils.getUdi(code);
|
|
|
|
|
//修改码数量
|
|
|
|
|
int actCount = invCountCodesService.getActCount(udi.getUdi());
|
|
|
|
|
//使用此盘点单据详情的盘盈数量 / 实际数量,计算得出扫码数量
|
|
|
|
|
int codeNum = invCountOrderDetail.getProfitNum() / actCount;
|
|
|
|
|
warehouseEntity.setCount(codeNum);
|
|
|
|
|
warehouseEntity.setReCount(codeNum);
|
|
|
|
|
setSupInfo(warehouseEntity, "profit");
|
|
|
|
|
inOrderCodes.add(warehouseEntity);
|
|
|
|
|
log.info("添加库存条码");
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
for (String code : profitCodes) {
|
|
|
|
|
log.info("添加盘盈入库条码");
|
|
|
|
|
if (!verifyCodeExist(inOrderCodes, code)) {
|
|
|
|
|
//生成码详情
|
|
|
|
|
IoCodeTempEntity warehouseEntity = buildWarehouse(invCountOrder, code, Long.parseLong(invCountOrderDetail.getProductId()));
|
|
|
|
|
//判断此条码,是否有批次号和序列号
|
|
|
|
|
UdiEntity udi = FilterUdiUtils.getUdi(code);
|
|
|
|
|
if ((StrUtil.isBlank(udi.getBatchNo()) && StrUtil.isBlank(udi.getSerialNo())) || (StrUtil.isBlank(udi.getSerialNo()) && StrUtil.isNotBlank(udi.getBatchNo()))) {
|
|
|
|
|
//修改码数量
|
|
|
|
|
int actCount = invCountCodesService.getActCount(udi.getUdi());
|
|
|
|
|
//使用此盘点单据详情的盘盈数量 / 实际数量,计算得出扫码数量
|
|
|
|
|
int codeNum = invCountOrderDetail.getProfitNum() / actCount;
|
|
|
|
|
warehouseEntity.setCount(codeNum);
|
|
|
|
|
warehouseEntity.setReCount(codeNum);
|
|
|
|
|
} else {
|
|
|
|
|
//修改实际数量
|
|
|
|
|
int actCount = invCountCodesService.getActCount(udi.getUdi());
|
|
|
|
|
warehouseEntity.setCount(actCount);
|
|
|
|
|
warehouseEntity.setReCount(actCount);
|
|
|
|
|
}
|
|
|
|
|
setSupInfo(warehouseEntity, "profit");
|
|
|
|
|
inOrderCodes.add(warehouseEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("盘盈单据码详情生成完毕");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InvCountSettingEntity invCountSettingEntity = list.get(0);
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(inOrderCodes)) {
|
|
|
|
|
log.info("盘点单据:{} 生成盘盈入库单据", invCountOrder.getOrderId());
|
|
|
|
|
IoOrderEntity order = createOrder(invCountSettingEntity, invCountOrder, ConstantType.TYPE_PUT);
|
|
|
|
|
log.info("盘盈入库单据号:{}", order.getBillNo());
|
|
|
|
|
inOrderCodes.forEach(warehouseEntity -> {
|
|
|
|
|
warehouseEntity.setOrderId(order.getBillNo());
|
|
|
|
|
warehouseEntity.setAction(order.getAction());
|
|
|
|
|
warehouseEntity.setCorpOrderId(order.getCorpOrderId());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
invCountOrder.setInOrderIds(order.getBillNo());
|
|
|
|
|
orderDao.insert(order);
|
|
|
|
|
codesTempDao.insertBatch(inOrderCodes);
|
|
|
|
|
log.info("盘盈入库单据生成成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(outOrderCodes)) {
|
|
|
|
|
log.info("盘点单据:{} 生成盘亏入库单据", invCountOrder.getOrderId());
|
|
|
|
|
IoOrderEntity order = createOrder(invCountSettingEntity, invCountOrder, ConstantType.TYPE_OUT);
|
|
|
|
|
log.info("盘亏入库单据号:{}", order.getBillNo());
|
|
|
|
|
outOrderCodes.forEach(warehouseEntity -> {
|
|
|
|
|
warehouseEntity.setOrderId(order.getBillNo());
|
|
|
|
|
warehouseEntity.setAction(order.getAction());
|
|
|
|
|
warehouseEntity.setCorpOrderId(order.getCorpOrderId());
|
|
|
|
|
String supId = codesDao.selectSupIdByCode(warehouseEntity.getCode());
|
|
|
|
|
warehouseEntity.setSupId(supId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
invCountOrder.setOutOrderIds(order.getBillNo());
|
|
|
|
|
orderDao.insert(order);
|
|
|
|
|
codesTempDao.insertBatch(outOrderCodes);
|
|
|
|
|
log.info("盘亏入库单据生成成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新盘点单据生成的扫码单据号
|
|
|
|
|
invCountOrderDao.updateByOrderId(invCountOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新版盘点单据转换
|
|
|
|
|
*/
|
|
|
|
|
private void countTransferOrder(InvCountOrderEntity invCountOrder) {
|
|
|
|
|
|
|
|
|
|
List<InvCountSettingEntity> list = invCountSettingDao.filterList(null);
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
log.error("未配置盘点单据设置参数,无法转单");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
InvCountSettingEntity invCountSettingEntity = list.get(0);
|
|
|
|
|
|
|
|
|
|
List<InvCountOrderDetailEntity> orderDetailList = invCountOrderDetailDao.selectByOrderId(invCountOrder.getOrderId());
|
|
|
|
|
List<IoCodeTempEntity> lossCodesList = new ArrayList<>();
|
|
|
|
|
List<IoCodeTempEntity> profitCodesList = new ArrayList<>();
|
|
|
|
|
if (CollUtil.isNotEmpty(orderDetailList)) {
|
|
|
|
|
for (InvCountOrderDetailEntity invCountOrderDetail : orderDetailList) {
|
|
|
|
|
if (IntUtil.value(invCountOrderDetail.getLossNum()) > 0) {
|
|
|
|
|
IoCodeTempEntity warehouseEntity = buildCodeEntity(invCountOrderDetail, invCountOrder, ConstantType.TYPE_OUT);
|
|
|
|
|
warehouseEntity.setSupId(getSupId(warehouseEntity));
|
|
|
|
|
lossCodesList.add(warehouseEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IntUtil.value(invCountOrderDetail.getProfitNum()) > 0) {
|
|
|
|
|
IoCodeTempEntity warehouseEntity = buildCodeEntity(invCountOrderDetail, invCountOrder, ConstantType.TYPE_PUT);
|
|
|
|
|
warehouseEntity.setSupId(getSupId(warehouseEntity));
|
|
|
|
|
profitCodesList.add(warehouseEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生成盘亏出库单
|
|
|
|
|
if (CollUtil.isNotEmpty(lossCodesList)) {
|
|
|
|
|
IoOrderEntity order = createOrder(invCountSettingEntity, invCountOrder, ConstantType.TYPE_OUT);
|
|
|
|
|
lossCodesList.forEach(warehouseEntity -> {
|
|
|
|
|
warehouseEntity.setOrderId(order.getBillNo());
|
|
|
|
|
warehouseEntity.setAction(order.getAction());
|
|
|
|
|
warehouseEntity.setCorpOrderId(order.getCorpOrderId());
|
|
|
|
|
});
|
|
|
|
|
orderDao.insert(order);
|
|
|
|
|
codesTempDao.insertBatch(lossCodesList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生成盘盈入库单
|
|
|
|
|
if (CollUtil.isNotEmpty(profitCodesList)) {
|
|
|
|
|
IoOrderEntity order = createOrder(invCountSettingEntity, invCountOrder, ConstantType.TYPE_PUT);
|
|
|
|
|
profitCodesList.forEach(warehouseEntity -> {
|
|
|
|
|
warehouseEntity.setOrderId(order.getBillNo());
|
|
|
|
|
warehouseEntity.setAction(order.getAction());
|
|
|
|
|
warehouseEntity.setCorpOrderId(order.getCorpOrderId());
|
|
|
|
|
});
|
|
|
|
|
orderDao.insert(order);
|
|
|
|
|
codesTempDao.insertBatch(profitCodesList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IoCodeTempEntity buildCodeEntity(InvCountOrderDetailEntity invCountOrderDetail, InvCountOrderEntity invCountOrder, String mainAction) {
|
|
|
|
|
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
|
|
|
|
|
filterUdiRelRequest.setId(Long.parseLong(invCountOrderDetail.getProductId()));
|
|
|
|
|
List<UdiRelevanceResponse> udiRelevanceResponses = udiRelevanceDao.filterUdiRelevance(filterUdiRelRequest);
|
|
|
|
|
String code = FilterUdiUtils.transGlxpNoSerStr(udiRelevanceResponses, invCountOrderDetail);
|
|
|
|
|
IoCodeTempEntity warehouseEntity = new IoCodeTempEntity();
|
|
|
|
|
warehouseEntity.setOrderId(invCountOrder.getOrderId());
|
|
|
|
|
warehouseEntity.setCode(code);
|
|
|
|
|
warehouseEntity.setRelId(Long.parseLong(invCountOrderDetail.getProductId()));
|
|
|
|
|
warehouseEntity.setMainAction(mainAction);
|
|
|
|
|
warehouseEntity.setInvCode(invCountOrder.getInvStorageCode());
|
|
|
|
|
warehouseEntity.setWarehouseCode(invCountOrder.getInvWarehouseCode());
|
|
|
|
|
UdiEntity udi = FilterUdiUtils.getUdi(code);
|
|
|
|
|
warehouseEntity.setBatchNo(udi.getBatchNo());
|
|
|
|
|
warehouseEntity.setProduceDate(udi.getProduceDate());
|
|
|
|
|
warehouseEntity.setExpireDate(udi.getExpireDate());
|
|
|
|
|
warehouseEntity.setSerialNo(udi.getSerialNo());
|
|
|
|
|
warehouseEntity.setNameCode(udi.getUdi());
|
|
|
|
|
if (mainAction.equals(ConstantType.TYPE_PUT)) {
|
|
|
|
|
warehouseEntity.setCount(invCountOrderDetail.getProfitNum());
|
|
|
|
|
warehouseEntity.setReCount(invCountOrderDetail.getProfitNum());
|
|
|
|
|
} else {
|
|
|
|
|
warehouseEntity.setCount(invCountOrderDetail.getLossNum());
|
|
|
|
|
warehouseEntity.setReCount(invCountOrderDetail.getLossNum());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return warehouseEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 对条码添加供应商信息
|
|
|
|
|
*
|
|
|
|
|
* @param warehouseEntity 码明细
|
|
|
|
|
* @param countStatus 盈亏状态
|
|
|
|
|
*/
|
|
|
|
|
private void setSupInfo(IoCodeTempEntity warehouseEntity, String countStatus) {
|
|
|
|
|
/**
|
|
|
|
|
* 根据此码明细的盈亏状态,使用不同的逻辑生成供应商信息
|
|
|
|
|
* 盘盈:此条码不存在于库存详情中,需要从供应商产品信息表查询供应商信息
|
|
|
|
|
* 盘亏:此条码在库存中存在,但是盘点中没有此条码,直接查询库存详情表中的供应商ID
|
|
|
|
|
*
|
|
|
|
|
* 若查询出的供应商信息多余1条,则表明此产品被多个供应商绑定,在此处不进行绑定,单据生成之后会进入异常单据页面,在异常单据页面手动指定供应商
|
|
|
|
|
*/
|
|
|
|
|
if (countStatus.equals("loss")) {
|
|
|
|
|
log.info("生成盘亏单据条码供应商详情,条码信息:{}", warehouseEntity.getCode());
|
|
|
|
|
List<String> supIds = invProductDetailDao.selectSupIdByCode(warehouseEntity.getCode());
|
|
|
|
|
if (CollUtil.isNotEmpty(supIds)) {
|
|
|
|
|
if (supIds.size() == 1) {
|
|
|
|
|
//此产品只绑定了一个供应商,若绑定了多个供应商,则不填供应商ID字段,生成单据之后会进入异常单据页面,手动指定供应商
|
|
|
|
|
warehouseEntity.setSupId(supIds.get(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("生成盘盈单据条码供应商详情,条码信息:{}", warehouseEntity.getCode());
|
|
|
|
|
List<String> unitFkList = companyProductRelevanceDao.selectUnitFkByUdiRlIdFk(warehouseEntity.getRelId() + "");
|
|
|
|
|
if (CollUtil.isNotEmpty(unitFkList)) {
|
|
|
|
|
if (unitFkList.size() == 1) {
|
|
|
|
|
//此产品只绑定了一个供应商,若绑定了多个供应商,则不填供应商ID字段,生成单据之后会进入异常单据页面,手动指定供应商
|
|
|
|
|
warehouseEntity.setSupId(unitFkList.get(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验码重复
|
|
|
|
|
*
|
|
|
|
|
* @param codes
|
|
|
|
|
* @param code
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean verifyCodeExist(List<IoCodeTempEntity> codes, String code) {
|
|
|
|
|
for (IoCodeTempEntity warehouseEntity : codes) {
|
|
|
|
|
if (warehouseEntity.getCode().equals(code)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IoCodeTempEntity buildWarehouse(InvCountOrderEntity invCountOrder, String code, Long productId) {
|
|
|
|
|
IoCodeTempEntity warehouseEntity = new IoCodeTempEntity();
|
|
|
|
|
warehouseEntity.setOrderId(invCountOrder.getOrderId());
|
|
|
|
|
warehouseEntity.setCode(code);
|
|
|
|
|
warehouseEntity.setRelId(productId);
|
|
|
|
|
warehouseEntity.setMainAction(ConstantType.TYPE_PUT);
|
|
|
|
|
warehouseEntity.setInvCode(invCountOrder.getInvStorageCode());
|
|
|
|
|
warehouseEntity.setWarehouseCode(invCountOrder.getInvWarehouseCode());
|
|
|
|
|
UdiEntity udi = FilterUdiUtils.getUdi(code);
|
|
|
|
|
warehouseEntity.setBatchNo(udi.getBatchNo());
|
|
|
|
|
warehouseEntity.setProduceDate(udi.getProduceDate());
|
|
|
|
|
warehouseEntity.setExpireDate(udi.getExpireDate());
|
|
|
|
|
warehouseEntity.setSerialNo(udi.getSerialNo());
|
|
|
|
|
warehouseEntity.setNameCode(udi.getUdi());
|
|
|
|
|
warehouseEntity.setCount(1);
|
|
|
|
|
warehouseEntity.setReCount(1);
|
|
|
|
|
return warehouseEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成单据和条码数据
|
|
|
|
|
*
|
|
|
|
|
* @param invCountSettingEntity
|
|
|
|
|
* @param invCountOrder
|
|
|
|
|
* @param type
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public IoOrderEntity createOrder(InvCountSettingEntity invCountSettingEntity, InvCountOrderEntity invCountOrder, String type) {
|
|
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity;
|
|
|
|
|
|
|
|
|
|
if (ConstantType.TYPE_PUT.equals(type)) {
|
|
|
|
|
bussinessTypeEntity = basicBussinessTypeService.findByAction(invCountSettingEntity.getInAction());
|
|
|
|
|
} else {
|
|
|
|
|
bussinessTypeEntity = basicBussinessTypeService.findByAction(invCountSettingEntity.getOutAction());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//构造单据数据
|
|
|
|
|
IoOrderEntity orderEntity = new IoOrderEntity();
|
|
|
|
|
orderEntity.setMainAction(bussinessTypeEntity.getMainAction());
|
|
|
|
|
orderEntity.setAction(bussinessTypeEntity.getAction());
|
|
|
|
|
orderEntity.setCreateTime(new Date());
|
|
|
|
|
orderEntity.setInvCode(invCountOrder.getInvStorageCode());
|
|
|
|
|
//查询单据往来单位数据
|
|
|
|
|
BasicCorpEntity unitMaintainEntity = unitMaintainDao.selectByErpId(bussinessTypeEntity.getDefaultUnit());
|
|
|
|
|
orderEntity.setFromCorp(unitMaintainEntity.getErpId());
|
|
|
|
|
orderEntity.setCorpOrderId(CustomUtil.getId() + "x");
|
|
|
|
|
orderEntity.setExportStatus(0); //设置导出状态为未导出
|
|
|
|
|
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESS);
|
|
|
|
|
orderEntity.setFromType(ConstantStatus.FROM_COUNT); //单据来源设置为盘点单据转单
|
|
|
|
|
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trim(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
|
|
|
|
|
orderEntity.setBillNo(orderNo);
|
|
|
|
|
return orderEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getSupId(IoCodeTempEntity warehouseEntity) {
|
|
|
|
|
List<String> supIds = companyProductRelevanceDao.selectUnitFkByUdiRlIdFk(warehouseEntity.getRelId() + "");
|
|
|
|
|
if (CollUtil.isNotEmpty(supIds) && supIds.size() == 1) {
|
|
|
|
|
return supIds.get(0);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|