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
<?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.testor.module.partner.dao.TPartnerOrgDao">
<!-- 开启二级缓存 -->
<!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.testor.module.partner.model.domain.TPartnerOrg">
<id column="id" property="id"/>
<id column="name" property="name"/>
<id column="credit_code" property="creditCode"/>
<id column="legal_person" property="legalPerson"/>
<id column="is_blacklist" property="isBlacklist"/>
<id column="blacklist_reason" property="blacklistReason"/>
<id column="tenant_id" property="tenantId"/>
</resultMap>
<select id="getResid" resultType="com.testor.module.partner.model.dto.TPartnerOrgDTO">
select a.name , b.id as id,b.partner_id from t_partner_org a
left join t_partner_org_res b on a.id = b.partner_id
where a.status = 0 and a.is_blacklist = '0'
<if test="query.name!='' and query.name!=null">
and a.name like concat('%', #{query.name},'%')
</if>
<if test="query.id!='' and query.id!=null">
and b.org_id = #{query.id}
</if>
</select>
<sql id="select_base_column">
po.id,po.org_id orgId, po.type_id typeId, po.name, po.credit_code as creditCode, po.legal_person legalPerson, po.responsible_person responsiblePerson,
po.phone, po.contract_start_date contractStartDate, po.contract_end_date contractEndDate,
po.is_blacklist isBlacklist, po.blacklist_reason blacklistReason,
po.tenant_id as tenantId, po.status, po.remarks, po.create_by createBy, po.create_date createDate,
po.update_by as updateBy, po.update_date updateDate
</sql>
<sql id="common_where_if">
<if test="query.id!=null and query.id!=''">
and po.id=#{query.id}
</if>
<if test="query.orgId!=null and query.orgId!=''">
and po.org_id=#{query.orgId}
</if>
<if test="query.typeId!='' and query.typeId!=null">
and po.type_id=#{query.typeId}
</if>
<if test="query.name!='' and query.name!=null">
and po.name like concat('%',#{query.name},'%')
</if>
<if test="query.creditCode!='' and query.creditCode!=null">
and po.credit_code=#{query.creditCode}
</if>
<if test="query.legalPerson!='' and query.legalPerson!=null">
and po.legal_person=#{query.legalPerson}
</if>
<if test="query.responsiblePerson!='' and query.responsiblePerson!=null">
and po.responsible_person=#{query.responsiblePerson}
</if>
<if test="query.phone!='' and query.phone!=null">
and po.phone=#{query.phone}
</if>
<if test="query.contractStartDate!='' and query.contractStartDate!=null">
and po.contract_start_date > #{query.contractStartDate}
</if>
<if test="query.contractEndDate!='' and query.contractEndDate!=null">
and #{query.contractEndDate} > po.contract_end_date
</if>
<if test="query.isBlacklist!='' and query.isBlacklist!=null">
and po.is_blacklist=#{query.isBlacklist}
</if>
</sql>
<!-- (@i:=@i+1) AS 'serialNumber',-->
<!-- (SELECT @i:=0) AS itable,-->
<!--<select id="findPartnerExportData" resultType="com.testor.module.partner.model.excel.PartnerReport"
parameterType="com.testor.module.partner.model.dto.TPartnerOrgParam">
select
po.id,po.name, po.credit_code as creditCode, po.legal_person legalPerson, po.responsible_person
responsiblePerson,
po.phone, po.contract_start_date contractStartDate, po.contract_end_date contractEndDate,
pc.name certificateName, pc.valid_end_date certificateValidEndDate,
py.name as typeName
from t_partner_org po
left join t_partner_type py on po.type_id = py.id
left join t_partner_certificate pc on po.id = pc.biz_id and pc.type=1 and pc.status='0'
<where>
po.status = '0'
<include refid="common_where_if"></include>
<if test="query.condOrgIdList!=null">
and po.org_id in
<foreach collection="query.condOrgIdList" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</select>-->
<select id="findPartnerExportData" resultType="com.testor.module.partner.model.excel.PartnerReport"
parameterType="arraylist">
SELECT tpo.name AS partner_name,
tpo.credit_code,
tpt.name AS type_name,
tpo.legal_person,
tpor.responsible_person,
tpor.phone,
tpor.contract_start_date,
tpor.contract_end_date,
tpc.type AS certificate_name,
tpc.valid_end_date AS certificate_valid_end_date,
tpor.id
FROM
t_partner_org_res AS tpor
LEFT JOIN t_partner_org AS tpo ON tpor.partner_id = tpo.id
LEFT JOIN t_partner_certificate AS tpc ON tpo.id=tpc.biz_id
LEFT JOIN t_partner_type AS tpt ON tpor.type_id = tpt.id
<where>
<if test="query!=null">
and tpor.org_id in
<foreach collection="query" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</select>
<select id="list" resultType="com.testor.module.partner.model.vo.PartnerOrgVO"
parameterType="com.testor.module.partner.model.dto.TPartnerOrgParam">
select * from (
select
org_name,
partner_name,
type_name,
legal_person,
responsible_person,
phone,
is_blacklist,
partner_id,
res_id,
case when a != 0 then 0 else 1 end as certificate_status
from (
SELECT
tso.org_name,
tpo.name AS partner_name,
tpt.name AS type_name,
tpo.legal_person,
tpor.responsible_person,
tpor.phone,
tpor.certificate_status,
tpo.is_blacklist,
tpo.id AS partner_id,
tpor.id AS res_id,
sum(CASE
WHEN tpc.valid_end_date!=null and tpc.valid_end_date < NOW() THEN 1 ELSE 0 END) as a
FROM
t_partner_org_res AS tpor
LEFT JOIN t_partner_org AS tpo ON tpor.partner_id = tpo.id
LEFT JOIN t_partner_type AS tpt ON tpor.type_id = tpt.id
LEFT JOIN t_sys_org AS tso ON tpor.org_id=tso.org_id
left join t_partner_certificate tpc on tpo.id = tpc.biz_id
<where>
<if test="query.name!=null and query.name!=''">
AND tpo.name like concat('%',#{query.name},'%')
</if>
<if test="query.condOrgIdList!=null">
AND tpor.org_id IN
<foreach collection="query.condOrgIdList" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
and tpor.org_id in (select org.org_id from t_sys_org org where org.org_id = '${query.orgId}')
</where>
group by tpor.id,tso.org_name,tpo.name,tpt.name,tpo.legal_person,tpor.responsible_person,tpor.phone,tpo.is_blacklist,tpo.id,tpor.id
ORDER BY tpor.create_date DESC) a ) b
<where>
<if test="query.certificateStatus!=null ">
AND certificate_status = #{query.certificateStatus}
</if>
</where>
</select>
<select id="detail" resultType="com.testor.module.partner.model.vo.PartnerOrgDetailVO"
parameterType="string">
SELECT tpo.name AS partner_name,
tpor.id AS res_id,
tpo.id AS partner_id,
tpo.credit_code,
tpo.legal_person,
tpt.name AS type_name,
tpor.responsible_person,
tpor.phone,
tpor.contract_start_date,
tpor.contract_end_date,
tpor.certificate_status,
tpo.is_blacklist,
tpo.blacklist_reason
FROM
t_partner_org_res AS tpor
LEFT JOIN t_partner_org AS tpo
ON tpor.partner_id = tpo.id
LEFT JOIN t_partner_type AS tpt ON tpor.type_id = tpt.id
WHERE tpor.id=#{resId}
</select>
<select id="blacklist" resultType="com.testor.module.partner.model.vo.PartnerOrgBlacklistVO"
parameterType="com.testor.module.partner.model.dto.TPartnerOrgParam">
-- 相关方黑名单列表
SELECT
tpo.name AS partner_name,
tpo.credit_code,
tpo.legal_person,
tpor.certificate_status,
tpor.id,
tso.org_name,
tpo.blacklist_reason,
tpo.id AS partner_id
FROM
t_partner_org_res AS tpor
LEFT JOIN t_partner_org AS tpo ON tpor.partner_id = tpo.id
LEFT JOIN t_sys_org AS tso ON tpo.is_blacklist_by = tso.org_id
WHERE tpo.is_blacklist=#{query.isBlacklist}
<if test="query.certificateStatus!=null">
AND tpor.certificate_status = #{query.certificateStatus}
</if>
<if test="query.name!=null and query.name!=''">
AND tpo.name = #{query.name}
</if>
-- group by tpo.id
ORDER BY tpor.create_date DESC
</select>
<select id="getOrgId" resultType="com.testor.module.partner.model.dto.TPartnerOrgDTO">
select b.name , b.id as id,a.partner_id from t_partner_org_res a left join t_partner_org b on a.partner_id = b.id
where a.status = 0 and b.is_blacklist = '0'
and a.org_id = #{query.id}
<if test="query.name!='' and query.name!=null">
and a.name like concat('%', #{query.name},'%')
</if>
</select>
</mapper>