fix(wms): 解决钢卷回滚操作中的重复号检查和操作记录清理问题
- 添加原始钢卷当前钢卷号重复检查,防止回滚时出现重复钢卷号冲突 - 在回滚操作完成后删除对应的操作记录,保持数据一致性 - 添加母卷当前钢卷号重复检查,确保拆分回滚时的数据完整性 - 实现删除回滚操作记录的辅助方法,清理不需要的待处理动作记录
This commit is contained in:
@@ -3119,6 +3119,17 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("部分原始钢卷不存在,无法回滚");
|
||||
}
|
||||
|
||||
// 检查恢复的钢卷的当前钢卷号是否重复
|
||||
for (WmsMaterialCoil originalCoil : originalCoils) {
|
||||
Map<String, Object> duplicateCheck = checkCoilNoDuplicate(originalCoil.getCoilId(), originalCoil.getEnterCoilNo(), originalCoil.getCurrentCoilNo());
|
||||
boolean currentCoilNoDuplicate = (boolean) duplicateCheck.get("currentCoilNoDuplicate");
|
||||
if (currentCoilNoDuplicate) {
|
||||
String errorMsg = "无法恢复原始钢卷,存在重复的钢卷号:原始钢卷的当前钢卷号[" + originalCoil.getCurrentCoilNo() + "]重复。";
|
||||
errorMsg += "重复的钢卷无法进行回滚操作。";
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// 释放当前合卷钢卷占用的实际库区
|
||||
if (currentCoil.getActualWarehouseId() != null) {
|
||||
WmsActualWarehouseBo releaseBo = new WmsActualWarehouseBo();
|
||||
@@ -3137,6 +3148,9 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
.set(WmsMaterialCoil::getDataType, 1)
|
||||
.set(WmsMaterialCoil::getActualWarehouseId, (Long) null);
|
||||
baseMapper.update(null, updateWrapper);
|
||||
|
||||
// 删除操作记录
|
||||
deletePendingActionForRollback(originalCoil.getCoilId());
|
||||
}
|
||||
|
||||
// 更新二维码记录
|
||||
@@ -3204,6 +3218,20 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("以下钢卷不是现存钢卷,无法回滚:" + String.join(", ", invalidCoilNos));
|
||||
}
|
||||
|
||||
// 检查恢复的母卷的当前钢卷号是否重复
|
||||
if (motherCoilId != null) {
|
||||
WmsMaterialCoil motherCoil = baseMapper.selectById(motherCoilId);
|
||||
if (motherCoil != null) {
|
||||
Map<String, Object> duplicateCheck = checkCoilNoDuplicate(motherCoilId, motherCoil.getEnterCoilNo(), motherCoil.getCurrentCoilNo());
|
||||
boolean currentCoilNoDuplicate = (boolean) duplicateCheck.get("currentCoilNoDuplicate");
|
||||
if (currentCoilNoDuplicate) {
|
||||
String errorMsg = "无法恢复母卷,存在重复的钢卷号:母卷的当前钢卷号[" + motherCoil.getCurrentCoilNo() + "]重复。";
|
||||
errorMsg += "重复的钢卷无法进行回滚操作。";
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 释放所有子钢卷占用的实际库区并删除所有子钢卷
|
||||
for (WmsMaterialCoil childCoil : childCoils) {
|
||||
if (childCoil.getActualWarehouseId() != null) {
|
||||
@@ -3223,6 +3251,9 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
.set(WmsMaterialCoil::getActualWarehouseId, (Long) null);
|
||||
baseMapper.update(null, updateWrapper);
|
||||
|
||||
// 删除母卷的操作记录
|
||||
deletePendingActionForRollback(motherCoilId);
|
||||
|
||||
// 更新二维码记录
|
||||
updateQrcodeForSplitRollback(qrcodeRecord, currentCoil, motherCoilId);
|
||||
}
|
||||
@@ -3237,6 +3268,25 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除回滚操作记录
|
||||
* 删除最晚的一条且actionType不在401-405范围内,并且coilId等于指定ID的操作记录
|
||||
*/
|
||||
private void deletePendingActionForRollback(Long coilId) {
|
||||
LambdaQueryWrapper<WmsCoilPendingAction> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(WmsCoilPendingAction::getCoilId, coilId)
|
||||
.notIn(WmsCoilPendingAction::getActionType, Arrays.asList(401, 402, 403, 404, 405))
|
||||
.eq(WmsCoilPendingAction::getDelFlag, 0)
|
||||
.eq(WmsCoilPendingAction::getActionStatus, 2)
|
||||
.orderByDesc(WmsCoilPendingAction::getCreateTime)
|
||||
.last("LIMIT 1");
|
||||
|
||||
WmsCoilPendingAction latestAction = coilPendingActionMapper.selectOne(queryWrapper);
|
||||
if (latestAction != null) {
|
||||
coilPendingActionMapper.deleteById(latestAction.getActionId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚普通更新操作(原有逻辑)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user