Browse Source

库存移动修改

andy 2 years ago
parent
commit
0aa7fb08fc

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

@@ -21,6 +21,8 @@ import com.ruoyi.ams.config.domain.vo.FlowConfigHeaderVO;
 import com.ruoyi.ams.config.domain.vo.LotattConfigVO;
 import com.ruoyi.ams.config.service.IFlowConfigHeaderService;
 import com.ruoyi.ams.config.service.ILotattConfigService;
+import com.ruoyi.ams.inv.form.InvTransferPickForm;
+import com.ruoyi.ams.inv.service.IInvLotLocIdService;
 import com.ruoyi.ams.lineCall.domain.form.LineCallDetailsForm;
 import com.ruoyi.ams.lineCall.domain.form.LineCallForm;
 import com.ruoyi.ams.lineCall.domain.form.LineCallListFrom;
@@ -50,6 +52,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -88,6 +91,8 @@ public class PdaController {
     private IWmsBoxInfoService wmsBoxInfoService;
     @Autowired
     private IWmsDocAsnDetailsService wmsDocAsnDetailsService;
+    @Autowired
+    private IInvLotLocIdService invLotLocIdService;
 
     /**
      * 查询批次属性后台配置
@@ -433,4 +438,20 @@ public class PdaController {
             return AjaxResult.error("查询不到入库单明细");
         }
     }
+
+    /**
+     * 按照托盘进行库存调整
+     */
+    @Log(title = "按照托盘进行库存调整", businessType = BusinessType.UPDATE)
+    @PostMapping("/inv/invTransferPick")
+    public AjaxResult invTransferPick(@Validated @RequestBody InvTransferPickForm invTransferPickForm) {
+        LotattDTO lotattDTO = new LotattDTO();
+        lotattDTO.setLotatt07(invTransferPickForm.getPalletNoFrom());
+        lotattDTO.setLotatt08(invTransferPickForm.getAsnNo());
+        CodeSkuRelationshipVO codeSkuRelationshipVO = codeSkuRelationshipService.snCheck(invTransferPickForm.getSn());
+        if (codeSkuRelationshipVO.isProduct()) {
+            lotattDTO.setLotatt02(codeSkuRelationshipVO.getSn());
+        }
+        return invLotLocIdService.invTransferPick(lotattDTO, new BigDecimal(invTransferPickForm.getQty()), invTransferPickForm.getPalletNoTo());
+    }
 }

+ 4 - 3
warewms-ams/src/main/java/com/ruoyi/ams/asn/service/impl/WmsDocAsnHeaderServiceImpl.java

@@ -198,7 +198,7 @@ public class WmsDocAsnHeaderServiceImpl implements IWmsDocAsnHeaderService {
         List<WmsDocAsnDetails> detailsList = new ArrayList<>();
         long lineNo = wmsDocAsnHeaderMapper.selectLineNo(wmsDocAsnDetails.getAsnNo());
         wmsDocAsnDetails.setAsnLineNo(lineNo + 1);
-        wmsDocAsnDetails.setExpectedQtyEach(BigDecimal.ZERO);
+        wmsDocAsnDetails.setExpectedQtyEach(wmsDocAsnDetails.getExpectedQty());
         wmsDocAsnDetails.setReceivedQty(BigDecimal.ZERO);
         wmsDocAsnDetails.setReceivedQtyEach(BigDecimal.ZERO);
         detailsList.add(wmsDocAsnDetails);
@@ -435,6 +435,7 @@ public class WmsDocAsnHeaderServiceImpl implements IWmsDocAsnHeaderService {
                             for (WmsDocAsnDetails d : detailsCheckList) {
                                 if (!d.getLineStatus().equals("40")) {
                                     asnStatus = "30";
+                                    break;
                                 }
                             }
                             WmsDocAsnHeader headerUpdate = new WmsDocAsnHeader();
@@ -455,7 +456,7 @@ public class WmsDocAsnHeaderServiceImpl implements IWmsDocAsnHeaderService {
                             lotattDTO.setLotatt12("Y");
                             lotattDTO.setLotatt13(DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD));
                             lotattDTO.setLotatt14(stockForm.getOrderNo());
-                            String lotnum = invLotLocIdService.initInv(STAGE01, codeSkuRelationshipVO.getSku(), Constant.CUSTOMER_ID, current.doubleValue(), lotattDTO, BigDecimal.ZERO);
+                            invLotLocIdService.initInv(STAGE01, codeSkuRelationshipVO.getSku(), Constant.CUSTOMER_ID, current.doubleValue(), lotattDTO, BigDecimal.ZERO);
                         } else {
                             break;
                         }
@@ -618,7 +619,7 @@ public class WmsDocAsnHeaderServiceImpl implements IWmsDocAsnHeaderService {
     @Override
     public CodeSkuRelationshipVO searchSn(SnCheckForm snCheckForm) {
         CodeSkuRelationshipVO codeSkuRelationshipVO = codeSkuRelationshipService.snCheck(snCheckForm.getSn());
-        if (snCheckForm.getAsnNoList() != null) {
+        if (snCheckForm.getAsnNoList() != null && snCheckForm.getAsnNoList().size()>0) {
             Double receivedQty = wmsDocAsnHeaderMapper.selectReceivedQtyByAsnNos(codeSkuRelationshipVO.getSku(), snCheckForm.getAsnNoList());
             if (receivedQty == null) {
                 receivedQty = 0d;

+ 18 - 0
warewms-ams/src/main/java/com/ruoyi/ams/inv/form/InvTransferPickForm.java

@@ -0,0 +1,18 @@
+package com.ruoyi.ams.inv.form;
+
+import lombok.Data;
+import javax.validation.constraints.NotEmpty;
+
+@Data
+public class InvTransferPickForm {
+    @NotEmpty(message = "起始托盘号不能为空")
+    private String palletNoFrom;
+    @NotEmpty(message = "目标托盘号不能为空")
+    private String palletNoTo;
+    @NotEmpty(message = "sn不能为空")
+    private String sn;
+    @NotEmpty(message = "数量不能为空")
+    private String qty;
+    @NotEmpty
+    private String asnNo;
+}

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

@@ -28,6 +28,15 @@ public interface InvLotLocIdMapper {
      */
     List<InvLotLocId> selectInvLotLocIdByLotnum(String lotnum);
 
+    /**
+     * 查询库存根据lotnum和库位id
+     *
+     * @param lotnum
+     * @param locationId
+     * @return
+     */
+    InvLotLocId selectInvLotLocIdByKey(@Param("lotnum") String lotnum, @Param("locationId") String locationId, @Param("customerId") String customerId, @Param("sku") String sku);
+
     /**
      * 查询库存(根据主键)
      *
@@ -148,7 +157,7 @@ public interface InvLotLocIdMapper {
      * @param locationTo
      * @return
      */
-    int updateInvLotLocIdLotnum(@Param("locationFrom") Long locationFrom,@Param("lotnum") String lotnum, @Param("locationTo") Long locationTo);
+    int updateInvLotLocIdLotnum(@Param("locationFrom") Long locationFrom, @Param("lotnum") String lotnum, @Param("locationTo") Long locationTo);
 
     /**
      * 根据托盘号将库存更新到目标库位

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

@@ -190,12 +190,22 @@ public interface IInvLotLocIdService {
      * 库存转移
      *
      * @param locationFrom 起始点位
-     * @param palletNo 托盘编号
+     * @param palletNo     托盘编号
      * @param locationTo   目标点位
      * @return
      */
     int stockTransfer(Long locationFrom, String palletNo, Long locationTo);
 
+    /**
+     * 库存按数量转移(根据托盘编号)
+     *
+     * @param palletNoTo 目标托盘
+     * @param qty 需要拣出的数量
+     * @param fromQtyAtt  起始库位库存的批次属性
+     * @return
+     */
+    AjaxResult invTransferPick(LotattDTO fromQtyAtt, BigDecimal qty, String palletNoTo);
+
     /**
      * 根据物料编号和批次属性查询库存数量
      *

+ 79 - 25
warewms-ams/src/main/java/com/ruoyi/ams/inv/service/impl/InvLotLocIdServiceImpl.java

@@ -254,7 +254,6 @@ public class InvLotLocIdServiceImpl implements IInvLotLocIdService {
         // 更新目标库位空闲有货
         baseLocationInfoService.updateLocationIdleAndNoEmpty(baseLocationTo.getId(), warehouseId, updateBy);
 
-
         // todo 事务
 
         return AjaxResult.success("操作成功!");
@@ -448,31 +447,38 @@ public class InvLotLocIdServiceImpl implements IInvLotLocIdService {
         BeanUtils.copyProperties(lotattDTO, invLotAtt);
         //查询lotatt是否存在
         String lotnum;
-        /*List<InvLotAtt> queryList = invLotAttMapper.selectInvLotAttList(invLotAtt);
+        List<InvLotAtt> queryList = invLotAttMapper.selectInvLotAttList(invLotAtt);
         if (queryList != null && queryList.size() > 0) {
             invLotAtt = queryList.get(0);
             lotnum = invLotAtt.getLotnum();
-        } else {*/
-        lotnum = idSequenceUtils.generateId("LOTNUMBER");
-        invLotAtt.setLotnum(lotnum);
-        invLotAtt.setSku(sku);
-        invLotAtt.setCustomerId(customerId);
-        invLotAtt.setCreateTime(DateUtils.getNowDate());
-        invLotAttMapper.insertInvLotAtt(invLotAtt);
-        //}
-        InvLotLocId invLotLocId = new InvLotLocId();
-        invLotLocId.setLotnum(lotnum);
-        invLotLocId.setLocationId(locationFrom);
-        invLotLocId.setSku(sku);
-        invLotLocId.setCustomerId(customerId);
-        invLotLocId.setQty(new BigDecimal(qty));
-        invLotLocId.setQtyEach(new BigDecimal(qty));
-        invLotLocId.setQtyallocated(qtyallocated);
-        invLotLocId.setQtyallocatedEach(qtyallocated);
-        invLotLocId.setQtypa(BigDecimal.ZERO);
-        invLotLocId.setQtyrpin(BigDecimal.ZERO);
-        invLotLocId.setCreateTime(new Date());
-        invLotLocIdMapper.insertInvLotLocId(invLotLocId);
+        } else {
+            lotnum = idSequenceUtils.generateId("LOTNUMBER");
+            invLotAtt.setLotnum(lotnum);
+            invLotAtt.setSku(sku);
+            invLotAtt.setCustomerId(customerId);
+            invLotAtt.setCreateTime(DateUtils.getNowDate());
+            invLotAttMapper.insertInvLotAtt(invLotAtt);
+        }
+        InvLotLocId query = invLotLocIdMapper.selectInvLotLocIdByKey(lotnum, locationFrom, customerId, sku);
+        if (query != null) {
+            query.setQty(query.getQty().add(BigDecimal.valueOf(qty)));
+            query.setQtyEach(query.getQty());
+            invLotLocIdService.updateInvLotLocId(query);
+        } else {
+            InvLotLocId invLotLocId = new InvLotLocId();
+            invLotLocId.setLotnum(lotnum);
+            invLotLocId.setLocationId(locationFrom);
+            invLotLocId.setSku(sku);
+            invLotLocId.setCustomerId(customerId);
+            invLotLocId.setQty(new BigDecimal(qty));
+            invLotLocId.setQtyEach(new BigDecimal(qty));
+            invLotLocId.setQtyallocated(qtyallocated);
+            invLotLocId.setQtyallocatedEach(qtyallocated);
+            invLotLocId.setQtypa(BigDecimal.ZERO);
+            invLotLocId.setQtyrpin(BigDecimal.ZERO);
+            invLotLocId.setCreateTime(new Date());
+            invLotLocIdMapper.insertInvLotLocId(invLotLocId);
+        }
 
         BaseLocationInfo baseLocationInfo = new BaseLocationInfo();
         baseLocationInfo.setId(Long.parseLong(locationFrom));
@@ -510,13 +516,60 @@ public class InvLotLocIdServiceImpl implements IInvLotLocIdService {
         }
     }
 
+    @Transactional
+    @Override
+    public AjaxResult invTransferPick(LotattDTO lotattDTO, BigDecimal qty, String palletNoTo) {
+        WmsBoxInfo wmsBoxInfoTo = iWmsBoxInfoService.selectWmsBoxInfoByBoxNo(palletNoTo);
+        InvLotAtt queryAtt = new InvLotAtt();
+        BeanUtils.copyProperties(lotattDTO, queryAtt);
+        List<InvLotLocId> invLotLocIds = invLotLocIdMapper.queryInvByInvLotatt(queryAtt);
+        BigDecimal total = qty;
+        BigDecimal sumQty = BigDecimal.ZERO;
+        if (invLotLocIds != null && invLotLocIds.size() > 0) {
+            for (InvLotLocId inv : invLotLocIds) {
+                BigDecimal currentQtyTotal = inv.getQty().subtract(inv.getQtyallocated());
+                BigDecimal currentQty;
+                if (currentQtyTotal.compareTo(total) == 1) {
+                    currentQty = qty;
+                    //当前数量大于拣出数
+                } else {
+                    currentQty = inv.getQty();
+                    //当前数量小于等于拣出数
+                }
+                //目标库位生成新库存
+                LotattDTO newLot = new LotattDTO();
+                BeanUtils.copyProperties(lotattDTO, newLot);
+                newLot.setLotatt07(palletNoTo);
+                invLotLocIdService.initInv(wmsBoxInfoTo.getLocationId().toString(), inv.getSku(), inv.getCustomerId(), currentQty.doubleValue(), newLot, BigDecimal.ZERO);
+
+                //扣减原库存
+                inv.setQty(inv.getQty().subtract(currentQty));
+                inv.setQtyEach(inv.getQty().subtract(currentQty));
+                //inv.setQtyallocated(inv.getQtyallocated().subtract(currentQty));
+                //inv.setQtyallocatedEach(inv.getQtyallocatedEach().subtract(currentQty));
+                invLotLocIdService.updateInvLotLocId(inv);
+
+                sumQty = sumQty.add(currentQty);
+                total = total.subtract(currentQty);
+
+                if (total.compareTo(sumQty) == 0) {
+                    break;
+                }
+            }
+            return AjaxResult.success("操作成功");
+        } else {
+            throw new ServiceException("查询不到库存信息");
+        }
+    }
+
     @Override
     public Double queryInvBySku(String sku, LotattDTO lotattDTO, List<String> zoneIdList) {
         return invLotLocIdMapper.queryInvBySku(sku, lotattDTO, zoneIdList);
     }
 
     @Override
-    public List<InvLotLocId> queryInvOrderBy(String lotnum, String sku, String location, String customerId, LotattDTO lotattDTO) {
+    public List<InvLotLocId> queryInvOrderBy(String lotnum, String sku, String location, String
+            customerId, LotattDTO lotattDTO) {
         return invLotLocIdMapper.queryInvOrderBy(lotnum, sku, location, customerId, lotattDTO);
     }
 
@@ -546,7 +599,8 @@ public class InvLotLocIdServiceImpl implements IInvLotLocIdService {
 
     @Transactional
     @Override
-    public AjaxResult stockTransferPick(Long locationFrom, Long locationTo, String lotnum, BigDecimal qty, String boxNo) {
+    public AjaxResult stockTransferPick(Long locationFrom, Long locationTo, String lotnum, BigDecimal qty, String
+            boxNo) {
         List<InvLotLocId> invLotLocIds = invLotLocIdMapper.selectInvLotLocIdByLotnum(lotnum);
         if (invLotLocIds != null && invLotLocIds.size() > 0) {
             for (InvLotLocId inv : invLotLocIds) {

+ 1 - 0
warewms-ams/src/main/java/com/ruoyi/ams/order/service/impl/WmsDocOrderHeaderServiceImpl.java

@@ -498,6 +498,7 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
         if (wmsDocOrderDetails.getOrderLineNo() == null) {
             long lineNo = wmsDocOrderHeaderMapper.selectLineNo(wmsDocOrderDetails.getOrderNo());
             wmsDocOrderDetails.setOrderLineNo(BigDecimal.valueOf(lineNo + 1));
+            wmsDocOrderDetails.setQtyOrderedEach(wmsDocOrderDetails.getQtyOrdered());
         }
         return wmsDocOrderDetailsMapper.insertWmsDocOrderDetails(wmsDocOrderDetails);
     }

+ 5 - 0
warewms-ams/src/main/resources/mapper/ams/InvLotLocIdMapper.xml

@@ -138,6 +138,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where lotnum = #{lotnum}
     </select>
 
+    <select id="selectInvLotLocIdByKey" resultMap="InvLotLocIdResult">
+        <include refid="selectInvLotLocIdVo"/>
+        where lotnum = #{lotnum} and location_id = #{locationId} and customer_id = #{customerId} and sku = #{sku}
+    </select>
+
     <select id="queryById" parameterType="InvLotLocId" resultMap="InvLotLocIdResult">
         <include refid="selectInvLotLocIdVo"/>
         where lotnum = #{lotnum}