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
<?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.by4cloud.platformx.business.mapper.ContractMapper">
 
    <select id="pageByCredit" resultType="com.by4cloud.platformx.business.vo.ContractCreditSalesPageVo">
        SELECT
        id,
        contract_no,
        contract_name,
        party_a_id,
        party_a,
        party_b_id,
        party_b,
        amount,
        currency,
        contract_type,
        supply_attribute,
        contract_status,
        contract_attribute,
        sign_date,
        effective_date,
        delivery_cycle,
        expiration_date,
        attachment_url,
        remark,
        parent_id,
        approve_time,
        arrival_schedule_id,
        accept_schedule_id,
        erp_push_flag,
        billing_status,
        next_schedule_name,
        template_id,
        sales_model,
        paid_amount,
        create_by,
        update_by,
        create_time,
        update_time,
        del_flag,
        comp_id,
        (SELECT GROUP_CONCAT(DISTINCT t1.material_internal_name) from contract_subject_matter t1 WHERE t1.contract_id = t.id) productNames,
        IFNULL( t.billing_amout, 0 ) billing_amout,
        ( SELECT IFNULL( sum( unit_price * delivered_quantity ), 0 ) FROM contract_subject_matter t1 WHERE t1.contract_id = t.id ) outBoundAmount,
        ((
        SELECT
        IFNULL( sum( unit_price * delivered_quantity ), 0 )
        FROM
        contract_subject_matter t1
        WHERE
        t1.contract_id = t.id
        ) - IFNULL( t.billing_amout, 0 )) creditAmount
        FROM
        contract t
        WHERE
        (
        IFNULL( t.billing_amout, 0 )&lt;(
        SELECT
        IFNULL( sum( unit_price * delivered_quantity ), 0 )
        FROM
        contract_subject_matter t1
        WHERE
        t1.contract_id = t.id
        ))=1
        <if test="queryDTO.contractName !=null and queryDTO.contractName !=''">
            and t.contract_name LIKE CONCAT('%', #{queryDTO.contractName}, '%')
        </if>
        <if test="queryDTO.partyA !=null and queryDTO.partyA !=''">
            and t.party_a LIKE CONCAT('%', #{queryDTO.partyA}, '%')
        </if>
        <if test="queryDTO.productNames !=null and queryDTO.productNames !=''">
            and (SELECT GROUP_CONCAT(DISTINCT t1.material_internal_name) from contract_subject_matter t1 WHERE t1.contract_id = t.id) LIKE CONCAT('%', #{queryDTO.productNames}, '%')
        </if>
        <choose>
            <when test="queryDTO.sortFiled !=null and queryDTO.sortFiled !='' and queryDTO.sortFiled == 'sign_date'">
                order by ${queryDTO.sortFiled}
            </when>
            <when test="queryDTO.sortFiled !=null and queryDTO.sortFiled !='' and queryDTO.sortFiled == 'creditAmount'">
                order by ((
                SELECT
                IFNULL( sum( unit_price * delivered_quantity ), 0 )
                FROM
                contract_subject_matter t1
                WHERE
                t1.contract_id = t.id
                ) - IFNULL( t.billing_amout, 0 ))
            </when>
            <otherwise>
                order by t.create_time
            </otherwise>
        </choose>
        <choose>
            <when test="queryDTO.sortMethod !=null and queryDTO.sortMethod !=''">
                ${queryDTO.sortMethod}
            </when>
            <otherwise>
                desc
            </otherwise>
        </choose>
    </select>
</mapper>