CompanyVoiceRoboticCallLogCallphoneMapper.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.company.mapper.CompanyVoiceRoboticCallLogCallphoneMapper">
  6. <resultMap type="CompanyVoiceRoboticCallLogCallphone" id="CompanyVoiceRoboticCallLogCallphoneResult">
  7. <result property="logId" column="log_id" />
  8. <result property="roboticId" column="robotic_id" />
  9. <result property="callerId" column="caller_id" />
  10. <result property="runTime" column="run_time" />
  11. <result property="runParam" column="run_param" />
  12. <result property="result" column="result" />
  13. <result property="status" column="status" />
  14. <result property="createTime" column="create_time" />
  15. <result property="recordPath" column="record_path" />
  16. <result property="contentList" column="content_list" />
  17. <result property="callerNum" column="caller_num" />
  18. <result property="calleeNum" column="callee_num" />
  19. <result property="uuid" column="uuid" />
  20. <result property="callCreateTime" column="call_create_time" />
  21. <result property="callAnswerTime" column="call_answer_time" />
  22. <result property="intention" column="intention" />
  23. <result property="companyId" column="company_id" />
  24. <result property="companyUserId" column="company_user_id" />
  25. <result property="callTime" column="call_time" />
  26. <result property="cost" column="cost" />
  27. <result property="callType" column="call_type" />
  28. <result property="hangupType" column="hangup_type" />
  29. <result property="isWarning" column="is_warning" />
  30. </resultMap>
  31. <sql id="selectCompanyVoiceRoboticCallLogCallphoneVo">
  32. 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
  33. </sql>
  34. <select id="selectCompanyVoiceRoboticCallLogCallphoneList" parameterType="CompanyVoiceRoboticCallLogCallphone" resultMap="CompanyVoiceRoboticCallLogCallphoneResult">
  35. <include refid="selectCompanyVoiceRoboticCallLogCallphoneVo"/>
  36. <where>
  37. <if test="roboticId != null "> and robotic_id = #{roboticId}</if>
  38. <if test="callerId != null "> and caller_id = #{callerId}</if>
  39. <if test="runTime != null "> and run_time = #{runTime}</if>
  40. <if test="runParam != null and runParam != ''"> and run_param = #{runParam}</if>
  41. <if test="result != null and result != ''"> and result = #{result}</if>
  42. <if test="status != null "> and status = #{status}</if>
  43. <if test="recordPath != null and recordPath != ''"> and record_path = #{recordPath}</if>
  44. <if test="contentList != null and contentList != ''"> and content_list = #{contentList}</if>
  45. <if test="callerNum != null and callerNum != ''"> and caller_num = #{callerNum}</if>
  46. <if test="calleeNum != null and calleeNum != ''"> and callee_num = #{calleeNum}</if>
  47. <if test="uuid != null and uuid != ''"> and uuid = #{uuid}</if>
  48. <if test="callCreateTime != null "> and call_create_time = #{callCreateTime}</if>
  49. <if test="callAnswerTime != null "> and call_answer_time = #{callAnswerTime}</if>
  50. <if test="intention != null and intention != ''"> and intention = #{intention}</if>
  51. <if test="companyId != null "> and company_id = #{companyId}</if>
  52. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  53. <if test="callTime != null "> and call_time = #{callTime}</if>
  54. <if test="cost != null "> and cost = #{cost}</if>
  55. <if test="callType != null "> and call_type = #{callType}</if>
  56. <if test="isWarning != null "> and is_warning = #{isWarning}</if>
  57. </where>
  58. </select>
  59. <select id="selectCompanyVoiceRoboticCallLogCallphoneByLogId" parameterType="Long" resultMap="CompanyVoiceRoboticCallLogCallphoneResult">
  60. <include refid="selectCompanyVoiceRoboticCallLogCallphoneVo"/>
  61. where log_id = #{logId}
  62. </select>
  63. <insert id="insertCompanyVoiceRoboticCallLogCallphone" parameterType="CompanyVoiceRoboticCallLogCallphone" useGeneratedKeys="true" keyProperty="logId">
  64. insert into company_voice_robotic_call_log_callphone
  65. <trim prefix="(" suffix=")" suffixOverrides=",">
  66. <if test="callbackUuid != null">callback_uuid,</if>
  67. <if test="roboticId != null">robotic_id,</if>
  68. <if test="callerId != null">caller_id,</if>
  69. <if test="runTime != null">run_time,</if>
  70. <if test="runParam != null">run_param,</if>
  71. <if test="result != null">result,</if>
  72. <if test="status != null">status,</if>
  73. <if test="createTime != null">create_time,</if>
  74. <if test="recordPath != null">record_path,</if>
  75. <if test="contentList != null">content_list,</if>
  76. <if test="callerNum != null">caller_num,</if>
  77. <if test="calleeNum != null">callee_num,</if>
  78. <if test="uuid != null">uuid,</if>
  79. <if test="callCreateTime != null">call_create_time,</if>
  80. <if test="callAnswerTime != null">call_answer_time,</if>
  81. <if test="intention != null">intention,</if>
  82. <if test="companyId != null">company_id,</if>
  83. <if test="companyUserId != null">company_user_id,</if>
  84. <if test="callTime != null">call_time,</if>
  85. <if test="cost != null">cost,</if>
  86. <if test="callType != null">call_type,</if>
  87. <if test="hangupType != null">hangup_type,</if>
  88. <if test="isWarning != null">is_warning,</if>
  89. <if test="violationNum != null">violation_num,</if>
  90. </trim>
  91. <trim prefix="values (" suffix=")" suffixOverrides=",">
  92. <if test="callbackUuid != null">#{callbackUuid},</if>
  93. <if test="roboticId != null">#{roboticId},</if>
  94. <if test="callerId != null">#{callerId},</if>
  95. <if test="runTime != null">#{runTime},</if>
  96. <if test="runParam != null">#{runParam},</if>
  97. <if test="result != null">#{result},</if>
  98. <if test="status != null">#{status},</if>
  99. <if test="createTime != null">#{createTime},</if>
  100. <if test="recordPath != null">#{recordPath},</if>
  101. <if test="contentList != null">#{contentList},</if>
  102. <if test="callerNum != null">#{callerNum},</if>
  103. <if test="calleeNum != null">#{calleeNum},</if>
  104. <if test="uuid != null">#{uuid},</if>
  105. <if test="callCreateTime != null">#{callCreateTime},</if>
  106. <if test="callAnswerTime != null">#{callAnswerTime},</if>
  107. <if test="intention != null">#{intention},</if>
  108. <if test="companyId != null">#{companyId},</if>
  109. <if test="companyUserId != null">#{companyUserId},</if>
  110. <if test="callTime != null">#{callTime},</if>
  111. <if test="cost != null">#{cost},</if>
  112. <if test="callType != null">#{callType},</if>
  113. <if test="hangupType != null">#{hangupType},</if>
  114. <if test="isWarning != null">#{isWarning},</if>
  115. <if test="violationNum != null">#{violationNum},</if>
  116. </trim>
  117. </insert>
  118. <update id="updateCompanyVoiceRoboticCallLogCallphone" parameterType="CompanyVoiceRoboticCallLogCallphone">
  119. update company_voice_robotic_call_log_callphone
  120. <trim prefix="SET" suffixOverrides=",">
  121. <if test="roboticId != null">robotic_id = #{roboticId},</if>
  122. <if test="callerId != null">caller_id = #{callerId},</if>
  123. <if test="runTime != null">run_time = #{runTime},</if>
  124. <if test="runParam != null">run_param = #{runParam},</if>
  125. <if test="result != null">result = #{result},</if>
  126. <if test="status != null">status = #{status},</if>
  127. <if test="createTime != null">create_time = #{createTime},</if>
  128. <if test="recordPath != null">record_path = #{recordPath},</if>
  129. <if test="contentList != null">content_list = #{contentList},</if>
  130. <if test="callerNum != null">caller_num = #{callerNum},</if>
  131. <if test="calleeNum != null">callee_num = #{calleeNum},</if>
  132. <if test="uuid != null">uuid = #{uuid},</if>
  133. <if test="callCreateTime != null">call_create_time = #{callCreateTime},</if>
  134. <if test="callAnswerTime != null">call_answer_time = #{callAnswerTime},</if>
  135. <if test="intention != null">intention = #{intention},</if>
  136. <if test="companyId != null">company_id = #{companyId},</if>
  137. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  138. <if test="callTime != null">call_time = #{callTime},</if>
  139. <if test="cost != null">cost = #{cost},</if>
  140. <if test="callType != null">call_type = #{callType},</if>
  141. <if test="hangupType != null">hangup_type = #{hangupType},</if>
  142. <if test="isWarning != null">is_warning = #{isWarning},</if>
  143. <if test="violationNum != null">violation_num = #{violationNum},</if>
  144. <if test="manualAnswered != null">manual_answered = #{manualAnswered},</if>
  145. <if test="handleFlag != null">handle_flag = #{handleFlag},</if>
  146. <if test="answeredExtNum != null">answered_ext_num = #{answeredExtNum},</if>
  147. <if test="manualAnsweredTime != null">manual_answered_time = #{manualAnsweredTime},</if>
  148. <if test="manualAnsweredTimeLen != null">manual_answered_time_len = #{manualAnsweredTimeLen},</if>
  149. </trim>
  150. where log_id = #{logId}
  151. </update>
  152. <delete id="deleteCompanyVoiceRoboticCallLogCallphoneByLogId" parameterType="Long">
  153. delete from company_voice_robotic_call_log_callphone where log_id = #{logId}
  154. </delete>
  155. <delete id="deleteCompanyVoiceRoboticCallLogCallphoneByLogIds" parameterType="String">
  156. delete from company_voice_robotic_call_log_callphone where log_id in
  157. <foreach item="logId" collection="array" open="(" separator="," close=")">
  158. #{logId}
  159. </foreach>
  160. </delete>
  161. <select id="selectNoResultLogByCallees" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallees" resultType="CompanyVoiceRoboticCallLogCallphone">
  162. select * from company_voice_robotic_call_log_callphone where robotic_id = #{roboticId} And caller_id = #{id} And status = 1
  163. </select>
  164. <select id="selectLogByRoboticIdAndCallerId" resultType="CompanyVoiceRoboticCallLogCallphone">
  165. select * from company_voice_robotic_call_log_callphone where robotic_id = #{roboticId} And caller_id = #{callerId} order by run_time asc limit 1
  166. </select>
  167. <select id="selectCompanyVoiceRoboticCallLogCallphoneListData" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone" resultType="CompanyVoiceRoboticCallLogCallphone">
  168. select
  169. t1.*,
  170. t2.company_name as companyName,
  171. t3.nick_name as companyUserName
  172. from company_voice_robotic_call_log_callphone t1
  173. left join company t2 on t1.company_id = t2.company_id
  174. left join company_user t3 on t3.user_id = t1.company_user_id
  175. <where>
  176. <if test="logId != null">and t1.log_id = #{logId}</if>
  177. <if test="roboticId != null "> and t1.robotic_id = #{roboticId}</if>
  178. <if test="callerId != null "> and t1.caller_id = #{callerId}</if>
  179. <if test="callerIds != null">
  180. AND t1.caller_id IN
  181. <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
  182. #{item}
  183. </foreach>
  184. </if>
  185. </where>
  186. </select>
  187. <select id="selectCallLogByCallbackUuid" resultType="CompanyVoiceRoboticCallLogCallphone">
  188. select * from company_voice_robotic_call_log_callphone where callback_uuid = #{uuid}
  189. </select>
  190. <select id="selectRunningCallbackUuidsByCompanyId" resultType="java.lang.String">
  191. SELECT DISTINCT t1.callback_uuid
  192. FROM company_voice_robotic_call_log_callphone t1
  193. INNER JOIN company_voice_robotic cvr ON cvr.id = t1.robotic_id
  194. WHERE cvr.company_id = #{companyId}
  195. AND cvr.task_status = 1
  196. AND (cvr.del_flag = 0 OR cvr.del_flag IS NULL)
  197. AND t1.status = 1
  198. AND t1.callback_uuid IS NOT NULL
  199. AND t1.callback_uuid != ''
  200. </select>
  201. <select id="countTodayCallsByBusinessId" resultType="int">
  202. SELECT IFNULL(COUNT(*), 0)
  203. FROM company_voice_robotic_callees es
  204. INNER JOIN company_voice_robotic_call_log_callphone callphone
  205. ON callphone.caller_id = es.id
  206. AND es.is_generate = 0
  207. WHERE es.phone = (
  208. SELECT es.phone
  209. FROM company_voice_robotic_business bes
  210. INNER JOIN company_voice_robotic_callees es
  211. ON es.id = bes.callee_id
  212. WHERE bes.id = #{businessId}
  213. AND es.is_generate = 0
  214. )
  215. AND callphone.company_id = #{companyId}
  216. AND callphone.create_time >= CURDATE()
  217. AND callphone.create_time &lt; CURDATE() + INTERVAL 1 DAY
  218. </select>
  219. <select id="selectCompanyVoiceRoboticCallPhoneLogGroupList" resultType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
  220. select
  221. robotic_id,
  222. cvr.name as robotic_name,
  223. count(1) as totalRecordCount,
  224. sum(case when status = 1 then 1 else 0 end) as runningCount,
  225. sum(case when status = 2 then 1 else 0 end) as successCount,
  226. sum(case when status = 3 then 1 else 0 end) as failCount,
  227. concat(round(sum(case when call_time is not null then 1 else 0 end) * 100.0 / count(1), 2), '%') as successRate
  228. from company_voice_robotic_call_log_callphone t1
  229. inner join company_voice_robotic cvr on cvr.id = t1.robotic_id
  230. <where>
  231. <if test="roboticId != null">and robotic_id = #{roboticId}</if>
  232. <if test="companyId != null"> and cvr.company_id = #{companyId}</if>
  233. <if test="companyUserId != null"> and cvr.company_user_id = #{companyUserId}</if>
  234. </where>
  235. group by robotic_id
  236. order by t1.run_time desc
  237. </select>
  238. <select id="selectCompanyVoiceRoboticCallPhoneLogCount" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCount">
  239. select
  240. count(1) as recordCount,
  241. sum(case when status = 2 then 1 else 0 end) as successRecordCount,
  242. sum(case when run_time &gt;= CURDATE() and run_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todayCount,
  243. sum(case when status = 2 and run_time &gt;= CURDATE() and run_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todaySuccessCount,
  244. sum(case when call_time > 0 then 1 else 0 end) as connectionCount,
  245. sum(case when call_time &lt;= 0 or call_time is null then 1 else 0 end) as unansweredCallsCount,
  246. sum(case when call_time > 0 and run_time >= CURDATE() and run_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todayConnectionCount,
  247. sum(case when (call_time &lt;= 0 or call_time is null) and run_time >= CURDATE() and run_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY) then 1 else 0 end) as todayUnansweredCallsCount
  248. from company_voice_robotic_call_log_callphone cp
  249. inner join company_voice_robotic cvr on cvr.id = cp.robotic_id
  250. where cvr.company_id = #{companyId}
  251. <if test="companyUserId != null"> and cvr.company_user_id = #{companyUserId}</if>
  252. </select>
  253. <select id="listByRoboticId" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneVO" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
  254. SELECT
  255. t1.*,
  256. t2.company_name,
  257. t3.nick_name as companyUserName,
  258. cvr.name as robotic_name,
  259. ce.user_id as customer_id
  260. FROM company_voice_robotic_call_log_callphone t1
  261. left join company_voice_robotic_callees ce on ce.id = t1.caller_id
  262. left join company t2 on t1.company_id = t2.company_id
  263. left join company_user t3 on t3.user_id = t1.company_user_id
  264. left join company_voice_robotic cvr on cvr.id = t1.robotic_id
  265. where 1=1
  266. <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
  267. <if test="callerId != null">and t1.caller_id = #{callerId}</if>
  268. <if test="callerIds != null and callerIds.size() > 0">
  269. AND t1.caller_id IN
  270. <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
  271. #{item}
  272. </foreach>
  273. </if>
  274. <if test="callerNum != null and callerNum != ''">
  275. and t1.caller_num like concat('%', #{callerNum}, '%')
  276. </if>
  277. <choose>
  278. <when test="intentionEmpty != null and intentionEmpty">
  279. and (t1.intention is null or t1.intention = '' or t1.intention = '0')
  280. </when>
  281. <when test="intention != null and intention != ''">
  282. and t1.intention = #{intention}
  283. </when>
  284. </choose>
  285. <if test="isConnected != null and isConnected == 1">
  286. and t1.call_time &gt; 0
  287. </if>
  288. <if test="isConnected != null and isConnected == 0">
  289. and (t1.call_time is null or t1.call_time = 0)
  290. </if>
  291. <if test="minCallTime != null">
  292. and t1.call_time &gt;= #{minCallTime}
  293. </if>
  294. <if test="maxCallTime != null">
  295. and t1.call_time &lt;= #{maxCallTime}
  296. </if>
  297. </select>
  298. <sql id="detailListWhere">
  299. FROM company_voice_robotic_call_log_callphone t1
  300. inner join company_voice_robotic cvr on cvr.id = t1.robotic_id
  301. left join company_voice_robotic_callees ce on ce.id = t1.caller_id
  302. left join company t2 on t1.company_id = t2.company_id
  303. left join company_user t3 on t3.user_id = t1.company_user_id
  304. where cvr.company_id = #{companyId}
  305. <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
  306. <if test="status != null">and t1.status = #{status}</if>
  307. <if test="phone != null and phone != ''">
  308. and (t1.caller_num like concat('%', #{phone}, '%') or ce.phone = #{encryptedPhone})
  309. </if>
  310. <choose>
  311. <when test="intentionEmpty != null and intentionEmpty">
  312. and (t1.intention is null or t1.intention = '' or t1.intention = '0')
  313. </when>
  314. <when test="intention != null and intention != ''">
  315. and t1.intention = #{intention}
  316. </when>
  317. </choose>
  318. <if test="isConnected != null and isConnected == 1">
  319. and t1.call_time &gt; 0
  320. </if>
  321. <if test="isConnected != null and isConnected == 0">
  322. and (t1.call_time is null or t1.call_time = 0)
  323. </if>
  324. <if test="minCallTime != null">
  325. and t1.call_time &gt;= #{minCallTime}
  326. </if>
  327. <if test="maxCallTime != null">
  328. and t1.call_time &lt;= #{maxCallTime}
  329. </if>
  330. <if test="beginRunTime != null and beginRunTime != ''">
  331. and date_format(t1.run_time,'%Y-%m-%d') &gt;= #{beginRunTime}
  332. </if>
  333. <if test="endRunTime != null and endRunTime != ''">
  334. and date_format(t1.run_time,'%Y-%m-%d') &lt;= #{endRunTime}
  335. </if>
  336. </sql>
  337. <select id="selectDetailList" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneVO" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
  338. SELECT
  339. t1.log_id as logId,
  340. t1.robotic_id as roboticId,
  341. t1.caller_id as callerId,
  342. t1.run_time as runTime,
  343. t1.run_param as runParam,
  344. t1.result as result,
  345. t1.status as status,
  346. t1.company_id as companyId,
  347. t1.company_user_id as companyUserId,
  348. COALESCE(NULLIF(TRIM(t1.caller_num), ''), ce.phone) as callerNum,
  349. t1.callee_num as calleeNum,
  350. t1.intention as intention,
  351. t1.call_time as callTime,
  352. t1.record_path as recordPath,
  353. t1.content_list as contentList,
  354. t1.cost as cost,
  355. t1.call_type as callType,
  356. t1.is_warning as isWarning,
  357. CASE WHEN t1.call_time IS NOT NULL AND t1.call_time &gt; 0 THEN CEILING(t1.call_time / 60.0) ELSE NULL END AS billingMinute,
  358. t2.company_name as companyName,
  359. t3.nick_name as companyUserName,
  360. cvr.name as roboticName,
  361. ce.user_id as customerId
  362. <include refid="detailListWhere"/>
  363. order by t1.run_time desc
  364. </select>
  365. <select id="selectDetailSummary" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogDetailSummary" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
  366. SELECT
  367. count(1) as totalCount,
  368. sum(case when t1.status = 2 then 1 else 0 end) as successCount,
  369. sum(case when t1.status = 3 then 1 else 0 end) as failCount,
  370. sum(case when t1.call_time is not null and t1.call_time &gt; 0 then 1 else 0 end) as connectedCount,
  371. sum(case when t1.call_time is not null and t1.call_time &gt; 0 then ceiling(t1.call_time / 60.0) else 0 end) as totalBillingMinute
  372. <include refid="detailListWhere"/>
  373. </select>
  374. <select id="listDecryptPhoneExport" resultType="com.fs.company.vo.CompanyVoiceRoboticCallLogCallPhoneDecryptQueryVO" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone">
  375. SELECT
  376. cvr.name as robotic_name,
  377. ce.user_name as user_name,
  378. t1.intention as intention,
  379. ce.phone as phone
  380. FROM company_voice_robotic_call_log_callphone t1
  381. inner join company_voice_robotic cvr on cvr.id = t1.robotic_id
  382. left join company_voice_robotic_callees ce on ce.id = t1.caller_id
  383. where cvr.company_id = #{companyId}
  384. <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
  385. <if test="callerId != null">and t1.caller_id = #{callerId}</if>
  386. <if test="callerIds != null and callerIds.size() > 0">
  387. AND t1.caller_id IN
  388. <foreach collection='callerIds' item='item' open='(' separator=',' close=')'>
  389. #{item}
  390. </foreach>
  391. </if>
  392. <if test="status != null">and t1.status = #{status}</if>
  393. <if test="phone != null and phone != ''">
  394. and (t1.caller_num like concat('%', #{phone}, '%') or ce.phone = #{encryptedPhone})
  395. </if>
  396. <choose>
  397. <when test="intentionEmpty != null and intentionEmpty">
  398. and (t1.intention is null or t1.intention = '' or t1.intention = '0')
  399. </when>
  400. <when test="intention != null and intention != ''">
  401. and t1.intention = #{intention}
  402. </when>
  403. </choose>
  404. <if test="isConnected != null and isConnected == 1">
  405. and t1.call_time &gt; 0
  406. </if>
  407. <if test="isConnected != null and isConnected == 0">
  408. and (t1.call_time is null or t1.call_time = 0)
  409. </if>
  410. <if test="minCallTime != null">
  411. and t1.call_time &gt;= #{minCallTime}
  412. </if>
  413. <if test="maxCallTime != null">
  414. and t1.call_time &lt;= #{maxCallTime}
  415. </if>
  416. <if test="beginRunTime != null and beginRunTime != ''">
  417. and date_format(t1.run_time,'%Y-%m-%d') &gt;= #{beginRunTime}
  418. </if>
  419. <if test="endRunTime != null and endRunTime != ''">
  420. and date_format(t1.run_time,'%Y-%m-%d') &lt;= #{endRunTime}
  421. </if>
  422. order by t1.run_time desc
  423. </select>
  424. <select id="selectCompanyIdByBusinessId" resultType="Long">
  425. 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
  426. </select>
  427. <select id="selectManualAnsweredList" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone" resultType="CompanyVoiceRoboticCallLogCallphone">
  428. select
  429. t1.*,
  430. t2.company_name as companyName,
  431. t3.nick_name as companyUserName,
  432. cvr.name as roboticName
  433. from company_voice_robotic_call_log_callphone t1
  434. left join company t2 on t1.company_id = t2.company_id
  435. left join company_user t3 on t3.user_id = t1.company_user_id
  436. left join company_voice_robotic cvr on cvr.id = t1.robotic_id
  437. <where>
  438. t1.manual_answered = 1
  439. <if test="companyId != null">and t1.company_id = #{companyId}</if>
  440. <if test="roboticId != null">and t1.robotic_id = #{roboticId}</if>
  441. <if test="answeredExtNum != null and answeredExtNum != ''">and t1.answered_ext_num = #{answeredExtNum}</if>
  442. <if test="companyUserId != null"> and cvr.company_user_id = #{companyUserId}</if>
  443. </where>
  444. order by t1.handle_flag asc, t1.call_create_time desc
  445. </select>
  446. <!-- 按 customer_id(= callees.user_id)批量统计今日 AI 外呼(总数 / 接通数) -->
  447. <select id="selectAiCallStatToday" resultType="com.fs.crm.vo.CustomerCallStatVO">
  448. SELECT
  449. ce.user_id AS customerId,
  450. COUNT(1) AS totalCount,
  451. SUM(CASE WHEN aic.call_time &gt; 0 THEN 1 ELSE 0 END) AS connectCount
  452. FROM company_voice_robotic_call_log_callphone aic
  453. INNER JOIN company_voice_robotic_callees ce ON ce.id = aic.caller_id
  454. WHERE ce.user_id IN
  455. <foreach collection="customerIds" item="id" open="(" separator="," close=")">
  456. #{id}
  457. </foreach>
  458. AND DATE(aic.create_time) = CURDATE()
  459. GROUP BY ce.user_id
  460. </select>
  461. <!-- 按 customer_id(= callees.user_id)批量统计累计 AI 外呼(总数 / 接通数) -->
  462. <select id="selectAiCallStatTotal" resultType="com.fs.crm.vo.CustomerCallStatVO">
  463. SELECT
  464. ce.user_id AS customerId,
  465. COUNT(1) AS totalCount,
  466. SUM(CASE WHEN aic.call_time &gt; 0 THEN 1 ELSE 0 END) AS connectCount
  467. FROM company_voice_robotic_call_log_callphone aic
  468. INNER JOIN company_voice_robotic_callees ce ON ce.id = aic.caller_id
  469. WHERE ce.user_id IN
  470. <foreach collection="customerIds" item="id" open="(" separator="," close=")">
  471. #{id}
  472. </foreach>
  473. GROUP BY ce.user_id
  474. </select>
  475. <select id="countRoboticCallOutByCustomerIds" resultType="com.fs.company.vo.CustomerRoboticCallOutCountVO">
  476. SELECT ce.user_id AS customerId, COUNT(1) AS callCount
  477. FROM company_voice_robotic_call_log_callphone log
  478. INNER JOIN company_voice_robotic_callees ce ON log.caller_id = ce.id
  479. WHERE ce.user_id IS NOT NULL
  480. AND ce.user_id &gt; 0
  481. <if test="companyId != null">
  482. AND log.company_id = #{companyId}
  483. </if>
  484. AND ce.user_id IN
  485. <foreach collection="customerIds" item="id" open="(" separator="," close=")">
  486. #{id}
  487. </foreach>
  488. GROUP BY ce.user_id
  489. </select>
  490. <select id="countRoboticCallOutByCalleeIds" resultType="com.fs.company.vo.CalleeRoboticCallOutCountVO">
  491. SELECT caller_id AS calleeId, COUNT(1) AS callCount
  492. FROM company_voice_robotic_call_log_callphone
  493. WHERE robotic_id = #{roboticId}
  494. <if test="companyId != null">
  495. AND company_id = #{companyId}
  496. </if>
  497. AND caller_id IN
  498. <foreach collection="calleeIds" item="id" open="(" separator="," close=")">
  499. #{id}
  500. </foreach>
  501. GROUP BY caller_id
  502. </select>
  503. <select id="selectPendingCallbackRecords" resultType="CompanyVoiceRoboticCallLogCallphone">
  504. select * from company_voice_robotic_call_log_callphone
  505. where status = 1
  506. and callback_uuid is not null
  507. and callback_uuid != ''
  508. and (retry_count is null or retry_count &lt; 3)
  509. order by create_time asc
  510. limit 100
  511. </select>
  512. <update id="updateRetryCountAndStatus" parameterType="CompanyVoiceRoboticCallLogCallphone">
  513. update company_voice_robotic_call_log_callphone
  514. <trim prefix="SET" suffixOverrides=",">
  515. <if test="retryCount != null">retry_count = #{retryCount},</if>
  516. <if test="status != null">status = #{status},</if>
  517. </trim>
  518. where log_id = #{logId}
  519. </update>
  520. <update id="incrementCallbackCompensateRetryCount">
  521. UPDATE company_voice_robotic_call_log_callphone
  522. SET retry_count = IFNULL(retry_count, 0) + 1
  523. WHERE log_id = #{logId}
  524. AND status = 1
  525. </update>
  526. <select id="selectPendingAiCallLogsForSync" resultType="com.fs.company.vo.PendingAiCallLogSyncVo">
  527. SELECT t1.log_id AS logId,
  528. t1.callback_uuid AS callbackUuid,
  529. t1.run_param AS runParam,
  530. t1.company_id AS companyId,
  531. IFNULL(t1.retry_count, 0) AS retryCount
  532. FROM company_voice_robotic_call_log_callphone t1
  533. INNER JOIN company_voice_robotic cvr ON cvr.id = t1.robotic_id
  534. WHERE cvr.task_status = 1
  535. AND (cvr.del_flag = 0 OR cvr.del_flag IS NULL)
  536. AND t1.status = 1
  537. AND t1.callback_uuid IS NOT NULL
  538. AND t1.callback_uuid != ''
  539. AND IFNULL(t1.retry_count, 0) &lt; #{maxRetryCount}
  540. </select>
  541. </mapper>