diff --git a/src/main/java/com/gaotao/modules/check/mapper/CountAdjustmentMapper.java b/src/main/java/com/gaotao/modules/check/mapper/CountAdjustmentMapper.java index 3630309..aac9d05 100644 --- a/src/main/java/com/gaotao/modules/check/mapper/CountAdjustmentMapper.java +++ b/src/main/java/com/gaotao/modules/check/mapper/CountAdjustmentMapper.java @@ -91,6 +91,40 @@ public interface CountAdjustmentMapper { int updateCountResultHandleFlag(@Param("countResultId") Long countResultId, @Param("username") String username); + // ==================== 库存操作(允许负库存)==================== - rqrq + + /** + * 查询库存记录是否存在 - rqrq + */ + int countInventoryStock(@Param("site") String site, @Param("warehouseId") String warehouseId, + @Param("partNo") String partNo, @Param("batchNo") String batchNo, + @Param("locationId") String locationId, @Param("wdr") String wdr, + @Param("engChgLevel") String engChgLevel); + + /** + * 创建0库存记录 - rqrq + */ + int insertZeroStock(@Param("site") String site, @Param("warehouseId") String warehouseId, + @Param("partNo") String partNo, @Param("batchNo") String batchNo, + @Param("locationId") String locationId, @Param("wdr") String wdr, + @Param("engChgLevel") String engChgLevel); + + /** + * 减少库存(允许负库存)- rqrq + */ + int reduceStock(@Param("site") String site, @Param("warehouseId") String warehouseId, + @Param("partNo") String partNo, @Param("batchNo") String batchNo, + @Param("locationId") String locationId, @Param("wdr") String wdr, + @Param("engChgLevel") String engChgLevel, @Param("reduceQty") BigDecimal reduceQty); + + /** + * 增加库存 - rqrq + */ + int addStock(@Param("site") String site, @Param("warehouseId") String warehouseId, + @Param("partNo") String partNo, @Param("batchNo") String batchNo, + @Param("locationId") String locationId, @Param("wdr") String wdr, + @Param("engChgLevel") String engChgLevel, @Param("addQty") BigDecimal addQty); + // ==================== 盘盈盘亏记录查询 ==================== - rqrq /** diff --git a/src/main/java/com/gaotao/modules/check/service/impl/CountAdjustmentServiceImpl.java b/src/main/java/com/gaotao/modules/check/service/impl/CountAdjustmentServiceImpl.java index 4c2682c..65c3fb3 100644 --- a/src/main/java/com/gaotao/modules/check/service/impl/CountAdjustmentServiceImpl.java +++ b/src/main/java/com/gaotao/modules/check/service/impl/CountAdjustmentServiceImpl.java @@ -1,5 +1,7 @@ package com.gaotao.modules.check.service.impl; +import com.gaotao.common.utils.DateUtil; +import com.gaotao.common.utils.DateUtils; import com.gaotao.modules.check.entity.*; import com.gaotao.modules.check.mapper.CountAdjustmentMapper; import com.gaotao.modules.check.service.CountAdjustmentService; @@ -9,7 +11,6 @@ import com.gaotao.modules.trans.entity.TransDetailSub; import com.gaotao.modules.trans.entity.TransNoControl; import com.gaotao.modules.trans.service.TransNoControlService; import com.gaotao.modules.trans.service.TransHeaderService; -import com.gaotao.modules.warehouse.service.InventoryStockService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import java.math.BigDecimal; +import java.text.ParseException; import java.util.*; import java.util.stream.Collectors; @@ -51,9 +53,6 @@ public class CountAdjustmentServiceImpl implements CountAdjustmentService { @Autowired private TransHeaderService transHeaderService; - - @Autowired - private InventoryStockService inventoryStockService; /** * 检查是否有需要系统处理的异常结果 - rqrq @@ -266,17 +265,8 @@ public class CountAdjustmentServiceImpl implements CountAdjustmentService { seqNo++; } - // 减少库存 - rqrq - inventoryStockService.reduceStockWithLock( - item.getSite(), - item.getWarehouseId(), - item.getPartNo(), - item.getBatchNo(), - item.getLocationId(), - item.getDiffQty().abs(), - item.getWdr(), - item.getEngChgLevel() - ); + // 减少库存(允许负库存)- rqrq + reduceStockAllowNegative(item); itemNo++; } @@ -331,17 +321,7 @@ public class CountAdjustmentServiceImpl implements CountAdjustmentService { } // 增加库存 - rqrq - inventoryStockService.updateStockWithLock( - item.getSite(), - item.getWarehouseId(), - item.getPartNo(), - item.getBatchNo(), - item.getLocationId(), - item.getWdr(), - item.getDiffQty(), - "N", - item.getEngChgLevel() - ); + addStockAllowCreate(item); itemNo++; } @@ -360,7 +340,11 @@ public class CountAdjustmentServiceImpl implements CountAdjustmentService { TransHeader header = new TransHeader(); header.setSite(site); header.setTransNo(transNo); - header.setTransDate(new Date()); + try { + header.setTransDate(DateUtil.getDate( DateUtil.getStringDate(new Date()))); + } catch (ParseException e) { + header.setTransDate(new Date()); + } header.setTransTypeDb(transType); header.setWarehouseId(warehouseId); header.setUserId(username); @@ -368,9 +352,9 @@ public class CountAdjustmentServiceImpl implements CountAdjustmentService { header.setOrderRef1(countNo); // 关联盘点单号 - rqrq header.setRemark(transType.equals("PK") ? "盘亏处理" : "盘盈处理"); header.setStatus("COMPLETED"); - header.setStatusDb("COMPLETED"); + header.setStatusDb("C"); header.setEnterDate(new Date()); - header.setIfsFlag("N"); + header.setIfsFlag("Y"); return header; } @@ -426,6 +410,68 @@ public class CountAdjustmentServiceImpl implements CountAdjustmentService { return sub; } + /** + * 减少库存(允许负库存)- rqrq + * + *

业务规则:

+ * + */ + private void reduceStockAllowNegative(CountAdjustmentItem item) { + BigDecimal reduceQty = item.getDiffQty().abs(); + + // 查询库存是否存在 - rqrq + int count = countAdjustmentMapper.countInventoryStock( + item.getSite(), item.getWarehouseId(), item.getPartNo(), + item.getBatchNo(), item.getLocationId(), item.getWdr(), item.getEngChgLevel()); + + if (count == 0) { + // 库存不存在,先创建0库存记录 - rqrq + log.info("库存不存在,创建0库存记录 - rqrq,partNo={}, locationId={}", item.getPartNo(), item.getLocationId()); + countAdjustmentMapper.insertZeroStock( + item.getSite(), item.getWarehouseId(), item.getPartNo(), + item.getBatchNo(), item.getLocationId(), item.getWdr(), item.getEngChgLevel()); + } + + // 减少库存(允许负库存)- rqrq + countAdjustmentMapper.reduceStock( + item.getSite(), item.getWarehouseId(), item.getPartNo(), + item.getBatchNo(), item.getLocationId(), item.getWdr(), item.getEngChgLevel(), reduceQty); + } + + /** + * 增加库存 - rqrq + * + *

业务规则:

+ * + */ + private void addStockAllowCreate(CountAdjustmentItem item) { + BigDecimal addQty = item.getDiffQty(); + + // 查询库存是否存在 - rqrq + int count = countAdjustmentMapper.countInventoryStock( + item.getSite(), item.getWarehouseId(), item.getPartNo(), + item.getBatchNo(), item.getLocationId(), item.getWdr(), item.getEngChgLevel()); + + if (count == 0) { + // 库存不存在,先创建0库存记录 - rqrq + log.info("库存不存在,创建0库存记录 - rqrq,partNo={}, locationId={}", item.getPartNo(), item.getLocationId()); + countAdjustmentMapper.insertZeroStock( + item.getSite(), item.getWarehouseId(), item.getPartNo(), + item.getBatchNo(), item.getLocationId(), item.getWdr(), item.getEngChgLevel()); + } + + // 增加库存 - rqrq + countAdjustmentMapper.addStock( + item.getSite(), item.getWarehouseId(), item.getPartNo(), + item.getBatchNo(), item.getLocationId(), item.getWdr(), item.getEngChgLevel(), addQty); + } + /** * 更新标签数量 - rqrq * diff --git a/src/main/resources/mapper/check/CountAdjustmentMapper.xml b/src/main/resources/mapper/check/CountAdjustmentMapper.xml index e59399e..656eba0 100644 --- a/src/main/resources/mapper/check/CountAdjustmentMapper.xml +++ b/src/main/resources/mapper/check/CountAdjustmentMapper.xml @@ -84,6 +84,66 @@ WHERE id = #{countResultId} + + + + + + + + INSERT INTO inventory_stock ( + site, warehouse_id, part_no, batch_no, location_id, wdr, eng_chg_level, + in_qty, in_standard_value, in_actual_value, out_qty, qty_on_hand, qty_reserved, + freeze_flag, first_in_date, latest_in_date, active_date + ) VALUES ( + #{site}, #{warehouseId}, #{partNo}, #{batchNo}, #{locationId}, #{wdr}, #{engChgLevel}, + 0, 0, 0, 0, 0, 0, + 'N', GETDATE(), GETDATE(), GETDATE() + ) + + + + + UPDATE inventory_stock + SET out_qty = out_qty + #{reduceQty}, + qty_on_hand = qty_on_hand - #{reduceQty}, + latest_out_date = GETDATE() + WHERE site = #{site} + AND warehouse_id = #{warehouseId} + AND part_no = #{partNo} + AND (batch_no = #{batchNo} OR (batch_no IS NULL AND #{batchNo} IS NULL)) + AND location_id = #{locationId} + AND (wdr = #{wdr} OR (wdr IS NULL AND #{wdr} IS NULL)) + AND (eng_chg_level = #{engChgLevel} OR (eng_chg_level IS NULL AND #{engChgLevel} IS NULL)) + + + + + UPDATE inventory_stock + SET in_qty = in_qty + #{addQty}, + qty_on_hand = qty_on_hand + #{addQty}, + latest_in_date = GETDATE() + WHERE site = #{site} + AND warehouse_id = #{warehouseId} + AND part_no = #{partNo} + AND (batch_no = #{batchNo} OR (batch_no IS NULL AND #{batchNo} IS NULL)) + AND location_id = #{locationId} + AND (wdr = #{wdr} OR (wdr IS NULL AND #{wdr} IS NULL)) + AND (eng_chg_level = #{engChgLevel} OR (eng_chg_level IS NULL AND #{engChgLevel} IS NULL)) + + + +