liujie
2026-09-15 5a95ec36565d7ecc1a5ecb261f26752c90dec120
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.estate.expert.admin.controller.admin.standard;
 
import com.estate.expert.admin.domain.standard.hierachy.HierarchyData;
import com.estate.expert.admin.service.HierarchyService;
import com.estate.expert.admin.service.ProblemService;
import com.estate.expert.common.log.IgnoreRequestLog;
import com.estate.expert.common.rpc.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
@Api(tags = "管理后台/业务标准/层级管理")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/admin/hierarchy")
@Validated
public class HierarchyController {
 
    @Resource
    private HierarchyService hierarchyService;
 
    @Resource
    private ProblemService problemService;
 
    @ApiOperation(value = "获取根节点", notes = "会将完整的树结构返回,包括所有子节点")
    @GetMapping("/root")
    @IgnoreRequestLog
    public Result root(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id) {
        return Result.success(hierarchyService.root(id));
    }
 
    @ApiOperation(value = "获取子节点")
    @GetMapping("/children")
    @IgnoreRequestLog
    public Result children(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id,
                           @ApiParam(value = "父节点路径") @RequestParam(value = "parentPath") String parentPath,
                           @ApiParam(value = "关键词") @RequestParam(value = "keyword", required = false) String keyword){
        return Result.success(hierarchyService.children(id, parentPath, keyword));
    }
 
    @ApiOperation(value = "获取特定节点")
    @GetMapping("/node")
    public Result node(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id,
                      @ApiParam(value = "路径") @RequestParam(value = "path") String path,
                      @ApiParam(value = "是否包含子节点") @RequestParam(value = "includeChildren", defaultValue = "false") boolean includeChildren) {
        return Result.success(hierarchyService.node(id, path, includeChildren));
    }
 
    @ApiOperation("添加节点")
    @PostMapping("/add")
    public Result add(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id,
                      @ApiParam(value = "父节点路径") @RequestParam(value = "parentPath") String parentPath,
                      @ApiParam(value = "名称") @RequestParam(value = "name") String name,
                      @Validated @RequestBody HierarchyData data) {
        hierarchyService.addChild(id, parentPath, name, data);
        return Result.success();
    }
 
    @ApiOperation("修改节点")
    @PostMapping("/edit")
    public Result edit(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id,
                       @ApiParam(value = "路径") @RequestParam(value = "path") String path,
                       @ApiParam(value = "名称") @RequestParam(value = "name") String name,
                       @Validated @RequestBody HierarchyData data) {
        hierarchyService.edit(id, path, name, data);
        return Result.success();
    }
 
    @ApiOperation("删除节点")
    @GetMapping("/del")
    public Result delete(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id,
                         @ApiParam(value = "路径") @RequestParam(value = "path") String path) {
        hierarchyService.deleteNode(id, path);
        return Result.success();
    }
 
    @ApiOperation("批量删除节点")
    @PostMapping("/batch/del")
    public Result delete(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id,
                        @RequestBody List<String> paths) {
        problemService.deleteByHierarchy(id, paths);
        hierarchyService.deleteNodes(id, paths);
        return Result.success();
    }
 
    @ApiOperation(value = "克隆节点", notes = "克隆节点到同一个父节点下,新节点名称为:原名称-(克隆),包括所有子节点和关联的问题")
    @PostMapping("/clone")
    public Result cloneNode(@ApiParam(value = "层级ID") @RequestParam(value = "id") Integer id,
                           @ApiParam(value = "源节点路径") @RequestParam(value = "sourcePath") String sourcePath) {
        var newNode = hierarchyService.cloneNode(id, sourcePath);
        return Result.success(newNode);
    }
}