| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.fs.company.mapper.CompanyVoiceRoboticCallLogCallphoneMapper">
- <resultMap type="CompanyVoiceRoboticCallLogCallphone" id="CompanyVoiceRoboticCallLogCallphoneResult">
- <result property="logId" column="log_id" />
- <result property="roboticId" column="robotic_id" />
- <result property="callerId" column="caller_id" />
- <result property="runTime" column="run_time" />
- <result property="runParam" column="run_param" />
- <result property="result" column="result" />
- <result property="status" column="status" />
- <result property="createTime" column="create_time" />
- <result property="recordPath" column="record_path" />
- <result property="contentList" column="content_list" />
- <result property="callerNum" column="caller_num" />
- <result property="calleeNum" column="callee_num" />
- <result property="uuid" column="uuid" />
- <result property="callCreateTime" column="call_create_time" />
- <result property="callAnswerTime" column="call_answer_time" />
- <result property="intention" column="intention" />
- <result property="companyId" column="company_id" />
- <result property="companyUserId" column="company_user_id" />
- <result property="callTime" column="call_time" />
- <result property="cost" column="cost" />
- <result property="callType" column="call_type" />
- <result property="hangupType" column="hangup_type" />
- <result property="isWarning" column="is_warning" />
- </resultMap>
- <sql id="selectCompanyVoiceRoboticCallLogCallphoneVo">
- select log_id, robotic_id, caller_id, run_time, run_param, result, status, create_time, record_path, content_list, caller_num, callee_num, uuid, call_create_time, call_answer_time, intention, company_id, company_user_id, call_time, cost, call_type, hangup_type, is_warning from company_voice_robotic_call_log_callphone
- </sql>
- <select id="selectCompanyVoiceRoboticCallLogCallphoneList" parameterType="CompanyVoiceRoboticCallLogCallphone" resultMap="CompanyVoiceRoboticCallLogCallphoneResult">
- <include refid="selectCompanyVoiceRoboticCallLogCallphoneVo"/>
- <where>
- <if test="roboticId != null "> and robotic_id = #{roboticId}</if>
- <if test="callerId != null "> and caller_id = #{callerId}</if>
- <if test="runTime != null "> and run_time = #{runTime}</if>
- <if test="runParam != null and runParam != ''"> and run_param = #{runParam}</if>
- <if test="result != null and result != ''"> and result = #{result}</if>
- <if test="status != null "> and status = #{status}</if>
- <if test="recordPath != null and recordPath != ''"> and record_path = #{recordPath}</if>
- <if test="contentList != null and contentList != ''"> and content_list = #{contentList}</if>
- <if test="callerNum != null and callerNum != ''"> and caller_num = #{callerNum}</if>
- <if test="calleeNum != null and calleeNum != ''"> and callee_num = #{calleeNum}</if>
- <if test="uuid != null and uuid != ''"> and uuid = #{uuid}</if>
- <if test="callCreateTime != null "> and call_create_time = #{callCreateTime}</if>
- <if test="callAnswerTime != null "> and call_answer_time = #{callAnswerTime}</if>
- <if test="intention != null and intention != ''"> and intention = #{intention}</if>
- <if test="companyId != null "> and company_id = #{companyId}</if>
- <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
- <if test="callTime != null "> and call_time = #{callTime}</if>
- <if test="cost != null "> and cost = #{cost}</if>
- <if test="callType != null "> and call_type = #{callType}</if>
- <if test="isWarning != null "> and is_warning = #{isWarning}</if>
- </where>
- </select>
- <select id="selectCompanyVoiceRoboticCallLogCallphoneByLogId" parameterType="Long" resultMap="CompanyVoiceRoboticCallLogCallphoneResult">
- <include refid="selectCompanyVoiceRoboticCallLogCallphoneVo"/>
- where log_id = #{logId}
- </select>
- <insert id="insertCompanyVoiceRoboticCallLogCallphone" parameterType="CompanyVoiceRoboticCallLogCallphone" useGeneratedKeys="true" keyProperty="logId">
- insert into company_voice_robotic_call_log_callphone
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="callbackUuid != null">callback_uuid,</if>
- <if test="roboticId != null">robotic_id,</if>
- <if test="callerId != null">caller_id,</if>
- <if test="runTime != null">run_time,</if>
- <if test="runParam != null">run_param,</if>
- <if test="result != null">result,</if>
- <if test="status != null">status,</if>
- <if test="createTime != null">create_time,</if>
- <if test="recordPath != null">record_path,</if>
- <if test="contentList != null">content_list,</if>
- <if test="callerNum != null">caller_num,</if>
- <if test="calleeNum != null">callee_num,</if>
- <if test="uuid != null">uuid,</if>
- <if test="callCreateTime != null">call_create_time,</if>
- <if test="callAnswerTime != null">call_answer_time,</if>
- <if test="intention != null">intention,</if>
- <if test="companyId != null">company_id,</if>
- <if test="companyUserId != null">company_user_id,</if>
- <if test="callTime != null">call_time,</if>
- <if test="cost != null">cost,</if>
- <if test="callType != null">call_type,</if>
- <if test="hangupType != null">hangup_type,</if>
- <if test="isWarning != null">is_warning,</if>
- <if test="violationNum != null">violation_num,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="callbackUuid != null">#{callbackUuid},</if>
- <if test="roboticId != null">#{roboticId},</if>
- <if test="callerId != null">#{callerId},</if>
- <if test="runTime != null">#{runTime},</if>
- <if test="runParam != null">#{runParam},</if>
- <if test="result != null">#{result},</if>
- <if test="status != null">#{status},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="recordPath != null">#{recordPath},</if>
- <if test="contentList != null">#{contentList},</if>
- <if test="callerNum != null">#{callerNum},</if>
- <if test="calleeNum != null">#{calleeNum},</if>
- <if test="uuid != null">#{uuid},</if>
- <if test="callCreateTime != null">#{callCreateTime},</if>
- <if test="callAnswerTime != null">#{callAnswerTime},</if>
- <if test="intention != null">#{intention},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="companyUserId != null">#{companyUserId},</if>
- <if test="callTime != null">#{callTime},</if>
- <if test="cost != null">#{cost},</if>
- <if test="callType != null">#{callType},</if>
- <if test="hangupType != null">#{hangupType},</if>
- <if test="isWarning != null">#{isWarning},</if>
- <if test="violationNum != null">#{violationNum},</if>
- </trim>
- </insert>
- <update id="updateCompanyVoiceRoboticCallLogCallphone" parameterType="CompanyVoiceRoboticCallLogCallphone">
- update company_voice_robotic_call_log_callphone
- <trim prefix="SET" suffixOverrides=",">
- <if test="roboticId != null">robotic_id = #{roboticId},</if>
- <if test="callerId != null">caller_id = #{callerId},</if>
- <if test="runTime != null">run_time = #{runTime},</if>
- <if test="runParam != null">run_param = #{runParam},</if>
- <if test="result != null">result = #{result},</if>
- <if test="status != null">status = #{status},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="recordPath != null">record_path = #{recordPath},</if>
- <if test="contentList != null">content_list = #{contentList},</if>
- <if test="callerNum != null">caller_num = #{callerNum},</if>
- <if test="calleeNum != null">callee_num = #{calleeNum},</if>
- <if test="uuid != null">uuid = #{uuid},</if>
- <if test="callCreateTime != null">call_create_time = #{callCreateTime},</if>
- <if test="callAnswerTime != null">call_answer_time = #{callAnswerTime},</if>
- <if test="intention != null">intention = #{intention},</if>
- <if test="companyId != null">company_id = #{companyId},</if>
- <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
- <if test="callTime != null">call_time = #{callTime},</if>
- <if test="cost != null">cost = #{cost},</if>
- <if test="callType != null">call_type = #{callType},</if>
- <if test="hangupType != null">hangup_type = #{hangupType},</if>
- <if test="isWarning != null">is_warning = #{isWarning},</if>
- <if test="violationNum != null">violation_num = #{violationNum},</if>
- <if test="manualAnswered != null">manual_answered = #{manualAnswered},</if>
- <if test="handleFlag != null">handle_flag = #{handleFlag},</if>
- <if test="answeredExtNum != null">answered_ext_num = #{answeredExtNum},</if>
- <if test="manualAnsweredTime != null">manual_answered_time = #{manualAnsweredTime},</if>
- <if test="manualAnsweredTimeLen != null">manual_answered_time_len = #{manualAnsweredTimeLen},</if>
- </trim>
- where log_id = #{logId}
- </update>
- <delete id="deleteCompanyVoiceRoboticCallLogCallphoneByLogId" parameterType="Long">
- delete from company_voice_robotic_call_log_callphone where log_id = #{logId}
- </delete>
- <delete id="deleteCompanyVoiceRoboticCallLogCallphoneByLogIds" parameterType="String">
- delete from company_voice_robotic_call_log_callphone where log_id in
- <foreach item="logId" collection="array" open="(" separator="," close=")">
- #{logId}
- </foreach>
- </delete>
- <select id="selectNoResultLogByCallees" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallees" resultType="CompanyVoiceRoboticCallLogCallphone">
- select * from company_voice_robotic_call_log_callphone where robotic_id = #{roboticId} And caller_id = #{id} And status = 1
- </select>
- <select id="selectLogByRoboticIdAndCallerId" resultType="CompanyVoiceRoboticCallLogCallphone">
- select * from company_voice_robotic_call_log_callphone where robotic_id = #{roboticId} And caller_id = #{callerId} order by run_time asc limit 1
- </select>
- <select id="selectCompanyVoiceRoboticCallLogCallphoneListData" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone" resultType="CompanyVoiceRoboticCallLogCallphone">
- select
- t1.*,
- t2.company_name as companyName,
- t3.nick_name as companyUserName
- from company_voice_robotic_call_log_callphone t1
- left join company t2 on t1.company_id = t2.company_id
- left join company_user t3 on t3.user_id = t1.company_user_id
- <where>
- <if test="logId != null">and t1.log_id = #{logId}</if>
- <if test="roboticId != null "> and t1.robotic_id = #{roboticId}</if>
- <if test="callerId != null "> and t1.caller_id = #{callerId}</if>
- <if test="callerIds != null">
- AND t1.caller_id IN
- <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
- #{item}
- </foreach>
- </if>
- </where>
- </select>
- <select id="selectCallLogByCallbackUuid" resultType="CompanyVoiceRoboticCallLogCallphone">
- select * from company_voice_robotic_call_log_callphone where callback_uuid = #{uuid}
- </select>
- <select id="selectRunningCallbackUuidsByCompanyId" resultType="java.lang.String">
- SELECT DISTINCT t1.callback_uuid
- FROM company_voice_robotic_call_log_callphone t1
- INNER JOIN company_voice_robotic cvr ON cvr.id = t1.robotic_id
- WHERE cvr.company_id = #{companyId}
- AND cvr.task_status = 1
- AND (cvr.del_flag = 0 OR cvr.del_flag IS NULL)
- AND t1.status = 1
- AND t1.callback_uuid IS NOT NULL
- AND t1.callback_uuid != ''
- </select>
- <select id="countTodayCallsByBusinessId" resultType="int">
- SELECT IFNULL(COUNT(*), 0)
- FROM company_voice_robotic_callees es
- INNER JOIN company_voice_robotic_call_log_callphone callphone
- ON callphone.caller_id = es.id
- AND es.is_generate = 0
- WHERE es.phone = (
- SELECT es.phone
- FROM company_voice_robotic_business bes
- INNER JOIN company_voice_robotic_callees es
- ON es.id = bes.callee_id
- WHERE bes.id = #{businessId}
- AND es.is_generate = 0
- )
- AND callphone.company_id = #{companyId}
- AND callphone.create_time >= CURDATE()
- AND callphone.create_time < CURDATE() + INTERVAL 1 DAY
- </select>
- <select id="selectCompanyVoiceRoboticCallPhoneLogGroupList" resultType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
- select
- robotic_id,
- cvr.name as robotic_name,
- count(1) as totalRecordCount,
- sum(case when status = 1 then 1 else 0 end) as runningCount,
- sum(case when status = 2 then 1 else 0 end) as successCount,
- sum(case when status = 3 then 1 else 0 end) as failCount,
- concat(round(sum(case when call_time is not null then 1 else 0 end) * 100.0 / count(1), 2), '%') as successRate
- from company_voice_robotic_call_log_callphone t1
- inner join company_voice_robotic cvr on cvr.id = t1.robotic_id
- <where>
- <if test="roboticId != null">and robotic_id = #{roboticId}</if>
- <if test="companyId != null"> and cvr.company_id = #{companyId}</if>
- <if test="companyUserId != null"> and cvr.company_user_id = #{companyUserId}</if>
- </where>
- group by robotic_id
- order by t1.run_time desc
- </select>
- <select id="selectCompanyVoiceRoboticCallPhoneLogCount" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCount">
- select
- count(1) as recordCount,
- sum(case when status = 2 then 1 else 0 end) as successRecordCount,
- sum(case when run_time >= CURDATE() and run_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todayCount,
- sum(case when status = 2 and run_time >= CURDATE() and run_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todaySuccessCount,
- sum(case when call_time > 0 then 1 else 0 end) as connectionCount,
- sum(case when call_time <= 0 or call_time is null then 1 else 0 end) as unansweredCallsCount,
- sum(case when call_time > 0 and run_time >= CURDATE() and run_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todayConnectionCount,
- sum(case when (call_time <= 0 or call_time is null) and run_time >= CURDATE() and run_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todayUnansweredCallsCount
- from company_voice_robotic_call_log_callphone cp
- inner join company_voice_robotic cvr on cvr.id = cp.robotic_id
- where cvr.company_id = #{companyId}
- <if test="companyUserId != null"> and cvr.company_user_id = #{companyUserId}</if>
- </select>
- <select id="listByRoboticId" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneVO" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
- SELECT
- t1.*,
- t2.company_name,
- t3.nick_name as companyUserName,
- cvr.name as robotic_name,
- ce.user_id as customer_id
- FROM company_voice_robotic_call_log_callphone t1
- left join company_voice_robotic_callees ce on ce.id = t1.caller_id
- left join company t2 on t1.company_id = t2.company_id
- left join company_user t3 on t3.user_id = t1.company_user_id
- left join company_voice_robotic cvr on cvr.id = t1.robotic_id
- where 1=1
- <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
- <if test="callerId != null">and t1.caller_id = #{callerId}</if>
- <if test="callerIds != null and callerIds.size() > 0">
- AND t1.caller_id IN
- <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
- #{item}
- </foreach>
- </if>
- <if test="callerNum != null and callerNum != ''">
- and t1.caller_num like concat('%', #{callerNum}, '%')
- </if>
- <choose>
- <when test="intentionEmpty != null and intentionEmpty">
- and (t1.intention is null or t1.intention = '' or t1.intention = '0')
- </when>
- <when test="intention != null and intention != ''">
- and t1.intention = #{intention}
- </when>
- </choose>
- <if test="isConnected != null and isConnected == 1">
- and t1.call_time > 0
- </if>
- <if test="isConnected != null and isConnected == 0">
- and (t1.call_time is null or t1.call_time = 0)
- </if>
- <if test="minCallTime != null">
- and t1.call_time >= #{minCallTime}
- </if>
- <if test="maxCallTime != null">
- and t1.call_time <= #{maxCallTime}
- </if>
- </select>
- <sql id="detailListWhere">
- FROM company_voice_robotic_call_log_callphone t1
- inner join company_voice_robotic cvr on cvr.id = t1.robotic_id
- left join company_voice_robotic_callees ce on ce.id = t1.caller_id
- left join company t2 on t1.company_id = t2.company_id
- left join company_user t3 on t3.user_id = t1.company_user_id
- where cvr.company_id = #{companyId}
- <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
- <if test="status != null">and t1.status = #{status}</if>
- <if test="phone != null and phone != ''">
- and (t1.caller_num like concat('%', #{phone}, '%') or ce.phone = #{encryptedPhone})
- </if>
- <choose>
- <when test="intentionEmpty != null and intentionEmpty">
- and (t1.intention is null or t1.intention = '' or t1.intention = '0')
- </when>
- <when test="intention != null and intention != ''">
- and t1.intention = #{intention}
- </when>
- </choose>
- <if test="isConnected != null and isConnected == 1">
- and t1.call_time > 0
- </if>
- <if test="isConnected != null and isConnected == 0">
- and (t1.call_time is null or t1.call_time = 0)
- </if>
- <if test="minCallTime != null">
- and t1.call_time >= #{minCallTime}
- </if>
- <if test="maxCallTime != null">
- and t1.call_time <= #{maxCallTime}
- </if>
- <if test="beginRunTime != null and beginRunTime != ''">
- and date_format(t1.run_time,'%Y-%m-%d') >= #{beginRunTime}
- </if>
- <if test="endRunTime != null and endRunTime != ''">
- and date_format(t1.run_time,'%Y-%m-%d') <= #{endRunTime}
- </if>
- </sql>
- <select id="selectDetailList" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneVO" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
- SELECT
- t1.log_id as logId,
- t1.robotic_id as roboticId,
- t1.caller_id as callerId,
- t1.run_time as runTime,
- t1.run_param as runParam,
- t1.result as result,
- t1.status as status,
- t1.company_id as companyId,
- t1.company_user_id as companyUserId,
- COALESCE(NULLIF(TRIM(t1.caller_num), ''), ce.phone) as callerNum,
- t1.callee_num as calleeNum,
- t1.intention as intention,
- t1.call_time as callTime,
- t1.record_path as recordPath,
- t1.content_list as contentList,
- t1.cost as cost,
- t1.call_type as callType,
- t1.is_warning as isWarning,
- CASE WHEN t1.call_time IS NOT NULL AND t1.call_time > 0 THEN CEILING(t1.call_time / 60.0) ELSE NULL END AS billingMinute,
- t2.company_name as companyName,
- t3.nick_name as companyUserName,
- cvr.name as roboticName,
- ce.user_id as customerId
- <include refid="detailListWhere"/>
- order by t1.run_time desc
- </select>
- <select id="selectDetailSummary" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogDetailSummary" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
- SELECT
- count(1) as totalCount,
- sum(case when t1.status = 2 then 1 else 0 end) as successCount,
- sum(case when t1.status = 3 then 1 else 0 end) as failCount,
- sum(case when t1.call_time is not null and t1.call_time > 0 then 1 else 0 end) as connectedCount,
- sum(case when t1.call_time is not null and t1.call_time > 0 then ceiling(t1.call_time / 60.0) else 0 end) as totalBillingMinute
- <include refid="detailListWhere"/>
- </select>
- <select id="listDecryptPhoneExport" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneDecryptQueryVO" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
- SELECT
- cvr.name as robotic_name,
- ce.user_name as user_name,
- t1.intention as intention,
- ce.phone as phone
- FROM company_voice_robotic_call_log_callphone t1
- inner join company_voice_robotic cvr on cvr.id = t1.robotic_id
- left join company_voice_robotic_callees ce on ce.id = t1.caller_id
- where cvr.company_id = #{companyId}
- <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
- <if test="callerId != null">and t1.caller_id = #{callerId}</if>
- <if test="callerIds != null and callerIds.size() > 0">
- AND t1.caller_id IN
- <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
- #{item}
- </foreach>
- </if>
- <if test="status != null">and t1.status = #{status}</if>
- <if test="phone != null and phone != ''">
- and (t1.caller_num like concat('%', #{phone}, '%') or ce.phone = #{encryptedPhone})
- </if>
- <choose>
- <when test="intentionEmpty != null and intentionEmpty">
- and (t1.intention is null or t1.intention = '' or t1.intention = '0')
- </when>
- <when test="intention != null and intention != ''">
- and t1.intention = #{intention}
- </when>
- </choose>
- <if test="isConnected != null and isConnected == 1">
- and t1.call_time > 0
- </if>
- <if test="isConnected != null and isConnected == 0">
- and (t1.call_time is null or t1.call_time = 0)
- </if>
- <if test="minCallTime != null">
- and t1.call_time >= #{minCallTime}
- </if>
- <if test="maxCallTime != null">
- and t1.call_time <= #{maxCallTime}
- </if>
- <if test="beginRunTime != null and beginRunTime != ''">
- and date_format(t1.run_time,'%Y-%m-%d') >= #{beginRunTime}
- </if>
- <if test="endRunTime != null and endRunTime != ''">
- and date_format(t1.run_time,'%Y-%m-%d') <= #{endRunTime}
- </if>
- order by t1.run_time desc
- </select>
- <select id="selectCompanyIdByBusinessId" resultType="Long">
- SELECT company_id FROM company_voice_robotic vr INNER JOIN company_voice_robotic_business rb ON vr.id = rb.robotic_id WHERE rb.id = 20 LIMIT 1
- </select>
- <select id="selectManualAnsweredList" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone" resultType="CompanyVoiceRoboticCallLogCallphone">
- select
- t1.*,
- t2.company_name as companyName,
- t3.nick_name as companyUserName,
- cvr.name as roboticName
- from company_voice_robotic_call_log_callphone t1
- left join company t2 on t1.company_id = t2.company_id
- left join company_user t3 on t3.user_id = t1.company_user_id
- left join company_voice_robotic cvr on cvr.id = t1.robotic_id
- <where>
- t1.manual_answered = 1
- <if test="companyId != null">and t1.company_id = #{companyId}</if>
- <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
- <if test="answeredExtNum != null and answeredExtNum != ''">and t1.answered_ext_num = #{answeredExtNum}</if>
- <if test="companyUserId != null"> and cvr.company_user_id = #{companyUserId}</if>
- </where>
- order by t1.handle_flag asc, t1.call_create_time desc
- </select>
- <!-- 按 customer_id(= callees.user_id)批量统计今日 AI 外呼(总数 / 接通数) -->
- <select id="selectAiCallStatToday" resultType="com.fs.crm.vo.CustomerCallStatVO">
- SELECT
- ce.user_id AS customerId,
- COUNT(1) AS totalCount,
- SUM(CASE WHEN aic.call_time > 0 THEN 1 ELSE 0 END) AS connectCount
- FROM company_voice_robotic_call_log_callphone aic
- INNER JOIN company_voice_robotic_callees ce ON ce.id = aic.caller_id
- WHERE ce.user_id IN
- <foreach collection="customerIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- AND DATE(aic.create_time) = CURDATE()
- GROUP BY ce.user_id
- </select>
- <!-- 按 customer_id(= callees.user_id)批量统计累计 AI 外呼(总数 / 接通数) -->
- <select id="selectAiCallStatTotal" resultType="com.fs.crm.vo.CustomerCallStatVO">
- SELECT
- ce.user_id AS customerId,
- COUNT(1) AS totalCount,
- SUM(CASE WHEN aic.call_time > 0 THEN 1 ELSE 0 END) AS connectCount
- FROM company_voice_robotic_call_log_callphone aic
- INNER JOIN company_voice_robotic_callees ce ON ce.id = aic.caller_id
- WHERE ce.user_id IN
- <foreach collection="customerIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- GROUP BY ce.user_id
- </select>
- <select id="countRoboticCallOutByCustomerIds" resultType="com.fs.company.vo.CustomerRoboticCallOutCountVO">
- SELECT ce.user_id AS customerId, COUNT(1) AS callCount
- FROM company_voice_robotic_call_log_callphone log
- INNER JOIN company_voice_robotic_callees ce ON log.caller_id = ce.id
- WHERE ce.user_id IS NOT NULL
- AND ce.user_id > 0
- <if test="companyId != null">
- AND log.company_id = #{companyId}
- </if>
- AND ce.user_id IN
- <foreach collection="customerIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- GROUP BY ce.user_id
- </select>
- <select id="countRoboticCallOutByCalleeIds" resultType="com.fs.company.vo.CalleeRoboticCallOutCountVO">
- SELECT caller_id AS calleeId, COUNT(1) AS callCount
- FROM company_voice_robotic_call_log_callphone
- WHERE robotic_id = #{roboticId}
- <if test="companyId != null">
- AND company_id = #{companyId}
- </if>
- AND caller_id IN
- <foreach collection="calleeIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- GROUP BY caller_id
- </select>
- <select id="selectPendingCallbackRecords" resultType="CompanyVoiceRoboticCallLogCallphone">
- select * from company_voice_robotic_call_log_callphone
- where status = 1
- and callback_uuid is not null
- and callback_uuid != ''
- and (retry_count is null or retry_count < 3)
- order by create_time asc
- limit 100
- </select>
- <update id="updateRetryCountAndStatus" parameterType="CompanyVoiceRoboticCallLogCallphone">
- update company_voice_robotic_call_log_callphone
- <trim prefix="SET" suffixOverrides=",">
- <if test="retryCount != null">retry_count = #{retryCount},</if>
- <if test="status != null">status = #{status},</if>
- </trim>
- where log_id = #{logId}
- </update>
- <update id="incrementCallbackCompensateRetryCount">
- UPDATE company_voice_robotic_call_log_callphone
- SET retry_count = IFNULL(retry_count, 0) + 1
- WHERE log_id = #{logId}
- AND status = 1
- </update>
- <select id="selectPendingAiCallLogsForSync" resultType="com.fs.company.vo.PendingAiCallLogSyncVo">
- SELECT t1.log_id AS logId,
- t1.callback_uuid AS callbackUuid,
- t1.run_param AS runParam,
- t1.company_id AS companyId,
- IFNULL(t1.retry_count, 0) AS retryCount
- FROM company_voice_robotic_call_log_callphone t1
- INNER JOIN company_voice_robotic cvr ON cvr.id = t1.robotic_id
- WHERE cvr.task_status = 1
- AND (cvr.del_flag = 0 OR cvr.del_flag IS NULL)
- AND t1.status = 1
- AND t1.callback_uuid IS NOT NULL
- AND t1.callback_uuid != ''
- AND IFNULL(t1.retry_count, 0) < #{maxRetryCount}
- </select>
- </mapper>
|