package com.fs.qw.mapper;

import com.fs.qw.domain.QwFriendWelcome;
import com.fs.qw.param.QwFriendWelcomeParam;
import com.fs.qw.vo.QwFriendWelcomeVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 好友欢迎语Mapper接口
 *
 * @author fs
 * @date 2024-07-20
 */
@Repository
public interface QwFriendWelcomeMapper
{
    /**
     * 查询好友欢迎语
     *
     * @param id 好友欢迎语主键
     * @return 好友欢迎语
     */
    @Select("SELECT * FROM qw_friend_welcome WHERE id = #{id} order by create_time desc")
    public QwFriendWelcomeVO selectQwFriendWelcomeByIdVO(Long id);


    /**
     * 查询好友欢迎语
     *
     */
    @Select("SELECT * FROM qw_friend_welcome " +
            "WHERE " +
            "corp_id = #{corpId} " +
            "AND is_send_msg = '1'  " +
            "AND JSON_CONTAINS(qw_user_ids,CAST(#{userID} AS JSON), '$') " +
            "ORDER BY create_time desc LIMIT 1 ")
    public QwFriendWelcomeVO selectQwFriendWelcomeByUserIdVO(@Param("userID") Long userID, @Param("corpId") String corpId);


    /**
     * 查询好友欢迎语列表
     *
     * @param qwFriendWelcomeParam 好友欢迎语
     * @return 好友欢迎语集合
     */
    public List<QwFriendWelcome> selectQwFriendWelcomeListVO(QwFriendWelcomeParam qwFriendWelcomeParam);

    /**
     * 查询我的好友欢迎语列表
     *
     * @param qwFriendWelcomeParam 好友欢迎语
     * @return 好友欢迎语集合
     */
    @Select("<script> " +
            "select  qfw.*  from qw_friend_welcome qfw " +
            "left join qw_user qu  ON FIND_IN_SET(qu.id,REPLACE(REPLACE(REPLACE(qfw.qw_user_ids, '[', ''), ']', ''), ' ', '')) > 0 " +
            "        <where>  \n" +
            "            <if test=\"qwUserIds != null  and qwUserIds != ''\"> and  FIND_IN_SET(#{qwUserIds},REPLACE(REPLACE(REPLACE(qw_user_ids, '[', ''), ']', ''), ' ', '')) > 0 </if>\n" +
            "            <if test=\"isSendMsg != null \"> and qfw.is_send_msg = #{isSendMsg}</if>\n" +
            "            <if test=\"welcomeText != null  and welcomeText != ''\"> and qfw.welcome_text = #{welcomeText}</if>\n" +
            "            <if test=\"isDayparting != null \"> and qfw.is_dayparting = #{isDayparting}</if>\n" +
            "            <if test=\"companyId != null \"> and qfw.company_id = #{companyId}</if>\n" +
            "            <if test=\"createTime != null \"> and qfw.create_time = #{createTime}</if>\n" +
            "            <if test=\"updateTime != null \"> and qfw.update_time = #{updateTime}</if>\n" +
            "            <if test=\"companyUserId != null \"> and qu.company_user_id = #{companyUserId}</if>\n" +
            " <if test=\"project != null \"> and project = #{project}</if> "+
            "        </where>" +
            "</script>")
    public List<QwFriendWelcome> selectQwFriendWelcomeListMyVO(QwFriendWelcomeParam qwFriendWelcomeParam);


    /**
     * 新增好友欢迎语
     *
     * @param qwFriendWelcomeParam 好友欢迎语
     * @return 结果
     */
    public int insertQwFriendWelcomeVO(QwFriendWelcomeParam qwFriendWelcomeParam);

    /**
     * 修改好友欢迎语
     *
     * @param qwFriendWelcome 好友欢迎语
     * @return 结果
     */
    public int updateQwFriendWelcome(QwFriendWelcome qwFriendWelcome);

    /**
     * 删除好友欢迎语
     *
     * @param id 好友欢迎语主键
     * @return 结果
     */
    public int deleteQwFriendWelcomeById(Long id);

    /**
     * 批量删除好友欢迎语
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteQwFriendWelcomeByIds(Long[] ids);
}
