package com.fs.crm.mapper;

import java.util.List;
import com.fs.crm.domain.CrmCustomerAssign;
import com.fs.crm.vo.CrmCustomerAssignListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 客户分配记录Mapper接口
 *
 * @author fs
 * @date 2023-03-30
 */
public interface CrmCustomerAssignMapper
{
    /**
     * 查询客户分配记录
     *
     * @param assignId 客户分配记录ID
     * @return 客户分配记录
     */
    public CrmCustomerAssign selectCrmCustomerAssignById(Long assignId);

    /**
     * 查询客户分配记录列表
     *
     * @param crmCustomerAssign 客户分配记录
     * @return 客户分配记录集合
     */
    public List<CrmCustomerAssign> selectCrmCustomerAssignList(CrmCustomerAssign crmCustomerAssign);

    /**
     * 新增客户分配记录
     *
     * @param crmCustomerAssign 客户分配记录
     * @return 结果
     */
    public int insertCrmCustomerAssign(CrmCustomerAssign crmCustomerAssign);

    /**
     * 修改客户分配记录
     *
     * @param crmCustomerAssign 客户分配记录
     * @return 结果
     */
    public int updateCrmCustomerAssign(CrmCustomerAssign crmCustomerAssign);

    /**
     * 删除客户分配记录
     *
     * @param assignId 客户分配记录ID
     * @return 结果
     */
    public int deleteCrmCustomerAssignById(Long assignId);

    /**
     * 批量删除客户分配记录
     *
     * @param assignIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteCrmCustomerAssignByIds(Long[] assignIds);
    @Select({"<script> " +
            "select a.*,c.company_name,cu.nick_name as company_nick_name,cu.user_name as company_user_name,su.user_name as sys_user_name,su.nick_name as sys_nick_name from crm_customer_assign a left join company_user cu on cu.user_id=a.company_user_id left join sys_user su on su.user_id=a.sys_user_id left join company c on c.company_id=a.company_id  " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null     '> " +
            "and a.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.assignType != null     '> " +
            "and a.assign_type =#{maps.assignType} " +
            "</if>" +
            "<if test = 'maps.beginTime != null and maps.beginTime != \"\" '> " +
            "AND date_format(a.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(a.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')"+
            "</if>" +
            "<if test = 'maps.sysUserName != null and maps.sysUserName != \"\"   '> " +
            "and su.user_name like CONCAT('%',#{maps.sysUserName},'%') " +
            "</if>" +
            "<if test = 'maps.companyUserName != null and maps.companyUserName != \"\"   '> " +
            "and cu.user_name like CONCAT('%',#{maps.companyUserName},'%') " +
            "</if>" +
            " order by assign_id desc "+
            "</script>"})
    List<CrmCustomerAssignListVO> selectCrmCustomerAssignListVO(@Param("maps")CrmCustomerAssign crmCustomerAssign);
    @Select({"<script> " +
            "select a.*,c.company_name,cu.nick_name as company_nick_name,cu.user_name as company_user_name,su.user_name as sys_user_name,su.nick_name as sys_nick_name from crm_customer_assign a left join company_user cu on cu.user_id=a.company_user_id left join sys_user su on su.user_id=a.sys_user_id left join company c on c.company_id=a.company_id  " +
            "where (a.assign_type=2 or a.assign_type=3 or a.assign_type=4) " +
            "<if test = 'maps.companyId != null     '> " +
            "and a.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.beginTime != null and maps.beginTime != \"\" '> " +
            "AND date_format(a.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(a.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')"+
            "</if>" +
            "<if test = 'maps.companyUserName != null and maps.companyUserName != \"\"   '> " +
            "and cu.user_name like CONCAT('%',#{maps.companyUserName},'%') " +
            "</if>" +
            " order by assign_id desc "+
            "</script>"})
    List<CrmCustomerAssignListVO> selectCompanyCrmCustomerAssignList(@Param("maps")CrmCustomerAssign crmCustomerAssign);
}
