liujie
2023-08-16 db7fa6a91b9534ac90e219b6f554c54c43c83a5a
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?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.supersavedriving.driver.modular.system.dao.RevenueMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.supersavedriving.driver.modular.system.model.Revenue">
        <id column="id" property="id" />
        <result column="type" property="type" />
        <result column="userType" property="userType" />
        <result column="userId" property="userId" />
        <result column="orderId" property="orderId" />
        <result column="amount" property="amount" />
        <result column="balance" property="balance"/>
        <result column="createTime" property="createTime" />
    </resultMap>
 
 
    <select id="queryTotalAmount" resultType="double">
        select sum(amount) as amount from t_revenue where userType = 2 and userId = #{driverId} and type in (1,2)
    </select>
 
 
    <select id="queryDriverRank" resultType="com.supersavedriving.driver.modular.system.warpper.PerformanceRankingWarpper">
        select
        aa.driverId,
        @ROW :=@ROW + 1 as rank,
        aa.`name`,
        UNIX_TIMESTAMP(aa.createTime) * 1000 as createTime,
        aa.number as amountOfData
        from (
        select
        a.userId as driverId,
        b.`name`,
        MAX(a.createTime) as createTime,
        sum(a.amount) as number
        from t_revenue a
        left join t_driver b on (a.userId = b.id)
        where a.userType = 2
        <if test="null != type">
            and a.type = #{type}
        </if>
        <if test="null != dayType and 1 == dayType"><!--天-->
            <if test="null != time and '' != time">
                and DATE_FORMAT(a.createTime, '%Y年%m月%d日') = #{time}
            </if>
        </if>
        <if test="null != dayType and 2 == dayType"><!--月-->
            <if test="null != time and '' != time">
                and DATE_FORMAT(a.createTime, '%Y年%m月') = #{time}
            </if>
        </if>
        <if test="null != dayType and 3 == dayType"><!--年-->
            <if test="null != time and '' != time">
                and DATE_FORMAT(a.createTime, '%Y年') = #{time}
            </if>
        </if>
        group by a.userId,b.`name`
        ) as aa,( SELECT @ROW := 0 ) AS itable order by aa.number desc
    </select>
 
 
    <select id="queryAgentBalance" resultType="double">
        select
        sum(aa.income) - sum(aa.disburse) as balance
        from (
        select sum(amount) as income, 0 as disburse from t_revenue where userType = 3 and userId = #{companyId}
        union all
        select 0 as ncome, sum(amount) as disburse from t_settlement_record where type = 2 and objectId = #{companyId}
        ) as aa
    </select>
 
 
 
    <select id="queryCompanyBalance" resultType="double">
        select
        sum(aa.income) - sum(aa.disburse) + sum(aa.recharge) as balance
        from (
        select sum(amount) as income, 0 as disburse, 0 as recharge from t_revenue where userType = 4
        union all
        select 0 as ncome, sum(amount) as disburse, 0 as recharge from t_settlement_record where type = 1
        union all
        select 0 as ncome, 0 as disburse, sum(surplusDividedAmount) as recharge from t_recharge_record where type = 4 and payStatus = 2
        ) as aa
    </select>
</mapper>