/*
 * Author: wangjian
 * 生成mapper
 */
package com.tofly.callcenter.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.callcenter.custom.entity.FlowNum;
import com.tofly.callcenter.custom.entity.dto.MissCallInfosDto;
import com.tofly.callcenter.custom.entity.dto.MissedCallsDto;
import com.tofly.callcenter.entity.PltCalllist1000;
import com.tofly.callcenter.entity.custom.CallSearch;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 通话记录(话单)坐席或分机之间呼叫只产生一条记录
 *
 * @author wangjieliu
 * @date Thu Jun 17 00:00:00 CST 2021
 */
public interface PltCalllist1000Mapper extends BaseMapper<PltCalllist1000> {

    String getCallResultName(@Param("callResult") Long callResult);

    List<Map<String, Object>> getPltCallInfo(@Param("crew") String crew,@Param("start")  String start, @Param("end") String end);

    String getCallTypeName(@Param("callType") Long callType);

    Long getCallInCount(@Param("currentDay") String currentDay);

    Long getNotCallInCount(@Param("currentDay") String currentDay);

    List<Map> getSatisfactionCount(@Param("yearMonth") String yearMonth);

    IPage<Map> getTelephoneSta(Page page, @Param("search") CallSearch search);

    IPage<Map> getSatisfactionStatis(Page page, @Param("search") CallSearch search);

    IPage<Map> getSatisfactionStatisInfo(Page page, @Param("search") CallSearch search);

    List<Map> getSatisfactionStatisInfo(@Param("search") CallSearch search);

    IPage<Map> getStateStatis(Page page, @Param("search") CallSearch search);

    FlowNum getFlowNum();

    @Update("update tf_ywpn_flowwarin_w set flow_Num = #{fn.flowNum},blockCall_Num = #{fn.blockCallNum} ,flag = '1' where id = 1")
    boolean configFlow(@Param("fn") FlowNum fn);

    /**
     * 获取呼入量
     *
     * @return list
     */
    @Select("select date_format(a.call_time, '%H') as sj,\n" +
            "       count(*)                       as t,\n" +
            "       (select count(*)\n" +
            "        from plt_service_list1000 c,\n" +
            "             plt_calllist1000 d\n" +
            "        where c.connectionid = d.connectionid\n" +
            "          and d.call_type = '1'\n" +
            "          and date_format(d.CALL_TIME, '%Y-%m-%d %H') = date_format(a.call_time, '%Y-%m-%d %H')\n" +
            "          and d.call_result = '1'\n" +
            "          and d.transfer_result = '1')   jtl\n" +
            "from plt_service_list1000 a,\n" +
            "     plt_calllist1000 b\n" +
            "where a.connectionid = b.connectionid\n" +
            "  and b.call_type = '1'\n" +
            "  and date_format(b.CALL_TIME, '%Y-%m-%d') = curdate()\n" +
            "group by date_format(a.CALL_TIME, '%H')\n" +
            "order by a.call_time desc")
    List<Map> getInboundVolume();

    @Select("select date_format(a.CALL_TIME, '%H') as                                                         sj,\n" +
            "       count(*)                                                                                  t,\n" +
            "       (select count(*)\n" +
            "        from plt_calllist1000 c\n" +
            "        where c.CALL_TYPE = a.CALL_TYPE\n" +
            "          and CALL_RESULT = 1\n" +
            "          and date_format(c.CALL_TIME, '%Y-%m-%d %H') = date_format(a.CALL_TIME, '%Y-%m-%d %H')) jtl\n" +
            "FROM plt_service_list1000 a,\n" +
            "     plt_calllist1000 b\n" +
            "where a.CONNECTIONID = b.CONNECTIONID\n" +
            "  and b.call_type = 2\n" +
            "  and date_format(a.CALL_TIME, '%Y-%m-%d') = curdate()\n" +
            "GROUP BY date_format(a.CALL_TIME, '%H')\n" +
            "ORDER BY a.CALL_TIME DESC")
    List<Map> getOutboundVolume();

    Map<String, BigDecimal> incomingCallCount(@Param("start") Date start, @Param("end") Date end);

    Map<String, BigDecimal> exhalationCount(@Param("start") Date start, @Param("end") Date end);

    Map<String, BigDecimal> getCallCount(@Param("start") Date start, @Param("end") Date end, @Param("userName") String userName);


    List<Map<String, Object>> missedCalls(@Param("dto")MissedCallsDto dto);

    Page<Map> missedCall(Page page,@Param("emp") String emp, @Param("tel") String tel);

    Map<String, BigDecimal> getUserScoreInfo(@Param("start") Date start, @Param("end") Date end, @Param("userName") String userName);

    Page<Map> missCallInfo(Page page, @Param("dto") MissCallInfosDto dto);
    List<Map> missCallInfo(@Param("dto") MissCallInfosDto dto);
}
