fix: 修复查询会话的sql和updatetime

11111
winter 1 year ago
parent fede04c70d
commit 76499c3904

@ -13,10 +13,10 @@ import java.util.List;
*/
@Repository
public interface ChatSessionRepository extends CosmosRepository<ChatSession, String> {
@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<ChatSession> 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<ChatSession> findByUserId(String userId);
@Query("SELECT value ARRAY_SLICE(c.history, -3) FROM c where c.id = @sessionId and c.code = 'ChatSession'")

@ -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<ChatSession> sessions = chatSessionRepository.findByUserId(userId);
// 按更新时间排序
if (ObjectUtils.isNotEmpty(sessions)) {
sessions = sessions.stream().sorted(Comparator.comparing(ChatSession::getUpdateTime)).collect(Collectors.toList());
}
return sessions;
}

Loading…
Cancel
Save