<?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.web.modules.stock.mapper.BizStockAdjustMapper">

    <insert id="insert" parameterType="com.ruoyi.web.modules.stock.domain.BizStockAdjust" useGeneratedKeys="true" keyProperty="adjustId">
        insert into biz_stock_adjust (
            shop_id, goods_id, sku_id, goods_name, spec_text,
            adjust_mode, adjust_type, adjust_qty, stock_before, stock_after,
            operator_id, operator_name, create_time
        ) values (
            #{shopId}, #{goodsId}, #{skuId}, #{goodsName}, #{specText},
            #{adjustMode}, #{adjustType}, #{adjustQty}, #{stockBefore}, #{stockAfter},
            #{operatorId}, #{operatorName}, #{createTime}
        )
    </insert>

    <select id="selectByGoodsId" resultType="com.ruoyi.web.modules.stock.vo.StockAdjustRecordRowVO">
        select adjust_id as adjustId,
               adjust_type as adjustType,
               stock_before as stockBefore,
               stock_after as stockAfter,
               operator_name as operatorName,
               create_time as createTime
        from biz_stock_adjust
        where shop_id = #{shopId}
          and goods_id = #{goodsId}
        <if test="adjustType != null and adjustType != ''">
            and adjust_type = #{adjustType}
        </if>
        order by create_time desc, adjust_id desc
    </select>

</mapper>
