Browse Source

会话排序为倒叙,添加更新会话主题、标记删除会话接口

zhaojinyu 2 weeks ago
parent
commit
c135efd853

+ 12 - 0
service-ai/service-ai-biz/src/main/java/com/usky/ai/controller/web/AiSessionController.java

@@ -72,4 +72,16 @@ public class AiSessionController {
 
         return ApiResult.success(sessions).getData();
     }
+
+    @PostMapping("/update")
+    public ApiResult updateSession(@RequestBody AiSession aiSession) {
+        aiSessionMapper.updateQuestion(aiSession.getSessionId(), aiSession.getQuestion());
+        return ApiResult.success();
+    }
+
+    @DeleteMapping("/delete")
+    public ApiResult deleteSession(@RequestParam String sessionId) {
+        aiSessionMapper.delete(sessionId);
+        return ApiResult.success();
+    }
 }

+ 15 - 9
service-ai/service-ai-biz/src/main/java/com/usky/ai/mapper/AiSessionMapper.java

@@ -2,9 +2,7 @@ package com.usky.ai.mapper;
 
 import com.usky.ai.service.AiQuestion;
 import com.usky.ai.service.AiSession;
-import org.apache.ibatis.annotations.Insert;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.*;
 
 import java.util.List;
 
@@ -15,17 +13,25 @@ public interface AiSessionMapper {
     void save(AiSession aiSession);
 
     //查询所有数据
-    @Select("SELECT * FROM ai_sessions ORDER BY ask_time ASC")
+    @Select("SELECT * FROM ai_sessions ORDER BY ask_time DESC")
     List<AiSession> findAll();
 
-    //根据user_id 查询数据
-    @Select("SELECT * FROM ai_sessions WHERE user_id = #{userId} ORDER BY ask_time ASC")
+    // 根据 user_id 查询未删除的数据
+    @Select("SELECT * FROM ai_sessions WHERE user_id = #{userId} AND deleted = false ORDER BY ask_time DESC")
     List<AiSession> findByUserId(Long userId);
 
-    // 检查是否存在指定的 session_id
-    @Select("SELECT COUNT(*) FROM ai_sessions WHERE session_id = #{sessionId}")
+    // 检查是否存在指定的 session_id 且未删除
+    @Select("SELECT COUNT(*) FROM ai_sessions WHERE session_id = #{sessionId} ORDER BY ask_time DESC")
     boolean existsBySessionId(String sessionId);
 
-    @Select("SELECT * FROM ai_questions WHERE session_id = #{sessionId} ORDER BY ask_time ASC")
+    @Select("SELECT * FROM ai_questions WHERE session_id = #{sessionId} ORDER BY ask_time DESC")
     List<AiQuestion> findQuestionsBySessionId(String sessionId);
+
+    // 更新会话主题
+    @Update("UPDATE ai_sessions SET question = #{question} WHERE session_id = #{sessionId}")
+    void updateQuestion(@Param("sessionId") String sessionId, @Param("question") String question);
+
+    //标记会话为删除
+    @Update("UPDATE ai_sessions SET deleted = true WHERE session_id = #{sessionId}")
+    void delete(String sessionId);
 }

+ 5 - 0
service-ai/service-ai-biz/src/main/java/com/usky/ai/service/AiSession.java

@@ -12,6 +12,7 @@ public class AiSession {
     private String question;
     private LocalDateTime askTime;
     private List<AiQuestionItem> itemList;
+    private boolean deleted; // 添加删除标识字段
 
     public Long getId() { return id; }
 
@@ -40,4 +41,8 @@ public class AiSession {
     public List<AiQuestionItem> getItemList() { return itemList; }
 
     public void setItemList(List<AiQuestionItem> itemList) { this.itemList = itemList; }
+
+    public boolean isDeleted() { return deleted; }
+
+    public void setDeleted(boolean deleted) { this.deleted = deleted; }
 }