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.
|
|
package com.iflytop.sgs.app.controller;
import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.iflytop.sgs.app.model.bo.status.device.DeviceState; import com.iflytop.sgs.app.model.dto.PauseCraftsDto; import com.iflytop.sgs.app.model.dto.ResumeCraftsDTO; import com.iflytop.sgs.app.model.dto.StartCraftsDTO; import com.iflytop.sgs.app.model.dto.StopCraftsDTO; import com.iflytop.sgs.app.model.entity.CraftMonitor; import com.iflytop.sgs.app.model.entity.Crafts; import com.iflytop.sgs.app.model.vo.CraftMonitorVO; import com.iflytop.sgs.app.model.vo.SetCraftsVO; import com.iflytop.sgs.app.service.api.CraftsService; import com.iflytop.sgs.app.service.device.DeviceStateService; import com.iflytop.sgs.common.base.BasePageQuery; import com.iflytop.sgs.common.result.PageResult; import com.iflytop.sgs.common.result.Result; import com.iflytop.sgs.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 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; private final DeviceStateService deviceStateService;
@Operation(summary = "根据矿石id获取工艺列表") @GetMapping("/list") public PageResult<Crafts> getPage(BasePageQuery pageQuery) { IPage<Crafts > result = craftsService.getPage(pageQuery); return PageResult.success(result); }
@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("/start") public Result<SetCraftsVO> startCrafts(@Valid @RequestBody StartCraftsDTO startCraftsDTO) { return Result.success(craftsService.startCrafts(startCraftsDTO)); }
@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(); }
@Operation(summary = "异常工艺删除") @DeleteMapping("/remove") public Result<String> removeMonitor(Long monitorId) { craftsService.removeMonitor(monitorId); return Result.success(); } @Operation(summary = "异常工艺恢复") @PostMapping("/restart") public Result<SetCraftsVO> restartCrafts(@Valid @RequestBody StartCraftsDTO startCraftsDTO) { return Result.success(); // return Result.success(craftsService.startCrafts(startCraftsDTO));
}
@Operation(summary = "获取异常工艺列表") @GetMapping("/monitor/list") public Result<List<CraftMonitorVO>> getMonitorList() { List<CraftMonitorVO> craftsDoingList = craftsService.getMonitorList(); return Result.success(craftsDoingList); }
@Operation(summary = "是否需要恢复异常工艺") @GetMapping("/restore") public Result<String> restore(@Parameter boolean isRestore) { if (isRestore) { CraftMonitor craftMonitor = craftsService.getOneOrderByTime(); if (craftMonitor != null) { String deviceStateStr = craftMonitor.getDeviceState(); DeviceState deviceStateRecord = JSONUtil.toBean(deviceStateStr, DeviceState.class); DeviceState deviceState = deviceStateService.getDeviceState(); deviceState.setTrays(deviceStateRecord.getTrays()); deviceState.setHeatModule(deviceStateRecord.getHeatModule()); } } else { craftsService.removeAllMonitor(); } return Result.success(); }
}
|