86c2df4784
- 完成情绪记录生成功能,支持AI分析聊天内容生成情绪记录 - 实现聊天页面历史记录查看,支持分页和搜索 - 修改日记页面展示情绪记录而非普通日记 - 添加情绪记录的增删改查API - 优化前端UI,添加情绪强度显示和详细信息展示 - 修复SCSS变量缺失问题
72 lines
2.6 KiB
Java
72 lines
2.6 KiB
Java
package com.emotion.mapper;
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.emotion.entity.Message;
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Select;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 消息Mapper接口
|
|
*
|
|
* @author emotion-museum
|
|
* @date 2025-07-23
|
|
*/
|
|
@Mapper
|
|
public interface MessageMapper extends BaseMapper<Message> {
|
|
|
|
/**
|
|
* 根据用户ID和时间范围查询消息
|
|
* 通过conversation表关联查询
|
|
*/
|
|
@Select("SELECT m.* FROM message m " +
|
|
"INNER JOIN conversation c ON m.conversation_id = c.id " +
|
|
"WHERE c.user_id = #{userId} " +
|
|
"AND m.create_time BETWEEN #{startTime} AND #{endTime} " +
|
|
"AND m.is_deleted = 0 " +
|
|
"ORDER BY m.create_time ASC")
|
|
List<Message> getByUserIdAndTimeRange(@Param("userId") String userId,
|
|
@Param("startTime") LocalDateTime startTime,
|
|
@Param("endTime") LocalDateTime endTime);
|
|
|
|
/**
|
|
* 根据用户ID分页查询消息
|
|
* 通过conversation表关联查询
|
|
*/
|
|
@Select("SELECT m.* FROM message m " +
|
|
"INNER JOIN conversation c ON m.conversation_id = c.id " +
|
|
"WHERE c.user_id = #{userId} " +
|
|
"AND m.is_deleted = 0 " +
|
|
"ORDER BY m.create_time DESC " +
|
|
"LIMIT #{offset}, #{size}")
|
|
List<Message> getByUserIdWithPageList(@Param("userId") String userId,
|
|
@Param("offset") Integer offset,
|
|
@Param("size") Integer size);
|
|
|
|
/**
|
|
* 统计用户消息总数
|
|
*/
|
|
@Select("SELECT COUNT(*) FROM message m " +
|
|
"INNER JOIN conversation c ON m.conversation_id = c.id " +
|
|
"WHERE c.user_id = #{userId} " +
|
|
"AND m.is_deleted = 0")
|
|
Long countByUserId(@Param("userId") String userId);
|
|
|
|
/**
|
|
* 根据用户ID和关键词搜索消息
|
|
*/
|
|
@Select("SELECT m.* FROM message m " +
|
|
"INNER JOIN conversation c ON m.conversation_id = c.id " +
|
|
"WHERE c.user_id = #{userId} " +
|
|
"AND m.content LIKE CONCAT('%', #{keyword}, '%') " +
|
|
"AND m.is_deleted = 0 " +
|
|
"ORDER BY m.create_time DESC " +
|
|
"LIMIT #{limit}")
|
|
List<Message> searchByUserIdAndKeyword(@Param("userId") String userId,
|
|
@Param("keyword") String keyword,
|
|
@Param("limit") Integer limit);
|
|
}
|