From ccf1a44c001e233c158bd168dc2d0d96721af929 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期一, 12 十月 2026 09:31:53 +0800
Subject: [PATCH] fix: 修改后台

---
 src/main/java/com/custom/webui/dto/req/ChatUpdateRequest.java    |   13 +
 src/main/java/com/custom/webui/dto/resp/ChatDTO.java             |   23 +++
 src/main/java/com/custom/webui/config/SecurityConfig.java        |    7 
 src/main/java/com/custom/webui/entity/Chat.java                  |   33 ++++
 src/main/java/com/custom/webui/service/impl/ChatServiceImpl.java |  104 +++++++++++++-
 src/main/java/com/custom/webui/service/ChatService.java          |   37 ++++
 src/main/resources/db/h2-schema.sql                              |   15 ++
 src/main/java/com/custom/webui/controller/ChatController.java    |   87 +++++++++++-
 src/main/java/com/custom/webui/config/StartupDiagnostics.java    |    4 
 pom.xml                                                          |   25 +++
 src/main/resources/application.yml                               |   20 ++
 11 files changed, 341 insertions(+), 27 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7b36be4..143bac9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,6 +91,31 @@
             <optional>true</optional>
         </dependency>
 
+        <!--
+          PDF 瀵煎嚭锛圓pache PDFBox锛孉pache-2.0锛�
+
+          涓轰粈涔堟槸 PDFBox 鑰屼笉鏄� iText / openhtmltopdf锛�
+            - iText 鏄� AGPL锛岄棴婧愬垎鍙戣涔板晢涓氭巿鏉冿紝鏈」鐩笉閫傚悎
+            - openhtmltopdf 渚濊禆閾惧緢闀匡紙鑷繁涔熻鎷� PDFBox锛夛紝鑰屾垜浠彧闇�瑕�
+              銆屾爣棰� + 鍏冧俊鎭� + 鑻ュ共鏉℃秷鎭�嶈繖涓�绉嶇増寮忥紝鐢ㄤ笉鐫� HTML/CSS 鎺掔増寮曟搸
+            - PDFBox 鍙涓や釜浼犻�掍緷璧栵紙fontbox銆乸dfbox-io锛夛紝涓旇兘鐩存帴宓屽叆
+              绯荤粺涓枃瀛椾綋骞舵寜瀛愰泦瑁佸壀锛屼竴涓腑鏂囧璇濆鍑虹殑 PDF 閫氬父鍙湁鍑犲崄 KB
+
+          commons-logging 涓轰粈涔堣鏄惧紡閽夌増鏈細pdfbox-parent 閲屽0鏄庣殑鏄� 1.3.3锛�
+          鑰屾湰椤圭洰绂荤嚎浠撳簱閲屽彧鏈� 1.3.4 鈥斺�� 涓嶉拤鐨勮瘽绂荤嚎鏋勫缓浼氳В鏋愬け璐ャ��
+          涓よ�呮槸鍚屼竴涓荤嚎鐨勮ˉ涓佺増鏈紝琛屼负鍏煎銆�
+        -->
+        <dependency>
+            <groupId>org.apache.pdfbox</groupId>
+            <artifactId>pdfbox</artifactId>
+            <version>3.0.3</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.3.4</version>
+        </dependency>
+
         <!-- 娴嬭瘯 -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
diff --git a/src/main/java/com/custom/webui/config/SecurityConfig.java b/src/main/java/com/custom/webui/config/SecurityConfig.java
index 14defd3..e71dbc7 100644
--- a/src/main/java/com/custom/webui/config/SecurityConfig.java
+++ b/src/main/java/com/custom/webui/config/SecurityConfig.java
@@ -103,8 +103,11 @@
                 "http://10.*.*.*:*"));
         config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
         config.setAllowedHeaders(List.of("*"));
-        // SSE 涓嶉渶瑕佹毚闇查澶栧ご锛屼繚鐣� Content-Type 渚夸簬鍓嶇鍒ゆ柇
-        config.setExposedHeaders(List.of("Content-Type"));
+        // 娴忚鍣ㄥ彧鍏佽鍓嶇鑴氭湰璇诲彇**鏄惧紡鏆撮湶**鐨勫搷搴斿ご銆�
+        // 瀵煎嚭鎺ュ彛鐨勫缓璁枃浠跺悕灏辨斁鍦� Content-Disposition 閲岋細
+        // 涓嶆毚闇茬殑璇濓紝鍗充娇鍝嶅簲閲屾湁杩欎釜澶村墠绔篃璇讳笉鍒帮紝
+        // 鍙兘閫�鍥炴湰鍦版嫾鐨勬枃浠跺悕 鈥斺�� 涓枃鏍囬涓庢椂闂存埑灏变涪浜嗐��
+        config.setExposedHeaders(List.of("Content-Type", "Content-Disposition"));
         config.setAllowCredentials(true);
         config.setMaxAge(3600L);
 
diff --git a/src/main/java/com/custom/webui/config/StartupDiagnostics.java b/src/main/java/com/custom/webui/config/StartupDiagnostics.java
index 51c13e5..8a1b4b9 100644
--- a/src/main/java/com/custom/webui/config/StartupDiagnostics.java
+++ b/src/main/java/com/custom/webui/config/StartupDiagnostics.java
@@ -84,6 +84,7 @@
     private final StorageProperties storageProperties;
     private final LlmProperties llmProperties;
     private final ObjectMapper objectMapper;
+    private final com.custom.webui.util.PdfFontSupport pdfFontSupport;
 
     // ------------------------------------------------------------------
     // 涓�銆佸瓨鍌ㄤ綅缃�
@@ -100,6 +101,9 @@
         log.info("  閰嶇疆鍊�       : {}", storageProperties.getLocation());
         log.info("  瀹為檯涓婁紶鐩綍 : {}", uploadRoot);
         log.info("  鐩綍鐘舵��     : {}", describe(uploadRoot));
+        // 椤轰究鎶ヤ竴涓� PDF 瀵煎嚭鐨勫瓧浣擄細鎵句笉鍒颁腑鏂囧瓧浣撴椂 PDF 瀵煎嚭浼氬け璐ワ紝
+        // 鑰岃繖浠朵簨鍦ㄥ惎鍔ㄦ椂璇翠竴鍙ワ紝姣旂瓑鐢ㄦ埛鐐逛簡銆屼笅杞� PDF銆嶅啀鎶ラ敊鍙嬪ソ寰楀
+        log.info("  瀵煎嚭鑷     : {}", pdfFontSupport.describe());
         log.info("=".repeat(66));
     }
 
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";
+    }
 }
diff --git a/src/main/java/com/custom/webui/dto/req/ChatUpdateRequest.java b/src/main/java/com/custom/webui/dto/req/ChatUpdateRequest.java
index ce159d4..a1eb11d 100644
--- a/src/main/java/com/custom/webui/dto/req/ChatUpdateRequest.java
+++ b/src/main/java/com/custom/webui/dto/req/ChatUpdateRequest.java
@@ -5,7 +5,7 @@
 import lombok.Data;
 
 /**
- * 淇敼浼氳瘽璇锋眰浣擄紝鐢ㄤ簬鏀规爣棰樺拰/鎴栨敼妯″瀷鍙傛暟銆�
+ * 淇敼浼氳瘽璇锋眰浣擄紝鐢ㄤ簬鏀规爣棰樸�佹ā鍨嬪弬鏁般�佺疆椤朵笌褰掓。銆�
  *
  * <p>瀛楁涓� null 琛ㄧず銆屼笉淇敼銆嶏紝鍥犳鍓嶇鍋氬眬閮ㄦ洿鏂版椂鍙紶闇�瑕佹敼鐨勫瓧娈靛嵆鍙��
  */
@@ -17,4 +17,15 @@
 
     @Valid
     private ChatMetaRequest meta;
+
+    /**
+     * 缃《寮�鍏炽�俷ull = 涓嶆敼銆�
+     *
+     * <p>娉ㄦ剰锛氱疆椤�**涓嶄細**鍒锋柊 {@code updatedAt} 鈥斺��
+     * 鍚﹀垯缃《涓�涓嬪氨浼氳鍒ゅ畾鎴愩�屽垰鍒氭椿璺冦�嶏紝鍦ㄦ椂闂村垎缁勯噷浠庛�屾洿鏃┿�嶈烦鍒般�屼粖澶┿�嶃��
+     */
+    private Boolean pinned;
+
+    /** 褰掓。寮�鍏炽�俷ull = 涓嶆敼銆傚綊妗e悓鏍锋槸杞敹璧凤紝涓嶅埛鏂� updatedAt */
+    private Boolean archived;
 }
diff --git a/src/main/java/com/custom/webui/dto/resp/ChatDTO.java b/src/main/java/com/custom/webui/dto/resp/ChatDTO.java
index 677630c..f946946 100644
--- a/src/main/java/com/custom/webui/dto/resp/ChatDTO.java
+++ b/src/main/java/com/custom/webui/dto/resp/ChatDTO.java
@@ -27,6 +27,29 @@
 
     private LocalDateTime updatedAt;
 
+    /**
+     * 鏄惁缃《銆�
+     *
+     * <p>鍓嶇鎹鎶婁細璇濇斁杩涙渶涓婃柟鐨勩�岀疆椤躲�嶅垎缁勶紝骞跺湪鏍囬鍓嶆樉绀哄浘閽夈��
+     */
+    private Boolean pinned;
+
+    /** 缃《鏃堕棿锛岀疆椤跺垎缁勬寜瀹冨�掑簭锛堜笌娲昏穬鏃堕棿鏃犲叧锛� */
+    private LocalDateTime pinnedAt;
+
+    /** 鏄惁宸插綊妗o紱涓诲垪琛ㄥ彧鍙� archived=false锛屽綊妗e垪琛ㄥ彧鍙� true */
+    private Boolean archived;
+
+    private LocalDateTime archivedAt;
+
+    /**
+     * 鎵�灞炶嚜寤哄垎缁� id锛寋@code null} = 鏈垎缁勩��
+     *
+     * <p>鍓嶇灏辨嬁杩欎釜瀛楁鎶婁細璇濇寕鍒板搴斿垎缁勪笅锛屼笉闇�瑕佸啀涓恒�屾煇涓垎缁勯噷鏈夊摢浜涗細璇濄��
+     * 鍗曠嫭鍙戣姹� 鈥斺�� 浼氳瘽鍒楄〃鏈潵灏变竴娆¤繑鍥炰簡鍏ㄩ儴銆�
+     */
+    private Long groupId;
+
     /** 浼氳瘽鍐呮秷鎭�绘暟锛岀敤浜庝晶杈规爮灞曠ず */
     private Long messageCount;
 
diff --git a/src/main/java/com/custom/webui/entity/Chat.java b/src/main/java/com/custom/webui/entity/Chat.java
index 6a3a1e9..fe77f6a 100644
--- a/src/main/java/com/custom/webui/entity/Chat.java
+++ b/src/main/java/com/custom/webui/entity/Chat.java
@@ -29,6 +29,39 @@
      */
     private String meta;
 
+    /**
+     * 鏄惁缃《锛�1=缃《锛夈��
+     *
+     * <p>鐢� {@code Boolean} 鑰屼笉鏄� {@code boolean}锛歁yBatis-Plus 鏇存柊鏃�
+     * 鍙妸闈� null 瀛楁鍐欒繘 SQL锛屾墍浠� partial update 鍦烘櫙涓� null 鎵嶄唬琛ㄣ�屼笉淇敼銆嶃��
+     */
+    private Boolean pinned;
+
+    /**
+     * 缃《鏃堕棿锛岀疆椤跺尯鎸夊畠鍊掑簭銆�
+     *
+     * <p>涓嶅鐢� {@code updatedAt}锛氱疆椤跺尯鍐呴儴瑕佹寜銆岀疆椤剁殑鍏堝悗銆嶆帓锛�
+     * 鑰� updatedAt 浼氶殢鏂版秷鎭彉鍖栵紝瀵艰嚧缃《鐨勮�佸璇濊亰涓�鍙ュ氨璺冲埌鏈�鍓嶉潰銆�
+     */
+    private LocalDateTime pinnedAt;
+
+    /** 鏄惁褰掓。锛�1=宸插綊妗o紝涓诲垪琛ㄤ笉鏄剧ず锛屼絾鏁版嵁鍏ㄩ儴淇濈暀锛� */
+    private Boolean archived;
+
+    /** 褰掓。鏃堕棿锛屽綊妗e垪琛ㄦ寜瀹冨�掑簭 */
+    private LocalDateTime archivedAt;
+
+    /**
+     * 鎵�灞炶嚜寤哄垎缁� id锛寋@code null} 琛ㄧず鏈垎缁勩��
+     *
+     * <p>鏈垎缁勭殑浼氳瘽缁х画鎸夈�屼粖澶� / 鏄ㄥぉ / 鏇存棭銆嶈嚜鍔ㄥ綊绫伙紱
+     * 涓�鏃︽斁杩涘垎缁勶紝灏卞彧鍑虹幇鍦ㄨ鍒嗙粍涓嬶紙涓嶅啀閲嶅鍑虹幇鍦ㄦ椂闂村垎缁勯噷锛夈��
+     *
+     * <p>鐢� NULL 鑰屼笉鏄摠鍏靛�艰〃杈俱�屾湭鍒嗙粍銆嶏細鍝ㄥ叺鍊间細璁╂瘡涓垽鏂
+     * 閮借璁板緱鐗规畩澶勭悊锛岃繜鏃╂紡涓�澶勩��
+     */
+    private Long groupId;
+
     private LocalDateTime createdAt;
 
     private LocalDateTime updatedAt;
diff --git a/src/main/java/com/custom/webui/service/ChatService.java b/src/main/java/com/custom/webui/service/ChatService.java
index 7d6d65b..9b9b710 100644
--- a/src/main/java/com/custom/webui/service/ChatService.java
+++ b/src/main/java/com/custom/webui/service/ChatService.java
@@ -16,14 +16,25 @@
  */
 public interface ChatService {
 
-    /** 褰撳墠鐢ㄦ埛鐨勪細璇濆垪琛紝鎸夋洿鏂版椂闂村�掑簭锛堟渶杩戞椿璺冪殑鍦ㄦ渶涓婃柟锛� */
-    List<ChatDTO> listByUser(Long userId);
+    /**
+     * 褰撳墠鐢ㄦ埛鐨勪細璇濆垪琛ㄣ��
+     *
+     * <p>鎺掑簭鍥哄畾涓恒�岀疆椤朵紭鍏堛�嶏細
+     * <pre>
+     *   ORDER BY pinned DESC, pinned_at DESC, updated_at DESC
+     * </pre>
+     * 缃《鍖哄唴鎸夌疆椤舵椂闂村�掑簭锛堟渶杩戦拤涓婂幓鐨勫湪鏈�鍓嶏級锛�
+     * 闈炵疆椤跺尯閲� pinned_at 鍏ㄤ负 NULL锛屼簬鏄嚜鐒堕��鍖栦负銆屾寜鏈�杩戞椿璺冨�掑簭銆嶃��
+     *
+     * @param archived false = 涓诲垪琛紙鏈綊妗o級锛泃rue = 褰掓。鍒楄〃
+     */
+    List<ChatDTO> listByUser(Long userId, boolean archived);
 
     /** 鏂板缓浼氳瘽锛宼itle 涓虹┖鏃朵娇鐢ㄩ粯璁ゃ�屾柊瀵硅瘽銆� */
     ChatDTO create(Long userId, ChatCreateRequest request);
 
     /**
-     * 淇敼鏍囬鎴栨ā鍨嬪弬鏁帮紝瀛楁涓� null 琛ㄧず涓嶄慨鏀广��
+     * 淇敼鏍囬銆佹ā鍨嬪弬鏁般�佺疆椤舵垨褰掓。锛屽瓧娈典负 null 琛ㄧず涓嶄慨鏀广��
      *
      * @throws com.custom.webui.exception.BusinessException 浼氳瘽涓嶅瓨鍦ㄦ垨涓嶅睘浜庤鐢ㄦ埛锛�404/403锛�
      */
@@ -39,6 +50,19 @@
     /** 鏍¢獙浼氳瘽褰掑睘锛岃繑鍥炲疄浣擄紱涓嶅睘浜庤鐢ㄦ埛鏃舵姏 404锛堣�岄潪 403锛岄伩鍏嶆帰娴嬩粬浜轰細璇濇槸鍚﹀瓨鍦級 */
     Chat requireOwnedChat(Long userId, Long chatId);
 
+    /**
+     * 鎶婁細璇濈Щ鍏� / 绉诲嚭鍒嗙粍銆�
+     *
+     * <p>鍗曠嫭涓�涓柟娉曡�屼笉鏄杩� {@link #update}锛氶偅閲岀殑绾﹀畾鏄�
+     * 銆屽瓧娈典负 null 琛ㄧず涓嶄慨鏀广�嶏紝鑰屻�岀Щ鍑哄垎缁勩�嶆鏄鎶� groupId 缃负 null锛�
+     * 鍚屼竴涓瓧娈典笂鏃犳硶鍚屾椂琛ㄨ揪杩欎袱绉嶈涔夈��
+     *
+     * @param groupId 鐩爣鍒嗙粍 id锛沶ull 琛ㄧず绉诲嚭鍒嗙粍
+     * @throws com.custom.webui.exception.BusinessException 浼氳瘽涓嶅睘浜庤鐢ㄦ埛锛�404锛夛紝
+     *         鎴栫洰鏍囧垎缁勪笉瀛樺湪 / 涓嶅睘浜庤鐢ㄦ埛锛�404锛�
+     */
+    ChatDTO moveToGroup(Long userId, Long chatId, Long groupId);
+
     /** 璇诲彇浼氳瘽鐨勬ā鍨嬪弬鏁帮紝meta 涓虹┖鎴栭潪娉� JSON 鏃惰繑鍥炲叏 null 鐨勫璞� */
     ChatMetaRequest parseMeta(Chat chat);
 
@@ -53,9 +77,10 @@
      *
      * <p>鎺掑簭锛氬懡涓殑浼氳瘽鎸夋渶杩戞椿璺冩椂闂村�掑簭锛屾渶澶氳繑鍥� {@code limit} 鏉°��
      *
-     * @param keyword 鍏抽敭璇嶏紝绌虹櫧鍒欒繑鍥炵┖鍒楄〃锛堜笉杩斿洖鍏ㄩ儴锛岄伩鍏嶆妸鎼滅储妗�
-     *                褰撴垚銆屾棤杩囨护鍒楄〃銆嶈鐢級
+     * @param keyword  鍏抽敭璇嶏紝绌虹櫧鍒欒繑鍥炵┖鍒楄〃锛堜笉杩斿洖鍏ㄩ儴锛岄伩鍏嶆妸鎼滅储妗�
+     *                 褰撴垚銆屾棤杩囨护鍒楄〃銆嶈鐢級
+     * @param archived 鎼滅储鑼冨洿锛歠alse = 鏈綊妗o紙涓庝富鍒楄〃涓�鑷达級锛宼rue = 褰掓。
      * @return 鍛戒腑鐨勪細璇濓紝闄勫甫鍛戒腑鐗囨涓庡懡涓被鍨�
      */
-    List<ChatDTO> search(Long userId, String keyword, int limit);
+    List<ChatDTO> search(Long userId, String keyword, int limit, boolean archived);
 }
diff --git a/src/main/java/com/custom/webui/service/impl/ChatServiceImpl.java b/src/main/java/com/custom/webui/service/impl/ChatServiceImpl.java
index 246a831..d3cb235 100644
--- a/src/main/java/com/custom/webui/service/impl/ChatServiceImpl.java
+++ b/src/main/java/com/custom/webui/service/impl/ChatServiceImpl.java
@@ -15,6 +15,7 @@
 import com.custom.webui.mapper.MessageMapper;
 import com.custom.webui.mapper.UploadFileMapper;
 import com.custom.webui.service.ChatService;
+import com.custom.webui.service.ChatGroupService;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -50,13 +51,20 @@
     private final MessageMapper messageMapper;
     private final UploadFileMapper uploadFileMapper;
     private final ChatCollectionMapper chatCollectionMapper;
+    private final ChatGroupService chatGroupService;
     private final ObjectMapper objectMapper;
 
     @Override
-    public List<ChatDTO> listByUser(Long userId) {
+    public List<ChatDTO> listByUser(Long userId, boolean archived) {
         List<Chat> chats = chatMapper.selectList(
                 Wrappers.<Chat>lambdaQuery()
                         .eq(Chat::getUserId, userId)
+                        .eq(Chat::getArchived, archived)
+                        // 缃《浼樺厛锛屽叾娆$疆椤舵椂闂村�掑簭锛屾渶鍚庢椿璺冩椂闂村�掑簭銆�
+                        // 闈炵疆椤惰鐨� pinned_at 鍏ㄤ负 NULL锛岀浜屾帓搴忛敭绛夊悓鏃犳晥锛�
+                        // 浜庢槸鑷劧閫�鍖栨垚銆屾寜鏈�杩戞椿璺冨�掑簭銆嶃��
+                        .orderByDesc(Chat::getPinned)
+                        .orderByDesc(Chat::getPinnedAt)
                         .orderByDesc(Chat::getUpdatedAt));
         if (chats.isEmpty()) {
             return Collections.emptyList();
@@ -107,8 +115,22 @@
     public ChatDTO update(Long userId, Long chatId, ChatUpdateRequest request) {
         Chat existing = requireOwnedChat(userId, chatId);
 
-        Chat update = new Chat();
-        update.setId(chatId);
+        /*
+         * 杩欓噷鍒绘剰鐢� UpdateWrapper 閫愬垪鏄惧紡 SET锛岃�屼笉鏄� updateById(entity)锛�
+         *
+         * 1) updateById 榛樿**蹇界暐 null 瀛楁**锛岃�屻�屽彇娑堢疆椤躲�嶆伆鎭拌鎶�
+         *    pinned_at 鍐欏洖 NULL锛岀敤瀹炰綋浼� null 琛ㄨ揪涓嶄簡杩欎釜鎰忓浘銆�
+         * 2) updated_at 杩欎竴鍒楀湪 MySQL 閲屽甫 ON UPDATE CURRENT_TIMESTAMP锛�
+         *    鍙 UPDATE 璇彞涓嶆樉寮忔彁鍒板畠锛屽畠灏变細琚暟鎹簱鑷姩鍒锋柊銆�
+         *    鑰岀疆椤�/褰掓。灞炰簬**瑙嗗浘鏁寸悊**鎿嶄綔锛屼笉璇ヨ褰撴垚銆屽垰鍒氭椿璺冦�嶁�斺��
+         *    鍚﹀垯缃《涓�涓嬶紝浼氳瘽灏变細鍦ㄦ椂闂村垎缁勯噷浠庛�屾洿鏃┿�嶈烦鍒般�屼粖澶┿�嶃��
+         *    鏄惧紡 SET updated_at = 鍘熷�� 鏄敮涓�鑳藉帇浣忚鑷姩琛屼负鐨勬柟寮�
+         *    锛圡ySQL 鏂囨。锛氳鏄惧紡璧嬪�肩殑鍒椾笉浼氬啀璧� ON UPDATE锛夈��
+         */
+        LocalDateTime now = LocalDateTime.now();
+        var wrapper = Wrappers.<Chat>lambdaUpdate().eq(Chat::getId, chatId);
+
+        boolean contentChanged = false;
 
         if (request.getTitle() != null) {
             String title = request.getTitle().trim();
@@ -116,16 +138,34 @@
                 throw BusinessException.badRequest("鏍囬涓嶈兘涓虹┖");
             }
             // 闃插尽瓒呴暱鏍囬锛氬垪瀹� 255锛岃秴鍑洪儴鍒嗙洿鎺ユ埅鏂�屼笉鏄姤鏁版嵁搴撻敊璇�
-            update.setTitle(title.length() > 255 ? title.substring(0, 255) : title);
+            wrapper.set(Chat::getTitle, title.length() > 255 ? title.substring(0, 255) : title);
+            contentChanged = true;
         }
 
         if (request.getMeta() != null) {
             // meta 鏄暣浣撹鐩栬涔夛細鍓嶇搴旀彁浜ゅ畬鏁寸殑鍙傛暟瀵硅薄
-            update.setMeta(writeMeta(request.getMeta()));
+            wrapper.set(Chat::getMeta, writeMeta(request.getMeta()));
+            contentChanged = true;
         }
 
-        update.setUpdatedAt(LocalDateTime.now());
-        chatMapper.updateById(update);
+        // ---- 缃《 ----
+        // 缃《鏃惰褰� pinned_at锛岀疆椤跺尯鍥犳鎸夈�岄拤涓婂幓鐨勫厛鍚庛�嶆帓搴忥紱
+        // 鍙栨秷缃《鍒欐竻鍥� NULL锛屼笉璁╂棫鏃堕棿娈嬬暀涓嬪幓褰卞搷鍚庣画鎺掑簭銆�
+        if (request.getPinned() != null) {
+            boolean pinned = request.getPinned();
+            wrapper.set(Chat::getPinned, pinned);
+            wrapper.set(Chat::getPinnedAt, pinned ? now : null);
+        }
+
+        // ---- 褰掓。 ----
+        if (request.getArchived() != null) {
+            boolean archived = request.getArchived();
+            wrapper.set(Chat::getArchived, archived);
+            wrapper.set(Chat::getArchivedAt, archived ? now : null);
+        }
+
+        wrapper.set(Chat::getUpdatedAt, contentChanged ? now : existing.getUpdatedAt());
+        chatMapper.update(null, wrapper);
 
         Chat refreshed = chatMapper.selectById(chatId);
         Long messageCount = messageMapper.selectCount(
@@ -134,7 +174,9 @@
                         Wrappers.<ChatCollection>lambdaQuery().eq(ChatCollection::getChatId, chatId))
                 .stream().map(ChatCollection::getCollectionName).toList();
 
-        log.debug("鏇存柊浼氳瘽 chatId={} 鍘焟eta={} 鏂癿eta={}", chatId, existing.getMeta(), refreshed.getMeta());
+        log.debug("鏇存柊浼氳瘽 chatId={} 鍘焟eta={} 鏂癿eta={} pinned={} archived={}",
+                chatId, existing.getMeta(), refreshed.getMeta(),
+                refreshed.getPinned(), refreshed.getArchived());
         return toDto(refreshed, messageCount, collections);
     }
 
@@ -163,6 +205,38 @@
         chatMapper.deleteById(chatId);
         log.info("鍒犻櫎浼氳瘽 userId={} chatId={} 杩炲甫鍒犻櫎娑堟伅 {} 鏉°�佽В缁戞枃浠� {} 涓�",
                 userId, chatId, msgDeleted, boundFiles.size());
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public ChatDTO moveToGroup(Long userId, Long chatId, Long groupId) {
+        Chat chat = requireOwnedChat(userId, chatId);
+
+        if (groupId != null) {
+            // 鐩爣鍒嗙粍蹇呴』鏄嚜宸辩殑 鈥斺�� 鍚﹀垯鐢ㄦ埛鍙互鎶婁細璇濄�岀Щ杩涖�嶅埆浜虹殑鍒嗙粍 id锛�
+            // 铏界劧鐪嬩笉鍒板鏂圭殑鍐呭锛屼絾浼氬湪瀵规柟鐨勫垪琛ㄩ噷鍑┖澶氬嚭涓�鏉′笉灞炰簬浠栫殑浼氳瘽
+            chatGroupService.requireOwnedGroup(userId, groupId);
+        }
+
+        // 涓�娆� UPDATE 鍚屾椂澶勭悊涓や欢浜嬶細
+        //   1. group_id 瑕佽兘鍐欐垚 NULL锛堢Щ鍑哄垎缁勶級锛屾墍浠ョ敤 UpdateWrapper 鏄惧紡 SET锛�
+        //      瀹炰綋閲岀殑 null 瀛楁浼氳 MyBatis-Plus 蹇界暐锛岃〃杈句笉浜嗐�岀疆绌恒��
+        //   2. updated_at 鏄惧紡鍐欏洖鍘熷�� 鈥斺�� 鏁寸悊鍔ㄤ綔涓嶈琚綋鎴愩�屽垰鍒氭椿璺冦�嶏紝
+        //      鍚﹀垯浼氳瘽浼氬湪鏃堕棿鍒嗙粍閲屼粠銆屾洿鏃┿�嶈烦鍒般�屼粖澶┿��
+        chatMapper.update(null,
+                Wrappers.<Chat>lambdaUpdate()
+                        .eq(Chat::getId, chatId)
+                        .set(Chat::getGroupId, groupId)
+                        .set(Chat::getUpdatedAt, chat.getUpdatedAt()));
+
+        Long messageCount = messageMapper.selectCount(
+                Wrappers.<Message>lambdaQuery().eq(Message::getChatId, chatId));
+        List<String> collections = chatCollectionMapper.selectList(
+                        Wrappers.<ChatCollection>lambdaQuery().eq(ChatCollection::getChatId, chatId))
+                .stream().map(ChatCollection::getCollectionName).toList();
+
+        log.info("浼氳瘽绉诲姩鍒嗙粍 userId={} chatId={} groupId={}", userId, chatId, groupId);
+        return toDto(chatMapper.selectById(chatId), messageCount, collections);
     }
 
     @Override
@@ -209,7 +283,7 @@
     }
 
     @Override
-    public List<ChatDTO> search(Long userId, String keyword, int limit) {
+    public List<ChatDTO> search(Long userId, String keyword, int limit, boolean archived) {
         if (keyword == null || keyword.isBlank()) {
             // 绌哄叧閿瘝鐩存帴杩斿洖绌猴紝鑰屼笉鏄繑鍥炲叏閮ㄤ細璇� 鈥斺��
             // 鍚﹀垯鎼滅储妗嗕細閫�鍖栨垚銆屾棤杩囨护鍒楄〃銆嶏紝鍜屼晶杈规爮鏈韩閲嶅
@@ -220,9 +294,14 @@
 
         // 鍏堝彇璇ョ敤鎴峰叏閮ㄤ細璇濓紙涓汉浼氳瘽閲忕骇閫氬父鍦ㄦ暟鐧撅紝涓�娆℃煡瀹屽啀鍋氬唴瀛樺尮閰嶏紝
         // 姣斾袱娆� LIKE 鏌ヨ + 鍚堝苟鏇寸畝鍗曪紝涔熼伩鍏嶄簡 title/message 涓ゆ寰�杩旓級銆�
+        //
+        // 鎼滅储鑼冨洿涓庡綋鍓嶈鍥句竴鑷达細涓诲垪琛ㄦ悳绱笉鎶婂綊妗e璇濇贩杩涙潵锛�
+        // 鍦ㄣ�屽綊妗e璇濄�嶉噷鎼滅储鍒欏彧鎼滃綊妗g殑 鈥斺�� 鍚﹀垯鐢ㄦ埛浼氭悳鍒颁竴鍫�
+        // 鑷繁鍒氬綊妗h捣鏉ャ�佸苟涓嶆兂鐪嬪埌鐨勫璇濄��
         List<Chat> chats = chatMapper.selectList(
                 Wrappers.<Chat>lambdaQuery()
                         .eq(Chat::getUserId, userId)
+                        .eq(Chat::getArchived, archived)
                         .orderByDesc(Chat::getUpdatedAt));
         if (chats.isEmpty()) {
             return Collections.emptyList();
@@ -346,6 +425,13 @@
         dto.setMeta(chat.getMeta() == null || chat.getMeta().isBlank() ? "{}" : chat.getMeta());
         dto.setCreatedAt(chat.getCreatedAt());
         dto.setUpdatedAt(chat.getUpdatedAt());
+        // 缃《/褰掓。鍒楀彲鑳戒负 NULL锛堜緥濡傝縼绉诲墠鐨勮�佹暟鎹鏄惧紡鏌ュ嚭锛夛紝缁熶竴鍏滃簳鎴� false锛�
+        // 鍏嶅緱鍓嶇鎷垮埌 null 杩樿鍒板鍒ょ┖
+        dto.setPinned(Boolean.TRUE.equals(chat.getPinned()));
+        dto.setPinnedAt(chat.getPinnedAt());
+        dto.setArchived(Boolean.TRUE.equals(chat.getArchived()));
+        dto.setArchivedAt(chat.getArchivedAt());
+        dto.setGroupId(chat.getGroupId());
         dto.setMessageCount(messageCount == null ? 0L : messageCount);
         dto.setCollectionNames(collections == null ? new ArrayList<>() : collections);
         return dto;
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index c140f17..f1c79d5 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -91,6 +91,26 @@
     # 鍗曟枃浠舵渶澶у瓧鑺傛暟锛�50MB锛�
     max-file-size: 52428800
 
+  # 浼氳瘽瀵煎嚭锛圝SON / TXT / PDF锛�
+  export:
+    # PDF 鐢ㄧ殑涓枃瀛椾綋鏂囦欢锛涚暀绌哄垯鑷姩鎺㈡祴绯荤粺瀛椾綋銆�
+    #
+    # 涓轰粈涔堣鏄惧紡宓屽叆瀛椾綋锛歅DF 鍐呯疆鐨� 14 涓爣鍑嗗瓧浣撳彧鏈� Latin-1锛�
+    # 鍐欎腑鏂囦細鐩存帴鎶涖�孨o glyph for U+4E2D銆嶏紱鑰屽紩鐢ㄧ郴缁� CJK 鏍囧噯瀛椾綋
+    # 铏界劧鐪佷簨锛屼絾瀵规柟鏈哄櫒娌¤灏辨槸涓�鐗囩┖鐧� 鈥斺�� 瀵煎嚭鏂囦欢鏄鍙戠粰鍒汉鐨勶紝
+    # 涓嶈兘璧屼粬鐨勭幆澧冦�傛墍浠ヨ繖閲屾壘涓�浠界湡瀹炲瓧浣�**鎸夊瓙闆嗗祵鍏�**
+    # 锛堝彧甯︾敤鍒扮殑瀛楀舰锛屼竴涓腑鏂囧璇濆鍑虹殑 PDF 閫氬父鍙湁鍑犲崄 KB锛夈��
+    #
+    # macOS 鏃犻渶閰嶇疆锛堜細鑷姩鐢� /System/Library/Fonts/Supplemental/Arial Unicode.ttf锛夛紱
+    # Linux / Windows 鑻ヨ嚜鍔ㄦ帰娴嬪け璐ワ紝鐢ㄨ繖閲屾寚瀹氾紝渚嬪锛�
+    #   pdf-font-path: /usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc
+    # 鍚姩鏃ュ織鐨勩�屽鍑鸿嚜妫�銆嶄細鍛婅瘔浣犳渶缁堢敤浜嗗摢涓瓧浣撱��
+    pdf-font-path: ${WEBUI_PDF_FONT:}
+    # 鍗曟瀵煎嚭鐨勬秷鎭潯鏁颁笂闄愪笌鍗曟潯娑堟伅瀛楃涓婇檺锛�
+    # 闃叉涓�鏉¤秴闀垮璇濈敓鎴愬嚑鍗佸厗鐨勬枃浠舵妸鍐呭瓨鎷栧灝銆傝秴鍑轰細鎴柇骞�**鍦ㄦ枃浠堕噷鍐欐槑**銆�
+    max-messages: 2000
+    max-chars-per-message: 20000
+
   llm:
     # 鍙�夊�硷細ollama / openai-compat / mock
     #   ollama        鈥斺�� Ollama 鍘熺敓鎺ュ彛锛�/api/chat锛孨DJSON 娴侊級
diff --git a/src/main/resources/db/h2-schema.sql b/src/main/resources/db/h2-schema.sql
index 34b11a6..65246bc 100644
--- a/src/main/resources/db/h2-schema.sql
+++ b/src/main/resources/db/h2-schema.sql
@@ -21,11 +21,26 @@
 );
 
 DROP TABLE IF EXISTS `chat`;
+DROP TABLE IF EXISTS `chat_group`;
+CREATE TABLE `chat_group` (
+  `id` bigint NOT NULL AUTO_INCREMENT,
+  `user_id` bigint NOT NULL,
+  `name` varchar(64) NOT NULL,
+  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  PRIMARY KEY (`id`),
+  UNIQUE (`user_id`, `name`)
+);
+
 CREATE TABLE `chat` (
   `id` bigint NOT NULL AUTO_INCREMENT,
   `user_id` bigint NOT NULL,
   `title` varchar(255) NOT NULL DEFAULT '鏂板璇�',
   `meta` varchar(4000) DEFAULT NULL,
+  `pinned` tinyint NOT NULL DEFAULT 0,
+  `pinned_at` timestamp DEFAULT NULL,
+  `archived` tinyint NOT NULL DEFAULT 0,
+  `archived_at` timestamp DEFAULT NULL,
+  `group_id` bigint DEFAULT NULL,
   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY (`id`)

--
Gitblit v1.9.1