石墨消解仪后端服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
4.1 KiB

2 months ago
3 months ago
2 months ago
3 months ago
3 months ago
  1. package com.iflytop.gd.app.controller;
  2. import com.iflytop.gd.app.model.dto.PauseCraftsDto;
  3. import com.iflytop.gd.app.model.dto.ResumeCraftsDTO;
  4. import com.iflytop.gd.app.model.dto.StartCraftsDTO;
  5. import com.iflytop.gd.app.model.dto.StopCraftsDTO;
  6. import com.iflytop.gd.app.model.entity.Crafts;
  7. import com.iflytop.gd.app.model.vo.SetCraftsVO;
  8. import com.iflytop.gd.app.service.api.CraftsService;
  9. import com.iflytop.gd.common.result.Result;
  10. import com.iflytop.gd.common.result.ResultCode;
  11. import io.swagger.v3.oas.annotations.Operation;
  12. import io.swagger.v3.oas.annotations.Parameter;
  13. import io.swagger.v3.oas.annotations.tags.Tag;
  14. import jakarta.validation.Valid;
  15. import jakarta.validation.constraints.Min;
  16. import jakarta.validation.constraints.NotNull;
  17. import lombok.RequiredArgsConstructor;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.validation.annotation.Validated;
  20. import org.springframework.web.bind.annotation.*;
  21. import java.util.List;
  22. @Tag(name = "工艺管理")
  23. @RestController
  24. @RequestMapping("/api/crafts")
  25. @RequiredArgsConstructor
  26. @Slf4j
  27. @Validated
  28. public class CraftsController {
  29. private final CraftsService craftsService;
  30. @Operation(summary = "根据矿石id获取工艺列表")
  31. @GetMapping("/list/{oresId}")
  32. public Result<List<Crafts>> getList(
  33. @NotNull(message = "矿石ID 不能为空")
  34. @Min(value = 1, message = "矿石ID 必须大于等于 1")
  35. @Parameter(description = "矿石ID") @PathVariable Long oresId) {
  36. List<Crafts> craftList = craftsService.selectAllByOresId(oresId);
  37. return Result.success(craftList);
  38. }
  39. @Operation(summary = "添加新工艺")
  40. @PostMapping("")
  41. public Result<String> add(@Valid @RequestBody Crafts crafts) {
  42. Crafts existingCrafts = craftsService.findByName(crafts.getName());
  43. if (existingCrafts == null) {
  44. boolean isSuccess = craftsService.save(crafts);
  45. if (isSuccess) {
  46. return Result.success();
  47. }
  48. } else {
  49. return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
  50. }
  51. return Result.failed();
  52. }
  53. @Operation(summary = "更新工艺")
  54. @PutMapping("")
  55. public Result<String> updateCrafts(@Valid @RequestBody Crafts crafts) {
  56. boolean isSuccess = craftsService.updateById(crafts);
  57. if (isSuccess) {
  58. return Result.success();
  59. }
  60. return Result.failed();
  61. }
  62. @Operation(summary = "删除工艺")
  63. @DeleteMapping("/{ids}")
  64. public Result<String> delete(@Parameter(description = "工艺ID,多个以英文逗号(,)分割") @PathVariable String ids) {
  65. boolean isSuccess = craftsService.deleteCrafts(ids);
  66. if (isSuccess) {
  67. return Result.success();
  68. }
  69. return Result.failed();
  70. }
  71. // @Operation(summary = "配置加热区工艺")
  72. // @PostMapping("/set")
  73. // public Result<SetCraftsVO> setCrafts(@Valid @RequestBody SetCraftsDTO setCraftsDTO) {
  74. // return Result.success(craftsService.setCraft(setCraftsDTO.getCraftId(), setCraftsDTO.getHeatId()));
  75. // }
  76. @Operation(summary = "开始执行工艺")
  77. @PostMapping("/start")
  78. public Result<SetCraftsVO> startCrafts(@Valid @RequestBody StartCraftsDTO startCraftsDTO) {
  79. return Result.success(craftsService.startCrafts(startCraftsDTO.getCraftId(), startCraftsDTO.getHeatId()));
  80. }
  81. @Operation(summary = "暂停执行工艺")
  82. @PostMapping("/pause")
  83. public Result<String> pauseCrafts(@Valid @RequestBody PauseCraftsDto pauseCraftsDto) {
  84. craftsService.pauseCrafts(pauseCraftsDto.getHeatId());
  85. return Result.success();
  86. }
  87. @Operation(summary = "恢复执行工艺")
  88. @PostMapping("/resume")
  89. public Result<String> resumeCrafts(@Valid @RequestBody ResumeCraftsDTO resumeCraftsDto) {
  90. craftsService.resumeCrafts(resumeCraftsDto.getHeatId());
  91. return Result.success();
  92. }
  93. @Operation(summary = "停止执行工艺")
  94. @PostMapping("/stop")
  95. public Result<String> stopCrafts(@Valid @RequestBody StopCraftsDTO stopCraftsDto) {
  96. craftsService.stopCrafts(stopCraftsDto.getHeatId());
  97. return Result.success();
  98. }
  99. }