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.
118 lines
4.3 KiB
118 lines
4.3 KiB
package com.iflytop.nuclear.controller;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.iflytop.nuclear.model.Account;
|
|
import com.iflytop.nuclear.model.NuclearCoreConfig;
|
|
import com.iflytop.nuclear.model.Task;
|
|
import com.iflytop.nuclear.service.NuclearCoreConfigService;
|
|
import com.iflytop.nuclear.service.TaskService;
|
|
import com.iflytop.nuclear.service.impl.CheckServiceImpl;
|
|
import com.iflytop.nuclear.utils.JwtTokenUtils;
|
|
import com.iflytop.nuclear.utils.ResponseData;
|
|
import com.iflytop.nuclear.vo.TaskVO;
|
|
import io.jsonwebtoken.Claims;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.io.IOException;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @author cool
|
|
* @date 2023/6/29 15:21
|
|
*/
|
|
@Slf4j
|
|
@RestController
|
|
@CrossOrigin
|
|
@RequestMapping("/task")
|
|
// @PreAuthorize("hasRole('ADMIN')")
|
|
public class TaskController {
|
|
|
|
@Autowired
|
|
TaskService taskService;
|
|
@Autowired
|
|
NuclearCoreConfigService nuclearCoreConfigService;
|
|
@Autowired
|
|
HttpServletRequest request;
|
|
@Autowired
|
|
CheckServiceImpl checkServiceImpl;
|
|
|
|
@PostMapping("/create")
|
|
public ResponseData createTask(@RequestBody Task taskInfo) {
|
|
taskInfo.setPublishTime(new Date());
|
|
taskInfo.setStatus(0);
|
|
boolean save = taskService.save(taskInfo);
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put("result", save);
|
|
return ResponseData.success(jsonObject);
|
|
}
|
|
|
|
@GetMapping("/list")
|
|
public ResponseData getTaskListByUserId() {
|
|
String token = request.getHeader("Authorization");
|
|
if (token.length() > 0){
|
|
String[] s = token.split(" ");
|
|
String username = JwtTokenUtils.getUsername(s[1]);
|
|
String user_role = JwtTokenUtils.getUserRole(s[1]);
|
|
List<TaskVO> taskList = taskService.getTaskInfoByUsername(username, user_role);
|
|
JSONObject jo = new JSONObject();
|
|
jo.put("list", taskList);
|
|
return ResponseData.success(taskList);
|
|
}
|
|
return ResponseData.fail("用户登陆信息错误");
|
|
}
|
|
|
|
@PostMapping("/delete/{id}")
|
|
public ResponseData deleteTask(@PathVariable(name = "id") int id) {
|
|
boolean b = taskService.removeById(id);
|
|
// 同时将对应的excel 配置删除
|
|
QueryWrapper<NuclearCoreConfig> nuclearCoreConfigQueryWrapper = new QueryWrapper<>();
|
|
nuclearCoreConfigQueryWrapper.eq("task_id", id);
|
|
boolean remove = nuclearCoreConfigService.remove(nuclearCoreConfigQueryWrapper);
|
|
JSONObject jo = new JSONObject();
|
|
jo.put("result", b);
|
|
return ResponseData.success(jo);
|
|
}
|
|
|
|
@PostMapping("/delete/excel/{id}")
|
|
public ResponseData deleteTaskExcel(@PathVariable(name = "id") int id) throws IOException {
|
|
QueryWrapper<NuclearCoreConfig> nuclearCoreConfigQueryWrapper = new QueryWrapper<>();
|
|
nuclearCoreConfigQueryWrapper.eq("task_id", id);
|
|
boolean remove = nuclearCoreConfigService.remove(nuclearCoreConfigQueryWrapper);
|
|
// 将当前任务状态修改为0
|
|
checkServiceImpl.updateCoordAndStatus(id, null, 0, false, false, null);
|
|
JSONObject jo = new JSONObject();
|
|
jo.put("result", remove);
|
|
return ResponseData.success(jo);
|
|
}
|
|
|
|
@PostMapping("/update/{id}")
|
|
public ResponseData updateOperInfo(@PathVariable(name = "id") int taskId, @RequestBody Map<String,String> taskInfo) {
|
|
UpdateWrapper<Task> taskUpdateWrapper = new UpdateWrapper<>();
|
|
taskUpdateWrapper.eq("id",taskId);
|
|
Task task = new Task();
|
|
task.setOperatorId(taskInfo.get("operatorId"));
|
|
boolean update = taskService.update(task, taskUpdateWrapper);
|
|
JSONObject jo = new JSONObject();
|
|
jo.put("result", update);
|
|
return ResponseData.success(jo);
|
|
}
|
|
|
|
/**
|
|
* 获取处于进行中任务的状态信息
|
|
* @return
|
|
*/
|
|
@GetMapping("/process")
|
|
public ResponseData getProcessTaskInfo() {
|
|
TaskVO taskVO = taskService.processTask();
|
|
return ResponseData.success(taskVO);
|
|
}
|
|
|
|
}
|