ReceptionHomePageMaterialConfigMapper.xml
10.2 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
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
<?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="cn.com.glsx.dj.mindworkplate.mapper.ReceptionHomePageMaterialConfigMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.ReceptionHomePageMaterialConfig">
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="business_type" property="businessType" jdbcType="INTEGER"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR"/>
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP"/>
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR"/>
</resultMap>
<resultMap id="dtoMap" extends="BaseResultMap"
type="cn.com.glsx.dj.mindworkplate.dto.ReceptionHomePageMaterialConfigDTO">
<result column="merchant_name" property="merchantName" jdbcType="VARCHAR"/>
<result column="brand_name" property="brandName" jdbcType="VARCHAR"/>
<result column="sub_brand_name" property="subBrandName" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, business_type, created_by, created_date, updated_by, updated_date, deleted_flag
</sql>
<select id="findHomePageConfigPage2" resultMap="dtoMap">
select rhpmc.*,
GROUP_CONCAT(DISTINCT
CASE WHEN rhpcr.rel_type = 1 THEN rhpcr.rel_item_name END
SEPARATOR ',') AS merchant_name,
GROUP_CONCAT(DISTINCT
CASE WHEN rhpcr.rel_type = 2 THEN rhpcr.rel_item_name END
SEPARATOR ',') AS brand_name,
GROUP_CONCAT(DISTINCT
CASE WHEN rhpcr.rel_type = 3 THEN rhpcr.rel_item_name END
SEPARATOR ',') AS sub_brand_name
from reception_home_page_material_config rhpmc
left join reception_home_page_config_rel rhpcr on rhpmc.id = rhpcr.config_id and rhpcr.deleted_flag = 'N'
left join reception_home_page_config_rel rhpcr1 on rhpmc.id = rhpcr1.config_id and rhpcr1.deleted_flag = 'N' and
rhpcr1.rel_type = 1
left join reception_home_page_config_rel rhpcr2 on rhpmc.id = rhpcr2.config_id and rhpcr2.deleted_flag = 'N' and
rhpcr2.rel_type = 2
left join reception_home_page_config_rel rhpcr3 on rhpmc.id = rhpcr3.config_id and rhpcr3.deleted_flag = 'N' and
rhpcr3.rel_type = 3 and rhpcr3.rel_parent_id = rhpcr2.id
where rhpmc.deleted_flag = 'N'
<if test="condition.merchantId != null">
and (rhpcr1.rel_business_id = -1 or rhpcr1.rel_business_id = #{condition.merchantId})
</if>
<if test="condition.brandId != null">
and (rhpcr2.rel_business_id = -1 or rhpcr2.rel_business_id = #{condition.brandId})
<if test="condition.subBrandId != null">
and (rhpcr3.rel_business_id = -1 or rhpcr3.rel_business_id = #{condition.subBrandId})
</if>
</if>
group by rhpmc.id
order by rhpmc.created_date desc
</select>
<select id="findHomePageConfigPage" resultMap="dtoMap">
select rhpmc.*,
GROUP_CONCAT(DISTINCT
CASE WHEN rhpcr.rel_type = 1 THEN rhpcr.rel_item_name END
SEPARATOR ',') AS merchant_name,
GROUP_CONCAT(DISTINCT
CASE WHEN rhpcr.rel_type = 2 THEN rhpcr.rel_item_name END
SEPARATOR ',') AS brand_name,
GROUP_CONCAT(DISTINCT
CASE WHEN rhpcr.rel_type = 3 THEN rhpcr.rel_item_name END
SEPARATOR ',') AS sub_brand_name
from reception_home_page_material_config rhpmc
left join reception_home_page_config_rel rhpcr on rhpmc.id = rhpcr.config_id and rhpcr.deleted_flag = 'N'
where rhpmc.deleted_flag = 'N'
and rhpmc.id in (select rhpmc.id from reception_home_page_material_config rhpmc
LEFT JOIN reception_home_page_config_rel rhpcr on rhpmc.id = rhpcr.config_id and rhpcr.deleted_flag = 'N'
where rhpmc.deleted_flag = 'N'
<if test="condition.merchantName != null and condition.merchantName != ''">
and rhpcr.rel_type = 1 and (rhpcr.rel_business_id = -1
or rhpcr.rel_item_name like concat('%', #{condition.merchantName}, '%'))
</if>
<if test="condition.merchantId != null">
and rhpcr.rel_type = 1 and (rhpcr.rel_business_id = -1 or rhpcr.rel_business_id = #{condition.merchantId})
</if>
<if test="condition.brandId != null">
and rhpcr.rel_type = 2 and (rhpcr.rel_business_id = -1 or rhpcr.rel_business_id = #{condition.brandId})
</if>
<if test="condition.subBrandId != null">
and rhpcr.rel_type = 3 and (rhpcr.rel_business_id = -1 or rhpcr.rel_business_id = #{condition.subBrandId})
</if>
group by rhpmc.id)
group by rhpmc.id
order by rhpmc.created_date desc
</select>
<select id="findHomePageVersionByCondition" resultMap="dtoMap">
select rhpmc.id,rhpcr1.rel_business_id merchantId,rhpcr1.rel_item_name merchantName,
rhpcr2.rel_business_id brandId,rhpcr2.rel_item_name brandName,
rhpcr3.rel_business_id subBrandId,rhpcr3.rel_item_name subBrandName
from reception_home_page_material_config rhpmc
left join reception_home_page_config_rel rhpcr1 on rhpmc.id = rhpcr1.config_id and rhpcr1.deleted_flag = 'N' and
rhpcr1.rel_type = 1
left join reception_home_page_config_rel rhpcr2 on rhpmc.id = rhpcr2.config_id and rhpcr2.deleted_flag = 'N' and
rhpcr2.rel_type = 2
left join reception_home_page_config_rel rhpcr3 on rhpmc.id = rhpcr3.config_id and rhpcr3.deleted_flag = 'N' and
rhpcr3.rel_type = 3 and rhpcr3.rel_parent_id = rhpcr2.rel_business_id
where rhpmc.deleted_flag = 'N'
and (rhpcr1.rel_business_id = -1
<if test="condition.merchantId != null">
or rhpcr1.rel_business_id = #{condition.merchantId}
</if>
)
<if test="condition.brandId != null">
and (rhpcr2.rel_business_id = -1
or rhpcr2.rel_business_id = #{condition.brandId}
<if test="condition.subBrandId != null">
and (rhpcr3.rel_business_id = -1 or rhpcr3.rel_business_id = #{condition.subBrandId}
or (rhpcr2.rel_business_id is not null and rhpcr3.rel_business_id is null))
</if>
)
</if>
<if test="condition.brandIdList != null and !condition.brandIdList.isEmpty()">
and (rhpcr2.rel_business_id = -1
or rhpcr2.rel_business_id IN
<foreach item="id" collection="condition.brandIdList" open="(" separator="," close=")">
#{id}
</foreach>
<if test="condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()">
and (rhpcr3.rel_business_id = -1 or rhpcr3.rel_business_id IN
<foreach item="id" collection="condition.subBrandIdList" open="(" separator="," close=")">
#{id}
</foreach>
or (rhpcr2.rel_business_id is not null and rhpcr3.rel_business_id is null))
</if>
)
</if>
group by rhpmc.id order by rhpcr3.rel_business_id desc,rhpcr2.rel_business_id desc,rhpcr1.rel_business_id desc
limit 1
</select>
<select id="selectConfigByBusinessIds" resultMap="dtoMap">
SELECT t.*,
CASE WHEN r1.rel_type = 1 and r1.rel_business_id != -1 THEN r1.rel_item_name END AS merchant_name,
CASE WHEN r1.rel_type = 2 and r1.rel_business_id != -1 THEN r1.rel_item_name END AS brand_name,
CASE WHEN r1.rel_type = 3 and r1.rel_business_id != -1 THEN r1.rel_item_name END AS sub_brand_name,
CASE WHEN r1.rel_type = 1 and r1.rel_business_id != -1 THEN 3
WHEN r1.rel_type = 2 and r1.rel_business_id != -1 THEN 2
WHEN r1.rel_type = 3 and r1.rel_business_id != -1 THEN 1
ELSE 4 END AS sort_priority
from reception_home_page_material_config t
left join reception_home_page_config_rel r1 on t.id = r1.config_id
WHERE r1.deleted_flag = 'N' and t.deleted_flag = 'N'
AND (
<if test="condition.brandIdList != null and !condition.brandIdList.isEmpty()">
(r1.rel_type = 2 AND (r1.rel_business_id IN
<foreach item="id" collection="condition.brandIdList" open="(" separator="," close=")">
#{id}
</foreach>
OR r1.rel_business_id = -1))
<if test="condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()">
OR
</if>
</if>
<if test="condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()">
(r1.rel_type = 3
AND (
(r1.rel_business_id IN
<foreach item="id" collection="condition.subBrandIdList" open="(" separator="," close=")">
#{id}
</foreach>
) OR r1.rel_business_id = -1
OR
EXISTS (
SELECT 1
FROM reception_home_page_config_rel r2
WHERE r2.rel_type = 2
AND r2.rel_business_id = -1
AND r2.rel_parent_id = r1.rel_parent_id ) ) )
<!-- <if test="condition.merchantIdList != null and !condition.merchantIdList.isEmpty()">-->
<!-- OR-->
<!-- </if>-->
</if>
<if test="condition.merchantIdList != null and !condition.merchantIdList.isEmpty()
and ((condition.brandIdList != null and !condition.brandIdList.isEmpty())
or (condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()))">
or (r1.rel_type = 1 AND (r1.rel_business_id IN
<foreach item="id" collection="condition.merchantIdList" open="(" separator="," close=")">
#{id}
</foreach>
) and r1.rel_business_id != -1)
</if>
)
group by t.id having count(t.id) > 1
ORDER BY sort_priority ASC
</select>
</mapper>