ProductPop.xml
13.7 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
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
<?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="ProductPopDao">
<!-- product_pop 所有查询列 -->
<sql id="QUERY_COLUMN_LIST">
<![CDATA[pid,name,product_type AS productType,index_top AS indexTop,cate_id AS cateId,seller,seller_name AS sellerName,shop,shop_name AS shopName,publish_time AS publishTime,status,extend,ctime,utime]]>
</sql>
<!-- product_pop 查询列来源表-->
<sql id="QUERY_FROM_TABLE"><![CDATA[FROM product_pop]]></sql>
<!-- 全部条件(更多功能可以通过queryData扩展实现) -->
<sql id="QUERY_WHERE_CLAUSE">
<where>
<if test="pid != null and pid != ''"><![CDATA[AND pid = #{pid}]]></if>
<if test="name != null and name != ''"><![CDATA[AND name = #{name}]]></if>
<if test="productType != null and productType != ''"><![CDATA[AND product_type = #{productType}]]></if>
<if test="productSample != null and productSample != ''"><![CDATA[AND product_sample = #{productSample}]]></if>
<if test="quotationType != null and quotationType != ''"><![CDATA[AND quotation_type = #{quotationType}]]></if>
<if test="cateId != null and cateId != ''"><![CDATA[AND cate_id = #{cateId}]]></if>
<if test="userDefined != null and userDefined != ''"><![CDATA[AND user_defined = #{userDefined}]]></if>
<if test="producingArea != null and producingArea != ''"><![CDATA[AND producing_area = #{producingArea}]]></if>
<if test="localityName != null and localityName != ''"><![CDATA[AND localityName = #{localityName}]]></if>
<if test="countryArea != null and countryArea != ''"><![CDATA[AND country_area = #{countryArea}]]></if>
<if test="foreignCityName != null and foreignCityName != ''"><![CDATA[AND foreign_city_name = #{foreignCityName}]]></if>
<if test="seller != null and seller != ''"><![CDATA[AND seller = #{seller}]]></if>
<if test="sellerName != null and sellerName != ''"><![CDATA[AND seller_name = #{sellerName}]]></if>
<if test="shop != null and shop != ''"><![CDATA[AND shop = #{shop}]]></if>
<if test="shopName != null and shopName != ''"><![CDATA[AND shop_name = #{shopName}]]></if>
<if test="indate != null and indate != ''"><![CDATA[AND indate = #{indate}]]></if>
<if test="publishMode != null and publishMode != ''"><![CDATA[AND publish_mode = #{publishMode}]]></if>
<if test="publishSettime != null and publishSettime != ''"><![CDATA[AND publish_settime = #{publishSettime}]]></if>
<if test="publishTime != null and publishTime != ''"><![CDATA[AND publish_time = #{publishTime}]]></if>
<if test="dropsTime != null and dropsTime != ''"><![CDATA[AND drops_time = #{dropsTime}]]></if>
<if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if>
<if test="foreignPid != null and foreignPid != ''"><![CDATA[AND foreign_pid = #{foreignPid}]]></if>
<if test="storeUnit != null and storeUnit != ''"><![CDATA[AND store_unit = #{storeUnit}]]></if>
<if test="manualAuditType != null and manualAuditType != ''"><![CDATA[AND manual_audit_type = #{manualAuditType}]]></if>
<if test="prepareTime != null and prepareTime != ''"><![CDATA[AND prepare_time = #{prepareTime}]]></if>
<if test="ctime != null and ctime != ''"><![CDATA[AND ctime = #{ctime}]]></if>
<if test="utime != null and utime != ''"><![CDATA[AND utime = #{utime}]]></if>
</where>
</sql>
<sql id="Query_SearchPopProduct_COLUMN_SET">
<where>
<if test="pstates != null and pstates != ''"><![CDATA[AND status IN ]]>
<foreach collection="pstates" item="pstate" open="(" separator="," close=")">
<![CDATA[#{pstate}]]>
</foreach>
</if>
<if test="pstate != null and pstate != '' and pstate>=4"><![CDATA[AND status >3]]></if>
<if test="pstate != null and pstate != '' and pstate < 4"><![CDATA[AND status = #{pstate}]]></if>
<if test="storeId != null"><![CDATA[ AND shop = #{storeId}]]></if>
<if test="title != null and title != ''"><![CDATA[AND name like CONCAT('%',#{title},'%')]]></if>
<if test="cname != null and cname != ''"><![CDATA[AND cate_id = #{cname}]]></if>
<if test="productType != null and productType != ''"><![CDATA[AND product_type = #{productType}]]></if>
<if test="productSample != null and productSample != ''"><![CDATA[AND product_sample = #{productSample}]]></if>
<if test="begin != null and begin != ''"><![CDATA[AND drops_time >= #{begin}]]></if>
<if test="end != null and end != ''"><![CDATA[AND drops_time = #{end}]]></if>
<if test="begin != null and end == null "><![CDATA[AND drops_time > #{begin}]]></if>
<if test="begin == null and end != null "><![CDATA[AND drops_time < DATE_ADD(#{end},INTERVAL 1 DAY)]]></if>
<if test="begin != null and end != null and begin != '' and end!= '' "><![CDATA[AND drops_time between #{begin} and DATE_ADD(#{end},INTERVAL 1 DAY)]]></if>
<if test="createBegin != null and createEnd == null "><![CDATA[AND ctime > #{createBegin}]]></if>
<if test="createBegin == null and createEnd != null "><![CDATA[AND ctime < DATE_ADD(#{createEnd},INTERVAL 1 DAY)]]></if>
<if test="createBegin != null and createEnd != null and begin != '' and end!= '' "><![CDATA[AND ctime between #{createBegin} and DATE_ADD(#{createEnd},INTERVAL 1 DAY)]]></if>
</where>
</sql>
<!-- 智能排序与分页 -->
<sql id="QUERY_ORDER_LIMIT_CONDTION">
<if test="orderField != null and orderField != '' and orderFieldType != null and orderFieldType != ''"><![CDATA[ORDER BY ${orderField} ${orderFieldType}]]></if>
<if test="startIndex != null and startIndex >= 0 and pageSize != null and pageSize > 0"><![CDATA[LIMIT #{startIndex},#{pageSize}]]></if>
</sql>
<!-- 更新列字段,只要不为NULL则更新,除开主键列 -->
<sql id="UPDATE_COLUMN_SET">
<set>
<if test="manualAuditType != null and manualAuditType != ''"><![CDATA[ manual_audit_type = #{manualAuditType},]]></if>
<if test="name != null and name != ''"><![CDATA[ name = #{name},]]></if>
<if test="productType != null and productType != ''"><![CDATA[AND product_type = #{productType}]]></if>
<if test="productSample != null and productSample != ''"><![CDATA[AND product_sample = #{productSample}]]></if>
<if test="quotationType != null and quotationType != ''"><![CDATA[ quotation_type = #{quotationType},]]></if>
<if test="cateId != null and cateId != ''"><![CDATA[cate_id = #{cateId},]]></if>
<if test="producingArea != null and producingArea != ''"><![CDATA[ producing_area = #{producingArea},]]></if>
<if test="localityName != null and localityName != ''"><![CDATA[ localityName = #{localityName},]]></if>
<if test="localityArea != null and localityArea != ''"><![CDATA[ locality_area = #{localityArea},]]></if>
<if test="countryArea != null and countryArea != ''"><![CDATA[ country_area = #{countryArea},]]></if>
<if test="foreignCityName != null and foreignCityName != ''"><![CDATA[ foreign_city_name = #{foreignCityName},]]></if>
<if test="seller != null and seller != ''"><![CDATA[ seller = #{seller},]]></if>
<if test="shop != null and shop != ''"><![CDATA[ shop = #{shop},]]></if>
<if test="hasExpress != null and hasExpress != ''"><![CDATA[ has_express = #{hasExpress},]]></if>
<if test="isAllowDelivery != null and isAllowDelivery != ''"><![CDATA[ is_allow_delivery = #{isAllowDelivery},]]></if>
<if test="publishMode != null and publishMode != '' and publishMode > 0 "><![CDATA[ publish_mode = #{publishMode},]]></if>
<if test="publishTime != null and publishTime != ''"><![CDATA[ publish_time = #{publishTime},]]></if>
<if test="publishSettime != null and publishSettime != ''"><![CDATA[ publish_settime = #{publishSettime},]]></if>
<if test="prepareTime != null and prepareTime != ''"><![CDATA[ prepare_time = #{prepareTime},]]></if>
<if test="dropsTime != null and dropsTime != ''"><![CDATA[ drops_time = #{dropsTime},]]></if>
<if test="status != null and status != ''"><![CDATA[`status` = #{status},]]></if>
<if test="foreignPid != null"><![CDATA[foreign_pid = #{foreignPid},]]></if>
<if test="extend != null and extend != '' "><![CDATA[`extend` = #{extend},]]></if>
<if test="ctime != null and ctime != ''"><![CDATA[ ctime = #{ctime},]]></if>
<![CDATA[ utime = now()]]>
</set>
</sql>
<!-- 插入product_pop记录 -->
<insert id="insertEntry" parameterType="productPop" >
<![CDATA[
INSERT INTO product_pop (pid,name,index_top,product_type,cate_id,seller,status,ctime,extend)
VALUES (#{pid},#{name},#{indexTop},#{productType},#{cateId},#{seller},#{status},now(),#{extend})
]]>
</insert>
<!-- 返回插入的编号,在事务开启状态下有效 -->
<select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS pid]]></select>
<!-- 删除记录,主键IN(array) -->
<delete id="deleteByArrayKey" parameterType="java.lang.reflect.Array" >
<![CDATA[DELETE FROM product_pop WHERE pid IN]]>
<foreach collection="array" item="pid" open="(" separator="," close=")">
<![CDATA[#{pid}]]>
</foreach>
</delete>
<!-- 删除,通过条件 -->
<update id="deleteByCondtion" parameterType="productPop" >
<![CDATA[DELETE FROM product_pop]]>
<include refid="QUERY_WHERE_CLAUSE"/>
</update>
<!-- 修改记录通过主键 -->
<update id="updateByKey" parameterType="productPop" >
<![CDATA[UPDATE product_pop]]>
<include refid="UPDATE_COLUMN_SET"/>
<![CDATA[WHERE pid = #{pid}]]>
</update>
<!-- 查询,通过主键IN(array) -->
<select id="selectEntryArray" parameterType="java.lang.reflect.Array" resultType="productPop">
<![CDATA[SELECT]]>
<include refid="QUERY_COLUMN_LIST"/>
<include refid="QUERY_FROM_TABLE"/>
<![CDATA[WHERE pid IN]]>
<foreach collection="array" item="pid" open="(" separator="," close=")">
<![CDATA[#{pid}]]>
</foreach>
</select>
<!-- 查询,通过条件 -->
<select id="selectEntryList" parameterType="productPop" resultType="productPop">
<![CDATA[SELECT]]>
<include refid="QUERY_COLUMN_LIST"/>
<include refid="QUERY_FROM_TABLE"/>
<include refid="QUERY_WHERE_CLAUSE"/>
<include refid="QUERY_ORDER_LIMIT_CONDTION"/>
</select>
<!-- 总数查询,通过条件 -->
<select id="selectEntryListCount" parameterType="productPop" resultType="int">
<![CDATA[SELECT COUNT(pid) AS dataCount]]>
<include refid="QUERY_FROM_TABLE"/>
<include refid="QUERY_WHERE_CLAUSE"/>
</select>
<!-- 其它SQL语句 -->
<!-- 删除第三方产品信息 -->
<update id="delProduct" parameterType="java.util.Map">
UPDATE product_pop
SET status=-1
WHERE
pid IN
<foreach collection="list" item="item" separator="," open="(" close=")">
<![CDATA[#{item} ]]>
</foreach>
<if test="sellerID!=null">
<![CDATA[ AND seller=#{sellerID} ]]>
</if>
</update>
<!-- 更新第三方产品信息状态 -->
<update id="updatePopProductStatus" parameterType="java.util.Map">
UPDATE
product_pop
SET
<![CDATA[ status=#{status}]]>
<if test="status==3">
,publish_time=now(),publish_mode=2,publish_settime=null
</if>
<if test="status==7">
,drops_time =now(),publish_mode=1,publish_settime=null
</if>
WHERE
<![CDATA[seller=#{sellerId}]]>
and
pid IN
<foreach collection="list" item="item" separator="," open="(" close=")">
<![CDATA[#{item} ]]>
</foreach>
</update>
<!-- 设置第三商品库分类 -->
<update id="setProductVirtualCid" parameterType="java.util.Map">
UPDATE
product_pop
SET
<![CDATA[ user_defined=#{vcid}]]>
WHERE
pid IN
<foreach collection="list" item="item" separator="," open="(" close=")">
<![CDATA[#{item} ]]>
</foreach>
</update>
<select id="listLatestProductId" parameterType="java.util.Map" resultType="java.lang.Long">
<![CDATA[SELECT pid ]]>
<include refid="QUERY_FROM_TABLE"/>
<![CDATA[
WHERE shop = #{shopId} AND status = 3
ORDER BY ctime desc
LIMIT #{num}
]]>
</select>
<!-- 查询类目列表 -->
<select id="selectPopProductCategroyByShopId" parameterType="java.util.Map" resultType="int">
SELECT DISTINCT t.`cate_id` FROM product_pop t WHERE t.`shop`=#{shopId}
<if test="pstatus != null and pstatus != '' and pstatus>=4"><![CDATA[ AND t.`status` >3]]></if>
<if test="pstatus != null and pstatus != '' and pstatus < 4"><![CDATA[AND t.`status` = #{pstatus}]]></if>
</select>
<select id="selectCountByShopId" parameterType="java.lang.Long" resultType="int">
<![CDATA[SELECT COUNT(pid) ]]>
<include refid="QUERY_FROM_TABLE"/>
<![CDATA[WHERE shop=#{shopId} and status>0 ]]>
</select>
<select id="countVirtualCatProducts" parameterType="java.lang.Long" resultType="long">
<![CDATA[SELECT COUNT(pid) ]]>
<include refid="QUERY_FROM_TABLE"/>
<![CDATA[WHERE user_defined=#{vcid} and status>0 ]]>
</select>
<select id="getCommonCateIds" parameterType="java.lang.Long" resultType="int">
<![CDATA[SELECT cate_id ]]>
<include refid="QUERY_FROM_TABLE"/>
<![CDATA[WHERE seller=#{userId} and status>0 GROUP BY cate_id ORDER BY count(pid) desc]]>
</select>
<select id="getCateIdByPids" parameterType="java.util.List" resultType="int">
<![CDATA[select distinct cate_id AS cateId from product_pop where pid in]]>
<foreach collection="list" item="item" separator="," open="(" close=")">
<![CDATA[#{item} ]]>
</foreach>
</select>
</mapper>