chengf
2026-01-27 b6184e2ddf3db37a94f7efb3b619bbc64642a292
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?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="mpPaymentRecordServiceDaoImpl">
 
 
    <!-- 保存打印支取到账记录信息 add by wuxw 2018-07-03 -->
    <insert id="saveMpPaymentRecordInfo" parameterType="Map">
        insert into mp_payment_record(
        mp_id, first_print_date, resolution_number, print_amount,
        arrival_date, arrival_amount, withdrawer, shortage_or_arrears,
        road_name, lane, `door`, room, owner_address, print_count, snake_case
        ) values (
        #{mpId}, #{firstPrintDate}, #{resolutionNumber},
        <if test="printAmount == null">0</if>
        <if test="printAmount != null">#{printAmount}</if>,
        #{arrivalDate},
        <if test="arrivalAmount == null">0</if>
        <if test="arrivalAmount != null">#{arrivalAmount}</if>,
        #{withdrawer},
        <if test="shortageOrArrears == null">0</if>
        <if test="shortageOrArrears != null">#{shortageOrArrears}</if>,
        #{roadName}, #{lane}, #{door}, #{room}, #{ownerAddress},
        #{printCount}, #{snakeCase}
        )
    </insert>
 
    <!-- 删除打印支取到账记录信息 -->
    <delete id="deleteMpPaymentRecordInfo" parameterType="Map">
        delete from mp_payment_record t
        where 1 = 1
        <!-- 支持按主键ID删除 -->
        <if test="id != null">
            and t.id = #{id}
        </if>
        <!-- 支持按mpId批量删除(可选条件) -->
        <if test="mpId != null and mpId != ''">
            and t.mp_id = #{mpId}
        </if>
        <!-- 支持按时间范围删除(可选条件) -->
        <if test="startDate != null">
            and t.first_print_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and t.first_print_date &lt;= #{endDate}
        </if>
        <!-- 新增snake_case删除条件 -->
        <if test="snakeCase != null and snakeCase != ''">
            and t.snake_case = #{snakeCase}
        </if>
    </delete>
    <!-- 查询打印支取到账记录信息 add by wuxw 2018-07-03 -->
    <select id="getMpPaymentRecordInfo" parameterType="Map" resultType="Map">
        select
        t.mp_id,t.mp_id mpId,
        t.first_print_date,t.first_print_date firstPrintDate,
        t.resolution_number,t.resolution_number resolutionNumber,
        t.print_amount,t.print_amount printAmount,
        t.arrival_date,t.arrival_date arrivalDate,
        t.arrival_amount,t.arrival_amount arrivalAmount,
        t.withdrawer,
        t.shortage_or_arrears,t.shortage_or_arrears shortageOrArrears,
        t.road_name,t.road_name roadName,
        t.lane,
        t.`door`,
        t.room,
        t.owner_address,t.owner_address ownerAddress,
        t.id,
        t.print_count, t.print_count printCount,
        t.snake_case, t.snake_case snakeCase  <!-- 新增snake_case字段查询 -->
        from mp_payment_record t
        where 1 =1
        <if test="mpId !=null and mpId != ''">
            and t.mp_id = #{mpId}
        </if>
        <if test="firstPrintDate !=null">
            and t.first_print_date = #{firstPrintDate}
        </if>
        <if test="resolutionNumber !=null and resolutionNumber != ''">
            and t.resolution_number = #{resolutionNumber}
        </if>
        <if test="printAmount !=null">
            and t.print_amount = #{printAmount}
        </if>
        <if test="arrivalDate !=null">
            and t.arrival_date = #{arrivalDate}
        </if>
        <if test="arrivalAmount !=null">
            and t.arrival_amount = #{arrivalAmount}
        </if>
        <if test="withdrawer !=null and withdrawer != ''">
            and t.withdrawer = #{withdrawer}
        </if>
        <if test="shortageOrArrears !=null">
            and t.shortage_or_arrears = #{shortageOrArrears}
        </if>
        <if test="roadName !=null and roadName != ''">
            and t.road_name = #{roadName}
        </if>
        <if test="lane !=null and lane != ''">
            and t.lane = #{lane}
        </if>
        <if test="door !=null and door != ''">
            and t.door = #{door}
        </if>
        <if test="room !=null and room != ''">
            and t.room = #{room}
        </if>
        <if test="ownerAddress !=null and ownerAddress != ''">
            and t.owner_address = #{ownerAddress}
        </if>
        <if test="id !=null">
            and t.id = #{id}
        </if>
        <!-- 新增printCount查询条件(字符串匹配) -->
        <if test="printCount !=null and printCount != ''">
            and t.print_count = #{printCount}
        </if>
        <!-- 新增snake_case查询条件 -->
        <if test="snakeCase !=null and snakeCase != ''">
            and t.snake_case = #{snakeCase}
        </if>
        <!-- 时间范围查询 -->
        <if test="startDate !=null">
            and t.first_print_date >= #{startDate}
        </if>
        <if test="endDate !=null">
            and t.first_print_date &lt;= #{endDate}
        </if>
        <if test="startArrivalDate !=null">
            and t.arrival_date >= #{startArrivalDate}
        </if>
        <if test="endArrivalDate !=null">
            and t.arrival_date &lt;= #{endArrivalDate}
        </if>
        order by t.id desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
 
    </select>
 
 
    <!-- 修改打印支取到账记录信息 add by wuxw 2018-07-03 -->
    <update id="updateMpPaymentRecordInfo" parameterType="Map">
        update mp_payment_record t set t.id = #{id}
        <if test="newBId != null and newBId != ''">
            ,t.b_id = #{newBId}
        </if>
        <if test="mpId !=null and mpId != ''">
            , t.mp_id = #{mpId}
        </if>
        <if test="firstPrintDate !=null">
            , t.first_print_date = #{firstPrintDate}
        </if>
        <if test="resolutionNumber !=null and resolutionNumber != ''">
            , t.resolution_number = #{resolutionNumber}
        </if>
        <if test="printAmount !=null">
            , t.print_amount = #{printAmount}
        </if>
        <if test="arrivalDate !=null">
            , t.arrival_date = #{arrivalDate}
        </if>
        <if test="arrivalAmount !=null">
            , t.arrival_amount = #{arrivalAmount}
        </if>
        <if test="withdrawer !=null and withdrawer != ''">
            , t.withdrawer = #{withdrawer}
        </if>
        <if test="shortageOrArrears !=null">
            , t.shortage_or_arrears = #{shortageOrArrears}
        </if>
        <if test="roadName !=null and roadName != ''">
            , t.road_name = #{roadName}
        </if>
        <if test="lane !=null and lane != ''">
            , t.lane = #{lane}
        </if>
        <if test="door !=null and door != ''">
            , t.door = #{door}
        </if>
        <if test="room !=null and room != ''">
            , t.room = #{room}
        </if>
        <if test="ownerAddress !=null and ownerAddress != ''">
            , t.owner_address = #{ownerAddress}
        </if>
        <!-- 新增printCount更新条件(字符串类型) -->
        <if test="printCount !=null and printCount != ''">
            , t.print_count = #{printCount}
        </if>
        <!-- 新增snake_case更新条件 -->
        <if test="snakeCase !=null and snakeCase != ''">
            , t.snake_case = #{snakeCase}
        </if>
        where 1=1
        <if test="id !=null">
            and t.id = #{id}
        </if>
 
    </update>
 
    <!-- 查询打印支取到账记录数量 add by wuxw 2018-07-03 -->
    <select id="queryMpPaymentRecordsCount" parameterType="Map" resultType="Map">
        select count(1) count
        from mp_payment_record t
        where 1 =1
        <if test="mpId !=null and mpId != ''">
            and t.mp_id = #{mpId}
        </if>
        <if test="firstPrintDate !=null">
            and t.first_print_date = #{firstPrintDate}
        </if>
        <if test="resolutionNumber !=null and resolutionNumber != ''">
            and t.resolution_number = #{resolutionNumber}
        </if>
        <if test="printAmount !=null">
            and t.print_amount = #{printAmount}
        </if>
        <if test="arrivalDate !=null">
            and t.arrival_date = #{arrivalDate}
        </if>
        <if test="arrivalAmount !=null">
            and t.arrival_amount = #{arrivalAmount}
        </if>
        <if test="withdrawer !=null and withdrawer != ''">
            and t.withdrawer = #{withdrawer}
        </if>
        <if test="shortageOrArrears !=null">
            and t.shortage_or_arrears = #{shortageOrArrears}
        </if>
        <if test="roadName !=null and roadName != ''">
            and t.road_name = #{roadName}
        </if>
        <if test="lane !=null and lane != ''">
            and t.lane = #{lane}
        </if>
        <if test="door !=null and door != ''">
            and t.door = #{door}
        </if>
        <if test="room !=null and room != ''">
            and t.room = #{room}
        </if>
        <if test="ownerAddress !=null and ownerAddress != ''">
            and t.owner_address = #{ownerAddress}
        </if>
        <if test="id !=null">
            and t.id = #{id}
        </if>
        <!-- 新增printCount查询条件(字符串匹配) -->
        <if test="printCount !=null and printCount != ''">
            and t.print_count = #{printCount}
        </if>
        <!-- 新增snake_case查询条件 -->
        <if test="snakeCase !=null and snakeCase != ''">
            and t.snake_case = #{snakeCase}
        </if>
        <!-- 时间范围查询 -->
        <if test="startDate !=null">
            and t.first_print_date >= #{startDate}
        </if>
        <if test="endDate !=null">
            and t.first_print_date &lt;= #{endDate}
        </if>
        <if test="startArrivalDate !=null">
            and t.arrival_date >= #{startArrivalDate}
        </if>
        <if test="endArrivalDate !=null">
            and t.arrival_date &lt;= #{endArrivalDate}
        </if>
    </select>
 
    <!-- 批量插入打印支取到账记录 -->
    <insert id="saveMpPaymentRecords" parameterType="Map">
        insert into mp_payment_record(
        mp_id, first_print_date, resolution_number, print_amount,
        arrival_date, arrival_amount, withdrawer, shortage_or_arrears,
        road_name, lane, `door`, room, owner_address, id, print_count, snake_case
        ) values
        <foreach collection="mpPaymentRecordPos" item="item" separator=",">
            ( #{item.mpId}, #{item.firstPrintDate}, #{item.resolutionNumber},
            <if test="item.printAmount == null">0</if><if test="item.printAmount != null">#{item.printAmount}</if>,
            #{item.arrivalDate},
            <if test="item.arrivalAmount == null">0</if><if test="item.arrivalAmount != null">#{item.arrivalAmount}</if>,
            #{item.withdrawer},
            <if test="item.shortageOrArrears == null">0</if><if test="item.shortageOrArrears != null">#{item.shortageOrArrears}</if>,
            #{item.roadName}, #{item.lane}, #{item.door}, #{item.room}, #{item.ownerAddress}, #{id},
            #{item.printCount}, #{item.snakeCase}  <!-- 新增snake_case字段 -->
            )
        </foreach>
    </insert>
 
    <!-- 查询统计信息 -->
    <select id="queryMpPaymentRecordStatistics" parameterType="Map" resultType="Map">
        select
        count(1) as total_count,
        sum(t.print_amount) as total_print_amount,
        sum(t.arrival_amount) as total_arrival_amount,
        sum(t.shortage_or_arrears) as total_shortage,
        avg(t.print_amount) as avg_print_amount,
        avg(t.arrival_amount) as avg_arrival_amount,
        min(t.first_print_date) as earliest_print_date,
        max(t.first_print_date) as latest_print_date,
        min(t.arrival_date) as earliest_arrival_date,
        max(t.arrival_date) as latest_arrival_date
        from mp_payment_record t
        where 1 =1
        <if test="mpId !=null and mpId != ''">
            and t.mp_id = #{mpId}
        </if>
        <if test="startDate !=null">
            and t.first_print_date >= #{startDate}
        </if>
        <if test="endDate !=null">
            and t.first_print_date &lt;= #{endDate}
        </if>
        <if test="startArrivalDate !=null">
            and t.arrival_date >= #{startArrivalDate}
        </if>
        <if test="endArrivalDate !=null">
            and t.arrival_date &lt;= #{endArrivalDate}
        </if>
        <if test="withdrawer !=null and withdrawer != ''">
            and t.withdrawer = #{withdrawer}
        </if>
        <if test="roadName !=null and roadName != ''">
            and t.road_name = #{roadName}
        </if>
        <!-- 新增snake_case统计筛选条件 -->
        <if test="snakeCase !=null and snakeCase != ''">
            and t.snake_case = #{snakeCase}
        </if>
    </select>
 
    <!-- 按月份分组统计 -->
    <select id="queryMpPaymentRecordByMonth" parameterType="Map" resultType="Map">
        select
        date_format(t.first_print_date, '%Y-%m') as month,
        count(1) as count,
        sum(t.print_amount) as print_amount_sum,
        sum(t.arrival_amount) as arrival_amount_sum,
        sum(t.shortage_or_arrears) as shortage_sum
        from mp_payment_record t
        where 1 =1
        <if test="mpId !=null and mpId != ''">
            and t.mp_id = #{mpId}
        </if>
        <if test="startDate !=null">
            and t.first_print_date >= #{startDate}
        </if>
        <if test="endDate !=null">
            and t.first_print_date &lt;= #{endDate}
        </if>
        <!-- 新增snake_case分组筛选条件 -->
        <if test="snakeCase !=null and snakeCase != ''">
            and t.snake_case = #{snakeCase}
        </if>
        group by date_format(t.first_print_date, '%Y-%m')
        order by month desc
    </select>
 
    <!-- 按支取人分组统计 -->
    <select id="queryMpPaymentRecordByWithdrawer" parameterType="Map" resultType="Map">
        select
        t.withdrawer,
        count(1) as count,
        sum(t.print_amount) as print_amount_sum,
        sum(t.arrival_amount) as arrival_amount_sum,
        sum(t.shortage_or_arrears) as shortage_sum
        from mp_payment_record t
        where 1 =1
        <if test="mpId !=null and mpId != ''">
            and t.mp_id = #{mpId}
        </if>
        <if test="startDate !=null">
            and t.first_print_date >= #{startDate}
        </if>
        <if test="endDate !=null">
            and t.first_print_date &lt;= #{endDate}
        </if>
        <!-- 新增snake_case分组筛选条件 -->
        <if test="snakeCase !=null and snakeCase != ''">
            and t.snake_case = #{snakeCase}
        </if>
        group by t.withdrawer
        order by print_amount_sum desc
    </select>
 
</mapper>