<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.icomsys.main_vm.db.mybatis.mapper.StatisticsCallInfoMapper">

	<select id="selectStatCallInfo" resultType="java.util.HashMap">
	/* StatisticsCallInfoMapper.selectStatCallInfo */
	<![CDATA[
	SELECT
		DATE_FORMAT(Z.CALL_INIT_DATE, '%Y-%m-%d') AS callInitDate
		 , Z.CALL_END_CONVERSION AS callEndConversion
		 , Z.CALL_END_REASON AS callEndReason
		 , (SELECT COUNT(*) FROM TB_CALL_USER_LOG WHERE TOKEN = Z.TOKEN AND TALK_SEQ != 1) AS talkSeqCnt
	FROM
		TB_CALL_INFO Z
		LEFT JOIN TB_CALL_USER_LOG Y ON Y.TOKEN = Z.TOKEN
	WHERE Z.IN_CHANNEL_TYPE = 'VOICE'
	]]>
	<if test="oprMngCode != null and oprMngCode != ''">
		<choose>
			<when test="oprMngCode == 'all'">
				<![CDATA[
				AND Z.OPR_MNG_CODE IN
			]]>
				<foreach item="item" index="index" collection="oprMngCodeList" open="(" separator="," close=")">
					#{item}
				</foreach>
			</when>
			<otherwise>
				<![CDATA[
				AND Z.OPR_MNG_CODE = #{oprMngCode}
			]]>
			</otherwise>
		</choose>
	</if>
	<if test="callInitDateFrom != null and callInitDateFrom != '' and callInitDateTo != null and callInitDateTo != ''">
		<![CDATA[
			AND Z.CALL_INIT_DATE > #{callInitDateFrom} AND Z.CALL_INIT_DATE < DATE_ADD(#{callInitDateTo}, INTERVAL 1 DAY)
		]]>
	</if>
	<![CDATA[
	GROUP BY Z.TOKEN
	ORDER BY callInitDate DESC
	]]>
	</select>


</mapper>
