diff --git a/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java b/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java index 364d479..f7740d4 100644 --- a/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java +++ b/src/main/java/com/zg/project/wisdom/service/impl/RkRecordServiceImpl.java @@ -125,13 +125,13 @@ public class RkRecordServiceImpl implements IRkRecordService rkRecord.setUpdateTime(DateUtils.getNowDate()); - /* ====================== 2. 查询原记录(唯一可信来源) ====================== */ + /* ====================== 2. 查询原记录 ====================== */ RkRecord oldRecord = rkRecordMapper.selectRkRecordById(rkRecord.getId()); if (oldRecord == null) { throw new RuntimeException("原出入库记录不存在"); } - /* ====================== 3. 获取并校验库存ID(必须来自 oldRecord) ====================== */ + /* ====================== 3. 获取库存ID ====================== */ Long rkInfoId = oldRecord.getRkInfoId(); if (rkInfoId == null) { throw new RuntimeException("出入库记录未关联库存,禁止修改"); @@ -145,7 +145,7 @@ public class RkRecordServiceImpl implements IRkRecordService String bizType = rkRecord.getBizType(); /* ========================================================= - * 【A】入库记录修改(bizType = 0) + * 【A】入库记录修改 * ========================================================= */ if ("0".equals(bizType)) { @@ -159,7 +159,6 @@ public class RkRecordServiceImpl implements IRkRecordService BigDecimal diff = newInQty.subtract(oldInQty); - /* ---------- 供应计划处理 ---------- */ Long gysJhId = oldRecord.getGysJhId(); if (gysJhId != null) { @@ -182,11 +181,11 @@ public class RkRecordServiceImpl implements IRkRecordService gysJh.setRealQty(newPlanRealQty); if (newPlanRealQty.compareTo(BigDecimal.ZERO) == 0) { - gysJh.setStatus("0"); // 未到货 + gysJh.setStatus("0"); } else if (planQty != null && newPlanRealQty.compareTo(planQty) >= 0) { - gysJh.setStatus("1"); // 已入库 + gysJh.setStatus("1"); } else { - gysJh.setStatus("2"); // 部分入库 + gysJh.setStatus("2"); } gysJh.setWlNo(rkRecord.getWlNo()); @@ -202,9 +201,8 @@ public class RkRecordServiceImpl implements IRkRecordService gysJhMapper.updateGysJh(gysJh); } - /* ---------- 同步库存(明确字段,禁止 BeanUtils) ---------- */ String scene = ""; - // 库位校验 + if (StringUtils.isNotBlank(info.getPcode())) { PcdeDetail pcde = pcdeDetailMapper.selectByPcodeAndWarehouse( rkRecord.getPcode(), @@ -213,12 +211,15 @@ public class RkRecordServiceImpl implements IRkRecordService if (pcde == null) { throw new RuntimeException("库位不存在:" + info.getPcode()); } + info.setPcodeId(pcde.getEncodedId()); - if(StringUtils.isNotBlank(pcde.getScene())){ + + if (StringUtils.isNotBlank(pcde.getScene())) { scene = pcde.getScene(); info.setScene(scene); } } + info.setRealQty(newInQty); info.setWlNo(rkRecord.getWlNo()); info.setWlMs(rkRecord.getWlMs()); @@ -235,26 +236,24 @@ public class RkRecordServiceImpl implements IRkRecordService } /* ========================================================= - * 【B】出库记录修改(bizType = 1) + * 【B】出库记录修改(修改逻辑) * ========================================================= */ if ("1".equals(bizType)) { - BigDecimal oldOutQty = oldRecord.getRealQty(); BigDecimal newOutQty = rkRecord.getRealQty(); BigDecimal stockQty = info.getRealQty(); - if (oldOutQty == null || newOutQty == null || stockQty == null) { + if (newOutQty == null || stockQty == null) { throw new RuntimeException("数量数据异常,无法修改出库记录"); } - BigDecimal diff = newOutQty.subtract(oldOutQty); - BigDecimal newStockQty = stockQty.subtract(diff); + /* 关键修改:直接用 newOutQty 计算库存 */ + BigDecimal newStockQty = stockQty.subtract(newOutQty); if (newStockQty.compareTo(BigDecimal.ZERO) < 0) { throw new RuntimeException("库存不足,无法修改出库数量"); } - info.setRealQty(newStockQty); info.setIsChuku(newStockQty.compareTo(BigDecimal.ZERO) == 0 ? "1" : "0"); info.setWlNo(rkRecord.getWlNo()); @@ -277,8 +276,8 @@ public class RkRecordServiceImpl implements IRkRecordService throw new RuntimeException("同步更新库存表失败"); } - /* ====================== 5. 最后更新 rk_record ====================== */ - rkRecord.setRkInfoId(rkInfoId); // 强制回填,防止被置空 + /* ====================== 5. 更新记录表 ====================== */ + rkRecord.setRkInfoId(rkInfoId); int rows = rkRecordMapper.updateRkRecord(rkRecord); if (rows <= 0) { throw new RuntimeException("更新出入库记录失败"); @@ -286,6 +285,7 @@ public class RkRecordServiceImpl implements IRkRecordService return rows; } + @Override @Transactional(rollbackFor = Exception.class) public int deleteRkRecordByIds(Long[] ids) {