package com.fs.qw.mapper;


import com.fs.qw.domain.QwForbiddenMessage;
import com.fs.qw.domain.QwForbiddenMessageList;
import com.fs.qw.param.QwForbiddenMessageParam;
import com.fs.qw.vo.QwForbiddenMessageListVO;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.util.List;

/**
 * 企微违禁消息Mapper接口
 *
 * @author fs
 * @date 2023-11-22
 */
public interface QwForbiddenMessageMapper
{
    /**
     * 查询企微违禁消息
     *
     * @param id 企微违禁消息ID
     * @return 企微违禁消息
     */
    public QwForbiddenMessage selectQwForbiddenMessageById(Long id);

    /**
     * 查询企微违禁消息列表
     *
     * @param qwForbiddenMessage 企微违禁消息
     * @return 企微违禁消息集合
     */
    public List<QwForbiddenMessage> selectQwForbiddenMessageList(QwForbiddenMessage qwForbiddenMessage);

    /**
     * 新增企微违禁消息
     *
     * @param qwForbiddenMessage 企微违禁消息
     * @return 结果
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertQwForbiddenMessage(QwForbiddenMessage qwForbiddenMessage);

    /**
     * 修改企微违禁消息
     *
     * @param qwForbiddenMessage 企微违禁消息
     * @return 结果
     */
    public int updateQwForbiddenMessage(QwForbiddenMessage qwForbiddenMessage);

    /**
     * 删除企微违禁消息
     *
     * @param id 企微违禁消息ID
     * @return 结果
     */
    public int deleteQwForbiddenMessageById(Long id);

    /**
     * 批量删除企微违禁消息
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteQwForbiddenMessageByIds(Long[] ids);

    @Select({"<script> " +
            "select  qfw.word,qa.user_id,c.company_name,cu.nick_name as companyUserName, qf.*,u.user_id as qwUserId, u.avatar,u.nick_name,u.corp_name from qw_forbidden_message qf left join company_user cu on qf.company_user_id = cu.user_id left join company c on " +
            " qf.company_id = c.company_id left join qw_account qa on qa.account = qf.account " +
            " left join qw_user u on u.device_id = qa.device_id  left join qw_forbidden_words qfw on qfw.id = qf.word_id " +
            "where 1=1 " +
            "<if test = 'maps.id != null      '> " +
            "and qf.id =#{maps.id} " +
            "</if>" +
            "<if test = 'maps.wordId != null      '> " +
            "and qfw.id =#{maps.wordId} " +
            "</if>" +
            "<if test = 'maps.companyId != null      '> " +
            "and qf.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test= 'maps.companyUserName != null  and maps.companyUserName !=\"\"    '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserName}, '%')  " +
            "</if>" +
            "<if test= 'maps.account != null  and maps.account !=\"\"    '> " +
            "and qf.account like concat('%', #{maps.account}, '%')  " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(qf.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(qf.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +
            " order by qf.id desc " +
            "</script>"})
    List<QwForbiddenMessageList> selectQwForbiddenMessageListVO(@Param("maps")QwForbiddenMessageParam param);
}
