package com.fs.company.mapper;

import java.util.List;

import com.fs.common.core.domain.entity.SysUser;
import com.fs.company.domain.CompanyVoiceCaller;
import com.fs.company.param.CompanyVoiceCallerParam;
import com.fs.company.vo.CompanyVoiceCallerListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 企业用户坐席Mapper接口
 *
 * @author fs
 * @date 2023-02-23
 */
public interface CompanyVoiceCallerMapper
{
    /**
     * 查询企业用户坐席
     *
     * @param callingId 企业用户坐席ID
     * @return 企业用户坐席
     */
    public CompanyVoiceCaller selectCompanyVoiceCallerById(Long callingId);
    /**
     * 查询企业用户坐席列表
     *
     * @param companyVoiceCaller 企业用户坐席
     * @return 企业用户坐席集合
     */
    public List<CompanyVoiceCaller> selectCompanyVoiceCallerList(CompanyVoiceCaller companyVoiceCaller);

    /**
     * 新增企业用户坐席
     *
     * @param companyVoiceCaller 企业用户坐席
     * @return 结果
     */
    public int insertCompanyVoiceCaller(CompanyVoiceCaller companyVoiceCaller);

    /**
     * 修改企业用户坐席
     *
     * @param companyVoiceCaller 企业用户坐席
     * @return 结果
     */
    public int updateCompanyVoiceCaller(CompanyVoiceCaller companyVoiceCaller);

    /**
     * 删除企业用户坐席
     *
     * @param callingId 企业用户坐席ID
     * @return 结果
     */
    public int deleteCompanyVoiceCallerById(Long callingId);

    /**
     * 批量删除企业用户坐席
     *
     * @param callingIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteCompanyVoiceCallerByIds(Long[] callingIds);
    @Select({"<script> " +
            "select vc.*,u.nick_name as company_user_nick_name,c.company_name " +
            "from company_voice_caller vc left join company c on c.company_id=vc.company_id left join  company_user u on u.user_id=vc.company_user_id " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null  '> " +
            "and vc.company_id = #{maps.companyId}" +
            "</if>" +
            "<if test = 'maps.companyUserId != null  '> " +
            "and vc.company_user_id = #{maps.companyUserId}" +
            "</if>" +
            "<if test = 'maps.callerNo != null and maps.callerNo != \"\" '> " +
            "and vc.caller_no like '%${maps.callerNo}%' " +
            "</if>" +
            "<if test = 'maps.mobile != null and maps.mobile != \"\" '> " +
            "and vc.mobile like '%${maps.mobile}%' " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and maps.companyUserNickName != \"\" '> " +
            "and u.nick_name like '%${maps.companyUserNickName}%' " +
            "</if>" +
            "<if test = 'maps.status != null '> " +
            "and vc.status = #{maps.status}" +
            "</if>" +
            "order by vc.caller_id desc " +
            "</script>"})
    List<CompanyVoiceCallerListVO> selectCompanyVoiceCallerListVO(@Param("maps")CompanyVoiceCallerParam param);
    @Select("select * from company_voice_caller where company_id=#{companyId} and company_user_id=#{companyUserId}")
    CompanyVoiceCaller selectCompanyVoiceCallerByUserId(@Param("companyId") Long companyId,@Param("companyUserId") Long companyUserId);

    @Select("select * from company_voice_caller where caller_no=#{callerNo}  ")
    CompanyVoiceCaller selectCompanyVoiceCallerByCallerNo(String callerNo);
    @Select("select * from company_voice_caller where  status=1  ")
    List<CompanyVoiceCaller> selectCompanyVoiceCallerByEnable();
    @Select("select ifnull(count(1),0) from company_voice_caller where company_id=#{companyId}  ")
    Integer selectCompanyVoiceCallerCountsByCompanyId(Long companyId);

    @Select("SELECT * FROM company_voice_caller WHERE status=0 AND bind_time <= DATE_SUB(NOW(), INTERVAL 30 DAY) ")
    List<CompanyVoiceCaller> selectCompanyVoiceCallerByRecover(@Param("days") Integer days);
}
