diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsFurnacePlanServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsFurnacePlanServiceImpl.java index 2d73acc4..99fab0d6 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsFurnacePlanServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsFurnacePlanServiceImpl.java @@ -267,6 +267,8 @@ public class WmsFurnacePlanServiceImpl implements IWmsFurnacePlanService { // 校验钢卷必须为现存钢卷(dataType=1),历史钢卷不能被加工 List coils = materialCoilMapper.selectBatchIds(coilIds); Set existingIds = coils.stream().map(WmsMaterialCoil::getCoilId).collect(Collectors.toSet()); + java.util.Map coilMap = coils.stream() + .collect(Collectors.toMap(WmsMaterialCoil::getCoilId, c -> c, (a, b) -> a)); for (Long coilId : coilIds) { if (!existingIds.contains(coilId)) { throw new ServiceException("钢卷被删除无法执行退火"); @@ -284,12 +286,20 @@ public class WmsFurnacePlanServiceImpl implements IWmsFurnacePlanService { .eq(WmsFurnacePlanCoil::getCoilId, coilId)) > 0) { continue; } + // 检查钢卷是否已被其他操作锁定(exclusiveStatus != 0) + // exclusiveStatus=1: 分卷中, exclusiveStatus=2: 已在其他计划中 + WmsMaterialCoil coil = coilMap.get(coilId); + if (coil != null && coil.getExclusiveStatus() != null && coil.getExclusiveStatus() != 0) { + throw new ServiceException("钢卷" + coil.getEnterCoilNo() + "正在进行其他操作,无法绑定"); + } WmsFurnacePlanCoil entity = new WmsFurnacePlanCoil(); entity.setPlanId(bo.getPlanId()); entity.setCoilId(coilId); entity.setLogicWarehouseId(bo.getLogicWarehouseId()); entity.setFurnaceLevel(bo.getFurnaceLevel()); planCoilMapper.insert(entity); + // 绑定计划时立即释放实际库区(锁卷) + releaseActualWarehouse(coilId); } return true; } @@ -300,9 +310,17 @@ public class WmsFurnacePlanServiceImpl implements IWmsFurnacePlanService { if (bo.getPlanId() == null || bo.getCoilId() == null) { throw new ServiceException("计划ID和钢卷ID不能为空"); } - return planCoilMapper.delete(Wrappers.lambdaQuery() + int deleted = planCoilMapper.delete(Wrappers.lambdaQuery() .eq(WmsFurnacePlanCoil::getPlanId, bo.getPlanId()) - .eq(WmsFurnacePlanCoil::getCoilId, bo.getCoilId())) > 0; + .eq(WmsFurnacePlanCoil::getCoilId, bo.getCoilId())); + if (deleted <= 0) { + throw new ServiceException("该钢卷未绑定到此计划,无需解绑"); + } + // 解绑后解锁钢卷 + materialCoilMapper.update(null, Wrappers.lambdaUpdate() + .eq(WmsMaterialCoil::getCoilId, bo.getCoilId()) + .set(WmsMaterialCoil::getExclusiveStatus, 0)); + return true; } @Override @@ -330,10 +348,6 @@ public class WmsFurnacePlanServiceImpl implements IWmsFurnacePlanService { updateFurnaceBusy(plan.getTargetFurnaceId(), 1); - List coils = queryPlanCoils(planId); - for (WmsFurnacePlanCoilVo coil : coils) { - releaseActualWarehouse(coil.getCoilId()); - } return true; }