Selaa lähdekoodia

PDA出库分配:
1.普通出库单必须完全分配
2.备货出库单可以部分分配
3.库存批次lotatt15作为记录分配出库单
4.某个库位的库存lotatt15不为空就不可以再被其他出库单分配

k 2 vuotta sitten
vanhempi
commit
87965e3202

+ 0 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/pda/PdaController.java

@@ -365,7 +365,6 @@ public class PdaController {
 
     //endregion
 
-
     //region PDA出库
 
     /**

+ 12 - 0
warewms-ams/src/main/java/com/ruoyi/ams/asn/service/impl/WmsDocAsnHeaderServiceImpl.java

@@ -577,6 +577,18 @@ public class WmsDocAsnHeaderServiceImpl implements IWmsDocAsnHeaderService {
         if (invLotLocIdList == null || invLotLocIdList.size() == 0) {
             return AjaxResult.error("该托盘不存在库存:" + unlockForm.getPalletNo());
         }
+        // 备货库存暂时不可解绑
+        boolean isCan = invLotLocIdList.stream().allMatch(v -> {
+            String lotnum = v.getLotnum();
+            InvLotAtt invLotAtt = invLotAttService.selectInvLotAttByLotnum(lotnum);
+            if (StringUtils.isEmpty(invLotAtt.getLotatt14())) {
+                return true;
+            }
+            return false;
+        });
+        if (!isCan) {
+            return AjaxResult.error("备货库存暂时不可解绑!");
+        }
         for (InvLotLocId inv : invLotLocIdList) {
             //修改入库单的接收数
             InvLotAtt qtt = invLotAttService.selectInvLotAttByLotnum(inv.getLotnum());

+ 2 - 1
warewms-ams/src/main/java/com/ruoyi/ams/inv/mapper/InvLotLocIdMapper.java

@@ -8,6 +8,7 @@ import com.ruoyi.ams.config.domain.dto.LotattDTO;
 import com.ruoyi.ams.inv.domain.InvLotAtt;
 import com.ruoyi.ams.inv.domain.InvLotLocId;
 import com.ruoyi.ams.inv.domain.form.InvLocIdSearchFrom;
+import com.ruoyi.ams.inv.domain.form.InvLotLocIdForm;
 import com.ruoyi.ams.inv.domain.vo.InvLotLocIdLotattVO;
 import com.ruoyi.base.domain.vo.BaseLocationLotattVO;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -252,7 +253,7 @@ public interface InvLotLocIdMapper {
      * @param customerId
      * @return
      */
-    List<InvLotLocId> queryInvOrderBy(@Param("lotnum") String lotnum, @Param("sku") String sku, @Param("location") String location, @Param("customerId") String customerId, @Param("lotattDTO") LotattDTO lotattDTO);
+    List<InvLotLocIdForm> queryInvOrderBy(@Param("lotnum") String lotnum, @Param("sku") String sku, @Param("location") String location, @Param("customerId") String customerId, @Param("lotattDTO") LotattDTO lotattDTO);
 
     /**
      * 根据托盘查询库存

+ 11 - 1
warewms-ams/src/main/java/com/ruoyi/ams/inv/service/IInvLotLocIdService.java

@@ -286,7 +286,7 @@ public interface IInvLotLocIdService {
      * @param customerId
      * @return
      */
-    List<InvLotLocId> queryInvOrderBy(String lotnum, String sku, String location, String customerId, LotattDTO lotattDTO);
+    List<InvLotLocIdForm> queryInvOrderBy(String lotnum, String sku, String location, String customerId, LotattDTO lotattDTO);
 
     /**
      * 根据托盘号查询库存
@@ -356,4 +356,14 @@ public interface IInvLotLocIdService {
      * @return
      */
     AjaxResult clearInvActOrderNoByPalletNo(String palletNo);
+
+
+    /**
+     * 根据库位将对应库存批次lotatt15改为出库单号
+     *
+     * @param locationId
+     * @param orderNo
+     * @return
+     */
+    AjaxResult updateLotatt15ByLocationId(String locationId,String orderNo);
 }

+ 19 - 1
warewms-ams/src/main/java/com/ruoyi/ams/inv/service/impl/InvLotLocIdServiceImpl.java

@@ -10,6 +10,7 @@ import com.ruoyi.ams.inv.domain.InvLotAtt;
 import com.ruoyi.ams.inv.domain.InvLotLocId;
 import com.ruoyi.ams.inv.domain.form.InvLocIdSearchFrom;
 import com.ruoyi.ams.inv.domain.form.InvLotLocIdAdjForm;
+import com.ruoyi.ams.inv.domain.form.InvLotLocIdForm;
 import com.ruoyi.ams.inv.domain.form.InvLotLocIdMoveForm;
 import com.ruoyi.ams.inv.domain.vo.InvLotLocIdLotattVO;
 import com.ruoyi.ams.inv.mapper.InvLotAttMapper;
@@ -734,7 +735,7 @@ public class InvLotLocIdServiceImpl implements IInvLotLocIdService {
     }
 
     @Override
-    public List<InvLotLocId> queryInvOrderBy(String lotnum, String sku, String location, String
+    public List<InvLotLocIdForm> queryInvOrderBy(String lotnum, String sku, String location, String
             customerId, LotattDTO lotattDTO) {
         return invLotLocIdMapper.queryInvOrderBy(lotnum, sku, location, customerId, lotattDTO);
     }
@@ -860,4 +861,21 @@ public class InvLotLocIdServiceImpl implements IInvLotLocIdService {
         }
         return AjaxResult.success();
     }
+
+    @Override
+    public AjaxResult updateLotatt15ByLocationId(String locationId, String orderNo) {
+        List<InvLotLocId> invLotLocIds = invLotLocIdService.selectInvLotLocIdList(Long.valueOf(locationId));
+        for (InvLotLocId invLotLocId : invLotLocIds) {
+            InvLotAtt invLotAtt = invLotAttMapper.selectInvLotAttByLotnum(invLotLocId.getLotnum());
+            if (invLotAtt != null ) {
+                if (StringUtils.isNotEmpty(invLotAtt.getLotatt15()) && invLotAtt.getLotatt15().equals(orderNo)) {
+                    break;
+                }
+                invLotAtt.setLotatt15(orderNo);
+                invLotAttMapper.updateInvLotAtt(invLotAtt);
+            }
+        }
+        return AjaxResult.success();
+    }
+
 }

+ 2 - 2
warewms-ams/src/main/java/com/ruoyi/ams/order/service/IWmsDocOrderHeaderService.java

@@ -105,7 +105,7 @@ public interface IWmsDocOrderHeaderService {
     int updateOrderDetailsStock(String orderNo, Long orderLoneNo, Double qty, String status);
 
     /**
-     * 拣货分配
+     * 出库分配
      *
      * @param orderNo
      * @return
@@ -129,7 +129,7 @@ public interface IWmsDocOrderHeaderService {
     AjaxResult doAllocation(List<String> orderNoList);
 
     /**
-     * 拣货分配(按明细分配)
+     * 出库分配
      *
      * @param details
      * @return

+ 20 - 20
warewms-ams/src/main/java/com/ruoyi/ams/order/service/impl/ActAllocationDetailsServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ruoyi.ams.order.service.impl;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 import com.ruoyi.ams.box.domain.WmsBoxInfo;
@@ -15,6 +16,7 @@ import com.ruoyi.base.domain.BaseLocationInfo;
 import com.ruoyi.base.service.IBaseLocationInfoService;
 import com.ruoyi.base.utils.IdSequenceUtils;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.ams.order.mapper.ActAllocationDetailsMapper;
@@ -156,22 +158,22 @@ public class ActAllocationDetailsServiceImpl implements IActAllocationDetailsSer
     public AjaxResult addActAllocationDetails(String lotnum, String locationId, BigDecimal qty, WmsDocOrderDetails orderDetails, String status) {
         WmsBoxInfo wmsBoxInfo = wmsBoxInfoService.selectByLocationId(locationId);
         // 查询分配明细 有就修改 没有新增
-        ActAllocationDetailsFrom actAllocationDetailsFrom = new ActAllocationDetailsFrom();
-        actAllocationDetailsFrom.setLotnum(lotnum);
-        actAllocationDetailsFrom.setOrderNo(orderDetails.getOrderNo());
-        actAllocationDetailsFrom.setLineNo(orderDetails.getOrderLineNo().longValue());
-        actAllocationDetailsFrom.setLocationId(Long.parseLong(locationId));
-        actAllocationDetailsFrom.setMaterial(orderDetails.getSku());
-        List<ActAllocationDetailsFrom> allocationDetailsFromList = actAllocationDetailsMapper.selectActAllocationDetailsInvLotAttList(actAllocationDetailsFrom);
-        if (allocationDetailsFromList.size() > 0) {
-            for (ActAllocationDetailsFrom allocationDetailsFrom : allocationDetailsFromList) {
-                ActAllocationDetails allocationDetailsUpdate = new ActAllocationDetails();
-                allocationDetailsUpdate.setAllocationId(allocationDetailsFrom.getAllocationId());
-                allocationDetailsUpdate.setStatus(Constant.ORDER_STS.STS20.getValue());
-                actAllocationDetailsMapper.updateActAllocationDetails(allocationDetailsUpdate);
-            }
-            return AjaxResult.success("分配明细生成成功");
-        }
+//        ActAllocationDetailsFrom actAllocationDetailsFrom = new ActAllocationDetailsFrom();
+//        actAllocationDetailsFrom.setLotnum(lotnum);
+//        actAllocationDetailsFrom.setOrderNo(orderDetails.getOrderNo());
+//        actAllocationDetailsFrom.setLineNo(orderDetails.getOrderLineNo().longValue());
+//        actAllocationDetailsFrom.setLocationId(Long.parseLong(locationId));
+//        actAllocationDetailsFrom.setMaterial(orderDetails.getSku());
+//        List<ActAllocationDetailsFrom> allocationDetailsFromList = actAllocationDetailsMapper.selectActAllocationDetailsInvLotAttList(actAllocationDetailsFrom);
+//        if (allocationDetailsFromList.size() > 0) {
+//            for (ActAllocationDetailsFrom allocationDetailsFrom : allocationDetailsFromList) {
+//                ActAllocationDetails allocationDetailsUpdate = new ActAllocationDetails();
+//                allocationDetailsUpdate.setAllocationId(allocationDetailsFrom.getAllocationId());
+//                allocationDetailsUpdate.setStatus(Constant.ORDER_STS.STS20.getValue());
+//                actAllocationDetailsMapper.updateActAllocationDetails(allocationDetailsUpdate);
+//            }
+//            return AjaxResult.success("分配明细生成成功");
+//        }
 
         String allocationId = idSequenceUtils.generateId("ANO");
         ActAllocationDetails actAllocationDetails = new ActAllocationDetails();
@@ -184,15 +186,13 @@ public class ActAllocationDetailsServiceImpl implements IActAllocationDetailsSer
         actAllocationDetails.setQty(qty);
         actAllocationDetails.setPickQty(BigDecimal.ZERO);
         actAllocationDetails.setLocationId(Long.parseLong(locationId));
+        actAllocationDetails.setCreateTime(new Date());
+        actAllocationDetails.setCreateBy(SecurityUtils.getLoginUser().getUsername());
         if (wmsBoxInfo != null) {
             actAllocationDetails.setUserdefine1(wmsBoxInfo.getBoxNo());
         }
         int count = actAllocationDetailsMapper.insertActAllocationDetails(actAllocationDetails);
         if (count > 0) {
-            //TODO 锁定库位(如果没有AGV需要把这部分去除)
-            /*BaseLocationInfo baseLocationInfo = baseLocationInfoService.selectBaseLocationInfoById(Long.parseLong(locationId));
-            baseLocationInfo.setStockStatus("10");
-            baseLocationInfoService.updateBaseLocationInfo(baseLocationInfo);*/
 
             return AjaxResult.success("分配明细生成成功", qty);
         } else {

+ 123 - 85
warewms-ams/src/main/java/com/ruoyi/ams/order/service/impl/WmsDocOrderHeaderServiceImpl.java

@@ -219,7 +219,7 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
 
     /**
      * 订单分配
-     *
+     * 只能完全分配
      * @param orderNo
      * @return
      */
@@ -230,9 +230,8 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
         if (orderHeader == null) {
             return AjaxResult.error("没有查询到订单");
         }
-        // TODO 改成可以部分分配
         if (!orderHeader.getOrderStatus().equals(Constant.ORDER_STS.STS00.getValue())) {
-            return AjaxResult.error("出库单为创建状态才可以分配");
+            return AjaxResult.success("出库单为创建状态才可以分配");
         }
         boolean isbf = false;
         boolean isAllocation = false;
@@ -255,9 +254,9 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
             }
         }
         if (isbf) {
+            // 不可部分分配
             orderHeader.setOrderStatus(Constant.ORDER_STS.STS10.getValue());
             wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
-            // TODO 改成可以部分分配
             throw new ServiceException("库存数量不足,分配失败!" + orderNo);
         }
         if (isAllocation) {
@@ -280,23 +279,12 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
     @Override
     public AjaxResult doAllocationBH(String orderNo) {
         WmsDocOrderHeader orderHeader = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderByOrderNo(orderNo);
-        // 为了可以重复下任务
-        if (StringUtils.isEmpty(orderHeader.getUserdefine6())) {
-            orderHeader.setUserdefine6("N");
-        }
         if (orderHeader == null) {
             return AjaxResult.error("没有查询到订单");
         }
-        if (!orderHeader.getOrderStatus().equals(Constant.ORDER_STS.STS23.getValue())) {
-            return AjaxResult.error("出库单为备货完成才可以分配");
-        }
-        // 是否已经生成分配明细
-        ActAllocationDetails allocationDetailsQuery = new ActAllocationDetails();
-        allocationDetailsQuery.setOrderNo(orderNo);
-        allocationDetailsQuery.setStatus(Constant.ORDER_STS.STS20.getValue());
-        List<ActAllocationDetails> actAllocationDetailsList = actAllocationDetailsService.selectActAllocationDetailsList(allocationDetailsQuery);
-        if (actAllocationDetailsList.size() > 0) {
-            return AjaxResult.error("出库单已经生成分配明细!");
+        if (!orderHeader.getOrderStatus().equals(Constant.ORDER_STS.STS00.getValue())
+                && !orderHeader.getOrderStatus().equals(Constant.ORDER_STS.STS10.getValue())){
+            return AjaxResult.success("出库单状态不可分配!");
         }
 
         boolean isbf = false;
@@ -304,7 +292,7 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
         BigDecimal total = BigDecimal.ZERO;
         List<WmsDocOrderDetails> orderDetails = orderHeader.getWmsDocOrderDetailsList();
         for (WmsDocOrderDetails o : orderDetails) {
-            total = total.add(o.getQtyOrdered());
+            total = total.add(o.getQtyOrdered().subtract(o.getQtyAllocated()));
         }
         for (WmsDocOrderDetails o : orderDetails) {
             AjaxResult result = wmsDocOrderHeaderService.doAllocationDetailsBH(orderHeader, o);
@@ -320,20 +308,16 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
             }
         }
         if (isbf) {
-            orderHeader.setOrderStatus(Constant.ORDER_STS.STS22.getValue());
+            orderHeader.setOrderStatus(Constant.ORDER_STS.STS10.getValue());
             wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
-            if (!orderHeader.getUserdefine6().equals("Y")) {
-                throw new ServiceException("库存数量不足,分配失败!" + orderNo);
-            }
+            return AjaxResult.success("部分分配成功!");
         }
         if (isAllocation) {
-            orderHeader.setOrderStatus(Constant.ORDER_STS.STS23.getValue());
-            // 偷懒 卡个bug
-            orderHeader.setUserdefine6("Y"); // 代表已经校验成功
+            orderHeader.setOrderStatus(Constant.ORDER_STS.STS20.getValue());
             wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
-            return AjaxResult.success("分配成功");
+            return AjaxResult.success("分配成功!");
         } else {
-            return AjaxResult.error("分配失败,没有可用的库存");
+            return AjaxResult.error("分配失败,没有可用的库存");
         }
     }
 
@@ -343,14 +327,18 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
         for (String s : orderNoList) {
             AjaxResult ajaxResult = null;
             WmsDocOrderHeader header = wmsDocOrderHeaderService.selectWmsDocOrderHeaderByOrderNo(s);
-            // 判断是否是已经备货完成的备货单
-            if (header.getOrderType().equals(Constant.ORDER_TYP.BH.getValue())
-                    && header.getOrderStatus().equals(Constant.ORDER_STS.STS23.getValue())) {
+            // 备货单
+            if (header.getOrderType().equals(Constant.ORDER_TYP.BH.getValue())) {
                 // 同一个类事务会失效 通过重新注入自己解决事务失效问题
                 ajaxResult = wmsDocOrderHeaderService.doAllocationBH(s);
-            } else {
+                // 正常出库单
+            } else if (header.getOrderType().equals(Constant.ORDER_TYP.ZC.getValue())) {
                 // 同一个类事务会失效 通过重新注入自己解决事务失效问题
                 ajaxResult = wmsDocOrderHeaderService.doAllocation(s);
+                // 库内理货单
+            } else if (header.getOrderType().equals(Constant.ORDER_TYP.LH.getValue())) {
+                // 库内理货不需要分配
+                ajaxResult = AjaxResult.success();
             }
             if (!ajaxResult.isSuccess()) {
                 builder.append(s).append(":").append(ajaxResult.getMsg()).append(";");
@@ -373,17 +361,22 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
     @Transactional
     @Override
     public synchronized AjaxResult doAllocationDetails(WmsDocOrderHeader header, WmsDocOrderDetails details) {
-        // TODO 改成可以部分分配
         if (!details.getLineStatus().equals(Constant.ORDER_STS.STS00.getValue())) {
             return AjaxResult.error("出库明细为创建状态才可以分配!");
         }
+        String orderNo = header.getOrderNo();
         LotattDTO lotattDTO = new LotattDTO();
-        // 备货分配
-        if (!StringUtils.isEmpty(header.getUserdefine1())) {
-            //如果备货的只能查询属于该出库单的库存
-            lotattDTO.setLotatt14(header.getOrderNo());
-        }
-        List<InvLotLocId> invList = invLotLocIdService.queryInvOrderBy(details.getLotnum(), details.getSku(), details.getLocation(), Constant.CUSTOMER_ID, lotattDTO);
+        // 根据sku查询出仓储区空闲库存
+        List<InvLotLocIdForm> invListAll = invLotLocIdService.queryInvOrderBy(details.getLotnum()
+                , details.getSku(), details.getLocation()
+                , Constant.CUSTOMER_ID, lotattDTO);
+        // 筛选出没有被分配过的库存
+        List<InvLotLocIdForm> invList = invListAll.stream().filter(v -> {
+            if (StringUtils.isEmpty(v.getLotatt15()) || orderNo.equals(v.getLotatt15())) {
+                return true;
+            }
+            return false;
+        }).collect(Collectors.toList());
         // 原始订单需分配数
         BigDecimal originalOrderQty = details.getQtyOrdered().subtract(details.getQtyAllocated());
         // 订单需分配数
@@ -394,18 +387,12 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
                         ? item.getQty().doubleValue() - item.getQtyallocated().doubleValue() : 0)
                 .sum();
         if (qtySum < orderQty.doubleValue()) {
-            // TODO 改成可以部分分配
             return AjaxResult.error("库存不足分配失败");
         }
-        for (InvLotLocId inv : invList) {
+        for (InvLotLocIdForm inv : invList) {
             if (orderQty.doubleValue() == 0) {
                 return AjaxResult.success("分配完成", originalOrderQty);
             }
-            //可以叫料且合格的库存
-            InvLotAtt lotAtt = invLotAttMapper.selectInvLotAttByLotnum(inv.getLotnum());
-            if (!lotAtt.getLotatt05().equals("90") || !lotAtt.getLotatt12().equals("Y")) {
-//                continue;
-            }
 
             BigDecimal canallocatedQty = inv.getQty().subtract(inv.getQtyallocated());
             if (canallocatedQty.doubleValue() > 0) {
@@ -426,6 +413,8 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
                             //生成分配明细
                             actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
                                     , Constant.ORDER_STS.STS20.getValue());
+                            //库位对应所有库存lotatt15记录分配出库单号
+                            invLotLocIdService.updateLotatt15ByLocationId(inv.getLocationId(),orderNo);
                         } else {
                             throw new ServiceException("占用库存分配数失败");
                         }
@@ -445,6 +434,8 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
                             //生成分配明细
                             actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
                                     , Constant.ORDER_STS.STS20.getValue());
+                            //库位对应所有库存lotatt15记录分配出库单号
+                            invLotLocIdService.updateLotatt15ByLocationId(inv.getLocationId(),orderNo);
                             return AjaxResult.success("分配完成", originalOrderQty);
                         } else {
                             throw new ServiceException("占用库存分配数失败");
@@ -463,6 +454,8 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
                             //生成分配明细
                             actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details
                                     , Constant.ORDER_STS.STS20.getValue());
+                            //库位对应所有库存lotatt15记录分配出库单号
+                            invLotLocIdService.updateLotatt15ByLocationId(inv.getLocationId(),orderNo);
                             return AjaxResult.success("分配完成", originalOrderQty);
 
                         } else {
@@ -475,7 +468,6 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
         return AjaxResult.success("库存数不足,部分分配", originalOrderQty.subtract(orderQty));
     }
 
-
     /**
      * 每次分配只能进入一条线程
      *
@@ -486,62 +478,108 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
     @Transactional
     @Override
     public synchronized AjaxResult doAllocationDetailsBH(WmsDocOrderHeader header, WmsDocOrderDetails details) {
-        if (!details.getLineStatus().equals(Constant.ORDER_STS.STS23.getValue())) {
-            return AjaxResult.error("出库明细为备货完成状态才可以分配!");
+        if (!details.getLineStatus().equals(Constant.ORDER_STS.STS00.getValue())
+                && !details.getLineStatus().equals(Constant.ORDER_STS.STS10.getValue())) {
+            return AjaxResult.error("出库明细状态不可分配!");
         }
+        String orderNo = header.getOrderNo();
         LotattDTO lotattDTO = new LotattDTO();
-        // 备货对应的出库单库存
-        lotattDTO.setLotatt14(header.getOrderNo());
-        List<InvLotLocId> invList = invLotLocIdService.queryInvOrderBy(details.getLotnum(), details.getSku(), details.getLocation(), Constant.CUSTOMER_ID, lotattDTO);
+        // 根据sku查询出仓储区空闲库存
+        List<InvLotLocIdForm> invListAll = invLotLocIdService.queryInvOrderBy(details.getLotnum()
+                , details.getSku(), details.getLocation()
+                , Constant.CUSTOMER_ID, lotattDTO);
+        // 筛选出没有被分配过的库存
+        List<InvLotLocIdForm> invList = invListAll.stream().filter(v -> {
+            if (StringUtils.isEmpty(v.getLotatt15()) || orderNo.equals(v.getLotatt15())) {
+                return true;
+            }
+            return false;
+        }).collect(Collectors.toList());
         // 原始订单需分配数
-        BigDecimal originalOrderQty = details.getQtyOrdered();
+        BigDecimal originalOrderQty = details.getQtyOrdered().subtract(details.getQtyAllocated());
         // 订单需分配数
-        BigDecimal orderQty = details.getQtyOrdered();
+        BigDecimal orderQty = details.getQtyOrdered().subtract(details.getQtyAllocated());
         // 判断匹配库存总数是否足够分配
-        double qtySum = invList.stream()
-                .mapToDouble(item -> item.getQty().doubleValue())
-                .sum();
-        if (qtySum < orderQty.doubleValue() && !header.getUserdefine6().equals("Y")) {
-            return AjaxResult.error("库存不足分配失败");
-        }
-        for (InvLotLocId inv : invList) {
+//        double qtySum = invList.stream()
+//                .mapToDouble(item -> item.getQty().doubleValue() > item.getQtyallocated().doubleValue()
+//                        ? item.getQty().doubleValue() - item.getQtyallocated().doubleValue() : 0)
+//                .sum();
+//        if (qtySum < orderQty.doubleValue()) {
+            // 备货可以部分分配
+//            return AjaxResult.error("库存不足分配失败");
+//        }
+        for (InvLotLocIdForm inv : invList) {
             if (orderQty.doubleValue() == 0) {
                 return AjaxResult.success("分配完成", originalOrderQty);
             }
-            //可以叫料且合格的库存
-            InvLotAtt lotAtt = invLotAttMapper.selectInvLotAttByLotnum(inv.getLotnum());
-            if (!lotAtt.getLotatt05().equals("90") || !lotAtt.getLotatt12().equals("Y")) {
-//                continue;
-            }
 
-            BigDecimal canallocatedQty = inv.getQty();
+            BigDecimal canallocatedQty = inv.getQty().subtract(inv.getQtyallocated());
             if (canallocatedQty.doubleValue() > 0) {
                 if (inv.getQty().intValue() > 0) {
                     // 当前库存可分配数量 < 订单需分配数
-                    if (inv.getQty().compareTo(orderQty) == -1) {
+                    if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == -1) {
                         //可以分配的库存
-                        BigDecimal allocatedQty = inv.getQty();
-                        orderQty = orderQty.subtract(allocatedQty);
-                        //生成分配明细
-                        actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
-                                , Constant.ORDER_STS.STS20.getValue());
-
+                        BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
+                        inv.setQtyallocated(inv.getQtyallocated().add(allocatedQty));
+                        inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(allocatedQty));
+                        if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
+                            orderQty = orderQty.subtract(allocatedQty);
+                            //修改出库单状态
+                            details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
+                            details.setQtyAllocatedEach(details.getQtyAllocated());
+                            details.setLineStatus(Constant.ORDER_STS.STS10.getValue());
+                            wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
+                            //生成分配明细
+                            actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
+                                    , Constant.ORDER_STS.STS20.getValue());
+                            //库位对应所有库存lotatt15记录分配出库单号
+                            invLotLocIdService.updateLotatt15ByLocationId(inv.getLocationId(),orderNo);
+                        } else {
+                            throw new ServiceException("占用库存分配数失败");
+                        }
                         // 当前库存可分配数量 = 订单需分配数
-                    } else if (inv.getQty().compareTo(orderQty) == 0) {
+                    } else if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == 0) {
                         //可以分配的库存
-                        BigDecimal allocatedQty = inv.getQty();
-                        //生成分配明细
-                        actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
-                                , Constant.ORDER_STS.STS20.getValue());
-                        return AjaxResult.success("分配完成", originalOrderQty);
-
+                        BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
+                        inv.setQtyallocated(inv.getQtyallocated().add(allocatedQty));
+                        inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(allocatedQty));
+                        if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
+                            orderQty = orderQty.subtract(allocatedQty);
+                            //修改出库单状态
+                            details.setLineStatus(Constant.ORDER_STS.STS20.getValue());
+                            details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
+                            details.setQtyAllocatedEach(details.getQtyAllocatedEach().add(allocatedQty));
+                            wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
+                            //生成分配明细
+                            actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
+                                    , Constant.ORDER_STS.STS20.getValue());
+                            //库位对应所有库存lotatt15记录分配出库单号
+                            invLotLocIdService.updateLotatt15ByLocationId(inv.getLocationId(),orderNo);
+                            return AjaxResult.success("分配完成", originalOrderQty);
+                        } else {
+                            throw new ServiceException("占用库存分配数失败");
+                        }
                         // 当前库存可分配数量 > 订单需分配数
                     } else {
                         BigDecimal currentQty = orderQty;
-                        //生成分配明细
-                        actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details
-                                , Constant.ORDER_STS.STS20.getValue());
-                        return AjaxResult.success("分配完成", originalOrderQty);
+                        inv.setQtyallocated(inv.getQtyallocated().add(currentQty));
+                        inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(currentQty));
+                        if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
+                            //修改出库单状态
+                            details.setLineStatus(Constant.ORDER_STS.STS20.getValue());
+                            details.setQtyAllocated(details.getQtyAllocated().add(currentQty));
+                            details.setQtyAllocatedEach(details.getQtyAllocatedEach().add(currentQty));
+                            wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
+                            //生成分配明细
+                            actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details
+                                    , Constant.ORDER_STS.STS20.getValue());
+                            //库位对应所有库存lotatt15记录分配出库单号
+                            invLotLocIdService.updateLotatt15ByLocationId(inv.getLocationId(),orderNo);
+                            return AjaxResult.success("分配完成", originalOrderQty);
+
+                        } else {
+                            throw new ServiceException("占用库存分配数失败");
+                        }
                     }
                 }
             }

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

@@ -505,8 +505,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
-    <select id="queryInvOrderBy" parameterType="InvLotLocId" resultMap="InvLotLocIdResult">
+    <select id="queryInvOrderBy" parameterType="object" resultType="invLotLocIdForm">
         select inv.*
+             ,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
         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