158 lines
5.1 KiB
Java
158 lines
5.1 KiB
Java
package com.muyu.quest.controller;
|
|
|
|
import java.util.*;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
|
import com.muyu.quest.req.NodeReq;
|
|
import com.muyu.quest.resp.NodeResp;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import javax.annotation.Resource;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.muyu.quest.domain.Node;
|
|
import com.muyu.quest.service.INodeService;
|
|
import com.muyu.common.core.web.controller.BaseController;
|
|
import com.muyu.common.core.domain.Result;
|
|
import com.muyu.common.core.utils.poi.ExcelUtil;
|
|
import com.muyu.common.security.utils.SecurityUtils;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import com.muyu.common.core.web.page.TableDataInfo;
|
|
|
|
/**
|
|
* 节点管理Controller
|
|
*
|
|
* @Author: 胡杨
|
|
* @date 2024-08-23
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/node")
|
|
public class NodeController extends BaseController {
|
|
@Resource
|
|
private INodeService nodeService;
|
|
|
|
/**
|
|
* 查询节点管理列表
|
|
*/
|
|
// @RequiresPermissions("quest:node:list")
|
|
@GetMapping("/list")
|
|
public Result<TableDataInfo<NodeResp>> list(NodeReq nodeReq) {
|
|
startPage();
|
|
List<Node> list = nodeService.selectNodeList(nodeReq);
|
|
return getDataTable(list
|
|
.stream()
|
|
.map(NodeResp::build)
|
|
.toList());
|
|
}
|
|
|
|
/**
|
|
* 导出节点管理列表
|
|
*/
|
|
// @RequiresPermissions("quest:node:export")
|
|
@PostMapping("/export")
|
|
public void export(HttpServletResponse response, NodeReq nodeReq) {
|
|
List<Node> list = nodeService.selectNodeList(nodeReq);
|
|
ExcelUtil<Node> util = new ExcelUtil<Node>(Node.class);
|
|
util.exportExcel(response, list, "节点管理数据");
|
|
}
|
|
|
|
/**
|
|
* 获取节点管理详细信息
|
|
*/
|
|
// @RequiresPermissions("quest:node:query")
|
|
@GetMapping(value = "/{id}")
|
|
public Result<List<Node>> getInfo(@PathVariable("id") Long id) {
|
|
return success(nodeService.selectNodeById(id));
|
|
}
|
|
|
|
/**
|
|
* 新增节点管理
|
|
*/
|
|
// @RequiresPermissions("quest:node:add")
|
|
@PostMapping
|
|
@Transactional
|
|
public Result<Integer> add(
|
|
@Validated @RequestBody Node node) {
|
|
if (nodeService.checkIdUnique(node)) {
|
|
return error("新增 节点管理 '" + node + "'失败,节点已存在");
|
|
}
|
|
String code = UUID.randomUUID().toString().replace("-", "");
|
|
node.setNodeCode(code);
|
|
node.setCreateBy(SecurityUtils.getUsername());
|
|
boolean save = nodeService.save(node);
|
|
// if (save){
|
|
// // 新增任务节点中间表信息
|
|
// middleService.save(new TaskNodeMiddle(null,taskCode,code));
|
|
// }
|
|
return toAjax(save);
|
|
}
|
|
|
|
/**
|
|
* 修改节点管理
|
|
*/
|
|
@RequiresPermissions("quest:node:edit")
|
|
@PutMapping
|
|
public Result<Integer> edit(
|
|
@Validated @RequestBody Node node) {
|
|
if (!nodeService.checkIdUnique(node)) {
|
|
return error("修改 节点管理 '" + node + "'失败,节点不存在");
|
|
}
|
|
node.setUpdateBy(SecurityUtils.getUsername());
|
|
return toAjax(nodeService.updateById(node));
|
|
}
|
|
|
|
/**
|
|
* 删除节点管理
|
|
*/
|
|
// @RequiresPermissions("quest:node:remove")
|
|
@DeleteMapping("/{ids}")
|
|
@Transactional
|
|
public Result<Integer> removeByIds(@PathVariable("ids") Long[] ids) {
|
|
nodeService.removeBatchByIds(Arrays.asList(ids));
|
|
return success();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param nodeCodes
|
|
* @param taskCode
|
|
* @return
|
|
*/
|
|
@DeleteMapping("/{taskCode}/{nodeCodes}")
|
|
@Transactional
|
|
public Result<Integer> removeByTaskCode(@PathVariable("nodeCodes") String[] nodeCodes, @PathVariable("taskCode") String taskCode) {
|
|
LambdaQueryWrapper<Node> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper.eq(Node::getTaskCode,taskCode);
|
|
if (!Arrays.asList(nodeCodes).isEmpty()){
|
|
queryWrapper.eq(Node::getNodeCode,nodeCodes);
|
|
}
|
|
nodeService.remove(queryWrapper);
|
|
return success();
|
|
}
|
|
|
|
/**
|
|
* 节点批量删除再批量新增
|
|
*/
|
|
@PostMapping("/batch/{taskCode}")
|
|
@Transactional
|
|
public Result<Integer> batch(@Validated @RequestBody ArrayList<Node> nodeList,@PathVariable("taskCode") String[] taskCode) {
|
|
// 批量删除
|
|
nodeService.batchDelect(taskCode);
|
|
|
|
if (nodeList.isEmpty()){
|
|
return Result.success();
|
|
}
|
|
// 批量添加
|
|
boolean save = nodeService.saveBatch(nodeList);
|
|
return toAjax(save);
|
|
}
|
|
}
|