From 9f9e043849b6f497e00399900ff234cf097eba82 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期三, 14 十月 2026 17:04:33 +0800
Subject: [PATCH] fix: 修改上下文

---
 src/main/java/com/custom/webui/controller/ChatController.java |   87 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/custom/webui/controller/ChatController.java b/src/main/java/com/custom/webui/controller/ChatController.java
index c7bd0e0..b7a2559 100644
--- a/src/main/java/com/custom/webui/controller/ChatController.java
+++ b/src/main/java/com/custom/webui/controller/ChatController.java
@@ -1,13 +1,17 @@
 package com.custom.webui.controller;
 
 import com.custom.webui.dto.req.ChatCreateRequest;
+import com.custom.webui.dto.req.ChatGroupMoveRequest;
 import com.custom.webui.dto.req.ChatUpdateRequest;
 import com.custom.webui.dto.resp.ChatDTO;
 import com.custom.webui.dto.resp.Result;
 import com.custom.webui.security.CurrentUser;
+import com.custom.webui.service.ChatExportService;
 import com.custom.webui.service.ChatService;
 import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -18,6 +22,8 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 /** 浼氳瘽 CRUD 鎺ュ彛锛屽搴斾晶杈规爮鐨勫璇濆垪琛ㄣ�� */
@@ -27,11 +33,20 @@
 public class ChatController {
 
     private final ChatService chatService;
+    private final ChatExportService chatExportService;
 
-    /** 褰撳墠鐢ㄦ埛鐨勫叏閮ㄤ細璇濓紝鎸夋渶杩戞椿璺冩帓搴� */
+    /**
+     * 褰撳墠鐢ㄦ埛鐨勪細璇濆垪琛ㄣ��
+     *
+     * <p>鎺掑簭鐢卞悗绔浐瀹氫负銆岀疆椤朵紭鍏堬紝鍏舵鏈�杩戞椿璺冦�嶁�斺�� 鍓嶇鍙礋璐f寜鏃堕棿鍒嗙粍锛�
+     * 涓嶉噸鏂版帓搴忥紝閬垮厤涓よ竟瑙勫垯涓嶄竴鑷村鑷村垪琛ㄩ『搴忚烦鍔ㄣ��
+     *
+     * @param archived false锛堥粯璁わ級= 涓诲垪琛紱true = 褰掓。鍒楄〃
+     */
     @GetMapping
-    public Result<List<ChatDTO>> list() {
-        return Result.success(chatService.listByUser(CurrentUser.requireUserId()));
+    public Result<List<ChatDTO>> list(
+            @RequestParam(value = "archived", defaultValue = "false") boolean archived) {
+        return Result.success(chatService.listByUser(CurrentUser.requireUserId(), archived));
     }
 
     /**
@@ -40,13 +55,17 @@
      * <p>鍚屾椂鍖归厤浼氳瘽鏍囬涓庢秷鎭唴瀹� 鈥斺�� 鐢ㄦ埛寰�寰�璁板緱銆岃亰杩囦粈涔堛�嶅嵈鎯充笉璧峰師璇濓紝
      * 鑰屾爣棰樺彧鏄鏉℃彁闂殑鎴柇锛屽彧鎼滄爣棰樹細婕忔帀澶ч噺缁撴灉銆�
      *
-     * @param q     鍏抽敭璇嶏紱涓虹┖鏃惰繑鍥炵┖鍒楄〃
-     * @param limit 鏈�澶氳繑鍥炴潯鏁帮紝榛樿 30锛屼笂闄� 100
+     * @param q        鍏抽敭璇嶏紱涓虹┖鏃惰繑鍥炵┖鍒楄〃
+     * @param limit    鏈�澶氳繑鍥炴潯鏁帮紝榛樿 30锛屼笂闄� 100
+     * @param archived 鎼滅储鑼冨洿锛氶粯璁ゅ彧鍦ㄦ湭褰掓。鐨勫璇濋噷鎼滐紝
+     *                 鍦ㄣ�屽綊妗e璇濄�嶇晫闈㈤噷鎼滃垯浼� true 鍙悳褰掓。鐨�
      */
     @GetMapping("/search")
-    public Result<List<ChatDTO>> search(@RequestParam("q") String q,
-                                       @RequestParam(value = "limit", defaultValue = "30") int limit) {
-        return Result.success(chatService.search(CurrentUser.requireUserId(), q, limit));
+    public Result<List<ChatDTO>> search(
+            @RequestParam("q") String q,
+            @RequestParam(value = "limit", defaultValue = "30") int limit,
+            @RequestParam(value = "archived", defaultValue = "false") boolean archived) {
+        return Result.success(chatService.search(CurrentUser.requireUserId(), q, limit, archived));
     }
 
     /** 鏂板缓浼氳瘽 */
@@ -56,7 +75,12 @@
         return Result.success(chatService.create(CurrentUser.requireUserId(), request));
     }
 
-    /** 淇敼浼氳瘽鏍囬鎴栨ā鍨嬪弬鏁帮紙temperature / top_p / systemPrompt / modelName锛� */
+    /**
+     * 淇敼浼氳瘽锛氭爣棰樸�佹ā鍨嬪弬鏁般�佺疆椤躲�佸綊妗c��
+     *
+     * <p>瀛楁涓� null 琛ㄧず涓嶆敼锛屽洜姝ゃ�岄噸鍛藉悕銆嶃�岀疆椤躲�嶃�屽綊妗c�嶉兘澶嶇敤杩欎竴涓帴鍙o紝
+     * 鍓嶇鍙彁浜ら渶瑕佸彉鍖栫殑瀛楁銆�
+     */
     @PutMapping("/{id}")
     public Result<ChatDTO> update(@PathVariable Long id,
                                  @Valid @RequestBody ChatUpdateRequest request) {
@@ -69,4 +93,49 @@
         chatService.delete(CurrentUser.requireUserId(), id);
         return Result.success();
     }
+
+    /**
+     * 鎶婁細璇濈Щ鍏� / 绉诲嚭鍒嗙粍銆�
+     *
+     * <p>body 閲� {@code groupId: null} 琛ㄧず绉诲嚭鍒嗙粍锛堝洖鍒版湭鍒嗙粍銆佺户缁寜鏃堕棿褰掔被锛夈��
+     * 鍗曠嫭涓�涓鐐规槸鍥犱负 {@code PUT /api/chats/{id}} 鐨勭害瀹氭槸
+     * 銆屽瓧娈典负 null = 涓嶄慨鏀广�嶏紝涓よ�呭湪鍚屼竴涓瓧娈典笂浼氭墦鏋躲��
+     */
+    @PutMapping("/{id}/group")
+    public Result<ChatDTO> moveToGroup(@PathVariable Long id,
+                                       @RequestBody(required = false) ChatGroupMoveRequest request) {
+        return Result.success(chatService.moveToGroup(
+                CurrentUser.requireUserId(), id, request == null ? null : request.getGroupId()));
+    }
+
+    /**
+     * 瀵煎嚭浼氳瘽涓� json / txt / pdf銆�
+     *
+     * <p>鐢� {@link ResponseEntity} 鑰屼笉鏄粺涓�鐨� {@code Result} 鍖呰锛�
+     * 瀵煎嚭瑕佽繑鍥炵殑鏄�**鏂囦欢鏈綋**锛屽涓�灞� JSON 灏辨病娉曠洿鎺ヤ繚瀛樹簡
+     * 锛堣繖涓� SSE 涓嶈蛋缁熶竴鍖呰鏄悓涓�涓悊鐢憋級銆�
+     */
+    @GetMapping("/{id}/export")
+    public ResponseEntity<byte[]> export(
+            @PathVariable Long id,
+            @RequestParam(value = "format", defaultValue = "txt") String format) {
+        ChatExportService.ExportFile file = chatExportService.export(
+                CurrentUser.requireUserId(), id, ChatExportService.Format.parse(format));
+
+        return ResponseEntity.ok()
+                .header(HttpHeaders.CONTENT_TYPE, file.contentType())
+                // filename 鐢� ASCII 鍏滃簳锛宖ilename* 鐢� UTF-8 缂栫爜缁欐敮鎸佺殑鏍囧噯娴忚鍣ㄧ敤銆�
+                // 涓枃鏍囬涓嶈繖涔堝鐞嗕細鍑虹幇涔辩爜鎴栦笅杞藉け璐ワ紙RFC 5987锛夈��
+                .header(HttpHeaders.CONTENT_DISPOSITION,
+                        "attachment; filename=\"export." + extOf(file.filename()) + "\"; filename*=UTF-8''"
+                                + URLEncoder.encode(file.filename(), StandardCharsets.UTF_8)
+                                .replace("+", "%20"))
+                .header(HttpHeaders.CACHE_CONTROL, "no-store")
+                .body(file.data());
+    }
+
+    private String extOf(String filename) {
+        int dot = filename.lastIndexOf('.');
+        return dot >= 0 ? filename.substring(dot + 1) : "bin";
+    }
 }

--
Gitblit v1.9.1