ShopGoodsMapper.xml 5.29 KB
Newer Older
张新旗 committed
1 2 3 4
<?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">
5
<mapper namespace="com.soss.system.mapper.ShopGoodsMapper">
张新旗 committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
    
    <resultMap type="ShopGoods" id="ShopGoodsResult">
        <result property="id"    column="id"    />
        <result property="shopId"    column="shop_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="turn"    column="turn"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectShopGoodsVo">
        select id, shop_id, goods_id, turn, created_at, updated_at from shop_goods
    </sql>

    <select id="selectShopGoodsList" parameterType="ShopGoods" resultMap="ShopGoodsResult">
        <include refid="selectShopGoodsVo"/>
        <where>  
            <if test="shopId != null  and shopId != ''"> and shop_id = #{shopId}</if>
            <if test="goodsId != null  and goodsId != ''"> and goods_id = #{goodsId}</if>
            <if test="turn != null  and turn != ''"> and turn = #{turn}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
29
        order by turn
张新旗 committed
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
    </select>
    
    <select id="selectShopGoodsById" parameterType="String" resultMap="ShopGoodsResult">
        <include refid="selectShopGoodsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertShopGoods" parameterType="ShopGoods" useGeneratedKeys="true" keyProperty="id">
        insert into shop_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shopId != null and shopId != ''">shop_id,</if>
            <if test="goodsId != null and goodsId != ''">goods_id,</if>
            <if test="turn != null and turn != ''">turn,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shopId != null and shopId != ''">#{shopId},</if>
            <if test="goodsId != null and goodsId != ''">#{goodsId},</if>
            <if test="turn != null and turn != ''">#{turn},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateShopGoods" parameterType="ShopGoods">
        update shop_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="shopId != null and shopId != ''">shop_id = #{shopId},</if>
            <if test="goodsId != null and goodsId != ''">goods_id = #{goodsId},</if>
            <if test="turn != null and turn != ''">turn = #{turn},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteShopGoodsById" parameterType="String">
        delete from shop_goods where id = #{id}
    </delete>

    <delete id="deleteShopGoodsByIds" parameterType="String">
        delete from shop_goods where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
76
    <select id="selectShopCategoryGoods" resultType="com.soss.system.domain.Goods">
张新旗 committed
77 78 79 80
        select g.* from shop_goods sg ,goods g where sg.goods_id =g.id and g.state ='1' and g.is_deleted =0
        and shop_id =#{shopId}
        order by sg.turn
    </select>
81
    <select id="selectShopCategoryGoodsByCategoryId" resultType="com.soss.system.domain.Goods">
张新旗 committed
82 83 84 85 86 87 88 89 90 91 92
        select
        g.id,
        g.name,
        g.category,
        g.price,
        g.discount,
        g.take_time,
        g.spec,
        g.pics,
        g.`desc`,
        g.remarks,
93 94
        g.shelf_at as shelfAt,
        g.code,
95 96
        '1' as state,
        case when sr.id>0 then 1 else 0 end as isRecommend,
97
        sr.recommend_price,
98 99 100 101 102
        sr.recommend_tag
        from goods g
        LEFT JOIN shop_goods sg ON g.id = sg.goods_id
        LEFT JOIN shop_recommend sr ON g.id = sr.goods_id and sr.`type` = 2
        where g.state ='3' and g.is_deleted = 0 and sg.shop_id = #{shopId} and category like concat('%,', #{categoryId}, ',%')
.  
weijiguang committed
103
        order by isRecommend DESC,sg.turn
张新旗 committed
104
    </select>
105
    <select id="selectShopNoAddGoods" resultType="com.soss.system.domain.Goods">
张新旗 committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        select id, name, category, price, discount, take_time, spec, pics, `desc`, remarks, state, is_deleted, created_at, updated_at, code,shelf_at from goods
        where
        id not in (
        SELECT
        sg.goods_id
        from
        shop_goods sg
        where
        sg.shop_id = #{shopId})
        and state ='3'
        <if test="goodsName!=null and goodsName!=''">
            and name  like concat('%', #{goodsName}, '%')
        </if>
        <if test="category!=null and category!=''">
            and category  like concat('%', #{category}, '%')
        </if>
    </select>
张新旗 committed
123 124 125 126 127 128 129
    <delete id="deleteByShopIdGoods">
        delete from shop_goods where shop_id =#{shopId}
        and goods_id in
        <foreach collection="goodsIds" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
张新旗 committed
130

张新旗 committed
131 132

</mapper>