package com.fs.sop.mapper;

import com.fs.common.annotation.DataSource;
import com.fs.common.enums.DataSourceType;
import com.fs.qw.param.SopUserLogsVO;
import com.fs.sop.domain.QwSopLogs;
import com.fs.sop.domain.SopUserLogs;
import com.fs.sop.params.SopUserLogsList;
import com.fs.sop.params.SopUserLogsParam;
import com.fs.sop.params.SopUserLogsParamByDate;
import com.fs.sop.vo.SopUserLogsInfoVo;
import com.fs.sop.vo.SopUserLogsVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
@DataSource(DataSourceType.SOP)
public interface SopUserLogsMapper {

    @DataSource(DataSourceType.SOP)
    public int insertSopUserLogsByList(@Param("data") SopUserLogsList userLogsList);

    @DataSource(DataSourceType.SOP)
    public int deleteSopUserLogsById(String id);

    @DataSource(DataSourceType.SOP)
    public int insertSopUserLogsByDate(@Param("data") SopUserLogsParamByDate logsParamByDate);

    @DataSource(DataSourceType.SOP)
    public int updateSopUserLogsByStatus(@Param("data") SopUserLogs sopUserLogs);

//    @DataSource(DataSourceType.SOP)
//    public int updateSopUserLogsDistinct(@Param("data") SopUserLogs sopUserLogs);

//    @DataSource(DataSourceType.SOP)
//    public int updateSopUserLogsByexternalContactId(@Param("data") SopUserLogsUpdateList userLogsUpdateList);

    @DataSource(DataSourceType.SOP)
    public int deleteSopUserLogsBySopId(@Param("sopId") String sopId);

    @DataSource(DataSourceType.SOP)
    public int deleteSopUserLogsByRemoveSop(@Param("sopId") String sopId,@Param("qwUserId") String qwUserId , @Param("corpId") String corpId);

    @DataSource(DataSourceType.SOP)
    public int updateSopUserLogsByTempId(@Param("sopTempId") String sopTempId,@Param("sopId") String sopId);

//    @DataSource(DataSourceType.SOP)
//    int updateSopUserLogsDistinctByList(@Param("data") SopUserLogsArray userLogsArray);

    @DataSource(DataSourceType.SOP)
    public List<SopUserLogsVo> selectSopUserLogsListByTime();

    @DataSource(DataSourceType.SOP)
    public List<SopUserLogs> meetsTheRatingByUserInfo();

    @DataSource(DataSourceType.SOP)
    public List<SopUserLogs> meetsTheRatingByUserInfoWithPagination(@Param("offset") int offset,@Param("pageSize") int pageSize);

    @DataSource(DataSourceType.SOP)
    public List<SopUserLogs> meetsTheRatingByUserInfoBySopId(@Param("sopId") String sopId);


    @DataSource(DataSourceType.SOP)
    public List<SopUserLogsVo> selectSopUserLogsListByTest();

    /**
     * 根据时间查询sopUserInfoLogs
     * @return
     */
    @DataSource(DataSourceType.SOP)
    public List<SopUserLogsInfoVo> selectSopUserInfoLogsListByTime();

    @DataSource(DataSourceType.SOP)
    public String selectSopUserLogsByUnionSopId(@Param("data") SopUserLogs sopUserLogs) ;

    @DataSource(DataSourceType.SOP)
    public String selectSopUserLogsByUpdate(@Param("data") SopUserLogs sopUserLogs) ;

    @DataSource(DataSourceType.SOP)
    int  deleteSopUserLogsBySopIds(@Param("sopIds") String[] sopIds) ;

    @DataSource(DataSourceType.SOP)
    List<SopUserLogsInfoVo> selectSopUserLogsInfoListByTime();


    @DataSource(DataSourceType.SOP)
    List<SopUserLogsVO> selectSopUserLogsListBySopId(@Param("data") SopUserLogs sopUserLogs);

    @DataSource(DataSourceType.SOP)
    List<SopUserLogs> selectSopUserLogsList(SopUserLogs sopUserLogs);

    /**
     * 查询sopUserLogs
     *
     * @param id sopUserLogs主键
     * @return sopUserLogs
     */
    @DataSource(DataSourceType.SOP)
    public SopUserLogs selectSopUserLogsById(String id);

    @DataSource(DataSourceType.SOP)
    public List<SopUserLogs> selectSopUserLogsBySopId(@Param("sopId") String sopId);



    @DataSource(DataSourceType.SOP)
    List<String> selectSopUserLogsByDate(@Param("scheduleStartTime") String scheduleStartTime, @Param("scheduleEndTime") String scheduleEndTime);

    @DataSource(DataSourceType.SOP)
    List<SopUserLogsVO> selectQwSopLogsMessSendList(@Param("sopIds") List<String> sopIds);

    @DataSource(DataSourceType.SOP)
    void updateSopUserLogsByStartTime(@Param("data") SopUserLogs param);

    @DataSource(DataSourceType.SOP)
    void updateSopUserLogsByCompanyInfo(@Param("data") SopUserLogs param);

    @DataSource(DataSourceType.SOP)
    List<SopUserLogs> repairSopUserLogsList();

    @DataSource(DataSourceType.SOP)
    SopUserLogs selectSopUserLogsByDateAndIds(SopUserLogsParamByDate sopUserLogs);

    @DataSource(DataSourceType.SOP)
    @Select({"<script> " +
            "SELECT DISTINCT\n" +
            "            l.id,\n" +
            "            l.sop_id,\n" +
            "            l.sop_temp_id,\n" +
            "            l.qw_user_id,\n" +
            "            l.corp_id,\n" +
            "            l.start_time,\n" +
            "            l.status,\n" +
            "            l.user_id,\n" +
            "            DATEDIFF(CURRENT_DATE, l.start_time) + 1 AS count_days,\n" +
            "            l.chat_id \n" +
            "        FROM sop_user_logs l " +
            "left join sop_user_logs_info i on l.id = i.user_logs_id "  +
            "where 1=1 " +
            "<if test = ' maps.id!=null '> " +
            "and l.id = #{maps.id} " +
            "</if>" +
            "<if test = ' maps.sopId != null '> " +
            "and l.sop_id = #{maps.sopId} " +
            "</if>" +
            "<if test = ' maps.sopTempId != null '> " +
            "and l.sop_temp_id = #{maps.sopTempId} " +
            "</if>" +
            "<if test = ' maps.qwUserId!=null  '> " +
            "and l.qw_user_id = #{maps.qwUserId} " +
            "</if>" +
            "<if test = ' maps.startTime!=null  '> " +
            "and l.start_time = #{maps.startTime} " +
            "</if>" +
            "<if test = ' maps.status!=null  '> " +
            "and l.status = #{maps.status} " +
            "</if>" +
            "<if test = ' maps.externalUserName!=null and maps.externalUserName != \"\"  '> " +
            "and i.external_user_name like concat('%', #{maps.externalUserName}, '%') " +
            "</if>" +
            "order by start_time desc" +
            "</script>"})
    List<SopUserLogsVO> selectSopUserLogsListByParam(@Param("maps") SopUserLogsParam param);

    @DataSource(DataSourceType.SOP)
    void batchInsertSopUserLogs(@Param("list") List<SopUserLogs> list);
    @DataSource(DataSourceType.SOP)
    List<SopUserLogs> selectSopUserLogByChatIds(@Param("ids") List<String> ids);

    List<SopUserLogs> queryExecuteLogBySopId(@Param("sopId") String id);

    @DataSource(DataSourceType.SOP)
    List<String> selectSopUserLogsByQwUserIds(@Param("qwUserIds") List<String> qwUserIdList);
}
