Browse Source

1.备货可以扫未分配的条码
2.备货出库分配可以零星库存先出,其次先进先出

k 1 year ago
parent
commit
0b65913887

+ 128 - 2
warewms-ams/src/main/java/com/ruoyi/ams/order/service/impl/WmsDocOrderHeaderServiceImpl.java

@@ -1339,7 +1339,9 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
         List<InvLotLocIdLotattVO> invLotLocIdLotattList = invLotLocIdService.selectInvLocIdLotattList(locIdSearchFrom);
         // 组盘是把出库的库存重新组到一个新的托盘上,所以起始托盘和条码理应可以查询到系统里有对应的库存。
         if (invLotLocIdLotattList.size() == 0) {
-            return AjaxResult.error(String.format("不存在对应库存!起始托盘:%s,条码:%s", palletNoFrom, sn));
+            // 备货(不是当前出库单分配的)
+            return groupDiskUnAllocationBH(groupDiskFrom);
+//            return AjaxResult.error(String.format("不存在对应库存!起始托盘:%s,条码:%s", palletNoFrom, sn));
         }
         // 产品的话基本只能查出有一条库存 但是物料可能会多条 但是我们只处理一条库存
         List<InvLotLocIdLotattVO> invLotLocIdLotattVOList = new ArrayList<>();
@@ -1444,7 +1446,131 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
         boxInfoUpdate.setId(wmsBoxInfo.getId());
         boxInfoUpdate.setLocationId(currentVirtualZone);
         wmsBoxInfoService.updateWmsBoxInfo(boxInfoUpdate);
-        return AjaxResult.success("组盘成功!");
+        return AjaxResult.success("备货成功!");
+    }
+
+    /**
+     * 备货(不是当前出库单分配的)
+     *
+     * @param groupDiskFrom
+     * @return
+     */
+    @Transactional
+    public AjaxResult groupDiskUnAllocationBH(GroupDiskFrom groupDiskFrom) {
+        String palletNoFrom = groupDiskFrom.getPalletNoFrom(); // 起始托盘
+        String palletNoTo = groupDiskFrom.getPalletNoTo(); // 目标托盘
+        String sn = groupDiskFrom.getSn(); // 条码号
+        String orderNo = ""; // 出库单号
+        String sku = ""; // 物料编码
+        Double qty = Double.valueOf(groupDiskFrom.getQty()); // 数量
+        boolean isAllUpdate = false; // 库存转移类型,是全部修改,还是拆分
+        boolean isStockPalletNoTo = groupDiskFrom.isStockPalletNoTo(); // 目标托盘是否是备货托盘,为了方便,目标托盘默认是备货托盘
+        final Double toQty;
+        Long currentVirtualZone; // 当前所在的虚拟区
+        if (StringUtils.isNotEmpty(groupDiskFrom.getOrderNo())) {
+            orderNo = groupDiskFrom.getOrderNo();
+        }
+        // 根据条码获取物料号
+        CodeSkuRelationshipVO codeSkuRelationshipVO = codeSkuRelationshipService.checkIsProduct(sn);
+        sku = codeSkuRelationshipVO.getSku();
+        if (codeSkuRelationshipVO.isProduct()) {
+            qty = 1.0; //产品默认为1
+        }
+        toQty = qty;
+        // 根据起始托盘,物料号查出库存
+        InvLocIdSearchFrom locIdSearchFrom = new InvLocIdSearchFrom();
+        locIdSearchFrom.setSku(sku);
+        LotattDTO lotattDTO = new LotattDTO();
+        lotattDTO.setLotatt07(palletNoFrom);
+        lotattDTO.setLotatt02(sn);
+//        lotattDTO.setLotatt15(orderNo);
+        locIdSearchFrom.setLotattDTO(lotattDTO);
+        List<InvLotLocIdLotattVO> invLotLocIdLotattList = invLotLocIdService.selectInvLocIdLotattList(locIdSearchFrom);
+        /// 筛选出未备货的库存
+//        invLotLocIdLotattList = invLotLocIdLotattList.stream().filter(v -> StringUtils.isEmpty(v.getLotatt14())).collect(Collectors.toList());
+//        if (invLotLocIdLotattList.size() == 0) {
+//            return AjaxResult.error(String.format("不存在对应库存!起始托盘:%s,条码:%s", palletNoFrom, sn));
+//        }
+        // 产品的话基本只能查出有一条库存 我们只处理一条库存
+        List<InvLotLocIdLotattVO> invLotLocIdLotattVOList = new ArrayList<>();
+        InvLotLocIdLotattVO endLotattVO = null;
+        List<InvLotLocIdLotattVO> equalInv = invLotLocIdLotattList.stream().filter(v -> v.getQty().compareTo(toQty) == 0).collect(Collectors.toList());
+        if (equalInv.size() > 0) {
+            endLotattVO = equalInv.get(0);
+            isAllUpdate = true;
+        } else {
+            List<InvLotLocIdLotattVO> greaterInv = invLotLocIdLotattList.stream().filter(v -> v.getQty().compareTo(toQty) == 1).collect(Collectors.toList());
+            if (greaterInv.size() > 0) {
+                endLotattVO = greaterInv.get(0);
+            }
+        }
+        if (endLotattVO == null) {
+            return AjaxResult.error("组盘数量大于单条库存数量!");
+        }
+        currentVirtualZone = endLotattVO.getLocationId();
+        invLotLocIdLotattVOList.add(endLotattVO);
+        // 验证备货库存是否已经备货
+        if (StringUtils.isNotEmpty(endLotattVO.getLotatt14())) {
+            return AjaxResult.error("扫描条码已经备货,对应出库单:" + endLotattVO.getLotatt14());
+        }
+        //验证目标托盘库存,一个托盘只能备货一个出库单
+        AjaxResult ajaxResultC = invLotLocIdService.checkPalletIsOnlyOrderNo(groupDiskFrom.getPalletNoTo()
+                , orderNo);
+        if (!ajaxResultC.isSuccess()) {
+            return ajaxResultC;
+        }
+        // 创建Lotnum和库存对应关系
+        Map<String, List<InvLotLocIdLotattVO>> lotnumAndInvLocIdMap = new HashMap<>();
+        invLotLocIdLotattVOList.stream().forEach(v -> {
+            if (lotnumAndInvLocIdMap.get(v) == null) {
+                lotnumAndInvLocIdMap.put(v.getLotnum(), Arrays.asList(v));
+            } else {
+                List<InvLotLocIdLotattVO> locIdLotattVOList = lotnumAndInvLocIdMap.get(v.getLotnum());
+                locIdLotattVOList.add(v);
+                lotnumAndInvLocIdMap.put(v.getLotnum(), locIdLotattVOList);
+            }
+        });
+        // 根据老Lotnum创建新的Lotnum
+        for (Map.Entry<String, List<InvLotLocIdLotattVO>> lotnumToInvLocId : lotnumAndInvLocIdMap.entrySet()) {
+            String lotnum = lotnumToInvLocId.getKey();
+            List<InvLotLocIdLotattVO> invLocIdList = lotnumToInvLocId.getValue();
+            InvLotAtt invLotAtt = invLotAttMapper.selectInvLotAttByLotnum(lotnum);
+            String newLotnum = idSequenceUtils.generateId("LOTNUMBER");
+            invLotAtt.setLotnum(newLotnum);
+            invLotAtt.setLotatt07(palletNoTo);
+            invLotAtt.setLotatt14(orderNo); // 备货对应的出库单号
+            InvLotLocIdLotattVO invLotLocIdLotattVO = invLocIdList.get(0);
+            if (StringUtils.isEmpty(invLotLocIdLotattVO.getLotatt15())) {
+                invLotAtt.setLotatt15(orderNo);
+            } else {
+                invLotAtt.setLotatt15(invLotLocIdLotattVO.getLotatt15());
+            }
+            invLotAtt.setCreateTime(DateUtils.getNowDate());
+            if (invLotAttMapper.insertInvLotAtt(invLotAtt) > 0) {
+                for (InvLotLocIdLotattVO v : invLocIdList) {
+                    if (isAllUpdate) {
+                        InvLotLocIdForm invLotLocIdUpdate = new InvLotLocIdForm();
+                        invLotLocIdUpdate.setLotnum(lotnum);
+                        invLotLocIdUpdate.setLocationId(v.getLocationId().toString());
+                        invLotLocIdUpdate.setCustomerId(v.getCustomerId());
+                        invLotLocIdUpdate.setSku(v.getSku());
+                        invLotLocIdUpdate.setQtyallocated(invLotLocIdUpdate.getQty());
+                        invLotLocIdUpdate.setLotnumTo(newLotnum);
+                        invLotLocIdService.updateInvLotLocId(invLotLocIdUpdate);
+                    }
+                    // 更新出库单备货数量
+                    wmsDocOrderHeaderService.modifystockCompletionStatus(orderNo, sku, new BigDecimal(toQty));
+                }
+
+            }
+        }
+        // 更新托盘
+        WmsBoxInfo wmsBoxInfo = wmsBoxInfoService.selectWmsBoxInfoByBoxNo(palletNoTo);
+        WmsBoxInfo boxInfoUpdate = new WmsBoxInfo();
+        boxInfoUpdate.setId(wmsBoxInfo.getId());
+        boxInfoUpdate.setLocationId(currentVirtualZone);
+        wmsBoxInfoService.updateWmsBoxInfo(boxInfoUpdate);
+        return AjaxResult.success("备货成功!(未分配条码)");
     }
 
     @Transactional

+ 3 - 1
warewms-ams/src/main/resources/mapper/ams/InvLotLocIdMapper.xml

@@ -519,9 +519,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
              , inv.sku, inv.qty, inv.qty_each qtyEach, inv.qtyallocated, inv.qtyallocated_each qtyallocatedEach
             ,att.lotatt01,att.lotatt02,att.lotatt03,att.lotatt04,att.lotatt05,att.lotatt06,att.lotatt07,att.lotatt08,att.lotatt09
              ,att.lotatt10,att.lotatt11,att.lotatt12,att.lotatt13,att.lotatt14,att.lotatt15,att.lotatt16,att.lotatt17,att.lotatt18
+        ,t3.orderByQty
         from inv_lot_loc_id inv
         left join base_location_info b on inv.location_id = b.id
         left join inv_lot_att att on inv.lotnum = att.lotnum
+        LEFT JOIN (SELECT t1.location_id,t1.sku,count(qty) orderByQty from inv_lot_loc_id t1 where t1.sku = #{sku} GROUP BY t1.location_id,t1.sku) t3 on t3.location_id = inv.location_id
         <where>
             <if test="lotnum != null  and lotnum != ''"> and inv.lotnum = #{lotnum}</if>
             <if test="sku != null  and sku != ''"> and inv.sku = #{sku}</if>
@@ -549,7 +551,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
             and b.stock_status = '00' and b.zone_id = '2'
         </where>
-        order by att.create_time,lpad(b.row_no, 11, '0'),b.row_index,lpad(b.shift_no, 11, '0'),b.shift_index,lpad(b.col_no, 11, '0'),b.col_index desc
+        ORDER BY t3.orderByQty,inv.create_time
     </select>
 
     <select id="queryInvByInvLotatt" resultMap="InvLotLocIdResult">