package com.fs.crm.mapper;

import com.fs.crm.domain.CrmEvent;
import com.fs.crm.param.CrmEventListQueryParam;
import com.fs.crm.vo.CrmEventListQueryVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 代办事项Mapper接口
 *
 * @author fs
 * @date 2022-12-21
 */
public interface CrmEventMapper
{
    /**
     * 查询代办事项
     *
     * @param eventId 代办事项ID
     * @return 代办事项
     */
    public CrmEvent selectCrmEventById(Long eventId);

    /**
     * 查询代办事项列表
     *
     * @param crmEvent 代办事项
     * @return 代办事项集合
     */
    public List<CrmEvent> selectCrmEventList(CrmEvent crmEvent);

    /**
     * 新增代办事项
     *
     * @param crmEvent 代办事项
     * @return 结果
     */
    public int insertCrmEvent(CrmEvent crmEvent);

    /**
     * 修改代办事项
     *
     * @param crmEvent 代办事项
     * @return 结果
     */
    public int updateCrmEvent(CrmEvent crmEvent);

    /**
     * 删除代办事项
     *
     * @param eventId 代办事项ID
     * @return 结果
     */
    public int deleteCrmEventById(Long eventId);

    /**
     * 批量删除代办事项
     *
     * @param eventIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteCrmEventByIds(Long[] eventIds);
    @Select({"<script> " +
            "select e.* from crm_event e " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null     '> " +
            "and e.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.companyUserId != null     '> " +
            "and e.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.status != null and maps.status !=\"\"     '> " +
            "and e.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.eventTypes != null and maps.eventTypes !=\"\"     '> " +
            "and find_in_set(e.event_type,#{maps.eventTypes}) " +
            "</if>" +
            "<if test = 'maps.startTime != null '> " +
            "and  DATE_FORMAT(e.start_time, '%Y-%m-%d')  = DATE_FORMAT(#{maps.startTime}, '%Y-%m-%d') " +
            "</if>" +
            "<if test = 'maps.searchMonth != null '> " +
            "and  DATE_FORMAT(e.start_time, '%Y-%m')  = DATE_FORMAT(#{maps.searchMonth}, '%Y-%m') " +
            "</if>" +
            " order by e.event_time desc "+
            "</script>"})
    List<CrmEventListQueryVO> selectCrmEventListQuery(@Param("maps") CrmEventListQueryParam param);
}
