ProductMapper.xml
9.8 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
<?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.yoho.ufo.dal.ProductMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.Product">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_name" jdbcType="VARCHAR" property="productName" />
<result column="product_code" jdbcType="VARCHAR" property="productCode" />
<result column="max_sort_id" jdbcType="INTEGER" property="maxSortId" />
<result column="mid_sort_id" jdbcType="INTEGER" property="midSortId" />
<result column="brand_id" jdbcType="INTEGER" property="brandId" />
<result column="series_id" jdbcType="INTEGER" property="seriesId" />
<result column="gender" jdbcType="CHAR" property="gender" />
<result column="sale_time" jdbcType="INTEGER" property="saleTime" />
<result column="min_price" jdbcType="DECIMAL" property="minPrice" />
<result column="max_price" jdbcType="DECIMAL" property="maxPrice" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<result column="shelve_time" jdbcType="INTEGER" property="shelveTime" />
<result column="edit_time" jdbcType="INTEGER" property="editTime" />
<result column="shelve_status" jdbcType="INTEGER" property="shelveStatus" />
<result column="storage" jdbcType="INTEGER" property="storage" />
<result column="key_words" jdbcType="VARCHAR" property="keyWords" />
<result column="del_status" jdbcType="INTEGER" property="delStatus" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from product
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.Product" useGeneratedKeys="true" keyProperty="id" >
insert into product (id, product_name, product_code,
max_sort_id, mid_sort_id, brand_id,
series_id, gender, sale_time,
min_price, max_price, create_time,
update_time, shelve_time, edit_time,
shelve_status, storage, key_words,
del_status)
values (#{id,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, #{productCode,jdbcType=VARCHAR},
#{maxSortId,jdbcType=INTEGER}, #{midSortId,jdbcType=INTEGER}, #{brandId,jdbcType=INTEGER},
#{seriesId,jdbcType=INTEGER}, #{gender,jdbcType=CHAR}, #{saleTime,jdbcType=INTEGER},
#{minPrice,jdbcType=DECIMAL}, #{maxPrice,jdbcType=DECIMAL}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}, #{shelveTime,jdbcType=INTEGER}, #{editTime,jdbcType=INTEGER},
#{shelveStatus,jdbcType=INTEGER}, #{storage,jdbcType=INTEGER}, #{keyWords,jdbcType=VARCHAR},
#{delStatus,jdbcType=INTEGER})
</insert>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.Product">
update product
set product_name = #{productName,jdbcType=VARCHAR},
product_code = #{productCode,jdbcType=VARCHAR},
max_sort_id = #{maxSortId,jdbcType=INTEGER},
mid_sort_id = #{midSortId,jdbcType=INTEGER},
brand_id = #{brandId,jdbcType=INTEGER},
series_id = #{seriesId,jdbcType=INTEGER},
gender = #{gender,jdbcType=CHAR},
sale_time = #{saleTime,jdbcType=INTEGER},
min_price = #{minPrice,jdbcType=DECIMAL},
max_price = #{maxPrice,jdbcType=DECIMAL},
update_time = unix_timestamp(),
edit_time = unix_timestamp(),
key_words = #{keyWords,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
shelve_status, storage, key_words, del_status
from product
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
shelve_status, storage, key_words, del_status
from product
</select>
<select id="selectPage" resultMap="BaseResultMap">
select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
shelve_status, storage, key_words, del_status
from product where del_status=0 <include refid="pageCondition" /> order by product.id desc limit #{start},#{rows}
</select>
<select id="selectCount" resultType="java.lang.Integer">
select count(*) from product where del_status=0 <include refid="pageCondition" />
</select>
<sql id="pageCondition" >
<if test="id != null and id > 0">
and id = #{id}
</if>
<if test="productName != null and productName !=''">
and product_name like "%"#{productName}"%"
</if>
<if test="maxSortId != null and maxSortId > 0">
and max_sort_id = #{maxSortId}
</if>
<if test="midSortId != null and midSortId > 0">
and mid_sort_id = #{midSortId}
</if>
<if test="brandId != null and brandId > 0">
and brand_id = #{brandId}
</if>
<if test="shelveStatus != null and shelveStatus > -1">
and shelve_status = #{shelveStatus}
</if>
</sql>
<select id="selectSkuPage" resultMap="BaseResultMap">
select distinct p.id from product p <include refid="skuPageCondition" /> order by p.id desc limit #{start},#{rows}
</select>
<select id="selectSkuCount" resultType="java.lang.Integer">
select count(*) from (select distinct p.id from product p <include refid="skuPageCondition" /> ) sub
</select>
<sql id="skuPageCondition" >
<if test="skuCondition == 1">
inner join storage s on p.id = s.product_id
</if>
<if test="skupCondition == 1">
inner join storage_price sp on p.id = sp.product_id
</if>
<if test="productCode != null and productCode !=''">
and product_code = #{productCode}
</if>
<if test="productName != null and productName !=''">
and product_name like "%"#{productName}"%"
</if>
<if test="maxSortId != null and maxSortId > 0">
and max_sort_id = #{maxSortId}
</if>
<if test="midSortId != null and midSortId > 0">
and mid_sort_id = #{midSortId}
</if>
<if test="brandId != null and brandId > 0">
and brand_id = #{brandId}
</if>
<if test="shelveStatus != null and shelveStatus > -1">
and shelve_status = #{shelveStatus}
</if>
<if test="storageId != null and storageId > 0">
and s.id = #{storageId}
</if>
<if test="sellerUid != null and sellerUid > 0">
and sp.seller_uid = #{sellerUid}
</if>
<if test="hasStock != null and hasStock == 0">
and s.storage_num = 0
</if>
<if test="hasStock != null and hasStock == 1">
and s.storage_num > 0
</if>
<if test="skup != null and skup > 0">
and sp.skup = #{skup}
</if>
</sql>
<select id="selectProductListByIds" resultMap="BaseResultMap">
select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
shelve_status, storage, key_words, del_status
from product where id in
<foreach item="item" index="index" collection="productIdList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<update id="updateStatusByPrimaryKey">
update product set
edit_time = unix_timestamp(),
update_time = unix_timestamp(),
shelve_status = #{shelveStatus,jdbcType=INTEGER}
<if test="shelveStatus != null and shelveStatus == 1">
,shelve_time = unix_timestamp()
</if>
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectProductStorageCount" resultType="java.lang.Integer">
select
<if test="product.storageNum != null"> count(DISTINCT p.id) </if>
<if test="product.storageNum == null"> count(p.id) </if>
from product p where
<include refid="skcPageCondition" />
</select>
<select id="selectProductStorageList" resultMap="BaseResultMap">
select
<if test="product.storageNum != null"> DISTINCT p.id, p.brand_id, p.product_name, p.max_sort_id, p.mid_sort_id </if>
<if test="product.storageNum == null"> p.id, p.brand_id, p.product_name, p.max_sort_id, p.mid_sort_id </if>
from product p
where <include refid="skcPageCondition" /> limit #{start},#{rows}
</select>
<sql id="skcPageCondition">
1 = 1
<if test="product.storageNum != null">
<if test="product.storageNum == 0">
And exists(SELECT 1 FROM storage s WHERE s.storage_num = 0 AND s.product_id= p.id)
</if>
<if test="product.storageNum != 0">
And exists(SELECT 1 FROM storage s WHERE s.storage_num >= 1 AND s.product_id= p.id)
</if>
</if>
<if test="product.id != null and product.id > 0">
and p.id = #{product.id}
</if>
<if test="product.productName != null and product.productName != ''">
and p.product_name like concat('%', #{product.productName}, '%')
</if>
<if test="product.maxSortId != null and product.maxSortId > 0">
and p.max_sort_id = #{product.maxSortId}
</if>
<if test="product.midSortId != null and product.midSortId > 0">
and p.mid_sort_id = #{product.midSortId}
</if>
<if test="product.brandId != null and product.brandId > 0">
and p.brand_id = #{product.brandId}
</if>
<if test="product.productIdList != null and product.productIdList.size()>0">
And p.id in
<foreach collection="product.productIdList" item="productID" open="(" close=")" separator=",">
#{productID}
</foreach>
</if>
</sql>
</mapper>