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
113 lines
4.1 KiB
package com.iflytop.gd.app.controller;
|
|
|
|
import com.iflytop.gd.app.model.dto.PauseCraftsDto;
|
|
import com.iflytop.gd.app.model.dto.ResumeCraftsDTO;
|
|
import com.iflytop.gd.app.model.dto.StartCraftsDTO;
|
|
import com.iflytop.gd.app.model.dto.StopCraftsDTO;
|
|
import com.iflytop.gd.app.model.entity.Crafts;
|
|
import com.iflytop.gd.app.model.vo.SetCraftsVO;
|
|
import com.iflytop.gd.app.service.api.CraftsService;
|
|
import com.iflytop.gd.common.result.Result;
|
|
import com.iflytop.gd.common.result.ResultCode;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.constraints.Min;
|
|
import jakarta.validation.constraints.NotNull;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@Tag(name = "工艺管理")
|
|
@RestController
|
|
@RequestMapping("/api/crafts")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
@Validated
|
|
public class CraftsController {
|
|
private final CraftsService craftsService;
|
|
|
|
@Operation(summary = "根据矿石id获取工艺列表")
|
|
@GetMapping("/list/{oresId}")
|
|
public Result<List<Crafts>> getList(
|
|
@NotNull(message = "矿石ID 不能为空")
|
|
@Min(value = 1, message = "矿石ID 必须大于等于 1")
|
|
@Parameter(description = "矿石ID") @PathVariable Long oresId) {
|
|
List<Crafts> craftList = craftsService.selectAllByOresId(oresId);
|
|
return Result.success(craftList);
|
|
}
|
|
|
|
@Operation(summary = "添加新工艺")
|
|
@PostMapping("")
|
|
public Result<String> add(@Valid @RequestBody Crafts crafts) {
|
|
Crafts existingCrafts = craftsService.findByName(crafts.getName());
|
|
if (existingCrafts == null) {
|
|
boolean isSuccess = craftsService.save(crafts);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
} else {
|
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
@Operation(summary = "更新工艺")
|
|
@PutMapping("")
|
|
public Result<String> updateCrafts(@Valid @RequestBody Crafts crafts) {
|
|
boolean isSuccess = craftsService.updateById(crafts);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
@Operation(summary = "删除工艺")
|
|
@DeleteMapping("/{ids}")
|
|
public Result<String> delete(@Parameter(description = "工艺ID,多个以英文逗号(,)分割") @PathVariable String ids) {
|
|
boolean isSuccess = craftsService.deleteCrafts(ids);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
// @Operation(summary = "配置加热区工艺")
|
|
// @PostMapping("/set")
|
|
// public Result<SetCraftsVO> setCrafts(@Valid @RequestBody SetCraftsDTO setCraftsDTO) {
|
|
// return Result.success(craftsService.setCraft(setCraftsDTO.getCraftId(), setCraftsDTO.getHeatId()));
|
|
// }
|
|
|
|
|
|
@Operation(summary = "开始执行工艺")
|
|
@PostMapping("/start")
|
|
public Result<SetCraftsVO> startCrafts(@Valid @RequestBody StartCraftsDTO startCraftsDTO) {
|
|
return Result.success(craftsService.startCrafts(startCraftsDTO.getCraftId(), startCraftsDTO.getHeatId()));
|
|
}
|
|
|
|
@Operation(summary = "暂停执行工艺")
|
|
@PostMapping("/pause")
|
|
public Result<String> pauseCrafts(@Valid @RequestBody PauseCraftsDto pauseCraftsDto) {
|
|
craftsService.pauseCrafts(pauseCraftsDto.getHeatId());
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "恢复执行工艺")
|
|
@PostMapping("/resume")
|
|
public Result<String> resumeCrafts(@Valid @RequestBody ResumeCraftsDTO resumeCraftsDto) {
|
|
craftsService.resumeCrafts(resumeCraftsDto.getHeatId());
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "停止执行工艺")
|
|
@PostMapping("/stop")
|
|
public Result<String> stopCrafts(@Valid @RequestBody StopCraftsDTO stopCraftsDto) {
|
|
craftsService.stopCrafts(stopCraftsDto.getHeatId());
|
|
return Result.success();
|
|
}
|
|
|
|
}
|