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.
83 lines
3.0 KiB
83 lines
3.0 KiB
package com.iflytop.gd.app.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.iflytop.gd.app.model.dto.GetAllTasksDTO;
|
|
import com.iflytop.gd.app.model.dto.TaskDTO;
|
|
import com.iflytop.gd.app.model.entity.Tasks;
|
|
import com.iflytop.gd.app.model.vo.TaskStepsVO;
|
|
import com.iflytop.gd.app.service.TasksService;
|
|
import com.iflytop.gd.common.result.PageResult;
|
|
import com.iflytop.gd.common.result.Result;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@Tag(name = "实验")
|
|
@RestController
|
|
@RequestMapping("/api/tasks")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class TasksController {
|
|
private final TasksService tasksService;
|
|
|
|
@Operation(summary = "实验列表")
|
|
@GetMapping("/list")
|
|
public PageResult<Tasks> list(GetAllTasksDTO getAllTasksDTO) {
|
|
LambdaQueryWrapper<Tasks> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper
|
|
.like(StringUtils.hasText(getAllTasksDTO.getName()), Tasks::getName, getAllTasksDTO.getName())
|
|
.orderByDesc(Tasks::getCreateTime);
|
|
|
|
IPage<Tasks> result = tasksService.page(
|
|
new Page<>(getAllTasksDTO.getPageNum(), getAllTasksDTO.getPageSize()),
|
|
queryWrapper
|
|
);
|
|
return PageResult.success(result);
|
|
}
|
|
|
|
@Operation(summary = "实验详情")
|
|
@GetMapping("/{id}")
|
|
public Result<TaskStepsVO> detail(@PathVariable Long id) {
|
|
return Result.success(tasksService.detail(id));
|
|
}
|
|
|
|
@Operation(summary = "获取正在进行的实验")
|
|
@GetMapping("/current")
|
|
public Result<Tasks> getCurrent() {
|
|
return Result.success(tasksService.getCurrent());
|
|
}
|
|
|
|
@Operation(summary = "开始新实验")
|
|
@PostMapping("/")
|
|
public Result<Tasks> start(@RequestBody TaskDTO dto) {
|
|
if (tasksService.getCurrent() != null) {
|
|
return Result.failed("存在正在运行的实验,请先终止");
|
|
}
|
|
return Result.success(tasksService.start(dto.getName()));
|
|
}
|
|
|
|
@Operation(summary = "更新实验")
|
|
@PutMapping("/")
|
|
public Result<?> updateTask(@RequestBody Tasks task) {
|
|
return Result.success(tasksService.updateById(task));
|
|
}
|
|
|
|
@Operation(summary = "删除实验")
|
|
@DeleteMapping("/{ids}")
|
|
public Result<?> deleteTask(@Parameter(description = "ID,多个以英文逗号(,)分割") @PathVariable String ids) {
|
|
return Result.success(tasksService.deleteTasks(ids));
|
|
}
|
|
|
|
@Operation(summary = "停止当前实验")
|
|
@PostMapping("/stop")
|
|
public Result<Integer> stop() {
|
|
tasksService.stop();
|
|
return Result.success();
|
|
}
|
|
}
|