fix(wms): 解决钢卷回滚操作中的独占状态检查问题
- 添加最后一步操作信息解析功能,用于检查独占状态 - 实现分卷操作的独占状态验证,防止母卷正在进行分卷时回滚 - 修复分卷回滚时子钢卷ID匹配逻辑 - 优化二维码内容解析,支持多步骤操作回滚 - 添加分卷回滚前的子钢卷有效性检查
This commit is contained in:
@@ -2988,11 +2988,25 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("二维码记录不存在或内容为空,无法回滚");
|
||||
}
|
||||
|
||||
// 5. 解析二维码内容,判断是合卷、分卷还是普通更新
|
||||
// 5. 解析二维码内容,获取最后一步操作信息
|
||||
// 直接从二维码解析最后一步操作,用于检查独占状态
|
||||
Map<String, Object> lastStepInfo = getLastOperationStepFromQrcode(qrcodeRecord.getContent());
|
||||
String lastOperation = (String) lastStepInfo.get("operation");
|
||||
Long oldCoilIdFromLastStep = (Long) lastStepInfo.get("oldCoilId");
|
||||
|
||||
// 如果最后一步是分卷操作并且old_coil_id正在处于单步分卷则当前钢卷不能回滚
|
||||
if ("分卷".equals(lastOperation) && oldCoilIdFromLastStep != null) {
|
||||
WmsMaterialCoil motherCoil = baseMapper.selectById(oldCoilIdFromLastStep);
|
||||
if (motherCoil != null && motherCoil.getExclusiveStatus() != null && motherCoil.getExclusiveStatus() == 1) {
|
||||
throw new RuntimeException("母卷[" + motherCoil.getCurrentCoilNo() + "]正在进行分卷操作,当前钢卷无法回滚");
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 解析二维码内容,判断是合卷、分卷还是普通更新
|
||||
Map<String, Object> rollbackInfo = parseRollbackInfoFromQrcode(qrcodeRecord.getContent(), currentCoilId);
|
||||
String operationType = (String) rollbackInfo.get("operationType");
|
||||
|
||||
// 6. 根据操作类型执行不同的回滚逻辑
|
||||
// 7. 根据操作类型执行不同的回滚逻辑
|
||||
if ("MERGE".equals(operationType)) {
|
||||
// 合卷回滚
|
||||
return rollbackMergeOperation(currentCoil, qrcodeRecord, rollbackInfo, result);
|
||||
@@ -3012,6 +3026,68 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从二维码内容中获取最后一步操作信息(用于检查独占状态)
|
||||
* 只返回最后一步的操作类型和old_coil_id,不进行复杂的回滚逻辑判断
|
||||
*/
|
||||
private Map<String, Object> getLastOperationStepFromQrcode(String content) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<String, Object> contentMap = objectMapper.readValue(content, Map.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> steps = (List<Map<String, Object>>) contentMap.get("steps");
|
||||
if (steps == null || steps.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 从后往前找到最后一个非回滚的步骤
|
||||
for (int i = steps.size() - 1; i >= 0; i--) {
|
||||
Map<String, Object> step = steps.get(i);
|
||||
String action = (String) step.get("action");
|
||||
|
||||
// 跳过回滚操作
|
||||
if ("回滚".equals(action)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 记录最后一步的操作类型
|
||||
result.put("operation", step.get("operation"));
|
||||
result.put("action", action);
|
||||
|
||||
// 获取old_coil_id
|
||||
Object oldCoilIdObj = step.get("old_coil_id");
|
||||
if (oldCoilIdObj != null) {
|
||||
try {
|
||||
result.put("oldCoilId", Long.parseLong(oldCoilIdObj.toString()));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取child_coil_ids(用于分卷判断)
|
||||
Object childCoilIdsObj = step.get("child_coil_ids");
|
||||
if (childCoilIdsObj != null) {
|
||||
result.put("childCoilIds", childCoilIdsObj.toString());
|
||||
}
|
||||
|
||||
// 获取parent_coil_ids(用于合卷判断)
|
||||
Object parentCoilIdsObj = step.get("parent_coil_ids");
|
||||
if (parentCoilIdsObj != null) {
|
||||
result.put("parentCoilIds", parentCoilIdsObj.toString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("解析二维码最后一步操作失败", e);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析二维码内容,获取回滚所需的信息
|
||||
* @return 包含operationType和相应参数的Map
|
||||
@@ -3076,6 +3152,8 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result.put("operationType", "SPLIT");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 如果找到普通更新操作
|
||||
@@ -3180,6 +3258,11 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("无法获取分卷的子钢卷ID,无法回滚");
|
||||
}
|
||||
|
||||
// 检查当前钢卷ID是否在childCoilIds里面,如果不在说明不是同一步骤则不能回滚
|
||||
if (!childCoilIds.contains(currentCoil.getCoilId())) {
|
||||
throw new RuntimeException("无可回滚的母卷");
|
||||
}
|
||||
|
||||
// 查询所有子钢卷
|
||||
List<WmsMaterialCoil> childCoils = baseMapper.selectBatchIds(childCoilIds);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user