From 726277045ffb397e4faf52c0394351e118489e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Mon, 28 Apr 2025 15:12:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=85=8D=E7=BD=AE=E5=B7=A5=E8=89=BA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=85=B7=E4=BD=93=E5=B7=A5?= =?UTF-8?q?=E8=89=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iflytop/gd/app/controller/CraftsController.java | 6 +++--- .../java/com/iflytop/gd/app/model/entity/Crafts.java | 2 ++ .../com/iflytop/gd/app/model/vo/SetCraftsVO.java | 20 ++++++++++++++++++++ .../com/iflytop/gd/app/service/CraftsService.java | 13 ++++++++++++- .../java/com/iflytop/gd/app/service/OresService.java | 4 +++- 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/iflytop/gd/app/model/vo/SetCraftsVO.java diff --git a/src/main/java/com/iflytop/gd/app/controller/CraftsController.java b/src/main/java/com/iflytop/gd/app/controller/CraftsController.java index 3fd2976..11961c9 100644 --- a/src/main/java/com/iflytop/gd/app/controller/CraftsController.java +++ b/src/main/java/com/iflytop/gd/app/controller/CraftsController.java @@ -3,6 +3,7 @@ package com.iflytop.gd.app.controller; import com.iflytop.gd.app.model.dto.*; import com.iflytop.gd.app.model.entity.Crafts; import com.iflytop.gd.app.model.vo.CraftStatusVO; +import com.iflytop.gd.app.model.vo.SetCraftsVO; import com.iflytop.gd.app.service.CraftsService; import com.iflytop.gd.common.result.Result; import com.iflytop.gd.common.result.ResultCode; @@ -76,9 +77,8 @@ public class CraftsController { @Operation(summary = "配置加热区工艺") @PostMapping("/set") - public Result setCrafts(@Valid @RequestBody SetCraftsDTO setCraftsDTO) { - craftsService.setCraft(setCraftsDTO.getCraftId(), setCraftsDTO.getHeatId()); - return Result.success(); + public Result setCrafts(@Valid @RequestBody SetCraftsDTO setCraftsDTO) { + return Result.success(craftsService.setCraft(setCraftsDTO.getCraftId(), setCraftsDTO.getHeatId())); } diff --git a/src/main/java/com/iflytop/gd/app/model/entity/Crafts.java b/src/main/java/com/iflytop/gd/app/model/entity/Crafts.java index ef786b9..b51a4b4 100644 --- a/src/main/java/com/iflytop/gd/app/model/entity/Crafts.java +++ b/src/main/java/com/iflytop/gd/app/model/entity/Crafts.java @@ -16,10 +16,12 @@ import lombok.EqualsAndHashCode; public class Crafts extends BaseEntity { @NotNull + @NotBlank @Schema(description = "工艺名称") private String name; @NotNull + @NotBlank @Schema(description = "工艺步骤") private String steps; diff --git a/src/main/java/com/iflytop/gd/app/model/vo/SetCraftsVO.java b/src/main/java/com/iflytop/gd/app/model/vo/SetCraftsVO.java new file mode 100644 index 0000000..d0f5384 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/model/vo/SetCraftsVO.java @@ -0,0 +1,20 @@ +package com.iflytop.gd.app.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class SetCraftsVO { + @Schema(description = "加热区id") + private String heatId; + + @Schema(description = "工艺名称") + private String craftsName; + @Schema(description = "工艺名称") + private Long craftsId; + + @Schema(description = "矿石名称") + private String oresName; + @Schema(description = "矿石ID") + private Long oresId; +} diff --git a/src/main/java/com/iflytop/gd/app/service/CraftsService.java b/src/main/java/com/iflytop/gd/app/service/CraftsService.java index 23571cb..cdffac6 100644 --- a/src/main/java/com/iflytop/gd/app/service/CraftsService.java +++ b/src/main/java/com/iflytop/gd/app/service/CraftsService.java @@ -7,7 +7,9 @@ import com.iflytop.gd.app.common.enums.CraftStates; import com.iflytop.gd.app.core.CraftsContext; import com.iflytop.gd.app.mapper.CraftsMapper; import com.iflytop.gd.app.model.entity.Crafts; +import com.iflytop.gd.app.model.entity.Ores; import com.iflytop.gd.app.model.vo.CraftStatusVO; +import com.iflytop.gd.app.model.vo.SetCraftsVO; import com.iflytop.gd.common.exception.AppException; import com.iflytop.gd.common.result.ResultCode; import jakarta.annotation.PostConstruct; @@ -32,6 +34,7 @@ public class CraftsService extends ServiceImpl { private final StateMachineFactory stateMachineFactory; private final WebSocketService webSocketService; private final CraftsStepService craftsStepService; + private final OresService oresService; private ExecutorService executor; private final ConcurrentHashMap contextMap = new ConcurrentHashMap<>(); @@ -45,7 +48,7 @@ public class CraftsService extends ServiceImpl { /** * 配置工艺 */ - public synchronized void setCraft(Long craftId, String heatId) { + public synchronized SetCraftsVO setCraft(Long craftId, String heatId) { // 校验已有上下文状态,仅允许在 READY、STOPPED 或 FINISHED 状态下重置 CraftsContext existing = contextMap.get(heatId); if (existing != null) { @@ -56,6 +59,7 @@ public class CraftsService extends ServiceImpl { clearCraftContext(heatId); } Crafts craft = this.getById(craftId); + Ores ores = oresService.getById(craft.getOresId()); CraftsContext ctx = new CraftsContext( heatId, craft, @@ -64,6 +68,13 @@ public class CraftsService extends ServiceImpl { craftsStepService ); contextMap.put(heatId, ctx); + SetCraftsVO setCraftsVO = new SetCraftsVO(); + setCraftsVO.setHeatId(heatId); + setCraftsVO.setCraftsName(craft.getName()); + setCraftsVO.setCraftsId(craft.getId()); + setCraftsVO.setOresName(ores.getName()); + setCraftsVO.setOresId(ores.getId()); + return setCraftsVO; } /** diff --git a/src/main/java/com/iflytop/gd/app/service/OresService.java b/src/main/java/com/iflytop/gd/app/service/OresService.java index 5c73e3f..2593cd4 100644 --- a/src/main/java/com/iflytop/gd/app/service/OresService.java +++ b/src/main/java/com/iflytop/gd/app/service/OresService.java @@ -60,7 +60,9 @@ public class OresService extends ServiceImpl { // 设置该矿石的工艺列表 List crafts = craftsMap.get(ores.getId()); - crafts.forEach(c -> c.setSteps(null)); + if (crafts != null) { + crafts.forEach(c -> c.setSteps(null)); + } oresCraftsListVO.setCraftsList(crafts); return oresCraftsListVO;