<?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.mall.mapper.SkuMapper">

    <resultMap type="Sku" id="SkuResult">
        <result property="id" column="id"/>
        <result property="productId" column="product_id"/>
        <result property="outSkuId" column="out_sku_id"/>
        <result property="price" column="price"/>
        <result property="pic" column="pic"/>
        <result property="spData" column="sp_data"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectSkuVo">
        select id, product_id, out_sku_id, price, pic, sp_data, create_by, create_time, update_by, update_time   from mall_sku
    </sql>
    <update id="updateStockById">
        update
            mall_sku
        set
            stock = stock - #{quantity},
            update_time = #{optDate}
        where id = #{skuId}
    </update>

    <select id="selectByEntity" parameterType="Sku" resultMap="SkuResult">
        <include refid="selectSkuVo"/>
        <where>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="outSkuId != null  and outSkuId != ''"> and out_sku_id = #{outSkuId}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="pic != null  and pic != ''"> and pic = #{pic}</if>
            <if test="spData != null  and spData != ''"> and sp_data = #{spData}</if>
        </where>
    </select>
</mapper>
