Parcourir la source

feat: add dimension config and knowledge base admin controllers

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Sisyphus il y a 3 mois
Parent
commit
f5eb706fde

+ 56 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/DimensionConfigController.java

@@ -0,0 +1,56 @@
+package com.etotem.cfc.controller.admin;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.entity.ProductDimensionConfig;
+import com.etotem.cfc.service.ProductDimensionConfigService;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/admin/dimension-config")
+public class DimensionConfigController {
+
+    @Resource
+    private ProductDimensionConfigService productDimensionConfigService;
+
+    @PostMapping("/list")
+    public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params) {
+        String dimensionType = (String) params.get("dimensionType");
+        Integer enabled = (Integer) params.get("enabled");
+        int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
+        int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
+        return Result.success(productDimensionConfigService.list(dimensionType, enabled, page, size));
+    }
+
+    @PostMapping("/get")
+    public Result<ProductDimensionConfig> get(@RequestParam Long id) {
+        ProductDimensionConfig config = productDimensionConfigService.getById(id);
+        if (config == null) {
+            return Result.error("维度配置不存在");
+        }
+        return Result.success(config);
+    }
+
+    @PostMapping("/save")
+    public Result<ProductDimensionConfig> save(@RequestBody ProductDimensionConfig config) {
+        return Result.success(productDimensionConfigService.saveConfig(config));
+    }
+
+    @PostMapping("/delete")
+    public Result<Void> delete(@RequestParam Long id) {
+        boolean success = productDimensionConfigService.deleteConfig(id);
+        return success ? Result.success(null) : Result.error("删除失败");
+    }
+
+    @PostMapping("/tree")
+    public Result<List<ProductDimensionConfig>> tree() {
+        return Result.success(productDimensionConfigService.tree());
+    }
+}

+ 85 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/KnowledgeBaseController.java

@@ -0,0 +1,85 @@
+package com.etotem.cfc.controller.admin;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.entity.DanKnowledgeBase;
+import com.etotem.cfc.service.DanKnowledgeBaseService;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/admin/knowledge-base")
+public class KnowledgeBaseController {
+
+    @Resource
+    private DanKnowledgeBaseService danKnowledgeBaseService;
+
+    @PostMapping("/list")
+    public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params) {
+        String keyword = (String) params.get("keyword");
+        Integer status = (Integer) params.get("status");
+        int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
+        int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
+        return Result.success(danKnowledgeBaseService.list(keyword, status, page, size));
+    }
+
+    @PostMapping("/get")
+    public Result<Map<String, Object>> get(@RequestParam Long id) {
+        Map<String, Object> result = danKnowledgeBaseService.getWithAssociations(id);
+        if (result == null) {
+            return Result.error("知识不存在");
+        }
+        return Result.success(result);
+    }
+
+    @SuppressWarnings("unchecked")
+    @PostMapping("/save")
+    public Result<DanKnowledgeBase> save(@RequestBody Map<String, Object> params) {
+        DanKnowledgeBase knowledge = new DanKnowledgeBase();
+        if (params.get("id") != null) {
+            knowledge.setId(((Number) params.get("id")).longValue());
+        }
+        knowledge.setTitle((String) params.get("title"));
+        knowledge.setContent((String) params.get("content"));
+        if (params.get("sort") != null) {
+            knowledge.setSort(((Number) params.get("sort")).intValue());
+        }
+        if (params.get("status") != null) {
+            knowledge.setStatus(((Number) params.get("status")).intValue());
+        }
+        knowledge.setRemark((String) params.get("remark"));
+        List<Long> dimensionIds = (List<Long>) params.get("dimensionIds");
+        List<Long> tagIds = (List<Long>) params.get("tagIds");
+        return Result.success(danKnowledgeBaseService.saveWithAssociations(knowledge, dimensionIds, tagIds));
+    }
+
+    @PostMapping("/delete")
+    public Result<Void> delete(@RequestParam Long id) {
+        boolean success = danKnowledgeBaseService.deleteKnowledge(id);
+        return success ? Result.success(null) : Result.error("删除失败");
+    }
+
+    @PostMapping("/bind-dimensions")
+    public Result<Void> bindDimensions(@RequestBody Map<String, Object> params) {
+        Long knowledgeId = ((Number) params.get("knowledgeId")).longValue();
+        @SuppressWarnings("unchecked")
+        List<Long> dimensionIds = (List<Long>) params.get("dimensionIds");
+        danKnowledgeBaseService.bindDimensions(knowledgeId, dimensionIds);
+        return Result.success(null);
+    }
+
+    @PostMapping("/bind-tags")
+    public Result<Void> bindTags(@RequestBody Map<String, Object> params) {
+        Long knowledgeId = ((Number) params.get("knowledgeId")).longValue();
+        @SuppressWarnings("unchecked")
+        List<Long> tagIds = (List<Long>) params.get("tagIds");
+        danKnowledgeBaseService.bindTags(knowledgeId, tagIds);
+        return Result.success(null);
+    }
+}

+ 37 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/KnowledgeTagController.java

@@ -0,0 +1,37 @@
+package com.etotem.cfc.controller.admin;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.entity.DanKnowledgeTag;
+import com.etotem.cfc.service.DanKnowledgeTagService;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/admin/knowledge-tag")
+public class KnowledgeTagController {
+
+    @Resource
+    private DanKnowledgeTagService danKnowledgeTagService;
+
+    @PostMapping("/list")
+    public Result<List<DanKnowledgeTag>> list() {
+        return Result.success(danKnowledgeTagService.listAll());
+    }
+
+    @PostMapping("/save")
+    public Result<DanKnowledgeTag> save(@RequestBody DanKnowledgeTag tag) {
+        return Result.success(danKnowledgeTagService.saveTag(tag));
+    }
+
+    @PostMapping("/delete")
+    public Result<Void> delete(@RequestParam Long id) {
+        boolean success = danKnowledgeTagService.deleteTag(id);
+        return success ? Result.success(null) : Result.error("删除失败");
+    }
+}