<?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.CompanyProductStockMapper">
    
    <resultMap type="CompanyProductStock" id="CompanyProductStockResult">
        <result property="id"    column="id"    />
        <result property="productId"    column="product_id"    />
        <result property="instockId"    column="instock_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="stock"    column="stock"    />
        <result property="sku"    column="sku"    />
        <result property="productNo"    column="product_no"    />
        <result property="storeCode"    column="store_code"    />
        <result property="enterTime"    column="enter_time"    />
        <result property="limitTime"    column="limit_time"    />
        <result property="storeAge"    column="store_age"    />
        <result property="costPrice"    column="cost_price"    />
        <result property="cretaeTime"    column="cretae_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"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectCompanyProductStockVo">
        select id, product_id, instock_id, company_id, stock, sku, product_no, store_code, enter_time, limit_time, store_age, cost_price, cretae_time, update_time, create_user_id, update_user_id, is_del, status from company_product_stock
    </sql>

    <select id="selectCompanyProductStockList" parameterType="CompanyProductStock" resultMap="CompanyProductStockResult">
        <include refid="selectCompanyProductStockVo"/>
        <where>  
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="instockId != null "> and instock_id = #{instockId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="stock != null "> and stock = #{stock}</if>
            <if test="sku != null  and sku != ''"> and sku = #{sku}</if>
            <if test="productNo != null  and productNo != ''"> and product_no = #{productNo}</if>
            <if test="storeCode != null  and storeCode != ''"> and store_code = #{storeCode}</if>
            <if test="enterTime != null "> and enter_time = #{enterTime}</if>
            <if test="limitTime != null "> and limit_time = #{limitTime}</if>
            <if test="storeAge != null "> and store_age = #{storeAge}</if>
            <if test="costPrice != null "> and cost_price = #{costPrice}</if>
            <if test="cretaeTime != null "> and cretae_time = #{cretaeTime}</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>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectCompanyProductStockById" parameterType="Long" resultMap="CompanyProductStockResult">
        <include refid="selectCompanyProductStockVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCompanyProductStock" parameterType="CompanyProductStock" useGeneratedKeys="true" keyProperty="id">
        insert into company_product_stock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productId != null">product_id,</if>
            <if test="instockId != null">instock_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="stock != null">stock,</if>
            <if test="sku != null">sku,</if>
            <if test="productNo != null">product_no,</if>
            <if test="storeCode != null">store_code,</if>
            <if test="enterTime != null">enter_time,</if>
            <if test="limitTime != null">limit_time,</if>
            <if test="storeAge != null">store_age,</if>
            <if test="costPrice != null">cost_price,</if>
            <if test="cretaeTime != null">cretae_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>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productId != null">#{productId},</if>
            <if test="instockId != null">#{instockId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="stock != null">#{stock},</if>
            <if test="sku != null">#{sku},</if>
            <if test="productNo != null">#{productNo},</if>
            <if test="storeCode != null">#{storeCode},</if>
            <if test="enterTime != null">#{enterTime},</if>
            <if test="limitTime != null">#{limitTime},</if>
            <if test="storeAge != null">#{storeAge},</if>
            <if test="costPrice != null">#{costPrice},</if>
            <if test="cretaeTime != null">#{cretaeTime},</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>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateCompanyProductStock" parameterType="CompanyProductStock">
        update company_product_stock
        <trim prefix="SET" suffixOverrides=",">
            <if test="productId != null">product_id = #{productId},</if>
            <if test="instockId != null">instock_id = #{instockId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="stock != null">stock = #{stock},</if>
            <if test="sku != null">sku = #{sku},</if>
            <if test="productNo != null">product_no = #{productNo},</if>
            <if test="storeCode != null">store_code = #{storeCode},</if>
            <if test="enterTime != null">enter_time = #{enterTime},</if>
            <if test="limitTime != null">limit_time = #{limitTime},</if>
            <if test="storeAge != null">store_age = #{storeAge},</if>
            <if test="costPrice != null">cost_price = #{costPrice},</if>
            <if test="cretaeTime != null">cretae_time = #{cretaeTime},</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>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanyProductStockById" parameterType="Long">
        delete from company_product_stock where id = #{id}
    </delete>

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