TCallRecordMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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.slibra.business.mapper.TCallRecordMapper">
  6. <resultMap type="TCallRecord" id="TCallRecordResult">
  7. <result property="id" column="id" />
  8. <result property="sessionId" column="session_id" />
  9. <result property="type" column="type" />
  10. <result property="userId" column="user_id" />
  11. <result property="userName" column="user_name" />
  12. <result property="serviceCategory" column="service_category" />
  13. <result property="timeBegin" column="time_begin" />
  14. <result property="timeEnd" column="time_end" />
  15. <result property="times" column="times" />
  16. <result property="category" column="category" />
  17. <result property="status" column="status" />
  18. <result property="phone" column="phone" />
  19. <result property="bussinessType" column="bussiness_type" />
  20. <result property="url" column="url" />
  21. <result property="remark" column="remark" />
  22. <result property="hasParsed" column="has_parsed" />
  23. <result property="parsedVoiceContent" column="parsed_voice_content" />
  24. <result property="delFlag" column="del_flag" />
  25. <result property="revision" column="revision" />
  26. <result property="createBy" column="create_by" />
  27. <result property="createTime" column="create_time" />
  28. <result property="updateBy" column="update_by" />
  29. <result property="updateTime" column="update_time" />
  30. <result property="transferUserId" column="transfer_user_id" />
  31. <result property="transferUserName" column="transfer_user_name" />
  32. </resultMap>
  33. <sql id="selectTCallRecordVo">
  34. select id, session_id, type, user_id, user_name, service_category, time_begin, time_end, times, category, status, phone, bussiness_type, url, remark, has_parsed, parsed_voice_content, del_flag, revision, create_by, create_time, update_by, update_time, transfer_user_id, transfer_user_name from t_call_record
  35. </sql>
  36. <select id="selectTCallRecordById" parameterType="Long" resultMap="TCallRecordResult">
  37. <include refid="selectTCallRecordVo"/>
  38. where id = #{id} and del_flag = 0
  39. </select>
  40. <insert id="insertTCallRecord" parameterType="TCallRecord" useGeneratedKeys="true" keyProperty="id">
  41. insert into t_call_record
  42. <trim prefix="(" suffix=")" suffixOverrides=",">
  43. <if test="sessionId != null">session_id,</if>
  44. <if test="type != null">type,</if>
  45. <if test="userId != null">user_id,</if>
  46. <if test="userName != null">user_name,</if>
  47. <if test="serviceCategory != null">service_category,</if>
  48. <if test="timeBegin != null">time_begin,</if>
  49. <if test="timeEnd != null">time_end,</if>
  50. <if test="times != null">times,</if>
  51. <if test="category != null">category,</if>
  52. <if test="status != null">status,</if>
  53. <if test="phone != null">phone,</if>
  54. <if test="bussinessType != null">bussiness_type,</if>
  55. <if test="url != null">url,</if>
  56. <if test="remark != null">remark,</if>
  57. <if test="hasParsed != null">has_parsed,</if>
  58. <if test="parsedVoiceContent != null">parsed_voice_content,</if>
  59. <if test="delFlag != null">del_flag,</if>
  60. <if test="revision != null">revision,</if>
  61. <if test="createBy != null">create_by,</if>
  62. <if test="createTime != null">create_time,</if>
  63. <if test="updateBy != null">update_by,</if>
  64. <if test="updateTime != null">update_time,</if>
  65. </trim>
  66. <trim prefix="values (" suffix=")" suffixOverrides=",">
  67. <if test="sessionId != null">#{sessionId},</if>
  68. <if test="type != null">#{type},</if>
  69. <if test="userId != null">#{userId},</if>
  70. <if test="userName != null">#{userName},</if>
  71. <if test="serviceCategory != null">#{serviceCategory},</if>
  72. <if test="timeBegin != null">#{timeBegin},</if>
  73. <if test="timeEnd != null">#{timeEnd},</if>
  74. <if test="times != null">#{times},</if>
  75. <if test="category != null">#{category},</if>
  76. <if test="status != null">#{status},</if>
  77. <if test="phone != null">#{phone},</if>
  78. <if test="bussinessType != null">#{bussinessType},</if>
  79. <if test="url != null">#{url},</if>
  80. <if test="remark != null">#{remark},</if>
  81. <if test="hasParsed != null">#{hasParsed},</if>
  82. <if test="parsedVoiceContent != null">#{parsedVoiceContent},</if>
  83. <if test="delFlag != null">#{delFlag},</if>
  84. <if test="revision != null">#{revision},</if>
  85. <if test="createBy != null">#{createBy},</if>
  86. <if test="createTime != null">#{createTime},</if>
  87. <if test="updateBy != null">#{updateBy},</if>
  88. <if test="updateTime != null">#{updateTime},</if>
  89. </trim>
  90. </insert>
  91. <update id="updateTCallRecord" parameterType="TCallRecord">
  92. update t_call_record
  93. <trim prefix="SET" suffixOverrides=",">
  94. <if test="sessionId != null">session_id = #{sessionId},</if>
  95. <if test="type != null">type = #{type},</if>
  96. <if test="userId != null">user_id = #{userId},</if>
  97. <if test="userName != null">user_name = #{userName},</if>
  98. <if test="serviceCategory != null">service_category = #{serviceCategory},</if>
  99. <if test="timeBegin != null">time_begin = #{timeBegin},</if>
  100. <if test="timeEnd != null">time_end = #{timeEnd},</if>
  101. <if test="times != null">times = #{times},</if>
  102. <if test="category != null">category = #{category},</if>
  103. <if test="status != null">status = #{status},</if>
  104. <if test="phone != null">phone = #{phone},</if>
  105. <if test="bussinessType != null">bussiness_type = #{bussinessType},</if>
  106. <if test="url != null">url = #{url},</if>
  107. <if test="remark != null">remark = #{remark},</if>
  108. <if test="hasParsed != null">has_parsed = #{hasParsed},</if>
  109. <if test="parsedVoiceContent != null">parsed_voice_content = #{parsedVoiceContent},</if>
  110. <if test="delFlag != null">del_flag = #{delFlag},</if>
  111. <if test="revision != null">revision = #{revision},</if>
  112. <if test="createBy != null">create_by = #{createBy},</if>
  113. <if test="createTime != null">create_time = #{createTime},</if>
  114. <if test="updateBy != null">update_by = #{updateBy},</if>
  115. <if test="updateTime != null">update_time = #{updateTime},</if>
  116. </trim>
  117. ,revision = revision + 1
  118. where id = #{id}
  119. </update>
  120. <delete id="deleteTCallRecordById" parameterType="Long">
  121. update t_call_record set del_flag = 2,revision = revision + 1 where del_flag = 0 and id = #{id}
  122. </delete>
  123. <delete id="deleteTCallRecordByIds" parameterType="String">
  124. update t_call_record set del_flag = 2,revision = revision + 1 where del_flag = 0 and id in
  125. <foreach item="id" collection="array" open="(" separator="," close=")">
  126. #{id}
  127. </foreach>
  128. </delete>
  129. <!-- 2024年11月12日09:51:10 下面是新增或者调整的,不允许覆盖 -->
  130. <select id="selectTCallRecordList" parameterType="TCallRecord" resultMap="TCallRecordResult">
  131. <include refid="selectTCallRecordVo"/>
  132. <where>
  133. 1 = 1
  134. <if test="sessionId != null and sessionId != ''"> and session_id = #{sessionId}</if>
  135. <if test="type != null "> and type = #{type}</if>
  136. <if test="userId != null "> and (user_id = #{userId} or transfer_user_id = #{userId})</if>
  137. <if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
  138. <if test="serviceCategory != null "> and service_category = #{serviceCategory}</if>
  139. <if test="timeBegin != null "> and time_begin &gt;= #{timeBegin}</if>
  140. <if test="timeEnd != null "> and time_end &lt;= #{timeEnd}</if>
  141. <if test="times != null and times != ''"> and times = #{times}</if>
  142. <if test="category != null "> and category = #{category}</if>
  143. <if test="status != null "> and status = #{status}</if>
  144. <if test="phone != null and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
  145. <if test="bussinessType != null and bussinessType != ''"> and bussiness_type = #{bussinessType}</if>
  146. <if test="hasParsed != null "> and has_parsed = #{hasParsed}</if>
  147. <if test="parsedVoiceContent != null and parsedVoiceContent != ''"> and parsed_voice_content = #{parsedVoiceContent}</if>
  148. <if test="revision != null "> and revision = #{revision}</if>
  149. <if test="timeBeginReq != null and timeBeginReq != ''"> and DATE_FORMAT(time_begin, '%Y-%m-%d') &gt;= #{timeBeginReq}</if>
  150. <if test="timeEndReq != null and timeEndReq != ''"> and DATE_FORMAT(time_begin, '%Y-%m-%d') &lt;= #{timeEndReq}</if>
  151. </where>
  152. and del_flag = 0 order by id desc
  153. </select>
  154. <select id="getBusinessTypeBySessionId" resultType="string">
  155. SELECT
  156. intent
  157. FROM
  158. botrecords
  159. WHERE
  160. `session` = #{sessionId}
  161. LIMIT 1
  162. </select>
  163. <select id="getContentsBySessionId" resultType="string">
  164. SELECT
  165. contents
  166. FROM
  167. botrecords
  168. WHERE
  169. `session` = #{sessionId}
  170. LIMIT 1
  171. </select>
  172. <select id="getAgentList" resultType="com.slibra.business.res.UserTypeResp">
  173. <!-- SELECT DISTINCT
  174. user_id id,
  175. user_name `name`
  176. FROM
  177. t_call_record
  178. WHERE user_id is not null -->
  179. <!-- SELECT DISTINCT
  180. user_id id,
  181. user_name `name`,
  182. CASE
  183. service_category
  184. WHEN 0 THEN
  185. 0 ELSE 1
  186. END serviceCategory
  187. FROM
  188. t_call_record
  189. WHERE
  190. user_id IS NOT NULL -->
  191. SELECT
  192. user_id id,
  193. user_name `name`,
  194. type
  195. FROM
  196. t_zuoxi_record
  197. WHERE
  198. del_flag = 0
  199. </select>
  200. <select id="getCallCountsByPhone" resultType="int">
  201. SELECT
  202. COUNT(*)
  203. FROM
  204. t_call_record
  205. WHERE
  206. phone = #{phone}
  207. </select>
  208. <select id="selectHistoriesByPhone" resultMap="TCallRecordResult">
  209. <include refid="selectTCallRecordVo"/>
  210. where phone = #{phone} and del_flag = 0 and id != #{id}
  211. </select>
  212. <select id="getTotalByType" resultType="int">
  213. SELECT
  214. COUNT(*)
  215. FROM
  216. t_call_record
  217. WHERE
  218. 1 = 1 AND del_flag = 0
  219. <if test="type != null ">
  220. <choose>
  221. <when test="2 == type">
  222. and category = 0 and type = 2
  223. </when>
  224. <when test="0 == type">
  225. and category = 0 and type = 0 and service_category = 0
  226. </when>
  227. <when test="1 == type">
  228. and category = 0 and type = 0 and (service_category = 1 or service_category = 2)
  229. </when>
  230. </choose>
  231. </if>
  232. </select>
  233. <select id="getTotalByIsAi" resultType="int">
  234. SELECT
  235. COUNT(*)
  236. FROM
  237. t_call_record
  238. WHERE
  239. 1 = 1 AND del_flag = 0
  240. <if test="businessType == 1 "> and category = 0 and type = 1 and bussiness_type != '不体验AI服务' </if>
  241. <if test="businessType == 0 "> and category = 0 and type = 1 and bussiness_type = '不体验AI服务'</if>
  242. <if test="businessType == 2 "> and category = 1 and type = 2</if>
  243. </select>
  244. <select id="getSpecialCount" resultType="int">
  245. SELECT
  246. COUNT(*)
  247. FROM
  248. t_call_record
  249. WHERE
  250. 1 = 1 and phone = '12345' AND del_flag = 0
  251. </select>
  252. <select id="getTransferCount" resultType="int">
  253. SELECT
  254. COUNT(*)
  255. FROM
  256. t_call_record
  257. WHERE
  258. 1 = 1 and service_category = 2 AND del_flag = 0
  259. <if test="userId != null "> and user_id = #{userId} </if>
  260. <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
  261. </select>
  262. <select id="getPersonCountByState" resultType="int">
  263. SELECT
  264. COUNT(*)
  265. FROM
  266. c_agent_monitor
  267. WHERE
  268. 1 = 1
  269. and check_state = 0
  270. <if test="state != null "> and service_state = #{state}</if>
  271. </select>
  272. <select id="getPersonCountRecordIsRobot" resultType="int">
  273. SELECT
  274. COUNT(*)
  275. FROM
  276. t_call_record
  277. WHERE
  278. 1 = 1
  279. AND del_flag = 0
  280. <if test="type == 0 "> and service_category = 0</if>
  281. <if test="type == 1 "> and (service_category = 1 or service_category = 2) </if>
  282. </select>
  283. <select id="getPersonCountByType" resultType="int">
  284. SELECT
  285. COUNT(*)
  286. FROM
  287. t_call_record
  288. WHERE
  289. 1 = 1
  290. AND del_flag = 0
  291. and service_category = 0
  292. <!--<if test="type == 0 "> and (user_id is null or user_id = '') </if>
  293. <if test="type == 1 "> and user_id is not null and user_id != ''</if>-->
  294. <if test="type == 0 "> and status = 0 </if>
  295. <if test="type == 1 "> and status = 1 </if>
  296. </select>
  297. <select id="getPersonTotalRecordIsRobot" resultType="long">
  298. SELECT
  299. IFNULL(SUM(times),0)
  300. FROM
  301. t_call_record
  302. WHERE
  303. 1 = 1
  304. AND del_flag = 0
  305. <if test="type == 0 "> and service_category = 0</if>
  306. <if test="type == 1 "> and service_category != 0 </if>
  307. <if test="userId != null "> and user_id = #{userId} </if>
  308. </select>
  309. <select id="selectAllUsersByType" resultType="com.slibra.business.res.CallUserCountInfo">
  310. SELECT DISTINCT
  311. user_id userId,
  312. user_name userName
  313. FROM
  314. t_call_record
  315. WHERE
  316. 1 = 1
  317. AND del_flag = 0
  318. AND user_id IS NOT NULL
  319. AND user_id != ''
  320. <if test="type == 0 "> and service_category = 0</if>
  321. <if test="type == 1 "> and service_category != 0 </if>
  322. </select>
  323. <select id="selectAllPersonUserIds" resultType="com.slibra.business.res.CallUserCountInfo">
  324. <!-- SELECT DISTINCT
  325. user_id userId
  326. FROM
  327. t_call_record
  328. WHERE
  329. 1 = 1
  330. AND del_flag = 0
  331. AND user_id IS NOT NULL
  332. AND user_id != ''
  333. and service_category = 0 -->
  334. <!-- 2025年01月10日11:05:02,逻辑调整,获取客服列表不再从通话记录,而是从坐席记录 -->
  335. SELECT DISTINCT
  336. user_id userId
  337. FROM
  338. t_zuoxi_record
  339. WHERE
  340. type = 0
  341. AND del_flag = 0
  342. </select>
  343. <select id="getStatusByUserId" resultType="java.lang.Integer">
  344. SELECT
  345. service_state
  346. FROM
  347. c_agent_monitor
  348. WHERE
  349. out_id = (
  350. SELECT
  351. out_id
  352. FROM
  353. c_agent
  354. WHERE
  355. user_id = #{userId} AND is_delete = 0 LIMIT 1)
  356. </select>
  357. <select id="getCountByTypeAndDate" resultType="int">
  358. SELECT
  359. COUNT(*)
  360. FROM
  361. t_call_record
  362. WHERE
  363. 1 = 1
  364. AND del_flag = 0
  365. AND category = #{category}
  366. AND user_id = #{userId}
  367. <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
  368. </select>
  369. <select id="getTotalInByType" resultType="int">
  370. SELECT
  371. COUNT(*)
  372. FROM
  373. t_call_record
  374. WHERE
  375. del_flag = 0
  376. AND category = 0
  377. AND DATE_FORMAT(create_time, '%Y-%m-%d') = #{date}
  378. <if test="type != null ">
  379. <choose>
  380. <when test="0 == type">
  381. AND status = 1
  382. </when>
  383. <when test="1 == type">
  384. AND status = 0
  385. </when>
  386. <when test="2 == type">
  387. AND (service_category = 1 or service_category = 2)
  388. </when>
  389. <when test="3 == type">
  390. AND service_category = 2
  391. </when>
  392. <when test="4 == type">
  393. AND service_category = 0
  394. </when>
  395. <when test="5 == type">
  396. AND service_category = 1
  397. </when>
  398. <when test="6 == type">
  399. AND (service_category = 2 or service_category = 0)
  400. </when>
  401. </choose>
  402. </if>
  403. </select>
  404. <select id="getRecentCallRecordAfterSomeDay" resultType="int">
  405. SELECT
  406. COUNT(*)
  407. FROM
  408. t_call_record
  409. WHERE
  410. del_flag = 0
  411. AND category = 0
  412. <if test="date != null and date != ''">
  413. AND DATE_FORMAT(create_time, '%Y-%m-%d') >= #{date}
  414. </if>
  415. <if test="type != null ">
  416. <choose>
  417. <when test="0 == type">
  418. AND status = 1
  419. </when>
  420. <!--<when test="1 == type">
  421. AND status = 0
  422. </when>
  423. <when test="2 == type">
  424. AND (service_category = 1 or service_category = 2)
  425. </when>
  426. <when test="3 == type">
  427. AND service_category = 2
  428. </when>
  429. <when test="4 == type">
  430. AND service_category = 0
  431. </when>
  432. <when test="5 == type">
  433. AND service_category = 1
  434. </when>
  435. <when test="6 == type">
  436. AND (service_category = 2 or service_category = 0)
  437. </when>-->
  438. </choose>
  439. </if>
  440. </select>
  441. <select id="getRecentCallTimes" resultType="long">
  442. SELECT
  443. IFNULL( SUM( times ), 0 )
  444. FROM
  445. t_call_record
  446. WHERE
  447. del_flag = 0
  448. AND category = 0
  449. <if test="date != null and date != ''">
  450. AND DATE_FORMAT( create_time, '%Y-%m-%d' ) >= #{date}
  451. </if>
  452. </select>
  453. </mapper>