BrokerageUserMapper.xml
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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="cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageUserMapper">
<sql id="OrderDirection">
<choose>
<when test="@cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils@isAscOrder(sortingField.order)">
ASC
</when>
<otherwise>
DESC
</otherwise>
</choose>
</sql>
<select id="selectSummaryPageByUserId"
resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO">
SELECT bu.id, bu.bind_user_time AS brokerageTime,
(SELECT SUM(price) FROM trade_brokerage_record r
WHERE r.user_id = bu.id AND biz_type = #{bizType} AND r.status = #{status} AND r.deleted = 0) AS brokeragePrice,
(SELECT COUNT(1) FROM trade_brokerage_record r
WHERE r.user_id = bu.id AND biz_type = #{bizType} AND r.status = #{status} AND r.deleted = 0) AS brokerageOrderCount,
(SELECT COUNT(1) FROM trade_brokerage_user c
WHERE c.bind_user_id = bu.id AND c.deleted = 0) AS brokerageUserCount
FROM trade_brokerage_user AS bu
<where>
bu.deleted = 0
<if test="ids != null and ids.size() > 0">
and bu.id in
<foreach collection="ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
</where>
<choose>
<when test="sortingField != null and sortingField.field == 'userCount'">
ORDER BY brokerageUserCount
<include refid="OrderDirection"/>
</when>
<when test="sortingField != null and sortingField.field == 'orderCount'">
ORDER BY brokerageOrderCount
<include refid="OrderDirection"/>
</when>
<when test="sortingField != null and sortingField.field == 'price'">
ORDER BY brokeragePrice
<include refid="OrderDirection"/>
</when>
<otherwise>
ORDER BY bu.bind_user_time DESC
</otherwise>
</choose>
</select>
</mapper>