CustomerMapper.xml
5.49 KB
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
<?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.lframework.xingyun.basedata.mappers.CustomerMapper">
<resultMap id="CustomerDto" type="com.lframework.xingyun.basedata.entity.Customer">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="name" property="name"/>
<result column="mnemonic_code" property="mnemonicCode"/>
<result column="contact" property="contact"/>
<result column="telephone" property="telephone"/>
<result column="email" property="email"/>
<result column="zip_code" property="zipCode"/>
<result column="fax" property="fax"/>
<result column="city_id" property="cityId"/>
<result column="address" property="address"/>
<result column="settle_type" property="settleType"/>
<result column="credit_code" property="creditCode"/>
<result column="tax_identify_no" property="taxIdentifyNo"/>
<result column="bank_name" property="bankName"/>
<result column="account_name" property="accountName"/>
<result column="account_no" property="accountNo"/>
<result column="available" property="available"/>
<result column="description" property="description"/>
<result column="create_by" property="createBy"/>
<result column="create_time" property="createTime"/>
<result column="update_by" property="updateBy"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="CustomerDto_sql">
SELECT DISTINCT
c.id,
c.code,
c.name,
c.mnemonic_code,
c.contact,
c.telephone,
c.email,
c.zip_code,
c.fax,
c.city_id,
c.address,
c.settle_type,
c.credit_code,
c.tax_identify_no,
c.bank_name,
c.account_name,
c.account_no,
c.available,
c.description,
c.create_by,
c.create_time,
c.update_by,
c.update_time
FROM base_data_customer c
</sql>
<select id="query" resultMap="CustomerDto">
<include refid="CustomerDto_sql"/>
<where>
<if test="vo != null">
<if test="vo.code != null and vo.code != ''">
AND c.code like CONCAT('%', #{vo.code}, '%')
</if>
<if test="vo.name != null and vo.name != ''">
AND c.name LIKE CONCAT('%', #{vo.name}, '%')
</if>
<if test="vo.available != null">
AND c.available = #{vo.available}
</if>
<choose>
<when test="vo.source == 'CUSTOMER_CREDIT'">
AND NOT EXISTS (
SELECT 1
FROM customer_credit cc
WHERE cc.company_id = c.id
AND cc.status != 'CANCEL'
)
</when>
<when test="vo.source == 'CUSTOMER_DEVELOP'">
AND NOT EXISTS (
SELECT 1
FROM customer_develop_plan cdp
WHERE cdp.customer_id = c.id
AND cdp.status != 'CANCEL'
)
</when>
<otherwise>
AND 1 = 1 <!-- 确保查询到任何数据 -->
</otherwise>
</choose>
</if>
</where>
ORDER BY c.code
</select>
<select id="getByName" resultMap="CustomerDto">
SELECT DISTINCT
c.id,
c.name
FROM base_data_customer AS c
<where>
<if test="name != null and name != ''">
AND name = #{name}
</if>
</where>
</select>
<select id="selector" resultMap="CustomerDto">
<include refid="CustomerDto_sql"/>
<where>
<if test="vo != null">
<if test="vo.code != null and vo.code != ''">
AND c.code = #{vo.code}
</if>
<if test="vo.name != null and vo.name != ''">
AND c.name LIKE CONCAT('%', #{vo.name}, '%')
</if>
<if test="vo.available != null">
AND c.available = #{vo.available}
</if>
<choose>
<when test="vo.source == 'CUSTOMER_CREDIT'">
AND NOT EXISTS (
SELECT 1
FROM customer_credit cc
WHERE cc.company_id = c.id
AND cc.status != 'CANCEL'
)
</when>
<when test="vo.source == 'CUSTOMER_DEVELOP'">
AND NOT EXISTS (
SELECT 1
FROM customer_develop_plan cdp
WHERE cdp.customer_id = c.id
AND cdp.status != 'CANCEL'
)
</when>
<otherwise>
AND 1 = 1 <!-- 确保查询到任何数据 -->
</otherwise>
</choose>
</if>
</where>
ORDER BY c.code
</select>
</mapper>