TCallRecordMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 "> and type = #{type}</if>
  220. </select>
  221. <select id="getTotalByIsAi" resultType="int">
  222. SELECT
  223. COUNT(*)
  224. FROM
  225. t_call_record
  226. WHERE
  227. 1 = 1 and type = 1 AND del_flag = 0
  228. <if test="businessType == 1 "> and (bussiness_type != '不体验AI服务' or bussiness_type is NULL or bussiness_type = '') and category = 0</if>
  229. <if test="businessType == 0 "> and bussiness_type = '不体验AI服务' and category = 0</if>
  230. <if test="businessType == 2 "> and category = 1</if>
  231. </select>
  232. <select id="getSpecialCount" resultType="int">
  233. SELECT
  234. COUNT(*)
  235. FROM
  236. t_call_record
  237. WHERE
  238. 1 = 1 and phone = '12345' AND del_flag = 0
  239. </select>
  240. <select id="getTransferCount" resultType="int">
  241. SELECT
  242. COUNT(*)
  243. FROM
  244. t_call_record
  245. WHERE
  246. 1 = 1 and service_category = 2 AND del_flag = 0
  247. <if test="userId != null "> and user_id = #{userId} </if>
  248. <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
  249. </select>
  250. <select id="getPersonCountByState" resultType="int">
  251. SELECT
  252. COUNT(*)
  253. FROM
  254. c_agent_monitor
  255. WHERE
  256. 1 = 1
  257. and check_state = 0
  258. <if test="state != null "> and service_state = #{state}</if>
  259. </select>
  260. <select id="getPersonCountRecordIsRobot" resultType="int">
  261. SELECT
  262. COUNT(*)
  263. FROM
  264. t_call_record
  265. WHERE
  266. 1 = 1
  267. AND del_flag = 0
  268. <if test="type == 0 "> and service_category = 0</if>
  269. <if test="type == 1 "> and service_category != 0 </if>
  270. </select>
  271. <select id="getPersonCountByType" resultType="int">
  272. SELECT
  273. COUNT(*)
  274. FROM
  275. t_call_record
  276. WHERE
  277. 1 = 1
  278. AND del_flag = 0
  279. and service_category = 0
  280. <if test="type == 0 "> and (user_id is null or user_id = '') </if>
  281. <if test="type == 1 "> and user_id is not null and user_id != ''</if>
  282. </select>
  283. <select id="getPersonTotalRecordIsRobot" resultType="long">
  284. SELECT
  285. IFNULL(SUM(times),0)
  286. FROM
  287. t_call_record
  288. WHERE
  289. 1 = 1
  290. AND del_flag = 0
  291. <if test="type == 0 "> and service_category = 0</if>
  292. <if test="type == 1 "> and service_category != 0 </if>
  293. <if test="userId != null "> and user_id = #{userId} </if>
  294. </select>
  295. <select id="selectAllUsersByType" resultType="com.slibra.business.res.CallUserCountInfo">
  296. SELECT DISTINCT
  297. user_id userId,
  298. user_name userName
  299. FROM
  300. t_call_record
  301. WHERE
  302. 1 = 1
  303. AND del_flag = 0
  304. AND user_id IS NOT NULL
  305. AND user_id != ''
  306. <if test="type == 0 "> and service_category = 0</if>
  307. <if test="type == 1 "> and service_category != 0 </if>
  308. </select>
  309. <select id="selectAllPersonUserIds" resultType="com.slibra.business.res.CallUserCountInfo">
  310. SELECT DISTINCT
  311. user_id userId
  312. FROM
  313. t_call_record
  314. WHERE
  315. 1 = 1
  316. AND del_flag = 0
  317. AND user_id IS NOT NULL
  318. AND user_id != ''
  319. and service_category = 0
  320. </select>
  321. <select id="getStatusByUserId" resultType="java.lang.Integer">
  322. SELECT
  323. service_state
  324. FROM
  325. c_agent_monitor
  326. WHERE
  327. out_id = (
  328. SELECT
  329. out_id
  330. FROM
  331. c_agent
  332. WHERE
  333. user_id = #{userId} AND is_delete = 0 LIMIT 1)
  334. </select>
  335. <select id="getCountByTypeAndDate" resultType="int">
  336. SELECT
  337. COUNT(*)
  338. FROM
  339. t_call_record
  340. WHERE
  341. 1 = 1
  342. AND del_flag = 0
  343. AND category = #{category}
  344. AND user_id = #{userId}
  345. <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
  346. </select>
  347. </mapper>