CallRecordMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.qingjian.module.call.mapper.CallRecordMapper">
  4. <!-- 定义结果映射:表字段 → 实体类属性(假设实体类属性与表字段名一致) -->
  5. <resultMap id="CallRecordResultMap" type="com.qingjian.common.model.call.entity.CallRecord">
  6. <id column="id" property="id"/>
  7. <result column="fileId" property="fileId"/>
  8. <result column="sheetId" property="sheetId"/>
  9. <result column="personName" property="personName"/>
  10. <result column="personPhone" property="personPhone"/>
  11. <result column="personPhoneArea" property="personPhoneArea"/>
  12. <result column="personCertNo" property="personCertNo"/>
  13. <result column="personRegionId" property="personRegionId"/>
  14. <result column="personCellId" property="personCellId"/>
  15. <result column="personStationName" property="personStationName"/>
  16. <result column="personStationLongitude" property="personStationLongitude"/>
  17. <result column="personStationLatitude" property="personStationLatitude"/>
  18. <result column="callDateTime" property="callDateTime"/>
  19. <result column="duration" property="duration"/>
  20. <result column="callDirection" property="callDirection"/>
  21. <result column="callType" property="callType"/>
  22. <result column="otherName" property="otherName"/>
  23. <result column="otherPhone" property="otherPhone"/>
  24. <result column="otherPhoneArea" property="otherPhoneArea"/>
  25. <result column="otherCertNo" property="otherCertNo"/>
  26. <result column="remark" property="remark"/>
  27. <result column="operatorId" property="operatorId"/>
  28. <result column="callLocal" property="callLocal"/>
  29. </resultMap>
  30. <!-- 全字段动态条件查询:所有字段均可作为查询条件,空值自动忽略 -->
  31. <select id="selectCallRecordPage" resultMap="CallRecordResultMap">
  32. SELECT
  33. id,
  34. fileId,
  35. sheetId,
  36. personName,
  37. personPhone,
  38. personPhoneArea,
  39. personCertNo,
  40. personRegionId,
  41. personCellId,
  42. personStationName,
  43. personStationLongitude,
  44. personStationLatitude,
  45. callDateTime,
  46. duration,
  47. callDirection,
  48. callType,
  49. otherName,
  50. otherPhone,
  51. otherPhoneArea,
  52. otherCertNo,
  53. remark,
  54. operatorId,
  55. callLocal
  56. FROM ${query.tableName}
  57. <where>
  58. <if test="query.ids != null and query.ids.size>0">
  59. AND id in
  60. <foreach item="id" collection="query.ids" separator="," open="(" close=")">
  61. #{id}
  62. </foreach>
  63. </if>
  64. <if test="query.id != null">
  65. AND id = #{query.id}
  66. </if>
  67. <if test="query.fileId != null">
  68. AND fileId = #{query.fileId}
  69. </if>
  70. <if test="query.sheetId != null">
  71. AND sheetId = #{query.sheetId}
  72. </if>
  73. <if test="query.personName != null and query.personName != ''">
  74. AND personName = #{query.personName}
  75. </if>
  76. <if test="query.personPhones != null and query.personPhones.size>0">
  77. AND personPhone in
  78. <foreach item="phone" collection="query.personPhones" separator="," open="(" close=")">
  79. #{phone}
  80. </foreach>
  81. </if>
  82. <if test="query.personPhoneArea != null and query.personPhoneArea != ''">
  83. AND personPhoneArea = #{query.personPhoneArea}
  84. </if>
  85. <if test="query.personCertNo != null and query.personCertNo != ''">
  86. AND personCertNo = #{query.personCertNo}
  87. </if>
  88. <if test="query.personRegionId != null and query.personRegionId != ''">
  89. AND personRegionId = #{query.personRegionId}
  90. </if>
  91. <if test="query.personCellId != null and query.personCellId != ''">
  92. AND personCellId = #{query.personCellId}
  93. </if>
  94. <if test="query.startDate != null">
  95. AND callDate >= #{query.startDate}
  96. </if>
  97. <if test="query.endDate != null">
  98. AND callDate &lt;= #{query.endDate}
  99. </if>
  100. <if test="query.startTime != null">
  101. AND (
  102. (#{query.startTime} &lt; #{query.endTime} AND callTime BETWEEN #{query.startTime} AND
  103. #{query.endTime})
  104. OR
  105. (#{query.startTime} &gt; #{query.endTime} AND (callTime >= #{query.startTime} OR callTime
  106. &lt; #{query.endTime}))
  107. )
  108. </if>
  109. <choose>
  110. <when test="query.symbol != 'ge'">
  111. <if test="query.duration != null">
  112. AND duration >= #{query.duration}
  113. </if>
  114. </when>
  115. <otherwise>
  116. <if test="query.duration != null">
  117. AND duration &lt;= #{query.duration}
  118. </if>
  119. </otherwise>
  120. </choose>
  121. <if test="query.callDirection != null and query.callDirection != ''">
  122. AND callDirection = #{query.callDirection}
  123. </if>
  124. <if test="query.callType != null and query.callType != ''">
  125. AND callType = #{query.callType}
  126. </if>
  127. <if test="query.otherName != null and query.otherName != ''">
  128. <choose>
  129. <when test="query.otherName == '未知对手'">
  130. and otherName IS NULL
  131. </when>
  132. <otherwise>
  133. and otherName = #{query.otherName}
  134. </otherwise>
  135. </choose>
  136. </if>
  137. <if test="query.otherPhones != null and query.otherPhones.size>0">
  138. AND otherPhone in
  139. <foreach item="phone" collection="query.otherPhones" separator="," open="(" close=")">
  140. #{phone}
  141. </foreach>
  142. </if>
  143. <if test="query.operatorId != null and query.operatorId != ''">
  144. AND operatorId LIKE CONCAT('%', #{query.operatorId}, '%')
  145. </if>
  146. </where>
  147. <if test="query.orderKey != null and query.orderKey != ''">
  148. order by ${query.orderKey} ${query.sort}
  149. </if>
  150. </select>
  151. <select id="statCall" resultType="com.qingjian.common.model.person.dto.CallDataProfileStatDTO">
  152. SELECT
  153. COUNT(*) AS callCount,
  154. COUNT(distinct otherPhone) as otherCount,
  155. COUNT() FILTER (callDirection = '主叫') AS outCount,
  156. COUNT() FILTER (callDirection = '被叫') AS inCount,
  157. MIN(callDate) AS callDateStart,
  158. MAX(callDate) AS callDateEnd
  159. FROM ${tableName}
  160. WHERE personName = #{personName}
  161. </select>
  162. <select id="callOftenTop10" resultType="com.qingjian.common.model.person.dto.CallOftenTop10DTO">
  163. SELECT COALESCE(otherPhone, '未知卡号') as otherPhone,
  164. COUNT(*) AS callCount
  165. FROM ${query.tableName}
  166. WHERE personName = #{query.personName}
  167. <if test="query.startDate != null">
  168. and callDate >= #{query.startDate}
  169. </if>
  170. <if test="query.endDate != null">
  171. and callDate &lt;= #{query.endDate}
  172. </if>
  173. GROUP BY COALESCE(otherPhone, '未知卡号')
  174. ORDER BY callCount, otherPhone DESC
  175. </select>
  176. <select id="callStatStation" resultType="com.qingjian.common.model.person.dto.CallStatStationDTO">
  177. SELECT count(*) as callCount,
  178. personRegionId,
  179. personCellId,
  180. any_value(personStationName) as personStationName,
  181. any_value(personStationLongitude) as personStationLongitude,
  182. any_value(personStationLatitude) as personStationLatitude
  183. FROM ${tableName}
  184. WHERE personName = #{personName}
  185. GROUP BY personRegionId, personCellId
  186. ORDER BY callCount DESC
  187. LIMIT ${limit}
  188. </select>
  189. <select id="getCallRecordSummary" resultType="com.qingjian.common.model.person.dto.CallRecordSummaryDTO">
  190. select personPhone,
  191. otherName,
  192. otherPhone,
  193. count(*) as callCount,
  194. from ${query.tableName}
  195. where personName = #{query.personName}
  196. <if test="query.otherName != null and query.otherName != ''">
  197. <choose>
  198. <when test="query.otherName == '未知对手'">
  199. and otherName IS NULL
  200. </when>
  201. <otherwise>
  202. and otherName = #{query.otherName}
  203. </otherwise>
  204. </choose>
  205. </if>
  206. <if test="query.otherPhone != null">
  207. and otherPhone = #{query.otherPhone}
  208. </if>
  209. <if test="query.startDate != null">
  210. AND callDate >= #{query.startDate}
  211. </if>
  212. <if test="query.endDate != null">
  213. AND callDate &lt;= #{query.endDate}
  214. </if>
  215. group by personPhone, otherName, otherPhone
  216. <choose>
  217. <when test="query.orderKey != null and query.orderKey != ''">
  218. order by ${query.orderKey} ${query.sort}
  219. </when>
  220. <otherwise>
  221. order by callCount desc
  222. </otherwise>
  223. </choose>
  224. </select>
  225. <select id="callGraphDetail" resultType="com.qingjian.common.model.call.entity.CallRecord">
  226. select * from (
  227. select *
  228. from ${query.tableName}
  229. where
  230. callDirection = '主叫'
  231. <if test="query.personPhone!=null">
  232. and personPhone = #{query.personPhone}
  233. </if>
  234. <if test="query.otherPhone!=null">
  235. and otherPhone = #{query.otherPhone}
  236. </if>
  237. union all
  238. select *
  239. from ${query.tableName}
  240. where
  241. callDirection != '主叫'
  242. <if test="query.personPhone!=null">
  243. and personPhone = #{query.otherPhone}
  244. </if>
  245. <if test="query.otherPhone!=null">
  246. and otherPhone = #{query.personPhone}
  247. </if>
  248. ) as temmp_msg_data
  249. <where>
  250. <if test="query.startDate != null">
  251. AND callDate >= #{query.startDate}
  252. </if>
  253. <if test="query.endDate != null">
  254. AND callDate &lt;= #{query.endDate}
  255. </if>
  256. </where>
  257. <if test="query.orderKey != null and query.orderKey != ''">
  258. order by ${query.orderKey} ${query.sort}
  259. </if>
  260. </select>
  261. </mapper>