zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
<?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.changhong.epc.form.mapper.tenant.FormDataMapper">
    
    <resultMap type="com.changhong.epc.form.service.budget.department.util.AddMoney" id="resultMoney">
        <result property="dataRowNum" column="DATAROWNUM"/>
        <result property="costType" column="C_Type"/>
        <result property="budgetItemBalance" column="budget_itemBalance"/>
        <result property="budgetAdditionalMoney" column="budget_AdditionalMoney"/>
        <result property="budgetItemMoney" column="budget_itemMoney"/>
        <result property="org" column="budget_itemDepartment"/>
        <result property="chooseSuperBudget" column="chooseSuperBudget"/>
        <result property="superDep" column="budget_superDepartement"/>
    </resultMap>
    
    
    <resultMap type="com.changhong.epc.form.service.budget.department.util.ContractStage" id="Sonresult">
        <result property="dataRowNum" column="DATAROWNUM"/>
        <result property="paymentMoney" column="payment_money"/>
        <result property="alreadyPaid" column="already_paid"/>
        <result property="fukuanjine" column="fukuanjine"/>
        <result property="paymentStage" column="payment_stage"/>
    </resultMap>
    
    <resultMap type="com.changhong.epc.form.service.budget.department.util.ContractStage" id="Sonsresult">
        <result property="dataRowNum" column="DATAROWNUM"/>
        <result property="paymentMoney" column="payment_money"/>
        <result property="alreadyPaid" column="already_paid"/>
        <result property="paymentStage" column="payment_stage"/>
    </resultMap>
    
    <resultMap type="com.changhong.epc.bean.form.ProcessState" id="stateResult">
        <result property="processState" column="processState"/>
        <result property="processLog" column="processLog"/>
        <result property="processTask" column="processTask"/>
        <result property="processUser" column="processUser"/>
        <result property="orderStatus" column="orderStatus"/>
        <result property="orderCode" column="orderCode"/>
        <result property="createUser" column="createUser"/>
    </resultMap>
 
    <update id="updataFormByCustom">
    
        update ${formName} 
            set 
        <foreach collection="fields" index="index" item="item" separator=",">
            `${index}` = #{item}
        </foreach>
            
        where dataRowNum = #{dataRowNum}
    
    </update>
 
    <delete id="deleteFormData" parameterType="com.changhong.epc.bean.form.FormDataEntity">
        delete from
        ${formName} where PARENTDATAROWNUM = #{dataRowNum}
    </delete>
 
    <insert id="insertFormData" parameterType="com.changhong.epc.bean.form.FormDataEntity"
        useGeneratedKeys="true" keyProperty="dataRowNum">
        insert into ${formName} 
        <foreach collection="map" index="key" item="val" separator="," open="(" close=")">
            ${key}
        </foreach>
            values
        <foreach collection="map" index="key" item="val" separator="," open="(" close=")">
            #{val}
        </foreach>
    </insert>
    
    <update id="updateExpendFormIfHaveOrderCode">
        update ${formName}
        set 
            <!-- 暂时打开orderCode,不知道为什么注释了-->
            orderCode = #{orderCode},
            orderStatus = 10
        where
            dataRowNum = #{dataRowNum}
        
    </update>
    
    <update id="updateFormData" parameterType="com.changhong.epc.bean.form.FormDataEntity">
        update ${formName} set
            <foreach collection="map" index="key" item="value" separator=",">
                ${key} = #{value}
            </foreach>
        where DATAROWNUM = #{dataRowNum}
    </update>
    <update id="updateExpendFormState" parameterType="java.lang.Integer">
            update ${formName} set 
                orderStatus = #{status}
                <if test="voucherCode != null">
                ,voucherCode = #{voucherCode}
                </if>
            where
             datarowNum = #{dataRowNum}    
    </update>
 
 
    <select id="searchFormData" parameterType="com.changhong.epc.bean.form.FormDataEntity" resultType="Map">
        select * from ${formName}
        where 
            DELETEFLG = 0
        <if test="parentDataRowNum != null">
             AND parentDataRowNum = #{parentDataRowNum}
        </if>
        <if test="dataRowNum != null">
             AND datarownum = #{dataRowNum}
        </if>
        
    </select>
 
    <select id="searchSubFormDataList" parameterType="com.changhong.epc.bean.form.FormDataEntity" resultType="Map">
        select * from ${formName}
        <where>
            <if test="parentDataRowNum != null">
                parentDataRowNum = #{parentDataRowNum}
            </if>
        </where>
    </select>
 
    
      <select id="searchBudgetSubForm" parameterType="com.changhong.epc.bean.form.FormDataEntity" resultType="com.changhong.epc.bean.form.BugetSubForm">
        select 
                * 
        FROM ${formName}
        where
            parentDataRowNum = #{parentDataRowNum}
        <if test=" set != null">
            and C_Type in
            <foreach collection="set" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        
        </if>        
        
        
    </select>
    
    <select id="selectRangeByIds" resultType="int">
        select DATAROWNUM from  ${formName}
<!--         &gt; -->
        where
            processState = '30' AND
         DATE(budgetStartDate) &lt;= #{formDate}
         <choose>
            <when test="budgetProject != null">
                AND budget_type = #{budProject} 
            </when>
<!--             <![CDATA[>]]> -->
            <otherwise>
                AND budget_type = #{budDep}
            </otherwise>
        </choose> 
         <choose>
            <when test="toDate != null">
                AND DATE(budgetEndDate) &gt;= #{toDate} 
            </when>
            <otherwise>
                AND budgetEndDate  &gt;= #{formDate}
            </otherwise>
        </choose>
         <if test="conditionMap != null">
             <foreach collection="conditionMap" index="key" item="value" separator=" ">
                AND ${key} = #{value}
             </foreach>
         </if>
         <if test="occupy != null">
             and occupy = #{occupy}
         </if>
         AND currency = #{currency}
        and DELETEFLG = 0
        ORDER BY DATAROWNUM DESC
    <!-- LIMIT #{pageNum}, #{pageSize} -->    
    </select>
     
    <select id="selectMainIdBySubIds" resultType="int">
        SELECT
            DATAROWNUM
        FROM
            ${formName}
        WHERE
            PARENTDATAROWNUM = #{dataRowNumber} 
        AND                  
            DELETEFLG = 0;
        
    </select>
 
 
     <select id="searchFormDataList" parameterType="com.changhong.epc.bean.form.FormDataEntity" resultType="Map">
        select * from ${formName} where DELETEFLG = 0 AND
        <choose>
            <when test="childAlias != null">
                PARENTDATAROWNUM = #{dataRowNum}
            </when>
            <otherwise>
                DATAROWNUM = #{dataRowNum}
            </otherwise>
        </choose>
            <if test="costType !=null ">
            and C_Type = #{costType}
            </if>
            
            <if test="NowDepartment !=null " >
             and budget_itemDepartment = #{NowDepartment}
            </if> 
 
            <if test="budgetProject !=null " >
             and budget_project = #{budgetProject}
            </if>
        <if test="dimensions != null">
            <foreach collection="dimensions" item="dimension" >
                <if test="dimension.value != null and dimension.value != ''">
                    AND ${dimension.column} = #{dimension.value}
                </if>
            </foreach>
        </if>
    </select>
 
    <select id="searchSubFormIds" resultType="java.lang.Integer">
        select
            DATAROWNUM
        from ${formName}
        where PARENTDATAROWNUM = #{dataRowNum}
    </select>
 
         <select id="searchFormDataLists" parameterType="com.changhong.epc.bean.form.FormDataEntity" resultType="Map">
        select * from ${formName} where
        <choose>
            <when test="childAlias != null">
                 PARENTDATAROWNUM = #{dataRowNum}
            </when>
            <otherwise>
                 DATAROWNUM = #{dataRowNum}
            </otherwise>
        </choose>
            <if test="costType !=null ">
            and C_Type = #{costType}
            </if>
            
            <if test="department !=null " >
             and budget_itemDepartment in
                <foreach collection="department" item="item" index="index" open="(" close=")" separator=",">
                     #{item}
                 </foreach>
            </if> 
 
            <if test="budgetProject !=null " >
             and budget_project = #{budgetProject}
            </if>
        <if test="dimensions != null">
            <foreach collection="dimensions" item="dimension" >
                <if test="dimension.value != null and dimension.value != ''">
                    AND ${dimension.column} = #{dimension.value}
                </if>
            </foreach>
        </if>
    </select>
    
    <select id="searchExtendFormData" resultMap="resultMoney">
        select * from ${formName} where DELETEFLG = 0 and
        <choose>
            <when test="parentDataRowNum != null">
                PARENTDATAROWNUM = #{parentDataRowNum}
            </when>
            <otherwise>
                DATAROWNUM = #{dataRowNum}
            </otherwise>
        </choose>
    </select>
    
    <update id="updateItemBalance">
        UPDATE  
            ${formName}
        <trim prefix="set"  suffixOverrides=",">
            <if test="add.budgetItemBalance != null">
                budget_itemBalance = #{add.budgetItemBalance},
            </if>
            <if test="add.budgetItemMoney !=null">
                budget_itemMoney = #{add.budgetItemMoney},
            </if>
            
            <if test="add.budgetSuperMoney !=null">
                budget_superMoney = #{add.budgetSuperMoney}
            </if>
            
            
        
        </trim>
        WHERE
            DATAROWNUM = #{add.dataRowNum}
    </update>
    
    <update id="updaterepayment">
        UPDATE
            ${formName}
        <trim prefix="set" suffixOverrides=",">
        <if test="OutstandingAmount != null">
            OUTSTANDINGAMOUNT = #{OutstandingAmount},
        </if>
        <if test="alreadyRepaid !=null">
            ALREADYREPAID = #{alreadyRepaid}
        </if>
        </trim>
        WHERE    
            DATAROWNUM = #{dataRowNum}
    </update>
    
     <select id="checkDate" resultType="java.lang.Integer">
     
            SELECT
                DATAROWNUM
            FROM
                ${formName}
            WHERE
                DATE(budgetStartDate)     <![CDATA[ != ]]>  #{startDate}
                
            AND DATE(budgetEndDate)       <![CDATA[ != ]]>  #{endDate}
            <!-- OR (
            
                DATE(budgetEndDate)     <![CDATA[ <= ]]>  #{endDate}
                AND DATE(budgetEndDate) <![CDATA[ >= ]]>  #{endDate}
            
            ) -->
            AND currency = #{currency}
            
    </select>
    
    <select id="queryFormByDataRowNum" resultType="java.util.Map">
        SELECT
            C_Type budget_itemCostType,
            `budget_itemDepartment`
        FROM
            ${formName}
            <if test=" dataRowNum != null ">
                WHERE
                PARENTDATAROWNUM IN
                <foreach item="item" index="index" collection="dataRowNum" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            
            </if>
        
    </select>
    
    <select id="selectBudget" resultType="java.util.Map">
    SELECT 
         *
       FROM 
           ${formName} 
       WHERE 
           BUDGET_ITEMDEPARTMENT = #{orgs} 
       AND 
           C_Type = #{budget_itemCostType}
       AND
           DELETEFLG = 0 
       LIMIT 1
    </select>
    
    <select id="selectSonForm" resultMap="Sonresult">
    
        select * from ${name} 
            where PARENTDATAROWNUM = #{num}
    
    </select>
    
    <select id="selectSonsForm" resultMap="Sonsresult">
    
        select * from ${name} 
            where PARENTDATAROWNUM = #{num}
    
    </select>
    
    <update id="updateContract">
        update ${name} set
            alreadyPaid = #{son.alreadyPaid}
            where DATAROWNUM = #{son.dataRowNum}
    </update>
    
    <select id="selectDataRowNum" resultType="java.lang.Integer">
             SELECT
                datarownum
            FROM
                    formdata_{tenantId}_${formId}
            WHERE
                    ORDERCODE = #{orderCode}
                AND TENANTID = #{tenantId}
    
    </select>
    
    <update id ="updateState">
        update formdata_${pro.tenantId}_${pro.formId}
            <trim prefix="set" suffixOverrides="," >
                <if test="pro.processState !=null">
                    processState = #{pro.processState},
                </if>
                <if test="pro.processLog !=null">
                    processLog = #{pro.processLog},
                </if>
                <if test="pro.processTask !=null">
                    processTask = #{pro.processTask},
                </if>
                <if test="pro.processUser !=null">
                    processUser = #{pro.processUser},
                </if>
                <if test="pro.solidification !=null">
                    solidification = #{pro.solidification},
                </if>
                <if test="pro.orderStatus !=null">
                    orderStatus = #{pro.orderStatus},
                </if>
                <if test="pro.voucherno !=null">
                    voucherno = #{pro.voucherno},
                </if>
                <if test="pro.conformingstate !=null">
                    conformingstate = #{pro.conformingstate},
                </if>
                <if test="pro.tradeNumber !=null">
                    tradeNumber = #{pro.tradeNumber},
                </if>
                <if test="pro.htmlUrl !=null">
                    htmlUrl = #{pro.htmlUrl},
                </if>
            </trim>
        where dataRowNum = #{pro.dataRowNum}    
    </update>
    
    <select id="selectState" resultMap="stateResult">
            SELECT
                processState,
                processLog,
                processTask,
                processUser,
                orderStatus,
                orderCode,
                createUser
            FROM
                formdata_${pro.tenantId}_${pro.formId}
            WHERE
                dataRowNum = #{pro.dataRowNum}
    </select>
    
     <select id="searchFormData1" parameterType="com.changhong.epc.bean.form.FormDataEntity" resultType="Map">
        select * from ${formName}
        where processState = '30'
        <if test="parentDataRowNum != null">
            and parentDataRowNum = #{parentDataRowNum}
        </if>
        <if test="dataRowNum != null">
             and datarownum = #{dataRowNum}
        </if>
        
    </select>
    
    <select id="selectRangeById" resultType="int">
        select DATAROWNUM from  ${formName}
<!--         &gt; -->
        where
            <!-- processState = '30' AND -->
         DATE(budgetStartDate) &lt;= #{formDate}
        <if test="budgetProject != null">
                AND budget_type = #{budgetProject} 
        </if>
         <if test="toDate != null">
                AND DATE(budgetEndDate) &gt;= #{toDate} 
        </if>
         <if test="currency != null">
             and currency = #{currency}
         </if>
        <if test="occupy != null">
            and occupy = #{occupy}
        </if>
        and DELETEFLG = 0 
        
    </select>
    <select id="selectRangeByIdOnlyOne" resultType="int">
        select DATAROWNUM from  ${formName}
<!--         &gt; -->
        where
            <!-- processState = '30' AND -->
         DATE(budgetStartDate) &lt;= #{formDate}
        <if test="budgetProject != null">
                AND budget_type = #{budgetProject}
        </if>
         <if test="toDate != null">
                AND DATE(budgetEndDate) &gt;= #{toDate}
        </if>
         <if test="currency != null">
             and currency = #{currency}
         </if>
        <if test="occupy != null">
            and occupy = #{occupy}
        </if>
            and DELETEFLG = '0'
            and DATAROWNUM not in
        (
            select PARENTDATAROWNUM from ${subFormName} where DATAROWNUM in
            <foreach item="item" index="index" collection="dataRowNum" open="(" close=")" separator=",">
                #{item.DATAROWNUM}
            </foreach>
 
        )
    </select>
 
    <select id="selectRangeByNumber" resultType="java.lang.String">
        select PARENTDATAROWNUM from  ${formName}
        where
            PARENTDATAROWNUM in
            <foreach item="item" index="index" collection="list" open="(" close=")" separator=",">
                    #{item}
                </foreach>
        <if test="C_Type != null">
            AND C_Type = #{C_Type} 
        </if>
        <if test="dep != null">
            AND budget_itemDepartment = #{dep} 
        </if>
        <if test=" budget_project != null">
            AND budget_project = #{budget_project}
        </if>
            LIMIT 1
    </select>
    
    <select id="selectByNumber" resultType="java.lang.String">
        select ${number} from  ${formName}
        where DATAROWNUM = #{id}
    </select>
    
    
    
    
    <select id="selectAssetOri" resultType="java.util.Map">
        select 
            originalMoney 
        from 
            formdata_{tenantId}_${formId}
        where 
            DATAROWNUM = #{assetId}    
        and
             DELETEFLG = 0
    </select>
    
    
    <update id="saveOccupant" parameterType="com.changhong.autoform.entity.FormData">
        UPDATE 
            formdata_{tenantId}_${formId}
        SET 
            occupant = #{reimbursement}
        WHERE
            DATAROWNUM = #{dataRowNum}
        AND 
            DELETEFLG = 0
    </update>
    
    
    
    <update id="delteOccupant" parameterType="com.changhong.autoform.entity.FormData">
        UPDATE 
            formdata_{tenantId}_${formId}
        SET 
            occupant = NULL
        WHERE
            DATAROWNUM = #{dataRowNum}
        AND 
            DELETEFLG = 0
    </update>
    
    
    <select id="selectToWriteBudgetByDataRowNum" resultType="java.util.Map">
        SELECT
            *
        FROM
            ${formName}
        WHERE
            DATAROWNUM = #{dataRowNum}
 
    </select>
    
 
    <select id="selectSQFormId" resultType="java.util.Map">
        SELECT
            a.*
        FROM
            epc_cost_from_mapping_{rule} a
        WHERE
            a.ct_id IN (
                SELECT
                    b.ct_id
                FROM
                    epc_cost_from_mapping_{rule} b
                WHERE
                    b.f_id = #{fId}
                AND b.ct_id =#{cId}
                AND b.data_start = 0
            )
        AND type = 'SQ'
        AND a.data_start = 0
 
 
    </select>
 
    <select id="selectNumber" resultType="java.util.LinkedHashMap">
    SELECT
        *
    FROM
        ${formName}
    WHERE
        DATAROWNUM = #{dataRowNum}
 
    </select>
    
    
    
    <select id="selectDataCountByUser" resultType="int">
        SELECT
            COUNT(1)
        FROM
            formdata_{tenantId}_${formId}
        WHERE
            DELETEFLG = 0
        AND CREATEUSER = #{openId}
        AND C_Type = #{costType}
    </select>
    
    
    <select id="selectDataListByUser" resultType="java.util.Map">
        (
            SELECT
                *
            FROM
                formdata_{tenantId}_${formId}
            WHERE
                DELETEFLG = 0
            AND occupant IS NULL
            AND CREATEUSER = #{openId}
            AND C_Type = #{costType}
            ORDER BY
                CREATEDATETIME DESC,
                C_Type ASC
        )
        UNION ALL
            (
                SELECT
                    *
                FROM
                    formdata_{tenantId}_${formId}
                WHERE
                    DELETEFLG = 0
                AND occupant IS NOT NULL
                AND CREATEUSER = #{openId}
                AND C_Type = #{costType}
                ORDER BY
                    CREATEDATETIME DESC,
                    C_Type ASC
            )
        LIMIT ${begin},${size}
    </select>
    
    
    <select id="selectFormIdByCostTypeAndFormType"  resultType="java.util.Map">
        SELECT
            *
        FROM
            epc_cost_from_mapping_{rule}
        WHERE
            data_start = 0
        AND ct_id = #{costType}
        AND type = #{formType}
    </select>
    
    <select id="selectDataBybussinessNumber" resultType="java.util.Map">
        SELECT
            *
        FROM
            formdata_{tenantId}_${formId}
        WHERE
            DELETEFLG = 0
        AND
            number_expend = #{bussinessNumber}    
    </select>
    
    <select id="getSumAlreadyPaid" resultType="java.util.Map">
        SELECT
            payment_stage,
            sum(paidMoney) as alreadypaid
        FROM
            ${formName}
        WHERE
         PARENTDATAROWNUM in
             <foreach collection="list" item="dataRowNum" separator="," open="(" close=")" >
                 #{dataRowNum}
             </foreach>
        GROUP BY payment_stage
    </select>
    
    <select id="selectDataRows" resultType="java.lang.Integer">
        SELECT
            dataRowNum
        FROM
            ${formName}
        WHERE
         processState = '30'
        AND    
         selectContracts = #{num}
         <if test="currDataRowNum !=null">
            AND dataRowNum != #{currDataRowNum}
         </if>
    </select>
 
    <select id="getPersionCostReturn"  resultType="java.util.Map">
        select
            *
        from
            formdata_{tenantId}_${formName} as f1
        left join
            formdata_{tenantId}_${formName2} as f2 on(f1.DATAROWNUM=f2.PARENTDATAROWNUM)
        where
          f1.DATAROWNUM=#{dateNum}
          and f1.DELETEFLG=0
          and f2.DELETEFLG=0
 
 
    </select>
 
    <select id="getBorrowMoney" resultType="java.util.Map">
        select *
        from formdata_{tenantId}_${forName}
        where OutstandingAmount>0
        and reimburseMan=#{openId} and DELETEFLG=0 and processState = '30'
    </select>
 
    <select id="selectTableExist" resultType="java.lang.Integer">
        select count(1)
        from information_schema.tables
        where table_name="formdata_{tenantId}_${formName}"
 
    </select>
 
    <select id="selectApply" parameterType="com.changhong.epc.bean.form.ApplyCostForm" resultType="java.util.Map">
 
        <foreach collection="costformMapping" close=" order by `CREATEDATETIME` DESC" item="data" separator="UNION ALL">
            SELECT
            dataRowNum,number_apply,reimburseMan,C_Type,applyDate,processLog,applyUseMoney,#{data.fName} formName
            , #{data.formId} formId,
            CREATEDATETIME
            FROM
            formdata_{tenantId}_${data.formId}
            WHERE
            processState = '30'
            and C_Type = #{data.ctId}
            AND ISNULL(processFlag)
            AND CREATEUSER = #{insP}
            AND DELETEFLG = 0
            AND (select count(0)
                 from formdata_{tenantId}_${data.expenseFormId}
                 where toWriteBudget = formdata_{tenantId}_${data.formId}.datarownum and deleteflg = 0) = 0
--             是否借款
            AND ((accountFlag = 'A000001' and orderStatus = '45')or (accountFlag = 'A000002' and processState = '30'))
        </foreach>
 
    </select>
 
    <select id="selectValueCount" resultType="java.lang.Integer">
        select count(*) from ${formName}
        where DELETEFLG = 0
        AND ${fieKey} = #{fieValue}
        <if test="dataRowNum != null">
            AND DATAROWNUM != #{dataRowNum}
        </if>
    </select>
 
    <resultMap id="searchSuperBudgetMap" type="java.util.Map">
        <id column="DATAROWNUM" property="DATAROWNUM"/>
        <result column="budgetStatement" property="budgetStatement"/>
        <result column="number_budget" property="number_budget"/>
        <result column="budgetStartDate" property="budgetStartDate"/>
        <result column="budgetEndDate" property="budgetEndDate"/>
        <result column="budget_type" property="budget_type"/>
        <result column="solidification" property="solidification"/>
        <collection property="budget_subFrom" ofType="java.util.Map" javaType="java.util.List">
            <id column="SUB_DATAROWNUM" property="DATAROWNUM"/>
            <result column="budget_superDepartement" property="budget_superDepartement"/>
            <result column="C_Type" property="C_Type"/>
            <result column="budget_itemBalance" property="budget_itemBalance"/>
            <result column="budget_itemMoney" property="budget_itemMoney"/>
            <result column="budget_project" property="budget_project"/>
            <result column="budget_itemDepartment" property="budget_itemDepartment"/>
            <result column="budget_superMoney" property="budget_superMoney"/>
        </collection>
    </resultMap>
 
    <select id="searchSuperBudget" parameterType="java.util.Map" resultMap="searchSuperBudgetMap">
        select
            b.DATAROWNUM,
            b.budgetStatement,
            b.number_budget,
            b.budgetStartDate,
            b.budgetEndDate,
            b.budget_type,
            b.solidification,
            bs.DATAROWNUM SUB_DATAROWNUM,
            bs.budget_superDepartement,
            bs.C_Type,
            bs.budget_itemBalance,
            bs.budget_itemMoney,
            bs.budget_project,
            bs.budget_itemDepartment,
            bs.budget_superMoney
        from (
            select
                DISTINCT
                b.DATAROWNUM
            from formdata_{tenantId}_${formId} b
            left join formdata_{tenantId}_${formId}_budget_subfrom bs on b.DATAROWNUM = bs.PARENTDATAROWNUM
            WHERE budgetStartDate &lt;= #{budgetStartDate}
            and budgetEndDate &gt;= #{budgetEndDate}
            and currency = #{currency}
            and occupy != #{occupy}
            and budget_type = #{budgetType}
            and b.processState = 30
            <if test="subData.size() != null">
                <foreach collection="subData" item="data" open="and (" close=")" separator=" or ">
                    <trim prefixOverrides="and">
                        <if test="data.C_Type != null">
                            and C_Type = #{data.C_Type}
                        </if>
                        <if test="data.budget_itemDepartment_crossLevel and data.budget_itemDepartment != null and data.budget_itemDepartment != ''">
                            and budget_itemDepartment like concat(#{data.budget_itemDepartment}, '%')
                            and length(budget_itemDepartment) &lt;= (#{data.budget_itemDepartment_length} - 4)
                        </if>
                        <if test="!data.budget_itemDepartment_crossLevel and data.budget_itemDepartment != null and data.budget_itemDepartment != ''">
                            and budget_itemDepartment = #{data.budget_itemDepartment}
                        </if>
                    </trim>
                </foreach>
            </if>
            order by b.DATAROWNUM desc
            LIMIT #{pageN}, #{pageS}
        ) pageInfo
        left join formdata_{tenantId}_${formId} b on pageInfo.DATAROWNUM = b.DATAROWNUM
        left join formdata_{tenantId}_${formId}_budget_subfrom bs on b.DATAROWNUM = bs.PARENTDATAROWNUM
        order by b.DATAROWNUM desc
    </select>
 
    <select id="searchBudget" parameterType="java.util.Map" resultMap="searchSuperBudgetMap">
        select
            b.DATAROWNUM,
            b.number_budget,
            b.budgetStartDate,
            b.budgetEndDate,
            b.budget_type,
            b.solidification
        from formdata_{tenantId}_${formId} b
        where b.DATAROWNUM = #{dataRowNum}
    </select>
 
    <select id="selectRepayment" resultType="java.lang.Integer">
        select
            count(0)
        from formdata_{tenantId}_${loanFormId} j
        LEFT JOIN formdata_{tenantId}_${repaymentFormId} h on j.DATAROWNUM = h.repaymentSuperLoan and h.processState = 30
        where j.processState = 30
        and h.DATAROWNUM is null
        and j.LoanPeople = #{borrowMoneyUser}
        and DATE_ADD(STR_TO_DATE(j.createDatetime, '%Y-%m-%d'), interval #{day} DAY) &lt; now()
    </select>
 
    <select id="selectApplyFormIds" resultType="com.changhong.epc.bean.tenant.cost.CostFromMapping">
        select
            DISTINCT
            f_id
        from epc_cost_from_mapping_100000001_7
        where type = 'SQ'
    </select>
 
    <select id="selectApplyRepayment" resultType="java.lang.Integer">
 
        select
            count(0)
        from (
            <foreach collection="formIds" item="formId" separator="union all">
                select alreadyRepaid, loanAmount
                from formdata_{tenantId}_${formId}
                where accountFlag = 'A000001'
                and processState = 30
                and reimburseMan = #{borrowMoneyUser}
            </foreach>
        ) a
        where alreadyRepaid &lt; loanAmount
 
    </select>
 
    <select id="searchSuperBudgetCount" parameterType="java.util.Map" resultType="java.lang.Long">
        select
            count(0)
        from (
            select
                DISTINCT
                b.DATAROWNUM
            from formdata_{tenantId}_${formId} b
            left join formdata_{tenantId}_${formId}_budget_subfrom bs on b.DATAROWNUM = bs.PARENTDATAROWNUM
            WHERE budgetStartDate &lt;= #{budgetStartDate}
            and budgetEndDate &gt;= #{budgetEndDate}
            and currency = #{currency}
            and occupy != #{occupy}
            and budget_type = #{budgetType}
            and b.processState = 30
            <if test="subData.size() != null">
                <foreach collection="subData" item="data" open="and (" close=")" separator=" or ">
                    C_Type = #{data.C_Type}
                    <if test="data.budget_itemDepartment_crossLevel">
                        and budget_itemDepartment like concat(#{data.budget_itemDepartment}, '%')
                        and length(budget_itemDepartment) &lt;= #{data.budget_itemDepartment_length} - 4
                    </if>
                    <if test="!data.budget_itemDepartment_crossLevel">
                        and budget_itemDepartment = #{data.budget_itemDepartment}
                    </if>
                </foreach>
            </if>
        ) pageInfo
    </select>
 
</mapper>