package com.fs.fastGpt.mapper;

import com.fs.fastGpt.domain.FastGptChatMsgLogs;
import com.fs.fastGpt.param.FastGptChatMsgLogsListParam;
import com.fs.fastGpt.vo.FastGptChatMsgLogsListCVO;
import com.fs.fastGpt.vo.FastGptChatMsgLogsVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 聊天记录日志Mapper接口
 * 
 * @author fs
 * @date 2024-10-10
 */
public interface FastGptChatMsgLogsMapper 
{
    /**
     * 查询聊天记录日志
     * 
     * @param logsId 聊天记录日志主键
     * @return 聊天记录日志
     */
    public FastGptChatMsgLogs selectFastGptChatMsgLogsByLogsId(Long logsId);

    /**
     * 查询聊天记录日志列表
     * 
     * @param fastGptChatMsgLogs 聊天记录日志
     * @return 聊天记录日志集合
     */
    public List<FastGptChatMsgLogs> selectFastGptChatMsgLogsList(FastGptChatMsgLogs fastGptChatMsgLogs);

    /**
     * 新增聊天记录日志
     * 
     * @param fastGptChatMsgLogs 聊天记录日志
     * @return 结果
     */
    public int insertFastGptChatMsgLogs(FastGptChatMsgLogs fastGptChatMsgLogs);

    /**
     * 修改聊天记录日志
     * 
     * @param fastGptChatMsgLogs 聊天记录日志
     * @return 结果
     */
    public int updateFastGptChatMsgLogs(FastGptChatMsgLogs fastGptChatMsgLogs);

    /**
     * 删除聊天记录日志
     * 
     * @param logsId 聊天记录日志主键
     * @return 结果
     */
    public int deleteFastGptChatMsgLogsByLogsId(Long logsId);

    /**
     * 批量删除聊天记录日志
     * 
     * @param logsIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFastGptChatMsgLogsByLogsIds(Long[] logsIds);

    @Select({"<script> " +
            "select l.*,u.nick_name from fastgpt_chat_msg_logs l LEFT JOIN company_user u on u.user_id=l.company_user_id "+
            "<where>  \n" +
            "            <if test=\"msgId != null \"> and msg_id = #{msgId}</if>\n" +
            "            <if test=\"logsType != null \"> and logs_type = #{logsType}</if>\n" +
            "            <if test=\"content != null  and content != ''\"> and content = #{content}</if>\n" +
            "            <if test=\"companyUserId != null \"> and company_user_id = #{companyUserId}</if>\n" +
            "</where>" +
            "order by logs_id desc"+
            "</script>"})
    List<FastGptChatMsgLogsVO> selectFastGptChatMsgLogsListVO(FastGptChatMsgLogs fastGptChatMsgLogs);

    @Select({"<script> " +
            "select l.*,u.nick_name as company_user_name,r.role_name,m.user_id,m.nick_name,c.company_name from fastgpt_chat_msg_logs l " +
            " left join fastgpt_chat_msg m on m.msg_id = l.msg_id " +
            " left join company c on c.company_id = l.company_id " +
            " left join company_user u on u.user_id=l.company_user_id  " +
            " left join fastgpt_role r on r.role_id=m.role_id " +
            "where 1=1  " +
            "<if test = ' maps.companyUserName!=null and maps.companyUserName != \"\"  '> " +
            "and u.nick_name like concat('%', #{maps.companyUserName}, '%') " +
            "</if>" +
            "<if test = ' maps.createBy!=null and maps.createBy != \"\"  '> " +
            "and l.create_by like concat('%', #{maps.createBy}, '%') " +
            "</if>" +
            "<if test = ' maps.companyId!=null  '> " +
            "and l.company_id = #{maps.companyId} " +
            "</if>" +
            "<if test = ' maps.roleId!=null  '> " +
            "and m.role_id = #{maps.roleId} " +
            "</if>" +
            "<if test=' maps.beginTime != null and maps.beginTime != \"\" '>" +
            "AND date_format(l.create_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d')  " +
            "</if>" +
            "<if test='maps.endTime != null and maps.endTime != \"\" '>" +
            "AND date_format(l.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')  " +
            "</if>" +
            " order by l.create_time desc "+
            "</script>"})
    List<FastGptChatMsgLogsListCVO> selectFastGptChatMsgLogsListCVO(@Param("maps") FastGptChatMsgLogsListParam param);
}
