Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?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.matrix.system.hive.dao.MoneyCardUseFlowDao">
    <!-- 定义MoneyCardUseFlow 的复杂关联map -->
    <resultMap type="com.matrix.system.hive.bean.MoneyCardUseFlow" id="MoneyCardUseFlowMap">
        <id property="id" column="id" />
        <result property="orderNo" column="order_no" />
        <result property="payNo" column="pay_no" />
        <result property="operationId" column="operation_id" />
        <result property="content" column="content" />
        <result property="createTime" column="create_time" />
        <result property="vipId" column="vip_id" />
        <result property="carUseId" column="car_use_id" />
        <result property="operVipId" column="oper_vip_id" />
        <result property="type" column="type" />
        <result property="total" column="total" />
        <result property="times" column="times" />
        <result property="giftMoney" column="gift_money" />
        <result property="balance" column="balance" />
 
        <!-- 扩展属性 -->
        <result property="operVipName" column="operVipName" />
        <result property="vipName" column="vipName" />
        <result property="staffName" column="staffName" />
        <result property="cardName" column="cardName" />
    </resultMap>
 
 
    <!-- 定义MoneyCardUseFlow 的简单map ,本map不添加其他的关联属性 -->
    <resultMap type="com.matrix.system.hive.bean.MoneyCardUseFlow" id="MoneyCardUseFlowSimpleMap">
        <id property="id" column="id" />
        <result property="orderNo" column="order_no" />
        <result property="payNo" column="pay_no" />
        <result property="operationId" column="operation_id" />
        <result property="content" column="content" />
        <result property="createTime" column="create_time" />
        <result property="vipId" column="vip_id" />
        <result property="carUseId" column="car_use_id" />
        <result property="operVipId" column="oper_vip_id" />
        <result property="type" column="type" />
        <result property="total" column="total" />
        <result property="times" column="times" />
        <result property="giftMoney" column="gift_money" />
        <result property="cardName" column="cardName" />
        <result property="balance" column="balance" />
    </resultMap>
 
    <!-- 插入方法 -->
    <insert id="insert" parameterType="com.matrix.system.hive.bean.MoneyCardUseFlow"
        useGeneratedKeys="true" keyProperty="id">
        INSERT INTO money_card_use_flow (
        id,
        order_no,
        pay_no,
        operation_id,
        content,
        create_time,
        vip_id,
        car_use_id,
        oper_vip_id,
        type,
        total,
        times,
        gift_money,
        balance
        )
        VALUES (
        #{id},
        #{orderNo},
        #{payNo},
        #{operationId},
        #{content},
        #{createTime},
        #{vipId},
        #{carUseId},
        #{operVipId},
        #{type},
        #{total},
        #{times},
        #{giftMoney},
        #{balance}
        )
    </insert>
 
 
    <!-- 根据id更新 部分更新 -->
    <update id="update" parameterType="Long">
        UPDATE money_card_use_flow
        <set>
            <if test="orderNo != null and orderNo !='' ">
                order_no = #{orderNo},
            </if>
            <if test="operationId != null and operationId !='' ">
                operation_id = #{operationId},
            </if>
            <if test="content != null and content !='' ">
                content = #{content},
            </if>
            <if test="createTime != null  ">
                create_time = #{createTime},
            </if>
            <if test="vipId != null and vipId !='' ">
                vip_id = #{vipId},
            </if>
            <if test="carUseId != null and carUseId !='' ">
                car_use_id = #{carUseId},
            </if>
            <if test="operVipId != null and operVipId !='' ">
                oper_vip_id = #{operVipId},
            </if>
            <if test="type != null and type !='' ">
                type = #{type},
            </if>
            <if test="total != null and total !='' ">
                total = #{total},
            </if>
            <if test="times != null and times !='' ">
                times = #{times},
            </if>
            <if test="giftMoney != null and giftMoney !='' ">
                gift_money = #{giftMoney},
            </if>
            <if test="balance != null and balance !='' ">
                balance = #{balance},
            </if>
        </set>
        WHERE id=#{id}
    </update>
 
 
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from money_card_use_flow where id in
        <foreach collection="list" index="index" item="item" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </delete>
 
    <!-- 根据id删除 -->
    <delete id="deleteById" parameterType="Long">
        DELETE FROM
        money_card_use_flow
        where id=#{id}
    </delete>
 
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="MoneyCardUseFlowMap">
        select
        id,
        order_no,
        pay_no,
        operation_id,
        content,
        create_time,
        vip_id,
        car_use_id,
        oper_vip_id,
        type,
        total,
        times,
        gift_money,
        balance,
        (SELECT su_name from sys_users a WHERE operation_id=a.su_id) staffName,
        (SELECT VIP_NAME FROM sys_vip_info b WHERE vip_id=b.ID) vipName,
        (SELECT card_NAME FROM money_card_use c WHERE car_use_id=c.ID) cardName
        from money_card_use_flow
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.orderNo != null and record.orderNo !='' ">
                and order_no = #{record.orderNo}
            </if>
            <if test="record.payNo != null and record.payNo !='' ">
                and pay_no = #{record.payNo}
            </if>
            <if test="record.operationId != null and record.operationId !='' ">
                and operation_id = #{record.operationId}
            </if>
            <if test="record.content != null and record.content !='' ">
                and content like CONCAT('%',#{record.content},'%')
            </if>
            <if test="record.createTime != null and record.createTime !='' ">
                and create_time = #{record.createTime}
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and vip_id = #{record.vipId}
            </if>
            <if test="record.carUseId != null and record.carUseId !='' ">
                and car_use_id = #{record.carUseId}
            </if>
                <if test="record.operVipId != null and record.operVipId!='' ">
                and oper_vip_id = #{record.operVipId}
            </if>
            <if test="record.type != null and record.type !='' ">
                and type = #{record.type}
            </if>
        </if>
        ORDER BY create_time desc
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <!-- 查询总条数 -->
    <select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer">
        select count(*)
        from money_card_use_flow
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.orderNo != null and record.orderNo !='' ">
                and order_no = #{record.orderNo}
            </if>
            <if test="record.payNo != null and record.payNo !='' ">
                and pay_no = #{record.payNo}
            </if>
            <if test="record.operationId != null and record.operationId !='' ">
                and operation_id = #{record.operationId}
            </if>
            <if test="record.content != null and record.content !='' ">
                and content like   CONCAT('%',#{record.content},'%')
            </if>
            <if test="record.createTime != null and record.createTime !='' ">
                and create_time = #{record.createTime}
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and vip_id = #{record.vipId}
            </if>
            <if test="record.carUseId != null and record.carUseId !='' ">
                and car_use_id = #{record.carUseId}
            </if>
            
            <if test="record.operVipId != null and record.operVipId!='' ">
                and oper_vip_id = #{record.operVipId}
            </if>
            <if test="record.type != null and record.type !='' ">
                and type = #{record.type}
            </if>
        </if>
    </select>
 
    <!-- 根据id查询 -->
    <select id="selectById" resultMap="MoneyCardUseFlowMap">
        select
        id,
        order_no,
        pay_no,
        operation_id,
        content,
        create_time,
        vip_id,
        car_use_id,
        oper_vip_id,
        type,
        balance,
        total,
        times,
        gift_money,
        (SELECT STAFF_NAME from sys_shopstaff_info a WHERE operation_id=a.id) staffName,
        (SELECT VIP_NAME FROM sys_vip_info a WHERE vip_id=a.ID) vipName,
        (SELECT VIP_NAME FROM sys_vip_info a WHERE oper_vip_id=a.ID) operVipName
        from money_card_use_flow
        where id=#{id}
    </select>
    
 
    <!-- 根据对象查询 -->
    <select id="selectByModel" resultMap="MoneyCardUseFlowMap">
        select
        id,
        order_no,
        pay_no,
        operation_id,
        content,
        create_time,
        vip_id,
        car_use_id,
        balance,
        oper_vip_id,
        type,
        total,
        times,
        gift_money,
        (SELECT STAFF_NAME from sys_shopstaff_info a WHERE operation_id=a.id) staffName,
        (SELECT VIP_NAME FROM sys_vip_info a WHERE vip_id=a.ID) vipName,
        (SELECT VIP_NAME FROM sys_vip_info a WHERE oper_vip_id=a.ID) operVipName
        from money_card_use_flow
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.orderNo != null and record.orderNo !='' ">
                and order_no = #{record.orderNo}
            </if>
            <if test="record.payNo != null and record.payNo !='' ">
                and pay_no = #{record.payNo}
            </if>
            <if test="record.operationId != null and record.operationId !='' ">
                and operation_id = #{record.operationId}
            </if>
            <if test="record.content != null and record.content !='' ">
                and content like   CONCAT('%',#{record.content},'%')
            </if>
            <if test="record.createTime != null and record.createTime !='' ">
                and create_time = #{record.createTime}
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and vip_id = #{record.vipId}
            </if>
            <if test="record.carUseId != null and record.carUseId !='' ">
                and car_use_id = #{record.carUseId}
            </if>
            <if test="record.operVipId != null and record.operVipId!='' ">
                and oper_vip_id = #{record.operVipId}
            </if>
            <if test="record.type != null and record.type !='' ">
                and type = #{record.type}
            </if>
        </if>
    </select>
 
    <select id="selectForWxInPage" resultMap="MoneyCardUseFlowMap">
        select
            id,
            order_no,
            pay_no,
            content,
            create_time,
            type,
            total,
            times,
            gift_money,
            balance,
            (SELECT su_name from sys_users a WHERE operation_id=a.su_id) staffName
        from money_card_use_flow
        <where>
                and car_use_id=#{record.carUseId}
            <if test="record.queryTime!=null and record.queryTime!=''">
                and DATE_FORMAT(create_time,'%Y-%m')=#{record.queryTime}
            </if>
            <if test="record.revenueType==1">
                and  total>0
            </if>
            <if test="record.revenueType==2">
                <![CDATA[ and total<0 ]]>
            </if>
        </where>
        order by  create_time desc
    </select>
 
    <update id="updateVipCardId">
        update money_card_use_flow
            set car_use_id=#{cardId}
        where vip_id=#{vipId} and type='会员充值'
    </update>
 
    <select id="selectCardUseAmount" resultType="java.lang.Double">
        select IFNULL(ABS(sum(IFNULL(total, 0))), 0)
        from money_card_use_flow
        where car_use_id=#{cardId} and type='消费扣款'
    </select>
</mapper>