From 181f0726d8c23c7b4107f30a9fce083b6aed01c9 Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Wed, 4 Mar 2026 15:04:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(wms):=20=E8=A7=A3=E5=86=B3=E9=92=A2?= =?UTF-8?q?=E5=8D=B7=E5=9B=9E=E6=BB=9A=E6=93=8D=E4=BD=9C=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=8B=AC=E5=8D=A0=E7=8A=B6=E6=80=81=E6=A3=80=E6=9F=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加最后一步操作信息解析功能,用于检查独占状态 - 实现分卷操作的独占状态验证,防止母卷正在进行分卷时回滚 - 修复分卷回滚时子钢卷ID匹配逻辑 - 优化二维码内容解析,支持多步骤操作回滚 - 添加分卷回滚前的子钢卷有效性检查 --- .../impl/WmsMaterialCoilServiceImpl.java | 87 ++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java index 230c86e5..0fda24c9 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java @@ -2988,11 +2988,25 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService { throw new RuntimeException("二维码记录不存在或内容为空,无法回滚"); } - // 5. 解析二维码内容,判断是合卷、分卷还是普通更新 + // 5. 解析二维码内容,获取最后一步操作信息 + // 直接从二维码解析最后一步操作,用于检查独占状态 + Map 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 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 getLastOperationStepFromQrcode(String content) { + Map result = new HashMap<>(); + try { + ObjectMapper objectMapper = new ObjectMapper(); + Map contentMap = objectMapper.readValue(content, Map.class); + + @SuppressWarnings("unchecked") + List> steps = (List>) contentMap.get("steps"); + if (steps == null || steps.isEmpty()) { + return result; + } + + // 从后往前找到最后一个非回滚的步骤 + for (int i = steps.size() - 1; i >= 0; i--) { + Map 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 childCoils = baseMapper.selectBatchIds(childCoilIds);