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