| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package com.lingyue.graph.controller;
- import com.lingyue.common.domain.AjaxResult;
- import com.lingyue.graph.dto.ElementDTO;
- import com.lingyue.graph.dto.PageResult;
- import com.lingyue.graph.dto.TemplateDTO;
- import com.lingyue.graph.service.TemplateService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.Parameter;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import lombok.Data;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- import java.util.Map;
- /**
- * 图谱模板管理控制器
- *
- * @author lingyue
- * @since 2026-02-12
- */
- @Slf4j
- @RestController
- @RequestMapping("/api/v1/graph/templates")
- @RequiredArgsConstructor
- @Tag(name = "图谱模板管理", description = "图谱模板CRUD、要素管理")
- public class GraphTemplateController {
- private final TemplateService templateService;
- @GetMapping
- @Operation(summary = "获取模板列表", description = "分页获取模板列表")
- public AjaxResult<PageResult<TemplateDTO>> list(
- @Parameter(description = "页码") @RequestParam(defaultValue = "1") int page,
- @Parameter(description = "每页数量") @RequestParam(defaultValue = "20") int pageSize,
- @Parameter(description = "关键词") @RequestParam(required = false) String keyword,
- @Parameter(description = "分类") @RequestParam(required = false) String category,
- @Parameter(description = "状态") @RequestParam(required = false) String status) {
- PageResult<TemplateDTO> result = templateService.list(page, pageSize, keyword, category, status);
- return AjaxResult.success(result);
- }
- @GetMapping("/{id}")
- @Operation(summary = "获取模板详情")
- public AjaxResult<TemplateDTO> getById(
- @Parameter(description = "模板ID", required = true) @PathVariable Long id) {
- TemplateDTO template = templateService.getById(id);
- if (template == null) {
- return AjaxResult.error("模板不存在: " + id, null);
- }
- return AjaxResult.success(template);
- }
- @PostMapping
- @Operation(summary = "创建模板")
- public AjaxResult<TemplateDTO> create(@RequestBody CreateTemplateRequest request) {
- TemplateDTO template = templateService.create(
- request.getName(),
- request.getCategory(),
- request.getDescription(),
- request.getSourceFileId(),
- request.getCreatedBy());
- return AjaxResult.success(template);
- }
- @PutMapping("/{id}")
- @Operation(summary = "更新模板")
- public AjaxResult<TemplateDTO> update(
- @Parameter(description = "模板ID", required = true) @PathVariable Long id,
- @RequestBody UpdateTemplateRequest request) {
- TemplateDTO template = templateService.update(
- id, request.getName(), request.getCategory(), request.getDescription(), request.getStatus());
- return AjaxResult.success(template);
- }
- @DeleteMapping("/{id}")
- @Operation(summary = "删除模板")
- public AjaxResult<?> delete(
- @Parameter(description = "模板ID", required = true) @PathVariable Long id) {
- templateService.delete(id);
- return AjaxResult.success("删除成功");
- }
- @GetMapping("/{templateId}/elements")
- @Operation(summary = "获取模板要素列表")
- public AjaxResult<List<ElementDTO>> listElements(
- @Parameter(description = "模板ID", required = true) @PathVariable Long templateId) {
- List<ElementDTO> elements = templateService.listElements(templateId);
- return AjaxResult.success(elements);
- }
- @PostMapping("/{templateId}/elements")
- @Operation(summary = "添加要素到模板")
- public AjaxResult<ElementDTO> addElement(
- @Parameter(description = "模板ID", required = true) @PathVariable Long templateId,
- @RequestBody AddElementRequest request) {
- ElementDTO element = templateService.addElement(
- templateId,
- request.getElementKey(),
- request.getName(),
- request.getElementType(),
- request.isRequired(),
- request.getDefaultValue(),
- request.getDescription());
- return AjaxResult.success(element);
- }
- @PutMapping("/{templateId}/elements/reorder")
- @Operation(summary = "调整要素顺序")
- public AjaxResult<?> reorderElements(
- @Parameter(description = "模板ID", required = true) @PathVariable Long templateId,
- @RequestBody ReorderRequest request) {
- templateService.reorderElements(templateId, request.getElementIds());
- return AjaxResult.success("排序成功");
- }
- @PostMapping("/{id}/create-report")
- @Operation(summary = "基于模板创建报告")
- public AjaxResult<Map<String, Object>> createReport(
- @Parameter(description = "模板ID", required = true) @PathVariable Long id,
- @RequestBody CreateReportFromTemplateRequest request) {
- Long reportId = templateService.createReportFromTemplate(
- id, request.getProjectId(), request.getReportName(), request.getCreatedBy());
- return AjaxResult.success(Map.of(
- "reportId", reportId,
- "templateId", id,
- "status", "draft"
- ));
- }
- @Data
- public static class CreateTemplateRequest {
- private String name;
- private String category;
- private String description;
- private Long sourceFileId;
- private Long createdBy;
- }
- @Data
- public static class UpdateTemplateRequest {
- private String name;
- private String category;
- private String description;
- private String status;
- }
- @Data
- public static class AddElementRequest {
- private String elementKey;
- private String name;
- private String elementType;
- private boolean required;
- private String defaultValue;
- private String description;
- }
- @Data
- public static class ReorderRequest {
- private List<Long> elementIds;
- }
- @Data
- public static class CreateReportFromTemplateRequest {
- private Long projectId;
- private String reportName;
- private Long createdBy;
- }
- }
|