xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?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.stylefeng.guns.modular.system.dao.PaymentRecordMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.PaymentRecord">
        <id column="id" property="id"/>
        <result column="category" property="category"/>
        <result column="userId" property="userId"/>
        <result column="type" property="type"/>
        <result column="orderId" property="orderId"/>
        <result column="orderType" property="orderType"/>
        <result column="payType" property="payType"/>
        <result column="amount" property="amount"/>
        <result column="code" property="code"/>
        <result column="state" property="state"/>
        <result column="insertTime" property="insertTime"/>
    </resultMap>
 
 
    <select id="query" resultType="PaymentRecord">
        select
        id as id,
        category as category,
        userId as userId,
        `type` as `type`,
        orderId as orderId,
        orderType as orderType,
        payType as payType,
        amount as amount,
        code as code,
        state as state,
        insertTime as insertTime
        from t_payment_record where category = #{category}
        <if test="null != userId">
            and userId = #{userId}
        </if>
        <if test="null != type">
            and type = #{type}
        </if>
        <if test="null != orderId">
            and orderId = #{orderId}
        </if>
        <if test="null != orderType">
            and orderType = #{orderType}
        </if>
        <if test="null != payType">
            and payType = #{payType}
        </if>
        <if test="null != state">
            and state = #{state}
        </if>
        order by insertTime desc limit 0,1
    </select>
 
    <select id="query_" resultType="PaymentRecord">
        select
        id as id,
        category as category,
        userId as userId,
        `type` as `type`,
        orderId as orderId,
        orderType as orderType,
        payType as payType,
        amount as amount,
        code as code,
        state as state,
        insertTime as insertTime
        from t_payment_record where category = #{category}
        <if test="null != userId">
            and userId = #{userId}
        </if>
        <if test="null != type">
            and type = #{type}
        </if>
        <if test="null != orderId">
            and orderId = #{orderId}
        </if>
        <if test="null != orderType">
            and orderType = #{orderType}
        </if>
        <if test="null != payType">
            and payType = #{payType}
        </if>
        <if test="null != state">
            and state = #{state}
        </if>
        order by insertTime desc
    </select>
 
 
    <select id="exportRecord" resultType="map">
        select
        case when pr.payType = 1 then '微信'
        when pr.payType = 2 then '支付宝' end payTypeStr,
        pr.amount,
        pr.code,
        pr.userId,
        DATE_FORMAT(pr.insertTime,'%Y-%m-%d %H:%i:%S') as insertTimeStr,
        case when pr.state = 1 then '失败'
        when pr.state = 2 then '成功' end stateStr,
        u.nickName,
        u.phone
        from t_payment_record pr
        left join t_user u
        on pr.userId = u.id
        where pr.type = 1 and pr.category = 2
        <if test="userName != null and userName != ''">
            and u.nickName like CONCAT('%',#{userName},'%')
        </if>
        <if test="phone != null and phone != ''">
            and u.phone like CONCAT('%',#{phone},'%')
        </if>
        <if test="code != null and code != ''">
            and pr.code like CONCAT('%',#{code},'%')
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            and (pr.insertTime between CONCAT(#{startTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
        </if>
        order by pr.id desc
    </select>
</mapper>