puzhibing
2023-08-16 d5b3e5a413bcfccba294793ee093722f31b2448a
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
<?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.AccountChangeDetailMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.supersavedriving.driver.modular.system.model.AccountChangeDetail">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="userType" property="userType"/>
        <result column="userId" property="userId"/>
        <result column="type" property="type"/>
        <result column="changeType" property="changeType"/>
        <result column="oldData" property="oldData"/>
        <result column="newData" property="newData"/>
        <result column="orderId" property="orderId"/>
        <result column="explain" property="explain"/>
        <result column="createTime" property="createTime"/>
    </resultMap>
 
 
 
    <select id="queryDriverIntegralIncomeAndExpenses" resultType="com.supersavedriving.driver.modular.system.warpper.IntegralIncomeAndExpensesWarpper">
        select * from (
        select
        `explain` as description,
        UNIX_TIMESTAMP(createTime) * 1000 as createTime,
        (newData - oldData) as integral
        from t_account_change_detail where `type` = 2 and userType = 2 and userId = #{driverId}
        ) as aa where 1 = 1
        <if test="null != type and 1 == type">
            and aa.integral &gt; 0
        </if>
        <if test="null != type and 2 == type">
            and aa.integral &lt; 0
        </if>
        order by aa.createTime desc limit #{pageNum}, #{pageSize}
    </select>
 
 
    <select id="queryCommissionDetail" resultType="com.supersavedriving.driver.modular.system.warpper.CommissionDetailWarpper">
        select
        `explain`,
        UNIX_TIMESTAMP(createTime) * 1000 as createTime,
        (newData - oldData) as money,
        newData as balance
        from t_account_change_detail where changeType not in (3, 4, 8, 9) and userType = 2 and `type` = 1 and userId = #{driverId}
        <if test="null != time and '' != time">
            and DATE_FORMAT(createTime, '%Y年%m月') = #{time}
        </if>
        order by createTime desc limit #{pageNum}, #{pageSize}
    </select>
 
 
    <select id="queryCommissionDetailTotal" resultType="double">
        select
        sum(money) as money
        from (
            select
            (newData - oldData) as money
            from t_account_change_detail where changeType not in (3, 4, 8, 9) and userType = 2 and `type` = 1 and userId = #{driverId}
            <if test="null != time and '' != time">
                and DATE_FORMAT(createTime, '%Y年%m月') = #{time}
            </if>
        ) as aa where aa.money > 0
    </select>
 
 
    <select id="queryBalanceDetail" resultType="com.supersavedriving.driver.modular.system.warpper.BalanceDetailWarpper">
        select
        code,
        changeType as `type`,
        UNIX_TIMESTAMP(createTime) * 1000 as createTime,
        (newData - oldData) as amount,
        newData as balance
        from t_account_change_detail where userType = 2 and userId = #{driverId} and changeType in (3, 8, 9)
        <if test="null != time and '' != time">
            and DATE_FORMAT(createTime, '%Y年%m月') = #{time}
        </if>
        <if test="null != type">
            and changeType = #{type}
        </if>
        order by createTime desc limit #{pageNum}, #{pageSize}
    </select>
</mapper>