CcCallPhoneMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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.ruoyi.aicall.mapper.CcCallPhoneMapper">
  6. <resultMap type="CcCallPhone" id="CcCallPhoneResult">
  7. <result property="id" column="id" />
  8. <result property="batchId" column="batch_id" />
  9. <result property="batchName" column="batchName" />
  10. <result property="telephone" column="telephone" />
  11. <result property="custName" column="cust_name" />
  12. <result property="createtime" column="createtime" />
  13. <result property="callstatus" column="callstatus" />
  14. <result property="calloutTime" column="callout_time" />
  15. <result property="callcount" column="callcount" />
  16. <result property="callEndTime" column="call_end_time" />
  17. <result property="timeLen" column="time_len" />
  18. <result property="validTimeLen" column="valid_time_len" />
  19. <result property="uuid" column="uuid" />
  20. <result property="connectedTime" column="connected_time" />
  21. <result property="hangupCause" column="hangup_cause" />
  22. <result property="answeredTime" column="answered_time" />
  23. <result property="dialogue" column="dialogue" />
  24. <result property="wavfile" column="wavfile" />
  25. <result property="recordServerUrl" column="record_server_url" />
  26. <result property="bizJson" column="biz_json" />
  27. <result property="dialogueCount" column="dialogue_count" />
  28. <result property="acdOpnum" column="acd_opnum" />
  29. <result property="acdQueueTime" column="dialogue_count" />
  30. <result property="acdWaitTime" column="dialogue_count" />
  31. <result property="ttsText" column="tts_text" />
  32. <result property="intent" column="intent" />
  33. <result property="asrSeconds" column="asr_seconds" />
  34. <result property="ttsTimes" column="tts_times" />
  35. <result property="ttsFlowTokens" column="tts_flow_tokens" />
  36. <result property="inputTokens" column="input_tokens" />
  37. <result property="outputTokens" column="output_tokens" />
  38. <result property="totalCost" column="total_cost" />
  39. <result property="billingStatus" column="billing_status" />
  40. <result property="callerNumber" column="caller_number" />
  41. <result property="ivrDtmfDigits" column="ivr_dtmf_digits" />
  42. <result property="manualAnsweredTime" column="manual_answered_time" />
  43. <result property="manualAnsweredTimeLen" column="manual_answered_time_len" />
  44. </resultMap>
  45. <sql id="selectCcCallPhoneVo">
  46. select id, batch_id, telephone, cust_name, createtime, callstatus, callout_time,
  47. callcount, call_end_time, time_len, valid_time_len, uuid, connected_time,
  48. hangup_cause, answered_time, dialogue, wavfile, record_server_url, biz_json,
  49. dialogue_count, acd_opnum, acd_queue_time, acd_wait_time, tts_text, intent,
  50. asr_seconds, tts_times, tts_flow_tokens, input_tokens, output_tokens,
  51. total_cost, billing_status, caller_number, ivr_dtmf_digits, manual_answered_time, manual_answered_time_len from cc_call_phone
  52. </sql>
  53. <sql id="ccCallPhoneListWhere">
  54. <if test="uuid != null and uuid != '' "> and cp.uuid = #{uuid}</if>
  55. <if test="telephone != null and telephone != ''"> and cp.telephone = #{telephone}</if>
  56. <if test="custName != null and custName != ''"> and cp.cust_name = #{custName}</if>
  57. <if test="callstatus != null "> and cp.callstatus = #{callstatus}</if>
  58. <if test="params.calloutTimeStart != null and params.calloutTimeStart != ''"><!-- 开始时间检索 -->
  59. AND cp.callout_time &gt;= #{params.calloutTimeStart}
  60. </if>
  61. <if test="params.calloutTimeEnd != null and params.calloutTimeEnd != ''"><!-- 结束时间检索 -->
  62. AND cp.callout_time &lt;= #{params.calloutTimeEnd}
  63. </if>
  64. <if test="params.callEndTimeStart != null and params.callEndTimeStart != ''"><!-- 开始时间检索 -->
  65. AND cp.call_end_time &gt;= #{params.callEndTimeStart}
  66. </if>
  67. <if test="params.callEndTimeEnd != null and params.callEndTimeEnd != ''"><!-- 结束时间检索 -->
  68. AND cp.call_end_time &lt;= #{params.callEndTimeEnd}
  69. </if>
  70. <if test="params.timeLenStart != null and params.timeLenStart != ''"><!-- 开始时间检索 -->
  71. AND cp.time_len &gt;= #{params.timeLenStart}
  72. </if>
  73. <if test="params.timeLenEnd != null and params.timeLenEnd != ''"><!-- 结束时间检索 -->
  74. AND cp.time_len &lt;= #{params.timeLenEnd}
  75. </if>
  76. <if test="params.connectedTimeStart != null and params.connectedTimeStart != ''"><!-- 开始时间检索 -->
  77. AND cp.connected_time &gt;= #{params.connectedTimeStart}
  78. </if>
  79. <if test="params.connectedTimeEnd != null and params.connectedTimeEnd != ''"><!-- 结束时间检索 -->
  80. AND cp.connected_time &lt;= #{params.connectedTimeEnd}
  81. </if>
  82. <if test="params.answeredTimeStart != null and params.answeredTimeStart != ''"><!-- 开始时间检索 -->
  83. AND cp.answered_time &gt;= #{params.answeredTimeStart}
  84. </if>
  85. <if test="params.answeredTimeEnd != null and params.answeredTimeEnd != ''"><!-- 结束时间检索 -->
  86. AND cp.answered_time &lt;= #{params.answeredTimeEnd}
  87. </if>
  88. <if test="batchId != null">
  89. AND cp.batch_id = #{batchId}
  90. </if>
  91. <if test="params.batchIds != null and params.batchIds.size() &gt; 0">
  92. AND cp.batch_id IN
  93. <foreach collection="params.batchIds" item="bid" open="(" separator="," close=")">
  94. #{bid}
  95. </foreach>
  96. </if>
  97. <if test="batchName != null and batchName != ''">
  98. AND EXISTS (
  99. SELECT 1 FROM cc_call_task ct
  100. WHERE ct.batch_id = cp.batch_id
  101. AND ct.batch_name like concat('%', #{batchName}, '%')
  102. )
  103. </if>
  104. <if test="intent != null and intent != ''">
  105. AND cp.intent = #{intent}
  106. </if>
  107. <if test="billingStatus != null ">
  108. and cp.billing_status = #{billingStatus}
  109. </if>
  110. <if test="callerNumber != null and callerNumber != '' ">
  111. and cp.caller_number = #{callerNumber}
  112. </if>
  113. AND cp.callstatus &gt;= 3 AND cp.call_end_time &gt; 0
  114. </sql>
  115. <!-- 列表完整查询(导出/API/计费等仍可用,含大字段) -->
  116. <select id="selectCcCallPhoneList" parameterType="CcCallPhone" resultMap="CcCallPhoneResult">
  117. select cp.*, ct.batch_name as batchName
  118. from cc_call_phone cp
  119. left join cc_call_task ct on cp.batch_id = ct.batch_id
  120. <where>
  121. <include refid="ccCallPhoneListWhere"/>
  122. </where>
  123. order by cp.call_end_time desc
  124. </select>
  125. <!-- 列表加速第1步:仅查 id,避免分页/COUNT 触碰 TEXT 大字段 -->
  126. <select id="selectCcCallPhoneIds" parameterType="CcCallPhone" resultType="java.lang.String">
  127. select cp.id
  128. from cc_call_phone cp
  129. <where>
  130. <include refid="ccCallPhoneListWhere"/>
  131. </where>
  132. order by cp.call_end_time desc
  133. </select>
  134. <!-- 列表加速第2步:按 id 回表列表展示字段(不含 dialogue/biz_json/tts_text) -->
  135. <select id="selectCcCallPhoneLiteByIds" resultMap="CcCallPhoneResult">
  136. select
  137. cp.id, cp.batch_id, cp.telephone, cp.cust_name, cp.createtime, cp.callstatus,
  138. cp.callout_time, cp.callcount, cp.call_end_time, cp.time_len, cp.valid_time_len,
  139. cp.uuid, cp.connected_time, cp.hangup_cause, cp.answered_time,
  140. cp.wavfile, cp.record_server_url, cp.dialogue_count, cp.acd_opnum,
  141. cp.acd_queue_time, cp.acd_wait_time, cp.intent, cp.caller_number,
  142. cp.ivr_dtmf_digits, cp.manual_answered_time, cp.manual_answered_time_len
  143. from cc_call_phone cp
  144. where cp.id in
  145. <foreach collection="ids" item="id" open="(" separator="," close=")">
  146. #{id}
  147. </foreach>
  148. order by field(cp.id,
  149. <foreach collection="ids" item="id" separator=",">
  150. #{id}
  151. </foreach>
  152. )
  153. </select>
  154. <select id="getCustIntentionList" parameterType="CcCallPhone" resultMap="CcCallPhoneResult">
  155. <include refid="selectCcCallPhoneVo"/>
  156. where intent = '' AND callstatus >= 3 AND call_end_time > 0 limit 100
  157. </select>
  158. <select id="selectCcCallPhoneById" parameterType="String" resultMap="CcCallPhoneResult">
  159. <include refid="selectCcCallPhoneVo"/>
  160. where id = #{id}
  161. </select>
  162. <insert id="insertCcCallPhone" parameterType="CcCallPhone">
  163. insert into cc_call_phone
  164. <trim prefix="(" suffix=")" suffixOverrides=",">
  165. <if test="id != null">id,</if>
  166. <if test="batchId != null">batch_id,</if>
  167. <if test="telephone != null and telephone != ''">telephone,</if>
  168. <if test="custName != null and custName != ''">cust_name,</if>
  169. <if test="createtime != null">createtime,</if>
  170. <if test="callstatus != null">callstatus,</if>
  171. <if test="calloutTime != null">callout_time,</if>
  172. <if test="callcount != null">callcount,</if>
  173. <if test="callEndTime != null">call_end_time,</if>
  174. <if test="timeLen != null">time_len,</if>
  175. <if test="validTimeLen != null">valid_time_len,</if>
  176. <if test="uuid != null and uuid != ''">uuid,</if>
  177. <if test="connectedTime != null">connected_time,</if>
  178. <if test="hangupCause != null and hangupCause != ''">hangup_cause,</if>
  179. <if test="answeredTime != null">answered_time,</if>
  180. <if test="dialogue != null">dialogue,</if>
  181. <if test="wavfile != null and wavfile != ''">wavfile,</if>
  182. <if test="recordServerUrl != null and recordServerUrl != ''">record_server_url,</if>
  183. <if test="bizJson != null and bizJson != ''">biz_json,</if>
  184. <if test="dialogueCount != null">dialogue_count,</if>
  185. <if test="acdOpnum != null and acdOpnum != ''">acd_opnum,</if>
  186. <if test="acdQueueTime != null">acd_queue_time,</if>
  187. <if test="acdWaitTime != null">acd_wait_time,</if>
  188. <if test="ttsText != null">tts_text,</if>
  189. <if test="intent != null">intent,</if>
  190. </trim>
  191. <trim prefix="values (" suffix=")" suffixOverrides=",">
  192. <if test="id != null">#{id},</if>
  193. <if test="batchId != null">#{batchId},</if>
  194. <if test="telephone != null and telephone != ''">#{telephone},</if>
  195. <if test="custName != null and custName != ''">#{cust_name},</if>
  196. <if test="createtime != null">#{createtime},</if>
  197. <if test="callstatus != null">#{callstatus},</if>
  198. <if test="calloutTime != null">#{calloutTime},</if>
  199. <if test="callcount != null">#{callcount},</if>
  200. <if test="callEndTime != null">#{callEndTime},</if>
  201. <if test="timeLen != null">#{timeLen},</if>
  202. <if test="validTimeLen != null">#{validTimeLen},</if>
  203. <if test="uuid != null and uuid != ''">#{uuid},</if>
  204. <if test="connectedTime != null">#{connectedTime},</if>
  205. <if test="hangupCause != null and hangupCause != ''">#{hangupCause},</if>
  206. <if test="answeredTime != null">#{answeredTime},</if>
  207. <if test="dialogue != null">#{dialogue},</if>
  208. <if test="wavfile != null and wavfile != ''">#{wavfile},</if>
  209. <if test="recordServerUrl != null and recordServerUrl != ''">#{recordServerUrl},</if>
  210. <if test="bizJson != null and bizJson != ''">#{bizJson},</if>
  211. <if test="dialogueCount != null">#{dialogueCount},</if>
  212. <if test="acdOpnum != null and acdOpnum != ''">#{acdOpnum},</if>
  213. <if test="acdQueueTime != null">#{acdQueueTime},</if>
  214. <if test="acdWaitTime != null">#{acdWaitTime},</if>
  215. <if test="ttsText != null">#{ttsText},</if>
  216. <if test="intent != null">#{intent},</if>
  217. </trim>
  218. </insert>
  219. <update id="updateCcCallPhone" parameterType="CcCallPhone">
  220. update cc_call_phone
  221. <trim prefix="SET" suffixOverrides=",">
  222. <if test="batchId != null">batch_id = #{batchId},</if>
  223. <if test="telephone != null and telephone != ''">telephone = #{telephone},</if>
  224. <if test="custName != null and custName != ''">cust_name = #{custName},</if>
  225. <if test="createtime != null">createtime = #{createtime},</if>
  226. <if test="callstatus != null">callstatus = #{callstatus},</if>
  227. <if test="calloutTime != null">callout_time = #{calloutTime},</if>
  228. <if test="callcount != null">callcount = #{callcount},</if>
  229. <if test="callEndTime != null">call_end_time = #{callEndTime},</if>
  230. <if test="timeLen != null">time_len = #{timeLen},</if>
  231. <if test="validTimeLen != null">valid_time_len = #{validTimeLen},</if>
  232. <if test="uuid != null and uuid != ''">uuid = #{uuid},</if>
  233. <if test="connectedTime != null">connected_time = #{connectedTime},</if>
  234. <if test="hangupCause != null and hangupCause != ''">hangup_cause = #{hangupCause},</if>
  235. <if test="answeredTime != null">answered_time = #{answeredTime},</if>
  236. <if test="dialogue != null">dialogue = #{dialogue},</if>
  237. <if test="wavfile != null and wavfile != ''">wavfile = #{wavfile},</if>
  238. <if test="recordServerUrl != null and recordServerUrl != ''">record_server_url = #{recordServerUrl},</if>
  239. <if test="bizJson != null and bizJson != ''">biz_json = #{bizJson},</if>
  240. <if test="dialogueCount != null">dialogue_count = #{dialogueCount},</if>
  241. <if test="acdOpnum != null and acdOpnum != ''">acd_opnum = #{acdOpnum},</if>
  242. <if test="acdQueueTime != null">acd_queue_time = #{acdQueueTime},</if>
  243. <if test="acdWaitTime != null">acd_wait_time = #{acdWaitTime},</if>
  244. <if test="ttsText != null">tts_text = #{ttsText},</if>
  245. <if test="intent != null">intent = #{intent},</if>
  246. </trim>
  247. where id = #{id}
  248. </update>
  249. <delete id="deleteCcCallPhoneById" parameterType="String">
  250. delete from cc_call_phone where id = #{id}
  251. </delete>
  252. <delete id="deleteCcCallPhoneByIds" parameterType="String">
  253. delete from cc_call_phone where id in
  254. <foreach item="id" collection="array" open="(" separator="," close=")">
  255. #{id}
  256. </foreach>
  257. </delete>
  258. <select id="statByBatchId" parameterType="Long" resultType="com.ruoyi.aicall.model.CallTaskStatModel">
  259. SELECT batch_id AS batchId,
  260. COUNT(1) AS phoneCount,
  261. SUM(CASE WHEN callout_time > 0 THEN 1 ELSE 0 END) AS callCount,
  262. SUM(CASE WHEN answered_time > 0 THEN 1 ELSE 0 END) AS connectCount
  263. FROM cc_call_phone
  264. WHERE batch_id = #{batchId}
  265. </select>
  266. <select id="statByBatchIds" resultType="com.ruoyi.aicall.model.CallTaskStatModel">
  267. SELECT batch_id AS batchId,
  268. COUNT(1) AS phoneCount,
  269. SUM(CASE WHEN callout_time > 0 THEN 1 ELSE 0 END) AS callCount,
  270. SUM(CASE WHEN answered_time > 0 THEN 1 ELSE 0 END) AS connectCount
  271. FROM cc_call_phone
  272. WHERE batch_id IN
  273. <foreach collection="batchIds" item="batchId" open="(" separator="," close=")">
  274. #{batchId}
  275. </foreach>
  276. GROUP BY batch_id
  277. </select>
  278. <insert id="batchInsertCcCallPhone" parameterType="java.util.List">
  279. INSERT INTO cc_call_phone (
  280. id, batch_id, telephone, cust_name, createtime, callstatus,
  281. callout_time, callcount, call_end_time, time_len, valid_time_len,
  282. uuid, connected_time, hangup_cause,
  283. answered_time, dialogue, wavfile, record_server_url, biz_json,
  284. dialogue_count,acd_opnum,acd_queue_time,acd_wait_time,
  285. tts_text, intent
  286. )
  287. VALUES
  288. <foreach collection="list" item="item" separator=",">
  289. (
  290. #{item.id}, #{item.batchId}, #{item.telephone}, #{item.custName},
  291. #{item.createtime}, #{item.callstatus}, #{item.calloutTime},
  292. #{item.callcount}, #{item.callEndTime}, #{item.timeLen},
  293. #{item.validTimeLen}, #{item.uuid},
  294. #{item.connectedTime}, #{item.hangupCause},
  295. #{item.answeredTime}, #{item.dialogue}, #{item.wavfile},
  296. #{item.recordServerUrl}, #{item.bizJson}, #{item.dialogueCount},
  297. #{item.acdOpnum}, #{item.acdQueueTime}, #{item.acdWaitTime},
  298. #{item.ttsText}, #{item.intent}
  299. )
  300. </foreach>
  301. </insert>
  302. <update id="updateIntentionByIds">
  303. UPDATE cc_call_phone
  304. SET intent = #{intention}
  305. WHERE id IN
  306. <foreach collection="phoneIds" item="id" open="(" separator="," close=")">
  307. #{id}
  308. </foreach>
  309. </update>
  310. <select id="selectNoHangupCalls" parameterType="Long" resultMap="CcCallPhoneResult">
  311. <include refid="selectCcCallPhoneVo"/>
  312. <where>
  313. AND batch_id = #{batchId}
  314. AND callstatus >= 2
  315. AND call_end_time = 0
  316. </where>
  317. order by call_end_time desc
  318. </select>
  319. <insert id="bakCallPhoneByBatchId" parameterType="Long">
  320. insert into his_cc_call_phone select * from cc_call_phone where batch_id = #{batchId}
  321. </insert>
  322. <delete id="delCallPhoneByBatchId" parameterType="Long">
  323. delete from cc_call_phone where batch_id = #{batchId}
  324. </delete>
  325. <select id="selectCcCallPhoneYlrzList" parameterType="CcCallPhone" resultMap="CcCallPhoneResult">
  326. select ccp.*, cct.batch_name as batchName from cc_call_phone ccp left join cc_call_task cct on cct.batch_id = ccp.batch_id
  327. <where>
  328. <if test="uuid != null and uuid != '' "> and ccp.uuid = #{uuid}</if>
  329. <if test="batchId != null "> and ccp.batch_id = #{batchId}</if>
  330. <if test="telephone != null and telephone != ''"> and ccp.telephone = #{telephone}</if>
  331. <if test="custName != null and custName != ''"> and ccp.cust_name = #{custName}</if>
  332. <if test="callstatus != null "> and ccp.callstatus = #{callstatus}</if>
  333. <if test="params.calloutTimeStart != null and params.calloutTimeStart != ''"><!-- 开始时间检索 -->
  334. AND ccp.callout_time &gt;= #{params.calloutTimeStart}
  335. </if>
  336. <if test="params.calloutTimeEnd != null and params.calloutTimeEnd != ''"><!-- 结束时间检索 -->
  337. AND ccp.callout_time &lt;= #{params.calloutTimeEnd}
  338. </if>
  339. <if test="params.callEndTimeStart != null and params.callEndTimeStart != ''"><!-- 开始时间检索 -->
  340. AND ccp.call_end_time &gt;= #{params.callEndTimeStart}
  341. </if>
  342. <if test="params.callEndTimeEnd != null and params.callEndTimeEnd != ''"><!-- 结束时间检索 -->
  343. AND ccp.call_end_time &lt;= #{params.callEndTimeEnd}
  344. </if>
  345. <if test="params.timeLenStart != null and params.timeLenStart != ''"><!-- 开始时间检索 -->
  346. AND ccp.time_len &gt;= #{params.timeLenStart}
  347. </if>
  348. <if test="params.timeLenEnd != null and params.timeLenEnd != ''"><!-- 结束时间检索 -->
  349. AND ccp.time_len &lt;= #{params.timeLenEnd}
  350. </if>
  351. <if test="params.connectedTimeStart != null and params.connectedTimeStart != ''"><!-- 开始时间检索 -->
  352. AND ccp.connected_time &gt;= #{params.connectedTimeStart}
  353. </if>
  354. <if test="params.connectedTimeEnd != null and params.connectedTimeEnd != ''"><!-- 结束时间检索 -->
  355. AND ccp.connected_time &lt;= #{connectedTimeEnd}
  356. </if>
  357. <if test="params.answeredTimeStart != null and params.answeredTimeStart != ''"><!-- 开始时间检索 -->
  358. AND ccp.answered_time &gt;= #{params.answeredTimeStart}
  359. </if>
  360. <if test="params.answeredTimeEnd != null and params.answeredTimeEnd != ''"><!-- 结束时间检索 -->
  361. AND ccp.answered_time &lt;= #{params.answeredTimeEnd}
  362. </if>
  363. <if test="batchId != null and batchId != ''">
  364. AND ccp.batch_id = #{batchId}
  365. </if>
  366. <if test="intent != null and intent != ''">
  367. AND ccp.intent = #{intent}
  368. </if>
  369. <if test="billingStatus != null ">
  370. and ccp.billing_status = #{billingStatus}
  371. </if>
  372. <if test="callerNumber != null and callerNumber != '' ">
  373. and ccp.caller_number = #{callerNumber}
  374. </if>
  375. AND ccp.callstatus >= 3 AND ccp.call_end_time > 0
  376. </where>
  377. order by ccp.call_end_time desc
  378. </select>
  379. <select id="selectCcCallPhoneListByIds" parameterType="java.util.List" resultMap="CcCallPhoneResult">
  380. <include refid="selectCcCallPhoneVo"/>
  381. where uuid is not null and id in
  382. <foreach item="id" collection="list" open="(" separator="," close=")">
  383. #{id}
  384. </foreach>
  385. </select>
  386. <select id="selectCcCallPhoneDialogueByUuid" resultType="java.lang.String">
  387. select dialogue from cc_call_phone where uuid = #{uuid} limit 1
  388. </select>
  389. </mapper>