| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.qingjian.module.trans.mapper.TransFrequencyMapper">
- <!--
- 统计首次交易频率信息
- 功能:按交易对手(姓名、卡号)分组,统计每组的:
- - 最早和最晚交易日期
- - 交易总次数
- - 交易总金额
- 筛选条件:交易次数大于指定阈值
- 排序:按交易次数降序排列
- -->
- <select id="statFirstTransFrequency" resultType="com.qingjian.common.model.trans.dto.TransFrequencyDTO">
- SELECT
- personName,
- COALESCE(otherName, '未知对手') as otherName,
- COALESCE(otherCardNo, '未知对手卡号') as otherCardNo,
- MIN(transDate) as startTransDate,
- MAX(transDate) as endTransDate,
- COUNT(*) AS transCount ,
- SUM(transAmount) AS transTotalAmount
- FROM ${query.tableName}
- <where>
- <if test="query.personNames != null and query.personNames.size > 0">
- AND personName IN
- <foreach collection="query.personNames" item="name" open="(" separator="," close=")">
- #{name}
- </foreach>
- </if>
- <if test="query.otherName != null and query.otherName != ''">
- <choose>
- <when test="query.otherName == '未知对手'">
- and otherName IS NULL
- </when>
- <otherwise>
- and otherName = #{query.otherName}
- </otherwise>
- </choose>
- </if>
- <if test="query.otherCardNo != null and query.otherCardNo != ''">
- <choose>
- <when test="query.otherCardNo == '未知对手卡号'">
- AND otherCardNo IS NULL
- </when>
- <otherwise>
- AND otherCardNo = #{query.otherCardNo}
- </otherwise>
- </choose>
- </if>
- <if test="query.startDate != null">
- and transDate >= #{query.startDate}
- </if>
- <if test="query.endDate != null">
- and transDate <= #{query.endDate}
- </if>
- </where>
- GROUP BY ALL
- <if test="query.transCount != null">
- HAVING transCount ${query.transCountSymbol} #{query.transCount}
- </if>
- <if test="query.orderKey != null and query.orderKey != ''">
- ORDER BY ${query.orderKey} ${query.sort}
- </if>
- </select>
-
- </mapper>
|