jiangqs
2023-05-09 0398509aa5f27bd6f987adf3d24eceef56b07b4c
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?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.ruoyi.order.mapper.goods.GoodsMapper">
 
    <resultMap type="Goods" id="GoodsResult">
        <result property="goodsId"    column="goods_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="goodsStatus"    column="goods_status"    />
        <result property="goodsType"    column="goods_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="goodsClassId"    column="goods_class_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="cycleNumFlag"    column="cycle_num_flag"    />
        <result property="serviceNum"    column="service_num"    />
        <result property="goodsIntroduction"    column="goods_introduction"    />
        <result property="salesPrice"    column="sales_price"    />
        <result property="mininumPrice"    column="mininum_price"    />
        <result property="subscriptionFlag"    column="subscription_flag"    />
        <result property="subscription"    column="subscription"    />
        <result property="goodsDetail"    column="goods_detail"    />
        <result property="recommendFlag"    column="recommend_flag"    />
        <result property="goodsNurses"    column="goods_nurses"    />
        <result property="goodsTags"    column="goods_tags"    />
    </resultMap>
 
    <sql id="selectGoodsVo">
        select goods_id, del_flag, goods_status, goods_type, create_time, create_user_id, update_time, update_user_id, goods_class_id, goods_name, cycle_num_flag, service_num, goods_introduction, sales_price, mininum_price, subscription_flag, subscription, goods_detail, recommend_flag, goods_nurses, goods_tags from t_goods
    </sql>
 
    <select id="selectGoodsList" parameterType="Goods" resultMap="GoodsResult">
        <include refid="selectGoodsVo"/>
        <where>
            <if test="goodsStatus != null "> and goods_status = #{goodsStatus}</if>
            <if test="goodsType != null "> and goods_type = #{goodsType}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
            <if test="goodsClassId != null "> and goods_class_id = #{goodsClassId}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="cycleNumFlag != null "> and cycle_num_flag = #{cycleNumFlag}</if>
            <if test="serviceNum != null "> and service_num = #{serviceNum}</if>
            <if test="goodsIntroduction != null  and goodsIntroduction != ''"> and goods_introduction = #{goodsIntroduction}</if>
            <if test="salesPrice != null "> and sales_price = #{salesPrice}</if>
            <if test="mininumPrice != null "> and mininum_price = #{mininumPrice}</if>
            <if test="subscriptionFlag != null "> and subscription_flag = #{subscriptionFlag}</if>
            <if test="subscription != null "> and subscription = #{subscription}</if>
            <if test="goodsDetail != null  and goodsDetail != ''"> and goods_detail = #{goodsDetail}</if>
            <if test="recommendFlag != null "> and recommend_flag = #{recommendFlag}</if>
            <if test="goodsNurses != null  and goodsNurses != ''"> and goods_nurses = #{goodsNurses}</if>
            <if test="goodsTags != null  and goodsTags != ''"> and goods_tags = #{goodsTags}</if>
        </where>
    </select>
 
    <select id="selectGoodsByGoodsId" parameterType="String" resultMap="GoodsResult">
        <include refid="selectGoodsVo"/>
        where goods_id = #{goodsId}
    </select>
 
    <insert id="insertGoods" parameterType="Goods">
        insert into t_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="goodsId != null">goods_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="goodsStatus != null">goods_status,</if>
            <if test="goodsType != null">goods_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="goodsClassId != null">goods_class_id,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="cycleNumFlag != null">cycle_num_flag,</if>
            <if test="serviceNum != null">service_num,</if>
            <if test="goodsIntroduction != null">goods_introduction,</if>
            <if test="salesPrice != null">sales_price,</if>
            <if test="mininumPrice != null">mininum_price,</if>
            <if test="subscriptionFlag != null">subscription_flag,</if>
            <if test="subscription != null">subscription,</if>
            <if test="goodsDetail != null">goods_detail,</if>
            <if test="recommendFlag != null">recommend_flag,</if>
            <if test="goodsNurses != null">goods_nurses,</if>
            <if test="goodsTags != null">goods_tags,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="goodsId != null">#{goodsId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="goodsStatus != null">#{goodsStatus},</if>
            <if test="goodsType != null">#{goodsType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="goodsClassId != null">#{goodsClassId},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="cycleNumFlag != null">#{cycleNumFlag},</if>
            <if test="serviceNum != null">#{serviceNum},</if>
            <if test="goodsIntroduction != null">#{goodsIntroduction},</if>
            <if test="salesPrice != null">#{salesPrice},</if>
            <if test="mininumPrice != null">#{mininumPrice},</if>
            <if test="subscriptionFlag != null">#{subscriptionFlag},</if>
            <if test="subscription != null">#{subscription},</if>
            <if test="goodsDetail != null">#{goodsDetail},</if>
            <if test="recommendFlag != null">#{recommendFlag},</if>
            <if test="goodsNurses != null">#{goodsNurses},</if>
            <if test="goodsTags != null">#{goodsTags},</if>
        </trim>
    </insert>
 
    <update id="updateGoods" parameterType="Goods">
        update t_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="goodsStatus != null">goods_status = #{goodsStatus},</if>
            <if test="goodsType != null">goods_type = #{goodsType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="goodsClassId != null">goods_class_id = #{goodsClassId},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="cycleNumFlag != null">cycle_num_flag = #{cycleNumFlag},</if>
            <if test="serviceNum != null">service_num = #{serviceNum},</if>
            <if test="goodsIntroduction != null">goods_introduction = #{goodsIntroduction},</if>
            <if test="salesPrice != null">sales_price = #{salesPrice},</if>
            <if test="mininumPrice != null">mininum_price = #{mininumPrice},</if>
            <if test="subscriptionFlag != null">subscription_flag = #{subscriptionFlag},</if>
            <if test="subscription != null">subscription = #{subscription},</if>
            <if test="goodsDetail != null">goods_detail = #{goodsDetail},</if>
            <if test="recommendFlag != null">recommend_flag = #{recommendFlag},</if>
            <if test="goodsNurses != null">goods_nurses = #{goodsNurses},</if>
            <if test="goodsTags != null">goods_tags = #{goodsTags},</if>
        </trim>
        where goods_id = #{goodsId}
    </update>
 
    <delete id="deleteGoodsByGoodsId" parameterType="String">
        delete from t_goods where goods_id = #{goodsId}
    </delete>
 
    <delete id="deleteGoodsByGoodsIds" parameterType="String">
        delete from t_goods where goods_id in
        <foreach item="goodsId" collection="array" open="(" separator="," close=")">
            #{goodsId}
        </foreach>
    </delete>
 
    <!--分页获取推荐商品-->
    <select id="pageRecommendGoods" resultType="com.ruoyi.order.domain.vo.AppSimpleGoodsVo">
        SELECT
        tg.goods_id goodsId,
        tg.goods_name goodsName,
        tg.goods_introduction goodsIntroduction,
        tg.goods_type goodsType,
        CASE tg.goods_type
        WHEN 1 THEN "周期"
        WHEN 2 THEN "服务"
        WHEN 3 THEN "体验"
        WHEN 4 THEN "单品"
        END goodsTag,
        IFNULL(tsg.sales_price,tg.sales_price) salesPrice,
        tgf.file_url goodsPicture,
        tg.goods_nurses goodsNurses
        FROM t_goods tg
        LEFT JOIN t_goods_file tgf ON tg.goods_id = tgf.goods_id AND tgf.del_flag = 0 AND tgf.file_type = 1
        LEFT JOIN t_shop_goods tsg ON tg.goods_id = tsg.goods_id AND tsg.shop_id = #{shopId}
        WHERE tg.del_flag = 0 AND tg.goods_status = 1 AND tg.recommend_flag = 1
        ORDER BY tg.create_time DESC
    </select>
 
    <!--分页获取商城商品列表-->
    <select id="pageShopGoods" resultType="com.ruoyi.order.domain.vo.AppSimpleGoodsVo">
        SELECT
        tg.goods_id goodsId,
        tg.goods_name goodsName,
        tg.goods_introduction goodsIntroduction,
        tg.goods_type goodsType,
        CASE tg.goods_type
        WHEN 1 THEN "周期"
        WHEN 2 THEN "服务"
        WHEN 3 THEN "体验"
        WHEN 4 THEN "单品"
        END goodsTag,
        IFNULL(tsg.sales_price,tg.sales_price) salesPrice,
        tgf.file_url goodsPicture,
        tg.goods_nurses goodsNurses
        FROM t_goods tg
        INNER JOIN t_goods_total tgt ON tg.goods_id = tgt.goods_id
        LEFT JOIN t_goods_file tgf ON tg.goods_id = tgf.goods_id AND tgf.del_flag = 0 AND tgf.file_type = 1
        LEFT JOIN t_shop_goods tsg ON tg.goods_id = tsg.goods_id AND tsg.shop_id = #{param.shopId}
        WHERE tg.del_flag = 0 AND tg.goods_status = 1
        <if test="param.goodsType!=null and param.goodsType != ''">
            AND tg.goods_type = #{param.goodsType}
        </if>
        <if test="param.goodsClassId!=null and param.goodsClassId != ''">
            AND tg.goods_class_id = #{param.goodsClassId}
        </if>
        <if test="param.keyword!=null and param.keyword != ''">
            AND tg.goods_name LIKE CONCAT('%',#{param.keyword},'%')
        </if>
        ORDER BY
        <if test="param.sort != null and param.sort != ''">
            <choose>
                <when test="param.sort==1">
                    salesPrice DESC,tg.create_time DESC
                </when>
                <when test="param.sort==2">
                    salesPrice ASC,tg.create_time DESC
                </when>
                <when test="param.sort==3">
                    tgt.buy_num_count ASC,tg.create_time DESC
                </when>
                <when test="param.sort==4">
                    tgt.buy_num_count DESC,tg.create_time DESC
                </when>
                <when test="param.sort==5">
                    tg.create_time DESC
                </when>
                <otherwise>
                    tg.create_time DESC
                </otherwise>
            </choose>
        </if>
    </select>
 
    <!--分页获取搜索商品列表-->
    <select id="pageSearchGoods" resultType="com.ruoyi.order.domain.vo.AppSimpleGoodsVo">
        SELECT
        tg.goods_id goodsId,
        tg.goods_name goodsName,
        tg.goods_introduction goodsIntroduction,
        tg.goods_type goodsType,
        CASE tg.goods_type
        WHEN 1 THEN "周期"
        WHEN 2 THEN "服务"
        WHEN 3 THEN "体验"
        WHEN 4 THEN "单品"
        END goodsTag,
        IFNULL(tsg.sales_price,tg.sales_price) salesPrice,
        tgf.file_url goodsPicture,
        tg.goods_tags goodsNurses
        FROM t_goods tg
        LEFT JOIN t_goods_file tgf ON tg.goods_id = tgf.goods_id AND tgf.del_flag = 0 AND tgf.file_type = 1
        LEFT JOIN t_shop_goods tsg ON tg.goods_id = tsg.goods_id AND tsg.shop_id = #{param.shopId}
        WHERE tg.del_flag = 0 AND tg.goods_status = 1
        <if test="param.keyword!=null and param.keyword != ''">
            AND tg.goods_name LIKE CONCAT('%',#{param.keyword},'%')
        </if>
        ORDER BY tg.create_time DESC
    </select>
 
    <!--分页获取搜索活动商品列表-->
    <select id="pageSearchActivityGoods" resultType="com.ruoyi.order.domain.vo.AppSimpleActivityGoodsVo">
        SELECT
        tg.goods_id goodsId,
        tg.goods_name goodsName,
        tg.goods_introduction goodsIntroduction,
        tg.goods_type goodsType,
        CASE tg.goods_type
        WHEN 1 THEN "周期"
        WHEN 2 THEN "服务"
        WHEN 3 THEN "体验"
        WHEN 4 THEN "单品"
        END goodsTag,
        GREATEST(tg.sales_price,IFNULL(tsg.sales_price,'0.00')) salesPrice,
        tag.activity_price activityPrice,
        tgf.file_url goodsPicture,
        tg.goods_tags goodsNurses,
        tag.activity_number activityNumber,
        tag.sales_number salesNumber
        FROM t_goods tg
        INNER JOIN t_activity_goods tag ON tg.goods_id = tag.goods_id
        LEFT JOIN t_goods_file tgf ON tg.goods_id = tgf.goods_id AND tgf.del_flag = 0 AND tgf.file_type = 1
        LEFT JOIN t_shop_goods tsg ON tg.goods_id = tsg.goods_id AND tsg.shop_id = #{param.shopId}
        WHERE tg.del_flag = 0 AND tg.goods_status = 1
        <if test="param.keyword!=null and param.keyword != ''">
            AND tg.goods_name LIKE CONCAT('%',#{param.keyword},'%')
        </if>
        ORDER BY tg.create_time DESC
    </select>
 
    <select id="pageMerShopGoods" resultType="com.ruoyi.order.domain.vo.MerGoodsPageVo">
        SELECT
        tg.goods_id goodsId,
        tg.goods_name goodsName,
        tg.goods_introduction goodsIntroduction,
        tg.goods_type goodsType,
        CASE tg.goods_type
        WHEN 1 THEN "周期"
        WHEN 2 THEN "服务"
        WHEN 3 THEN "体验"
        WHEN 4 THEN "单品"
        END goodsTag,
        IFNULL(tsg.sales_price,tg.sales_price) salesPrice,
        tg.sales_price suggestSalesPrice,
        tgf.file_url goodsPicture,
        tg.goods_nurses goodsNurses,
        tg.cycle_num_flag cycleNumFlag,
        tg.service_num defaultServiceNum,
        IFNULL(tsg.service_num,tg.service_num) serviceNum
        FROM t_goods tg
        LEFT JOIN t_goods_file tgf ON tg.goods_id = tgf.goods_id AND tgf.del_flag = 0 AND tgf.file_type = 1
        LEFT JOIN t_shop_goods tsg ON tg.goods_id = tsg.goods_id AND tsg.shop_id = #{param.shopId}
        WHERE tg.del_flag = 0 AND tg.goods_status = 1
        <if test="param.goodsType != null">
            AND tg.goods_type = #{param.goodsType}
        </if>
        <if test="param.goodsName != null and param.goodsName != ''">
            AND tg.goods_name LIKE CONCAT('%',#{param.goodsName},'%')
        </if>
        ORDER BY tg.create_time DESC
    </select>
</mapper>