<?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">
<!--suppress MybatisPlusMapperXmlInspection -->
<mapper namespace="com.wzj.soopin.goods.mapper.SkuMapper">

    <update id="updateStockById">
        update
            pms_sku
        set
            stock = stock - #{quantity},
            update_time = #{optDate}
        where id = #{skuId}
    </update>

    <select id="getlist" resultType="com.wzj.soopin.goods.domain.vo.SkuVO">
        SELECT s.id,
               s.product_id,
               s.out_sku_id,
               s.price,
               s.pic,
               s.sp_data,
               s.stock,
               s.create_by,
               s.create_time,
               s.update_by,
               s.update_time,
               p.name AS productName
        FROM pms_sku s
                 LEFT JOIN
             pms_product p ON s.product_id = p.id
        where s.del_flag = '0' and p.del_flag = '0'
        <if test="query.productName != null and query.productName != ''">
            AND p.name LIKE CONCAT('%', #{query.productName}, '%')
        </if>
        <if test="query.productId != null">
            AND p.id = #{query.productId}
        </if>
        <if test="query.outSkuId != null and query.outSkuId != ''">
            AND s.out_sku_id LIKE CONCAT('%', #{query.outSkuId}, '%')
        </if>
        <if test="query.price != null">
            AND s.price = #{query.price}
        </if>
        <if test="query.pic != null and query.pic != ''">
            AND s.pic LIKE CONCAT('%', #{query.pic}, '%')
        </if>
        <if test="query.tenantId != null and query.tenantId != ''">
            AND s.tenant_id = #{query.tenantId}
        </if>
        ORDER BY s.create_time DESC
    </select>


    <select id="selectSkuByid" resultType="com.wzj.soopin.goods.domain.vo.SkuVO">
        SELECT
            s.*,
            p.name AS productName
        FROM
            pms_sku s
                LEFT JOIN
            pms_product p ON s.product_id = p.id
        WHERE
            s.id = #{id}
        and s.del_flag = '0'
    </select>

</mapper>
