From 76499c390426916a6e89f9ff6e43db00653c8990 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Wed, 20 Dec 2023 15:09:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E7=9A=84sql=E5=92=8Cupdatetime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/teammodel/dao/ChatSessionRepository.java | 4 ++-- .../cn/teammodel/service/impl/ChatSessionServiceImpl.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/cn/teammodel/dao/ChatSessionRepository.java b/src/main/java/cn/teammodel/dao/ChatSessionRepository.java index 8f6f549..5be844e 100644 --- a/src/main/java/cn/teammodel/dao/ChatSessionRepository.java +++ b/src/main/java/cn/teammodel/dao/ChatSessionRepository.java @@ -13,10 +13,10 @@ import java.util.List; */ @Repository public interface ChatSessionRepository extends CosmosRepository { - @Query("select c.id, c.code, c.title, c.userId, c.createTime from c where c.code = 'ChatSession' and c.sessionId = @sessionId") + @Query("select c.id, c.code, c.title, c.userId, c.createTime from c where c.code = 'ChatSession' and c.id = @sessionId") List findBySessionId(String sessionId); - @Query("select c.id, c.code, c.title, c.userId, c.createTime from c where c.code = 'ChatSession' and c.userId = @userId") + @Query("select c.id, c.code, c.title, c.userId, c.createTime, c.updateTime from c where c.code = 'ChatSession' and c.userId = @userId") List findByUserId(String userId); @Query("SELECT value ARRAY_SLICE(c.history, -3) FROM c where c.id = @sessionId and c.code = 'ChatSession'") diff --git a/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java b/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java index 4ffd4ed..80c1d4e 100644 --- a/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java @@ -14,6 +14,7 @@ import cn.teammodel.service.ChatSessionService; import cn.teammodel.utils.RepositoryUtil; import com.azure.cosmos.models.CosmosPatchOperations; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -56,7 +57,9 @@ public class ChatSessionServiceImpl implements ChatSessionService { String userId = SecurityUtil.getUserId(); List sessions = chatSessionRepository.findByUserId(userId); // 按更新时间排序 - sessions = sessions.stream().sorted(Comparator.comparing(ChatSession::getUpdateTime)).collect(Collectors.toList()); + if (ObjectUtils.isNotEmpty(sessions)) { + sessions = sessions.stream().sorted(Comparator.comparing(ChatSession::getUpdateTime)).collect(Collectors.toList()); + } return sessions; }