cloudroam
2025-03-10 c306cba52bcc3e2c423f77d4a52c35ad04c52038
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<?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.jsh.erp.datasource.mappers.AccountMapperEx">
    <resultMap extends="com.jsh.erp.datasource.mappers.AccountMapper.BaseResultMap" id="ResultListMap" type="com.jsh.erp.datasource.vo.AccountVo4List">
        <result column="thisMonthAmount" jdbcType="VARCHAR" property="thisMonthAmount" />
    </resultMap>
 
    <resultMap id="ResultInOutList" type="com.jsh.erp.datasource.vo.AccountVo4InOutList">
        <result column="Number" jdbcType="VARCHAR" property="number" />
        <result column="newType" jdbcType="VARCHAR" property="type" />
        <result column="fromType" jdbcType="VARCHAR" property="fromType" />
        <result column="supplier" jdbcType="VARCHAR" property="supplierName" />
        <result column="change_amount" jdbcType="DECIMAL" property="changeAmount" />
        <result column="oTime" jdbcType="VARCHAR" property="operTime" />
        <result column="AList" jdbcType="VARCHAR" property="aList" />
        <result column="AMList" jdbcType="VARCHAR" property="amList" />
    </resultMap>
 
    <select id="getAccountByParam" resultType="com.jsh.erp.datasource.entities.Account">
        select *
        FROM jsh_account
        where 1=1
        <if test="name != null and name !=''">
            <bind name="bindName" value="'%'+name+'%'"/>
            and name like #{bindName}
        </if>
        <if test="serialNo != null and serialNo !=''">
            <bind name="bindSerialNo" value="'%'+serialNo+'%'"/>
            and serial_no like #{bindSerialNo}
        </if>
        and ifnull(delete_flag,'0') !='1'
    </select>
 
    <select id="selectByConditionAccount" parameterType="com.jsh.erp.datasource.entities.AccountExample" resultMap="ResultListMap">
        select *
        FROM jsh_account
        where 1=1
        <if test="name != null">
            <bind name="bindName" value="'%'+name+'%'"/>
            and name like #{bindName}
        </if>
        <if test="serialNo != null and serialNo !=''">
            <bind name="bindSerialNo" value="'%'+serialNo+'%'"/>
            and serial_no like #{bindSerialNo}
        </if>
        <if test="remark != null">
            <bind name="bindRemark" value="'%'+remark+'%'"/>
            and remark like #{bindRemark}
        </if>
        and ifnull(delete_flag,'0') !='1'
        order by sort asc, id desc
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
 
    <select id="countsByAccount" resultType="java.lang.Long">
        SELECT
        COUNT(id)
        FROM jsh_account
        WHERE 1=1
        <if test="name != null">
            <bind name="bindName" value="'%'+name+'%'"/>
            and name like #{bindName}
        </if>
        <if test="serialNo != null and serialNo !=''">
            <bind name="bindSerialNo" value="'%'+serialNo+'%'"/>
            and serial_no like #{bindSerialNo}
        </if>
        <if test="remark != null">
            <bind name="bindRemark" value="'%'+remark+'%'"/>
            and remark like #{bindRemark}
        </if>
        and ifnull(delete_flag,'0') !='1'
    </select>
 
    <select id="getAccountSum" resultType="java.math.BigDecimal">
        select ifnull(sum(dh.change_amount),0) from jsh_depot_head dh
        where 1=1 and dh.pay_type != '预付款'
        <if test="accountId != null">
            and dh.account_id = #{accountId}
        </if>
        <if test="beginTime != null">
            and dh.oper_time >= #{beginTime}
        </if>
        <if test="endTime != null">
            and dh.oper_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and (dh.status = '1' or dh.status = '2' or dh.status = '3')
        </if>
        and ifnull(dh.delete_flag,'0') !='1'
    </select>
 
    <select id="getAccountSumByHead" resultType="java.math.BigDecimal">
        select ifnull(sum(ah.change_amount),0) from jsh_account_head ah
        where 1=1
        <if test="accountId != null">
            and ah.account_id = #{accountId}
        </if>
        <if test="beginTime != null">
            and ah.bill_time >= #{beginTime}
        </if>
        <if test="endTime != null">
            and ah.bill_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and ah.status = '1'
        </if>
        and ifnull(ah.delete_flag,'0') !='1'
    </select>
 
    <select id="getAccountSumByDetail" resultType="java.math.BigDecimal">
        select ifnull(sum(ai.each_amount),0) from jsh_account_head ah
        left join jsh_account_item ai on ah.id = ai.header_id and ifnull(ai.delete_flag,'0') !='1'
        where 1=1
        <if test="accountId != null">
            and ai.account_id = #{accountId}
        </if>
        <if test="beginTime != null">
            and ah.bill_time >= #{beginTime}
        </if>
        <if test="endTime != null">
            and ah.bill_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and ah.status = '1'
        </if>
        and ifnull(ah.delete_flag,'0') !='1'
    </select>
 
    <select id="getManyAccountSum" resultType="com.jsh.erp.datasource.entities.DepotHead">
        select dh.account_id_list accountIdList, dh.account_money_list accountMoneyList from jsh_depot_head dh
        where 1=1
        <if test="accountId != null">
            <bind name="bindAccountId" value="'%'+accountId+'%'"/>
            and dh.account_id_list like #{bindAccountId}
        </if>
        <if test="beginTime != null">
            and dh.oper_time >= #{beginTime}
        </if>
        <if test="endTime != null">
            and dh.oper_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and (dh.status = '1' or dh.status = '2' or dh.status = '3')
        </if>
        and ifnull(dh.delete_flag,'0') !='1'
    </select>
 
    <select id="getAccountSumByParam" resultType="com.jsh.erp.datasource.entities.AccountVo4Sum">
        select a.id,
            (select ifnull(sum(dh.change_amount),0) from jsh_depot_head dh
            where 1=1 and dh.pay_type != '预付款'
            and dh.account_id = a.id
            <if test="beginTime != null">
                and dh.oper_time >= #{beginTime}
            </if>
            <if test="endTime != null">
                and dh.oper_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and (dh.status = '1' or dh.status = '2' or dh.status = '3')
            </if>
            and ifnull(dh.delete_flag,'0') !='1') accountSum,
            (select ifnull(sum(ah.change_amount),0) from jsh_account_head ah
            where 1=1 and ah.account_id = a.id
            <if test="beginTime != null">
                and ah.bill_time >= #{beginTime}
            </if>
            <if test="endTime != null">
                and ah.bill_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and ah.status = '1'
            </if>
            and ifnull(ah.delete_flag,'0') !='1') accountSumByHead,
            (select ifnull(sum(ai.each_amount),0) from jsh_account_head ah
            left join jsh_account_item ai on ah.id = ai.header_id and ifnull(ai.delete_flag,'0') !='1'
            where 1=1 and ai.account_id = a.id
            <if test="beginTime != null">
                and ah.bill_time >= #{beginTime}
            </if>
            <if test="endTime != null">
                and ah.bill_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and ah.status = '1'
            </if>
            and ifnull(ah.delete_flag,'0') !='1') accountSumByDetail
        from jsh_account a
        where 1=1
        <if test="name != null">
            <bind name="bindName" value="'%'+name+'%'"/>
            and a.name like #{bindName}
        </if>
        <if test="serialNo != null and serialNo !=''">
            <bind name="bindSerialNo" value="'%'+serialNo+'%'"/>
            and a.serial_no like #{bindSerialNo}
        </if>
        and ifnull(a.delete_flag,'0') !='1'
        order by a.sort asc, a.id desc
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
 
    <select id="getManyAccountSumByParam" resultType="com.jsh.erp.datasource.entities.DepotHead">
        select dh.account_id_list accountIdList, dh.account_money_list accountMoneyList
        from jsh_depot_head dh
        where 1=1
        and dh.account_id_list !=''
        <if test="beginTime != null">
            and dh.oper_time >= #{beginTime}
        </if>
        <if test="endTime != null">
            and dh.oper_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and (dh.status = '1' or dh.status = '2' or dh.status = '3')
        </if>
        and ifnull(dh.delete_flag,'0') !='1'
    </select>
 
    <select id="findAccountInOutList" parameterType="com.jsh.erp.datasource.entities.AccountExample" resultMap="ResultInOutList">
        <!--主表出入库涉及的账户 -->
        select dh.number,concat(dh.sub_type,dh.type) as newType, 'bill' as fromType, s.supplier,dh.change_amount,date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList
        from jsh_depot_head dh left join jsh_supplier s on dh.organ_id = s.id and ifnull(s.delete_flag,'0') !='1'
        where 1=1
        <if test="accountId != null">
            and dh.account_id=#{accountId}
        </if>
        <if test="number != null and number !=''">
            <bind name="bindNumber" value="'%'+number+'%'"/>
            and dh.number like #{bindNumber}
        </if>
        <if test="beginTime != null and beginTime !=''">
            and dh.oper_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime !=''">
            and dh.oper_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and (dh.status = '1' or dh.status = '2' or dh.status = '3')
        </if>
        and ifnull(dh.change_amount, 0)!=0
        and ifnull(dh.delete_flag,'0') !='1'
        <!--主表收入和支出涉及的账户 -->
        UNION ALL
        select ah.bill_no,ah.type as newType, 'financial' as fromType, s.supplier,ah.change_amount,date_format(ah.bill_time,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList
        from jsh_account_head ah left join jsh_supplier s on ah.organ_id=s.id and ifnull(s.delete_flag,'0') !='1'
        where ah.type!='转账'
        <if test="accountId != null">
            and ah.account_id=#{accountId}
        </if>
        <if test="number != null and number !=''">
            <bind name="bindNumber" value="'%'+number+'%'"/>
            and ah.bill_no like #{bindNumber}
        </if>
        <if test="beginTime != null and beginTime !=''">
            and ah.bill_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime !=''">
            and ah.bill_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and ah.status = '1'
        </if>
        and ifnull(ah.change_amount, 0)!=0
        and ifnull(ah.delete_flag,'0') !='1'
        <!--明细中涉及的账户(收款,付款,收预付款) -->
        UNION ALL
        select ah.bill_no,ah.type as newType, 'financial' as fromType, s.supplier,ai.each_amount change_amount,date_format(ah.bill_time,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList
        from jsh_account_head ah left join jsh_supplier s on ah.organ_id=s.id
        left join jsh_account_item ai on ai.header_id=ah.id and ifnull(ai.delete_flag,'0') !='1'
        where ah.type in ('收款','付款','收预付款')
        <if test="accountId != null">
            and ai.account_id=#{accountId}
        </if>
        <if test="number != null and number !=''">
            <bind name="bindNumber" value="'%'+number+'%'"/>
            and ah.bill_no like #{bindNumber}
        </if>
        <if test="beginTime != null and beginTime !=''">
            and ah.bill_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime !=''">
            and ah.bill_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and ah.status = '1'
        </if>
        and ifnull(ai.each_amount, 0)!=0
        and ifnull(ah.delete_flag,'0') !='1'
        <!--主表中转出的账户 -->
        UNION ALL
        select ah.bill_no,ah.type as newType, 'financial' as fromType, '' as sName,ah.change_amount,date_format(ah.bill_time,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList
        from jsh_account_head ah
        where ah.type='转账'
        <if test="accountId != null">
            and ah.account_id=#{accountId}
        </if>
        <if test="number != null and number !=''">
            <bind name="bindNumber" value="'%'+number+'%'"/>
            and ah.bill_no like #{bindNumber}
        </if>
        <if test="beginTime != null and beginTime !=''">
            and ah.bill_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime !=''">
            and ah.bill_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and ah.status = '1'
        </if>
        and ifnull(ah.change_amount, 0)!=0
        and ifnull(ah.delete_flag,'0') !='1'
        <!--明细中被转入的账户 -->
        UNION ALL
        select ah.bill_no,ah.type as newType, 'financial' as fromType, '' as sName,ai.each_amount change_amount,date_format(ah.bill_time,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList
        from jsh_account_head ah left join jsh_account_item ai on ai.header_id=ah.id and ifnull(ai.delete_flag,'0') !='1'
        where ah.type='转账'
        <if test="accountId != null">
            and ai.account_id=#{accountId}
        </if>
        <if test="number != null and number !=''">
            <bind name="bindNumber" value="'%'+number+'%'"/>
            and ah.bill_no like #{bindNumber}
        </if>
        <if test="beginTime != null and beginTime !=''">
            and ah.bill_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime !=''">
            and ah.bill_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and ah.status = '1'
        </if>
        and ifnull(ai.each_amount, 0)!=0
        and ifnull(ah.delete_flag,'0') !='1'
        <!--多账户的情况 -->
        UNION ALL
        select dh.number,concat(dh.sub_type,dh.type) as newType, 'bill' as fromType, s.supplier,dh.change_amount,date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime,
        dh.account_id_list as AList,dh.account_money_list as AMList
        from jsh_depot_head dh left join jsh_supplier s on dh.organ_id = s.id and ifnull(s.delete_flag,'0') !='1'
        where 1=1
        <if test="accountId != null">
            <bind name="bindAccountId" value="'%'+accountId+'%'"/>
            and dh.account_id_list like #{bindAccountId}
        </if>
        <if test="number != null and number !=''">
            <bind name="bindNumber" value="'%'+number+'%'"/>
            and dh.number like #{bindNumber}
        </if>
        <if test="beginTime != null and beginTime !=''">
            and dh.oper_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime !=''">
            and dh.oper_time &lt;= #{endTime}
        </if>
        <if test="forceFlag">
            and (dh.status = '1' or dh.status = '2' or dh.status = '3')
        </if>
        and ifnull(dh.change_amount, 0)!=0
        and ifnull(dh.delete_flag,'0') !='1'
        ORDER BY oTime desc
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
 
    <select id="findAccountInOutListCount" resultType="java.lang.Integer">
        select sum(a) from
        (
            <!--主表出入库涉及的账户 -->
            select count(1) a
            from jsh_depot_head dh left join jsh_supplier s on dh.organ_id = s.id and ifnull(s.delete_flag,'0') !='1'
            where 1=1
            <if test="accountId != null">
                and dh.account_id=#{accountId}
            </if>
            <if test="number != null and number !=''">
                <bind name="bindNumber" value="'%'+number+'%'"/>
                and dh.number like #{bindNumber}
            </if>
            <if test="beginTime != null and beginTime !=''">
                and dh.oper_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime !=''">
                and dh.oper_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and (dh.status = '1' or dh.status = '2' or dh.status = '3')
            </if>
            and ifnull(dh.change_amount, 0)!=0
            and ifnull(dh.delete_flag,'0') !='1'
            <!--主表收入和支出涉及的账户 -->
            UNION ALL
            select count(1) a
            from jsh_account_head ah left join jsh_supplier s on ah.organ_id=s.id and ifnull(s.delete_flag,'0') !='1'
            where ah.type!='转账'
            <if test="accountId != null">
                and ah.account_id=#{accountId}
            </if>
            <if test="number != null and number !=''">
                <bind name="bindNumber" value="'%'+number+'%'"/>
                and ah.bill_no like #{bindNumber}
            </if>
            <if test="beginTime != null and beginTime !=''">
                and ah.bill_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime !=''">
                and ah.bill_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and ah.status = '1'
            </if>
            and ifnull(ah.change_amount, 0)!=0
            and ifnull(ah.delete_flag,'0') !='1'
            <!--明细中涉及的账户(收款,付款,收预付款) -->
            UNION ALL
            select count(1) a
            from jsh_account_head ah left join jsh_supplier s on ah.organ_id=s.id
            left join jsh_account_item ai on ai.header_id=ah.Id and ifnull(ai.delete_flag,'0') !='1'
            where ah.Type in ('收款','付款','收预付款')
            <if test="accountId != null">
                and ai.account_id=#{accountId}
            </if>
            <if test="number != null and number !=''">
                <bind name="bindNumber" value="'%'+number+'%'"/>
                and ah.bill_no like #{bindNumber}
            </if>
            <if test="beginTime != null and beginTime !=''">
                and ah.bill_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime !=''">
                and ah.bill_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and ah.status = '1'
            </if>
            and ifnull(ai.each_amount, 0)!=0
            and ifnull(ah.delete_flag,'0') !='1'
            <!--主表中转出的账户 -->
            UNION ALL
            select count(1) a
            from jsh_account_head ah
            where ah.type='转账'
            <if test="accountId != null">
                and ah.account_id=#{accountId}
            </if>
            <if test="number != null and number !=''">
                <bind name="bindNumber" value="'%'+number+'%'"/>
                and ah.bill_no like #{bindNumber}
            </if>
            <if test="beginTime != null and beginTime !=''">
                and ah.bill_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime !=''">
                and ah.bill_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and ah.status = '1'
            </if>
            and ifnull(ah.change_amount, 0)!=0
            and ifnull(ah.delete_flag,'0') !='1'
            <!--明细中被转入的账户 -->
            UNION ALL
            select count(1) a
            from jsh_account_head ah left join jsh_account_item ai on ai.header_id=ah.id and ifnull(ai.delete_flag,'0') !='1'
            where ah.type='转账'
            <if test="accountId != null">
                and ai.account_id=#{accountId}
            </if>
            <if test="number != null and number !=''">
                <bind name="bindNumber" value="'%'+number+'%'"/>
                and ah.bill_no like #{bindNumber}
            </if>
            <if test="beginTime != null and beginTime !=''">
                and ah.bill_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime !=''">
                and ah.bill_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and ah.status = '1'
            </if>
            and ifnull(ai.each_amount, 0)!=0
            and ifnull(ah.delete_flag,'0') !='1'
            <!--多账户的情况 -->
            UNION ALL
            select count(1) a
            from jsh_depot_head dh left join jsh_supplier s on dh.organ_id = s.id and ifnull(s.delete_flag,'0') !='1'
            where 1=1
            <if test="accountId != null">
                <bind name="bindAccountId" value="'%'+accountId+'%'"/>
                and dh.account_id_list like #{bindAccountId}
            </if>
            <if test="number != null and number !=''">
                <bind name="bindNumber" value="'%'+number+'%'"/>
                and dh.number like #{bindNumber}
            </if>
            <if test="beginTime != null and beginTime !=''">
                and dh.oper_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime !=''">
                and dh.oper_time &lt;= #{endTime}
            </if>
            <if test="forceFlag">
                and (dh.status = '1' or dh.status = '2' or dh.status = '3')
            </if>
            and ifnull(dh.change_amount, 0)!=0
            and ifnull(dh.delete_flag,'0') !='1'
        ) cc
    </select>
 
    <update id="batchDeleteAccountByIds">
        update jsh_account
        set delete_flag='1'
        where 1=1
        and id in (
        <foreach collection="ids" item="id" separator=",">
            #{id}
        </foreach>
        )
    </update>
</mapper>