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; }