ShiShiYiBan/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml

46 lines
2.4 KiB
XML
Raw Normal View History

2023-09-22 22:12:15 +08:00
<?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">
<select id="selectSummaryPageByUserId"
resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO">
2023-09-24 11:56:00 +08:00
SELECT bu.id, bu.bind_user_time AS brokerageTime, u.nickname, u.avatar,
<!-- TODO @疯狂biz_type、status 可以通过参数传入哇? -->
2023-09-22 22:12:15 +08:00
(SELECT SUM(price) FROM trade_brokerage_record r
2023-09-24 11:56:00 +08:00
WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokeragePrice,
2023-09-22 22:12:15 +08:00
(SELECT COUNT(1) FROM trade_brokerage_record r
2023-09-24 11:56:00 +08:00
WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokerageOrderCount,
2023-09-22 22:12:15 +08:00
(SELECT COUNT(1) FROM trade_brokerage_user c
2023-09-24 11:56:00 +08:00
WHERE c.bind_user_id = u.id AND c.deleted = FALSE) AS brokerageUserCount
2023-09-22 22:12:15 +08:00
FROM member_user AS u
JOIN trade_brokerage_user AS bu ON bu.id = u.id
<!-- TODO @疯狂1bind_user_id 是不是可以先改成内存查询出 userId 的集合,然后去 in 哈2nickname 是不是可以基于查询出来的 userId 对应的 nickname 在内存里过滤,主要是避免和 member_user 链表 -->
<where>
2023-09-22 22:12:15 +08:00
<if test="param.nickname != null and param.nickname != ''">
AND u.nickname LIKE concat('', #{param.nickname}, '')
</if>
<if test="param.level == 1">
AND bu.bind_user_id = #{userId}
</if>
<if test="param.level == 2">
2023-09-24 11:56:00 +08:00
AND bu.bind_user_id IN (SELECT id FROM trade_brokerage_user c WHERE c.bind_user_id = #{userId})
2023-09-22 22:12:15 +08:00
</if>
</where>
<choose>
<when test="param.sortingField.field == 'userCount'">
ORDER BY brokerageUserCount ${param.sortingField.order}
</when>
<when test="param.sortingField.field == 'orderCount'">
ORDER BY brokerageOrderCount ${param.sortingField.order}
</when>
<when test="param.sortingField.field == 'price'">
ORDER BY brokeragePrice ${param.sortingField.order}
</when>
<otherwise>
ORDER BY bu.bind_user_time DESC
</otherwise>
</choose>
</select>
2023-09-24 11:56:00 +08:00
2023-09-22 22:12:15 +08:00
</mapper>