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

11111
winter 1 year ago
parent fede04c70d
commit 76499c3904

@ -13,10 +13,10 @@ import java.util.List;
*/ */
@Repository @Repository
public interface ChatSessionRepository extends CosmosRepository<ChatSession, String> { 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); 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); List<ChatSession> findByUserId(String userId);
@Query("SELECT value ARRAY_SLICE(c.history, -3) FROM c where c.id = @sessionId and c.code = 'ChatSession'") @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 cn.teammodel.utils.RepositoryUtil;
import com.azure.cosmos.models.CosmosPatchOperations; import com.azure.cosmos.models.CosmosPatchOperations;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -56,7 +57,9 @@ public class ChatSessionServiceImpl implements ChatSessionService {
String userId = SecurityUtil.getUserId(); String userId = SecurityUtil.getUserId();
List<ChatSession> sessions = chatSessionRepository.findByUserId(userId); List<ChatSession> 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; return sessions;
} }

Loading…
Cancel
Save