From 83e1b4d0e661f11a407fd6ea86e906b9b87b7180 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 31 七月 2026 17:57:09 +0800
Subject: [PATCH] feat(aftersales): 售后工单新增问题类型和严重程度字段

---
 yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java |  149 ++++++++++++++++++++++++-------------------------
 1 files changed, 73 insertions(+), 76 deletions(-)

diff --git a/yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java b/yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java
index 6c87be8..2d30199 100644
--- a/yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java
+++ b/yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java
@@ -1,39 +1,30 @@
 package cn.iocoder.yudao.module.ai.controller.admin.knowledge;
 
-import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.*;
-import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO;
 import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeSegmentDO;
 import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeDocumentService;
 import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeSegmentService;
 import cn.iocoder.yudao.module.ai.service.knowledge.bo.AiKnowledgeSegmentSearchReqBO;
 import cn.iocoder.yudao.module.ai.service.knowledge.bo.AiKnowledgeSegmentSearchRespBO;
 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 jakarta.annotation.Resource;
 import jakarta.validation.Valid;
-import org.hibernate.validator.constraints.URL;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
+import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
-@Tag(name = "绠$悊鍚庡彴 - AI 鐭ヨ瘑搴撴钀�")
+@Tag(name = "绠$悊鍚庡彴 - AI 鐭ヨ瘑搴撳垎娈�")
 @RestController
 @RequestMapping("/ai/knowledge/segment")
-@Validated
 public class AiKnowledgeSegmentController {
 
     @Resource
@@ -41,99 +32,105 @@
     @Resource
     private AiKnowledgeDocumentService documentService;
 
-    @GetMapping("/get")
-    @Operation(summary = "鑾峰彇娈佃惤璇︽儏")
-    @Parameter(name = "id", description = "娈佃惤缂栧彿", required = true, example = "1024")
+    @GetMapping("/split")
+    @Operation(summary = "棰勮鏂囨。鍒囧垎缁撴灉")
     @PreAuthorize("@ss.hasPermission('ai:knowledge:query')")
-    public CommonResult<AiKnowledgeSegmentRespVO> getKnowledgeSegment(@RequestParam("id") Long id) {
-        AiKnowledgeSegmentDO segment = segmentService.getKnowledgeSegment(id);
-        return success(BeanUtils.toBean(segment, AiKnowledgeSegmentRespVO.class));
+    public CommonResult<List<AiKnowledgeSegmentSplitRespVO>> previewSplit(@Valid AiKnowledgeSegmentSplitReqVO reqVO) {
+        String fileUrl = reqVO.getUrl();
+        if (fileUrl == null || fileUrl.isEmpty()) {
+            throw new IllegalArgumentException("鏂囨。 URL 涓嶈兘涓虹┖");
+        }
+        // 浠� URL 璺緞涓彁鍙栨枃浠跺悕
+        String name = fileUrl;
+        int queryIdx = name.indexOf('?');
+        if (queryIdx > 0) name = name.substring(0, queryIdx);
+        int slashIdx = name.lastIndexOf('/');
+        name = slashIdx >= 0 ? name.substring(slashIdx + 1) : name;
+        List<String> segments = documentService.previewSplit(fileUrl, name, reqVO.getSegmentMaxTokens());
+        List<AiKnowledgeSegmentSplitRespVO> result = new ArrayList<>();
+        for (String content : segments) {
+            result.add(new AiKnowledgeSegmentSplitRespVO()
+                    .setContent(content)
+                    .setContentLength(content.length())
+                    .setTokens(estimateTokens(content)));
+        }
+        return success(result);
+    }
+
+    private int estimateTokens(String text) {
+        if (text == null || text.isEmpty()) return 0;
+        int chineseChars = 0, englishWords = 0;
+        for (char c : text.toCharArray()) {
+            if (c >= 0x4E00 && c <= 0x9FA5) chineseChars++;
+        }
+        for (String word : text.split("\\s+")) {
+            if (word.matches(".*[a-zA-Z].*")) englishWords++;
+        }
+        return chineseChars + (int) (englishWords * 1.3);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "鑾峰彇鍒嗘")
+    @PreAuthorize("@ss.hasPermission('ai:knowledge:query')")
+    public CommonResult<AiKnowledgeSegmentRespVO> getSegment(@RequestParam("id") Long id) {
+        return success(BeanUtils.toBean(segmentService.getSegment(id), AiKnowledgeSegmentRespVO.class));
     }
 
     @GetMapping("/page")
-    @Operation(summary = "鑾峰彇娈佃惤鍒嗛〉")
+    @Operation(summary = "鑾峰彇鍒嗘鍒嗛〉")
     @PreAuthorize("@ss.hasPermission('ai:knowledge:query')")
-    public CommonResult<PageResult<AiKnowledgeSegmentRespVO>> getKnowledgeSegmentPage(
-            @Valid AiKnowledgeSegmentPageReqVO pageReqVO) {
-        PageResult<AiKnowledgeSegmentDO> pageResult = segmentService.getKnowledgeSegmentPage(pageReqVO);
+    public CommonResult<PageResult<AiKnowledgeSegmentRespVO>> getSegmentPage(@Valid AiKnowledgeSegmentPageReqVO pageReqVO) {
+        PageResult<AiKnowledgeSegmentDO> pageResult = segmentService.getSegmentPage(pageReqVO);
         return success(BeanUtils.toBean(pageResult, AiKnowledgeSegmentRespVO.class));
     }
 
     @PostMapping("/create")
-    @Operation(summary = "鍒涘缓娈佃惤")
+    @Operation(summary = "鍒涘缓鍒嗘")
     @PreAuthorize("@ss.hasPermission('ai:knowledge:create')")
-    public CommonResult<Long> createKnowledgeSegment(@Valid @RequestBody AiKnowledgeSegmentSaveReqVO createReqVO) {
-        return success(segmentService.createKnowledgeSegment(createReqVO));
+    public CommonResult<Long> createSegment(@Valid @RequestBody AiKnowledgeSegmentSaveReqVO saveReqVO) {
+        return success(segmentService.createSegment(saveReqVO));
     }
 
     @PutMapping("/update")
-    @Operation(summary = "鏇存柊娈佃惤鍐呭")
+    @Operation(summary = "鏇存柊鍒嗘")
     @PreAuthorize("@ss.hasPermission('ai:knowledge:update')")
-    public CommonResult<Boolean> updateKnowledgeSegment(@Valid @RequestBody AiKnowledgeSegmentSaveReqVO reqVO) {
-        segmentService.updateKnowledgeSegment(reqVO);
-        return success(true);
-    }
-
-    @PutMapping("/update-status")
-    @Operation(summary = "鍚鐢ㄦ钀藉唴瀹�")
-    @PreAuthorize("@ss.hasPermission('ai:knowledge:update')")
-    public CommonResult<Boolean> updateKnowledgeSegmentStatus(
-            @Valid @RequestBody AiKnowledgeSegmentUpdateStatusReqVO reqVO) {
-        segmentService.updateKnowledgeSegmentStatus(reqVO);
+    public CommonResult<Boolean> updateSegment(@Valid @RequestBody AiKnowledgeSegmentSaveReqVO saveReqVO) {
+        segmentService.updateSegment(saveReqVO);
         return success(true);
     }
 
     @DeleteMapping("/delete")
-    @Operation(summary = "鍒犻櫎娈佃惤")
-    @Parameter(name = "id", description = "娈佃惤缂栧彿", required = true, example = "1024")
+    @Operation(summary = "鍒犻櫎鍒嗘")
     @PreAuthorize("@ss.hasPermission('ai:knowledge:delete')")
-    public CommonResult<Boolean> deleteKnowledgeSegment(@RequestParam("id") Long id) {
-        segmentService.deleteKnowledgeSegment(id);
+    public CommonResult<Boolean> deleteSegment(@RequestParam("id") Long id) {
+        segmentService.deleteSegment(id);
         return success(true);
     }
 
-    @GetMapping("/split")
-    @Operation(summary = "鍒囩墖鍐呭")
-    @Parameters({
-            @Parameter(name = "url", description = "鏂囨。 URL", required = true),
-            @Parameter(name = "segmentMaxTokens", description = "鍒嗘鐨勬渶澶� Token 鏁�", required = true)
-    })
-    @PreAuthorize("@ss.hasPermission('ai:knowledge:query')")
-    public CommonResult<List<AiKnowledgeSegmentRespVO>> splitContent(
-            @RequestParam("url") @URL String url,
-            @RequestParam(value = "segmentMaxTokens") Integer segmentMaxTokens) {
-        List<AiKnowledgeSegmentDO> segments = segmentService.splitContent(url, segmentMaxTokens);
-        return success(BeanUtils.toBean(segments, AiKnowledgeSegmentRespVO.class));
+    @PutMapping("/update-status")
+    @Operation(summary = "鏇存柊鍒嗘鐘舵��")
+    @PreAuthorize("@ss.hasPermission('ai:knowledge:update')")
+    public CommonResult<Boolean> updateSegmentStatus(@Valid @RequestBody AiKnowledgeSegmentUpdateStatusReqVO updateStatusReqVO) {
+        segmentService.updateSegmentStatus(updateStatusReqVO);
+        return success(true);
     }
 
     @GetMapping("/get-process-list")
-    @Operation(summary = "鑾峰彇鏂囨。澶勭悊鍒楄〃")
-    @Parameter(name = "documentIds", description = "鏂囨。缂栧彿鍒楄〃", required = true, example = "1,2,3")
+    @Operation(summary = "鑾峰彇鏂囨。澶勭悊杩涘害")
     @PreAuthorize("@ss.hasPermission('ai:knowledge:query')")
-    public CommonResult<List<AiKnowledgeSegmentProcessRespVO>> getKnowledgeSegmentProcessList(
-            @RequestParam("documentIds") List<Long> documentIds) {
-        List<AiKnowledgeSegmentProcessRespVO> list = segmentService.getKnowledgeSegmentProcessList(documentIds);
-        return success(list);
+    public CommonResult<List<AiKnowledgeSegmentProcessRespVO>> getProcessList(@RequestParam("documentIds") List<Long> documentIds) {
+        return success(documentService.getDocumentProcessingProgress(documentIds));
     }
 
-    @GetMapping("/search")
-    @Operation(summary = "鎼滅储娈佃惤鍐呭")
+    @PostMapping("/search")
+    @Operation(summary = "妫�绱㈠垎娈碉紙RAG 鍚戦噺妫�绱級")
     @PreAuthorize("@ss.hasPermission('ai:knowledge:query')")
-    public CommonResult<List<AiKnowledgeSegmentSearchRespVO>> searchKnowledgeSegment(
-            @Valid AiKnowledgeSegmentSearchReqVO reqVO) {
-        // 1. 鎼滅储娈佃惤
-        List<AiKnowledgeSegmentSearchRespBO> segments = segmentService
-                .searchKnowledgeSegment(BeanUtils.toBean(reqVO, AiKnowledgeSegmentSearchReqBO.class));
-        if (CollUtil.isEmpty(segments)) {
-            return success(Collections.emptyList());
-        }
-
-        // 2. 鎷兼帴 VO
-        Map<Long, AiKnowledgeDocumentDO> documentMap = documentService.getKnowledgeDocumentMap(convertSet(
-                segments, AiKnowledgeSegmentSearchRespBO::getDocumentId));
-        return success(BeanUtils.toBean(segments, AiKnowledgeSegmentSearchRespVO.class,
-                segment -> MapUtils.findAndThen(documentMap, segment.getDocumentId(),
-                        document -> segment.setDocumentName(document.getName()))));
+    public CommonResult<List<AiKnowledgeSegmentSearchRespVO>> searchSegments(@Valid @RequestBody AiKnowledgeSegmentSearchReqVO searchReqVO) {
+        AiKnowledgeSegmentSearchReqBO searchReqBO = BeanUtils.toBean(searchReqVO, AiKnowledgeSegmentSearchReqBO.class);
+        List<AiKnowledgeSegmentSearchRespBO> results = segmentService.searchSegments(searchReqBO);
+        return success(results.stream()
+                .map(bo -> BeanUtils.toBean(bo, AiKnowledgeSegmentSearchRespVO.class))
+                .collect(Collectors.toList()));
     }
 
 }

--
Gitblit v1.9.3