|
@@ -3,8 +3,8 @@ package com.ruoyi.ams.order.service.impl;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.comparator.CompareUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
import com.ruoyi.ams.asn.service.IWmsDocAsnHeaderService;
|
|
|
import com.ruoyi.ams.box.domain.WmsBoxInfo;
|
|
|
import com.ruoyi.ams.box.mapper.WmsBoxInfoMapper;
|
|
@@ -33,6 +33,7 @@ import com.ruoyi.ams.order.domain.ActAllocationDetails;
|
|
|
import com.ruoyi.ams.order.domain.PalletMatchLog;
|
|
|
import com.ruoyi.ams.order.domain.WmsDocOrderDetails;
|
|
|
import com.ruoyi.ams.order.domain.WmsDocOrderHeader;
|
|
|
+import com.ruoyi.ams.order.dto.PdaGroupDiskDTO;
|
|
|
import com.ruoyi.ams.order.form.*;
|
|
|
import com.ruoyi.ams.order.mapper.WmsDocOrderDetailsMapper;
|
|
|
import com.ruoyi.ams.order.mapper.WmsDocOrderHeaderMapper;
|
|
@@ -2736,12 +2737,124 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * PDA理货备货
|
|
|
+ * @param pdaGroupDiskDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public synchronized AjaxResult pdaGroupDiskBH(PdaGroupDiskDTO pdaGroupDiskDTO) {
|
|
|
+ String palletNoFrom = pdaGroupDiskDTO.getPalletNoFrom(); // 起始托盘
|
|
|
+ String palletNoTo = pdaGroupDiskDTO.getPalletNoTo(); // 目标托盘
|
|
|
+ String sn = pdaGroupDiskDTO.getSn(); // 条码号
|
|
|
+ String orderNo = StringUtils.isNotBlank(pdaGroupDiskDTO.getOrderNo()) ? pdaGroupDiskDTO.getOrderNo() : ""; // 出库单号(备货才会传入)
|
|
|
+ String boxNo = StringUtils.isNotBlank(pdaGroupDiskDTO.getBoxNo()) ? pdaGroupDiskDTO.getBoxNo() : palletNoTo; //箱号
|
|
|
+ BigDecimal qty = new BigDecimal(pdaGroupDiskDTO.getQty()); // 数量
|
|
|
+
|
|
|
+ verifyWmsDocOrder(orderNo);
|
|
|
+
|
|
|
+ // 根据条码获取物料号
|
|
|
+ CodeSkuRelationshipVO codeSkuRelationshipVO = codeSkuRelationshipService.checkIsProduct(sn);
|
|
|
+ // 物料编码
|
|
|
+ String sku = codeSkuRelationshipVO.getSku();
|
|
|
+ //创建新批次
|
|
|
+ String lotNum = IdWorker.getIdStr();
|
|
|
+ invLotAttService.insertInvLotAtt(buildInvLotAtt(lotNum, palletNoTo, orderNo, sn, sku));
|
|
|
+ InvLotAtt invLotAtt = invLotAttService.queryInvLotAttBySn(palletNoFrom, sn);
|
|
|
+ InvLotLocId invLotLocId = invLotLocIdService.queryInvLotLocIdByLotnum(invLotAtt.getLotnum());
|
|
|
+ String locationId = invLotLocId.getLocationId();
|
|
|
+ BigDecimal qtyAllocated = ObjectUtil.isNotNull(invLotLocId.getQtyallocated()) ? invLotLocId.getQtyallocated() : BigDecimal.ZERO;
|
|
|
+ BigDecimal invLotLocQty = invLotLocId.getQty().subtract(qtyAllocated);
|
|
|
+ if (CompareUtil.compare(qty, invLotLocQty) >= 0){
|
|
|
+ invLotLocIdService.updateInvLotLocId(invLotLocId.getLotnum(), lotNum, invLotLocQty, sku, locationId);
|
|
|
+ }else {
|
|
|
+ // 拆分库存
|
|
|
+ // 修改原库存
|
|
|
+ invLotLocIdService.updateInvLotLocId(invLotLocId.getLotnum(), qtyAllocated.add(qty), invLotLocId.getSku());
|
|
|
+ // 插入新库存
|
|
|
+ invLotLocIdService.insertInvLotLocId(buildInvLotLocId(lotNum, qty, locationId, orderNo, sku));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WmsDocOrderDetails> wmsDocOrderDetailsList = wmsDocOrderDetailsService.queryWmsDocOrderDetailsByOrderNo(orderNo);
|
|
|
+ //筛选出相同sku并且数量未分配或未分配完的明细信息
|
|
|
+ List<WmsDocOrderDetails> wmsDocOrderDetailsFilterList = wmsDocOrderDetailsList.stream().filter(item -> CompareUtil.compare(item.getSku(), sku) == 0 &&
|
|
|
+ CompareUtil.compare(item.getQtyOrdered().subtract(item.getQtyAllocated()), BigDecimal.ZERO) > 0).collect(Collectors.toList());
|
|
|
+ for (WmsDocOrderDetails wmsDocOrderDetails : wmsDocOrderDetailsFilterList) {
|
|
|
+ //明细已分配数量
|
|
|
+ BigDecimal wmsDocOrderDetailsQtyAllocated = ObjectUtil.isNotNull(wmsDocOrderDetails.getQtyAllocated()) ? wmsDocOrderDetails.getQtyAllocated() : BigDecimal.ZERO;
|
|
|
+ //剩余需分配数量
|
|
|
+ BigDecimal wmsDocOrderDetailsQty = wmsDocOrderDetails.getQtyOrdered().subtract(wmsDocOrderDetailsQtyAllocated);
|
|
|
+ BigDecimal remainQty = qty.subtract(wmsDocOrderDetailsQty);
|
|
|
+ Boolean flag = CompareUtil.compare(remainQty, BigDecimal.ZERO) < 0;
|
|
|
+ wmsDocOrderDetails.setQtyAllocated(flag ? qty : wmsDocOrderDetailsQty);
|
|
|
+ wmsDocOrderDetails.setQtyAllocatedEach(wmsDocOrderDetails.getQtyAllocated());
|
|
|
+ wmsDocOrderDetails.setLineStatus(flag ? Constant.ORDER_STS.STS10.getValue() : Constant.ORDER_STS.STS20.getValue());
|
|
|
+ wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(wmsDocOrderDetails);
|
|
|
+ //生成分配明细
|
|
|
+ actAllocationDetailsService.addActAllocationDetails(lotNum, locationId, qty, wmsDocOrderDetails
|
|
|
+ , wmsDocOrderDetails.getLineStatus());
|
|
|
+ // 记录扫码数据
|
|
|
+ erpBarcodesService.recordErpBarcodeListSo(wmsDocOrderDetails, sn
|
|
|
+ , "SORTATION01", palletNoTo, BigDecimal.ONE, boxNo);
|
|
|
+ qty = remainQty;
|
|
|
+ if (flag || CompareUtil.compare(qty, BigDecimal.ZERO) == 0) break;
|
|
|
+ }
|
|
|
+ // 更新托盘
|
|
|
+ wmsBoxInfoService.updateWmsBoxLocationIdByBoxNo(boxNo, Long.parseLong(locationId));
|
|
|
+ return AjaxResult.success("当前托盘备货成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ private InvLotLocId buildInvLotLocId(String lotNum, BigDecimal qty, String locationId, String traceId, String sku){
|
|
|
+ InvLotLocId invLotLocId = new InvLotLocId();
|
|
|
+ invLotLocId.setLotnum(lotNum);
|
|
|
+ invLotLocId.setTraceid(traceId);
|
|
|
+ invLotLocId.setLocationId(locationId);
|
|
|
+ invLotLocId.setCustomerId(Constant.CUSTOMER_ID);
|
|
|
+ invLotLocId.setSku(sku);
|
|
|
+ invLotLocId.setQty(qty);
|
|
|
+ invLotLocId.setQtyEach(qty);
|
|
|
+ invLotLocId.setQtyallocated(BigDecimal.ZERO);
|
|
|
+ invLotLocId.setQtyallocatedEach(BigDecimal.ZERO);
|
|
|
+ return invLotLocId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private InvLotAtt buildInvLotAtt(String lotNum, String palletNoTo, String orderNo, String sn, String sku){
|
|
|
+ InvLotAtt invLotAtt = new InvLotAtt();
|
|
|
+ invLotAtt.setLotnum(lotNum);
|
|
|
+ invLotAtt.setLotatt07(palletNoTo);
|
|
|
+ invLotAtt.setLotatt14(orderNo); // 备货对应的出库单号
|
|
|
+ invLotAtt.setLotatt02(sn);
|
|
|
+ invLotAtt.setSku(sku);
|
|
|
+ invLotAtt.setCustomerId(Constant.CUSTOMER_ID);
|
|
|
+ invLotAtt.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return invLotAtt;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 验证出库单
|
|
|
+ * @param orderNo
|
|
|
+ */
|
|
|
+ private void verifyWmsDocOrder(String orderNo) {
|
|
|
+ WmsDocOrderHeader header = wmsDocOrderHeaderService.selectWmsDocOrderHeaderByOrderNo(orderNo);
|
|
|
+ if (ObjectUtil.isNull(header)) throw new BaseException("查无此出库单数据" + orderNo);
|
|
|
+ if (!header.getOrderType().equals(Constant.ORDER_TYP.BH.getValue())) {
|
|
|
+ throw new BaseException("出库单类型不可备货组盘!");
|
|
|
+ }
|
|
|
+ if (!header.getOrderStatus().equals(Constant.ORDER_STS.STS10.getValue())
|
|
|
+ && !header.getOrderStatus().equals(Constant.ORDER_STS.STS20.getValue())
|
|
|
+ && !header.getOrderStatus().equals(Constant.ORDER_STS.STS22.getValue())) {
|
|
|
+ throw new BaseException("出库单状态不可备货组盘!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 库存分配
|
|
|
* @param orderList
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public Boolean inventoryMatch(List<String> orderList) {
|
|
|
//根据erp单号获取出库单头列表
|
|
|
List<WmsDocOrderHeader> wmsDocOrderHeaderList = wmsDocOrderHeaderMapper.selectList(Wrappers.<WmsDocOrderHeader>lambdaQuery().in(WmsDocOrderHeader::getSoReference1, orderList).orderByDesc(WmsDocOrderHeader::getCreateTime));
|
|
@@ -2751,9 +2864,9 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
List<WmsDocOrderHeader> wmsDocOrderHeaderFilterList = wmsDocOrderHeaderList.stream().filter(item -> item.getOrderStatus().equals(Constant.ORDER_STS.STS00.getValue())
|
|
|
|| item.getOrderStatus().equals(Constant.ORDER_STS.STS10.getValue()) || item.getOrderStatus().equals(Constant.ORDER_STS.STS22.getValue())).collect(Collectors.toList());
|
|
|
if (CollectionUtil.isEmpty(wmsDocOrderHeaderFilterList)){
|
|
|
- throw new BaseException("出库单状态不可分配!");
|
|
|
+ throw new BaseException("出库单状态不可进行库存匹配!");
|
|
|
}
|
|
|
- List<WmsDocOrderDetails> wmsDocOrderDetailsList = wmsDocOrderDetailsService.queryWmsDocOrderDetailsByOrderNoList(wmsDocOrderHeaderFilterList.stream().filter(item -> StringUtils.isNotBlank(item.getOrderNo())).map(WmsDocOrderHeader::getOrderNo).collect(Collectors.toList()));
|
|
|
+ List<WmsDocOrderDetails> wmsDocOrderDetailsList = wmsDocOrderDetailsService.queryWmsDocOrderDetailsByOrderNo(wmsDocOrderHeaderFilterList.stream().filter(item -> StringUtils.isNotBlank(item.getOrderNo())).map(WmsDocOrderHeader::getOrderNo).collect(Collectors.toList()));
|
|
|
if (CollectionUtil.isEmpty(wmsDocOrderDetailsList)){
|
|
|
throw new BaseException("出库单明细为空!");
|
|
|
}
|