TransFrequencyMapper.xml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.trans.mapper.TransFrequencyMapper">
  4. <!--
  5. 统计首次交易频率信息
  6. 功能:按交易对手(姓名、卡号)分组,统计每组的:
  7. - 最早和最晚交易日期
  8. - 交易总次数
  9. - 交易总金额
  10. 筛选条件:交易次数大于指定阈值
  11. 排序:按交易次数降序排列
  12. -->
  13. <select id="statFirstTransFrequency" resultType="com.qingjian.common.model.trans.dto.TransFrequencyDTO">
  14. SELECT
  15. personName,
  16. COALESCE(otherName, '未知对手') as otherName,
  17. COALESCE(otherCardNo, '未知对手卡号') as otherCardNo,
  18. MIN(transDate) as startTransDate,
  19. MAX(transDate) as endTransDate,
  20. COUNT(*) AS transCount ,
  21. SUM(transAmount) AS transTotalAmount
  22. FROM ${query.tableName}
  23. <where>
  24. <if test="query.personNames != null and query.personNames.size > 0">
  25. AND personName IN
  26. <foreach collection="query.personNames" item="name" open="(" separator="," close=")">
  27. #{name}
  28. </foreach>
  29. </if>
  30. <if test="query.otherName != null and query.otherName != ''">
  31. <choose>
  32. <when test="query.otherName == '未知对手'">
  33. and otherName IS NULL
  34. </when>
  35. <otherwise>
  36. and otherName = #{query.otherName}
  37. </otherwise>
  38. </choose>
  39. </if>
  40. <if test="query.otherCardNo != null and query.otherCardNo != ''">
  41. <choose>
  42. <when test="query.otherCardNo == '未知对手卡号'">
  43. AND otherCardNo IS NULL
  44. </when>
  45. <otherwise>
  46. AND otherCardNo = #{query.otherCardNo}
  47. </otherwise>
  48. </choose>
  49. </if>
  50. <if test="query.startDate != null">
  51. and transDate >= #{query.startDate}
  52. </if>
  53. <if test="query.endDate != null">
  54. and transDate &lt;= #{query.endDate}
  55. </if>
  56. </where>
  57. GROUP BY ALL
  58. <if test="query.transCount != null">
  59. HAVING transCount ${query.transCountSymbol} #{query.transCount}
  60. </if>
  61. <if test="query.orderKey != null and query.orderKey != ''">
  62. ORDER BY ${query.orderKey} ${query.sort}
  63. </if>
  64. </select>
  65. </mapper>