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