<?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.system.mapper.GoodsCartMapper">
    
    <resultMap type="GoodsCart" id="GoodsCartResult">
        <result property="id"    column="id"    />
        <result property="uid"    column="uid"    />
        <result property="goodId"    column="good_id"    />
        <result property="goodNum"    column="good_num"    />
        <result property="sku"    column="sku"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectGoodsCartVo">
        select id, uid, good_id, good_num, sku, created_at, updated_at from goods_cart
    </sql>

    <select id="selectGoodsCartList" parameterType="GoodsCart" resultMap="GoodsCartResult">
        <include refid="selectGoodsCartVo"/>
        <where>  
            <if test="uid != null "> and uid = #{uid}</if>
            <if test="goodId != null "> and good_id = #{goodId}</if>
            <if test="goodNum != null "> and good_num = #{goodNum}</if>
            <if test="sku != null  and sku != ''"> and sku = #{sku}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectGoodsCartById" parameterType="Integer" resultMap="GoodsCartResult">
        <include refid="selectGoodsCartVo"/>
        where id = #{id}
    </select>

    <insert id="insertGoodsCart" parameterType="GoodsCart" useGeneratedKeys="true" keyProperty="id">
        insert into goods_cart
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="goodId != null">good_id,</if>
            <if test="goodNum != null">good_num,</if>
            <if test="sku != null">sku,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="goodId != null">#{goodId},</if>
            <if test="goodNum != null">#{goodNum},</if>
            <if test="sku != null">#{sku},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateGoodsCart" parameterType="GoodsCart">
        update goods_cart
        <trim prefix="SET" suffixOverrides=",">
            <if test="uid != null">uid = #{uid},</if>
            <if test="goodId != null">good_id = #{goodId},</if>
            <if test="goodNum != null">good_num = #{goodNum},</if>
            <if test="sku != null">sku = #{sku},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGoodsCartById" parameterType="Integer">
        delete from goods_cart where id = #{id}
    </delete>

    <delete id="deleteGoodsCartByIds" parameterType="String">
        delete from goods_cart where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>