package com.iailab.module.knowledge.controller; import com.iailab.common.annotation.LogOperation; import com.iailab.framework.common.page.PageData; import com.iailab.common.utils.Constant; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.util.validation.ValidationUtils; import com.iailab.framework.common.validation.group.AddGroup; import com.iailab.framework.common.validation.group.DefaultGroup; import com.iailab.framework.common.validation.group.UpdateGroup; import com.iailab.module.knowledge.dto.KnowledgePathDTO; import com.iailab.module.knowledge.service.KnowledgePathService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import javax.annotation.Resource; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; /** * @author PanZhibao * @Description * @createTime 2023年12月26日 09:12:00 */ @RestController @RequestMapping("/knowledge/path") @Tag(name = "知识库目录") public class KnowledgePathController { @Resource private KnowledgePathService knowledgePathService; @GetMapping("page") @Operation(summary = "分页") @Parameters({ @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true), @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true), @Parameter(name = Constant.ORDER_FIELD, description = "排序字段"), @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") }) public CommonResult> page(@RequestParam Map params) { PageData page = knowledgePathService.page(params); return new CommonResult>().setData(page); } @GetMapping("list") @Operation(summary = "列表") public CommonResult> list(@RequestParam Map params) { List data = knowledgePathService.list(params); return new CommonResult>().setData(data); } @GetMapping("tree") @Operation(summary = "列表") public CommonResult> tree() { List data = knowledgePathService.tree(); return new CommonResult>().setData(data); } @GetMapping("{id}") @Operation(summary = "信息") public CommonResult get(@PathVariable("id") String id) { KnowledgePathDTO data = knowledgePathService.get(id); return new CommonResult().setData(data); } @PostMapping @Operation(summary = "保存") @LogOperation("保存") public CommonResult save(@RequestBody KnowledgePathDTO dto) { //效验数据 ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class); knowledgePathService.save(dto); return new CommonResult(); } @PutMapping @Operation(summary = "修改") @LogOperation("修改") public CommonResult update(@RequestBody KnowledgePathDTO dto) { //效验数据 ValidationUtils.validate(dto, UpdateGroup.class, DefaultGroup.class); knowledgePathService.update(dto); return new CommonResult(); } @DeleteMapping("{id}") @Operation(summary = "删除") @LogOperation("删除") public CommonResult delete(@PathVariable("id") String id) { knowledgePathService.delete(id); return new CommonResult(); } }