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 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); } }