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