<?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.fs.company.mapper.CompanyProductOutstockMapper">
    
    <resultMap type="CompanyProductOutstock" id="CompanyProductOutstockResult">
        <result property="id"    column="id"    />
        <result property="productId"    column="product_id"    />
        <result property="stockId"    column="stock_id"    />
        <result property="planId"    column="plan_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="batchNo"    column="batch_no"    />
        <result property="num"    column="num"    />
        <result property="stock"    column="stock"    />
        <result property="storeCode"    column="store_code"    />
        <result property="sku"    column="sku"    />
        <result property="costPrice"    column="cost_price"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectCompanyProductOutstockVo">
        select id, product_id, stock_id, plan_id, company_id, batch_no, num, stock, store_code, sku, cost_price, status, create_time, update_time, create_user_id, update_user_id, is_del from company_product_outstock
    </sql>

    <select id="selectCompanyProductOutstockList" parameterType="CompanyProductOutstock" resultMap="CompanyProductOutstockResult">
        <include refid="selectCompanyProductOutstockVo"/>
        <where>  
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="stockId != null "> and stock_id = #{stockId}</if>
            <if test="planId != null "> and plan_id = #{planId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="batchNo != null  and batchNo != ''"> and batch_no = #{batchNo}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="stock != null "> and stock = #{stock}</if>
            <if test="storeCode != null  and storeCode != ''"> and store_code = #{storeCode}</if>
            <if test="sku != null  and sku != ''"> and sku = #{sku}</if>
            <if test="costPrice != null "> and cost_price = #{costPrice}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectCompanyProductOutstockById" parameterType="Long" resultMap="CompanyProductOutstockResult">
        <include refid="selectCompanyProductOutstockVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCompanyProductOutstock" parameterType="CompanyProductOutstock" useGeneratedKeys="true" keyProperty="id">
        insert into company_product_outstock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productId != null">product_id,</if>
            <if test="stockId != null">stock_id,</if>
            <if test="planId != null">plan_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="batchNo != null">batch_no,</if>
            <if test="num != null">num,</if>
            <if test="stock != null">stock,</if>
            <if test="storeCode != null">store_code,</if>
            <if test="sku != null">sku,</if>
            <if test="costPrice != null">cost_price,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productId != null">#{productId},</if>
            <if test="stockId != null">#{stockId},</if>
            <if test="planId != null">#{planId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="batchNo != null">#{batchNo},</if>
            <if test="num != null">#{num},</if>
            <if test="stock != null">#{stock},</if>
            <if test="storeCode != null">#{storeCode},</if>
            <if test="sku != null">#{sku},</if>
            <if test="costPrice != null">#{costPrice},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateCompanyProductOutstock" parameterType="CompanyProductOutstock">
        update company_product_outstock
        <trim prefix="SET" suffixOverrides=",">
            <if test="productId != null">product_id = #{productId},</if>
            <if test="stockId != null">stock_id = #{stockId},</if>
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="batchNo != null">batch_no = #{batchNo},</if>
            <if test="num != null">num = #{num},</if>
            <if test="stock != null">stock = #{stock},</if>
            <if test="storeCode != null">store_code = #{storeCode},</if>
            <if test="sku != null">sku = #{sku},</if>
            <if test="costPrice != null">cost_price = #{costPrice},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanyProductOutstockById" parameterType="Long">
        delete from company_product_outstock where id = #{id}
    </delete>

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