refactor(WmsMaterialCoilService): 优化钢卷操作类型判断逻辑
- 整合合卷、分卷和初始新增的判断逻辑到单一循环中 - 添加 isInitialCreate 标志变量统一管理新增状态判断 - 优化循环结构,按优先级顺序处理不同操作类型 - 修复初始新增判断位置错误的问题 - 改进异常日志记录,添加 currentCoilId 参数便于调试 - 简化返回值处理逻辑,提高代码可读性
This commit is contained in:
@@ -3027,54 +3027,51 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
}
|
||||
|
||||
String currentCoilIdStr = currentCoilId.toString();
|
||||
boolean isInitialCreate = false; // 标记是否为初始新增
|
||||
|
||||
// 检查是否为合卷或分卷的产物
|
||||
// 2. 从后往前遍历steps(最新操作优先),检查合卷/分卷产物
|
||||
// 倒序遍历,确保取到最新的操作状态
|
||||
// 倒序遍历所有步骤,整合所有判断逻辑
|
||||
for (int i = steps.size() - 1; i >= 0; i--) {
|
||||
Map<String, Object> step = steps.get(i);
|
||||
String operation = (String) step.get("operation");
|
||||
String action = (String) step.get("action");
|
||||
|
||||
// 检查合卷操作(优先判断,因为合卷可能是后续操作)
|
||||
// 1. 优先判断初始新增(仅第一个步骤可能是新增)
|
||||
if (i == 0 && "新增".equals(action)) {
|
||||
Object coilIdObj = contentMap.get("coil_id");
|
||||
Object currentCoilIdObj = contentMap.get("current_coil_id");
|
||||
|
||||
if (coilIdObj != null && currentCoilIdObj != null) {
|
||||
String coilIdStr = coilIdObj.toString();
|
||||
String currentCoilIdStrInContent = currentCoilIdObj.toString();
|
||||
|
||||
if (coilIdStr.equals(currentCoilIdStrInContent) && coilIdStr.equals(currentCoilIdStr)) {
|
||||
isInitialCreate = true;
|
||||
break; // 确认是初始新增,直接退出循环
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 检查合卷操作(最新操作优先)
|
||||
if ("合卷".equals(operation)) {
|
||||
Object parentCoilIdsObj = step.get("parent_coil_ids");
|
||||
if (parentCoilIdsObj != null) {
|
||||
String parentCoilIdsStr = parentCoilIdsObj.toString();
|
||||
// 校验当前钢卷ID是否在合卷的父卷列表中
|
||||
if (parentCoilIdsStr.contains(currentCoilIdStr)) {
|
||||
return "MERGE_PRODUCT";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查分卷操作
|
||||
// 3. 检查分卷操作
|
||||
if ("分卷".equals(operation)) {
|
||||
return "SPLIT_PRODUCT";
|
||||
}
|
||||
}
|
||||
|
||||
// 首先检查是否为初始新增操作
|
||||
Map<String, Object> firstStep = steps.get(0);
|
||||
String action = (String) firstStep.get("action");
|
||||
if ("新增".equals(action)) {
|
||||
Object coilIdObj = contentMap.get("coil_id");
|
||||
Object currentCoilIdObj = contentMap.get("current_coil_id");
|
||||
|
||||
if (coilIdObj != null && currentCoilIdObj != null) {
|
||||
String coilIdStr = coilIdObj.toString();
|
||||
String currentCoilIdStrInContent = currentCoilIdObj.toString();
|
||||
|
||||
if (coilIdStr.equals(currentCoilIdStrInContent) && coilIdStr.equals(currentCoilIdStr)) {
|
||||
return "INITIAL_CREATE";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return "UNKNOWN";
|
||||
// 最终判断:如果是初始新增则返回,否则返回UNKNOWN
|
||||
return isInitialCreate ? "INITIAL_CREATE" : "UNKNOWN";
|
||||
} catch (Exception e) {
|
||||
log.error("检查回滚阻止原因失败", e);
|
||||
log.error("检查回滚阻止原因失败, currentCoilId:{}", currentCoilId, e);
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user