package com.fs.chat.mapper;

import com.fs.chat.domain.ChatMsgLogs;
import com.fs.chat.param.ChatMsgLogsListCParam;
import com.fs.chat.vo.ChatMsgLogsListCVO;
import com.fs.chat.vo.ChatMsgLogsVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 消息操作日志Mapper接口
 *
 * @author fs
 * @date 2024-05-10
 */
public interface ChatMsgLogsMapper
{
    /**
     * 查询消息操作日志
     *
     * @param logsId 消息操作日志主键
     * @return 消息操作日志
     */
    public ChatMsgLogs selectChatMsgLogsByLogsId(Long logsId);

    /**
     * 查询消息操作日志列表
     *
     * @param chatMsgLogs 消息操作日志
     * @return 消息操作日志集合
     */
    public List<ChatMsgLogs> selectChatMsgLogsList(ChatMsgLogs chatMsgLogs);

    /**
     * 新增消息操作日志
     *
     * @param chatMsgLogs 消息操作日志
     * @return 结果
     */
    public int insertChatMsgLogs(ChatMsgLogs chatMsgLogs);

    /**
     * 修改消息操作日志
     *
     * @param chatMsgLogs 消息操作日志
     * @return 结果
     */
    public int updateChatMsgLogs(ChatMsgLogs chatMsgLogs);

    /**
     * 删除消息操作日志
     *
     * @param logsId 消息操作日志主键
     * @return 结果
     */
    public int deleteChatMsgLogsByLogsId(Long logsId);

    /**
     * 批量删除消息操作日志
     *
     * @param logsIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteChatMsgLogsByLogsIds(Long[] logsIds);
    @Select({"<script> " +
            "select l.*,u.nick_name from 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<ChatMsgLogsVO> selectChatMsgLogsListCVO(ChatMsgLogs chatMsgLogs);

    @Select({"<script> " +
            "select l.*,u.nick_name as company_user_name,r.role_name,m.user_id,cu.nickname,c.company_name from chat_msg_logs l " +
            " left join 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 chat_role r on r.role_id=m.role_id " +
            " left join chat_user cu on cu.external_userid = m.user_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<ChatMsgLogsListCVO> selectChatLogsMsgListCVO(@Param("maps") ChatMsgLogsListCParam param);
}
