From 56b05a02a115ef742f6a0035f2cb5d6367e25e78 Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Fri, 13 Mar 2026 10:58:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(wms):=20=E8=A7=A3=E5=86=B3=E5=B7=B2?= =?UTF-8?q?=E5=8F=91=E8=B4=A7=E9=92=A2=E5=8D=B7=E5=8D=A0=E7=94=A8=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E5=BA=93=E5=8C=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了对已发货钢卷的状态检查,防止其占用实际库区 - 实现了已发货钢卷释放旧库区的功能 - 优化了库区状态更新逻辑,增加了对-1标识的判断 - 在钢卷占用库区时添加了发货状态验证 refactor(da): 优化酸轧OEE月度任务初始化方式 - 将@PostConstruct替换为ApplicationRunner接口实现 - 添加@Async注解实现异步执行,避免阻塞项目启动 - 重构了启动时OEE汇总计算的执行时机和方式 --- .../java/com/klp/da/task/AcidOeeMonthTask.java | 16 +++++++++++----- .../impl/WmsMaterialCoilServiceImpl.java | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/klp-da/src/main/java/com/klp/da/task/AcidOeeMonthTask.java b/klp-da/src/main/java/com/klp/da/task/AcidOeeMonthTask.java index 16af3a5c..8097f3b4 100644 --- a/klp-da/src/main/java/com/klp/da/task/AcidOeeMonthTask.java +++ b/klp-da/src/main/java/com/klp/da/task/AcidOeeMonthTask.java @@ -7,10 +7,13 @@ import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; + import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -32,7 +35,7 @@ import java.util.concurrent.TimeUnit; @Slf4j @RequiredArgsConstructor @Component -public class AcidOeeMonthTask { +public class AcidOeeMonthTask implements ApplicationRunner { /** Redis 缓存 key 模板:当月 OEE 汇总(酸轧线) */ private static final String SUMMARY_KEY_PATTERN = "oee:report:month:summary:%s:SY"; @@ -48,10 +51,13 @@ public class AcidOeeMonthTask { private final StringRedisTemplate stringRedisTemplate; /** - * 项目启动完成后立即计算一次当月酸轧 OEE 汇总并写入 Redis。 + * 项目启动完成后计算一次当月酸轧 OEE 汇总并写入 Redis。 + * 使用 ApplicationRunner 在 Spring Boot 启动完成后执行。 + * 使用 @Async 异步执行,不阻塞项目启动。 */ - @PostConstruct - public void init() { + @Async + @Override + public void run(ApplicationArguments args) throws Exception { try { computeCurrentMonth("startup"); } catch (Exception e) { 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 18b2ad20..dec15a0c 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 @@ -1167,6 +1167,13 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService { throw new RuntimeException("历史钢卷不允许占用实际库区!"); } } + + // 2. 已发货的钢卷不能占用实际库区,给出提醒 + if (bo.getStatus() != null && bo.getStatus().equals(1)) { + if (bo.getActualWarehouseId() != null && !bo.getActualWarehouseId().equals(-1L)) { + throw new RuntimeException("已发货的钢卷不允许占用实际库区!"); + } + } // 直接更新钢卷属性 WmsMaterialCoil updateCoil = BeanUtil.toBean(bo, WmsMaterialCoil.class); validEntityBeforeSave(updateCoil); @@ -1188,8 +1195,14 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService { // 更新实际库区的启用状态 if (flag) { - // 只有当新的库区ID不为空且与原库区ID不同时才更新库区状态 - if (bo.getActualWarehouseId() != null && !bo.getActualWarehouseId().equals(oldCoil.getActualWarehouseId())) { + // 已发货的钢卷不能占用实际库区,释放旧库区 + if (bo.getStatus() != null && bo.getStatus().equals(1)) { + if (oldCoil.getActualWarehouseId() != null) { + updateActualWarehouseEnableStatus(oldCoil.getActualWarehouseId(), null); + } + } else if (bo.getActualWarehouseId() != null && !bo.getActualWarehouseId().equals(-1L) + && !bo.getActualWarehouseId().equals(oldCoil.getActualWarehouseId())) { + // 只有当新的库区ID不为空(且不为-1)且与原库区ID不同时才更新库区状态 updateActualWarehouseEnableStatus(oldCoil.getActualWarehouseId(), bo.getActualWarehouseId()); } }