<?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.oms.mapper.OmsProductMapper">

    <resultMap type="OmsProduct" id="OmsProductResult">
        <result property="productId"    column="product_id"    />
        <result property="image"    column="image"    />
        <result property="sliderImage"    column="slider_image"    />
        <result property="productName"    column="product_name"    />
        <result property="productInfo"    column="product_info"    />
        <result property="barCode"    column="bar_code"    />
        <result property="cateId"    column="cate_id"    />
        <result property="price"    column="price"    />
        <result property="otPrice"    column="ot_price"    />
        <result property="cost"    column="cost"    />
        <result property="specType"    column="spec_type"    />
        <result property="unitName"    column="unit_name"    />
        <result property="sort"    column="sort"    />
        <result property="productType"    column="product_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="isAudit"    column="is_audit"    />
    </resultMap>

    <sql id="selectOmsProductVo">
        select product_id, image, slider_image, product_name, product_info, bar_code, cate_id, price, ot_price, cost, spec_type, unit_name, sort, product_type, create_time, update_time, is_del, is_audit from oms_product
    </sql>

    <select id="selectOmsProductList" parameterType="OmsProduct" resultMap="OmsProductResult">
        <include refid="selectOmsProductVo"/>
        <where>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="sliderImage != null  and sliderImage != ''"> and slider_image = #{sliderImage}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="productInfo != null  and productInfo != ''"> and product_info = #{productInfo}</if>
            <if test="barCode != null  and barCode != ''"> and bar_code = #{barCode}</if>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="otPrice != null "> and ot_price = #{otPrice}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="specType != null "> and spec_type = #{specType}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="productType != null "> and product_type = #{productType}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="isAudit != null "> and is_audit = #{isAudit}</if>
        </where>
    </select>

    <select id="selectOmsProductById" parameterType="Long" resultMap="OmsProductResult">
        <include refid="selectOmsProductVo"/>
        where product_id = #{productId}
    </select>

    <insert id="insertOmsProduct" parameterType="OmsProduct" useGeneratedKeys="true" keyProperty="productId">
        insert into oms_product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="image != null and image != ''">image,</if>
            <if test="sliderImage != null and sliderImage != ''">slider_image,</if>
            <if test="productName != null">product_name,</if>
            <if test="productInfo != null">product_info,</if>
            <if test="barCode != null">bar_code,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="price != null">price,</if>
            <if test="otPrice != null">ot_price,</if>
            <if test="cost != null">cost,</if>
            <if test="specType != null">spec_type,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="sort != null">sort,</if>
            <if test="productType != null">product_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="isAudit != null">is_audit,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="image != null and image != ''">#{image},</if>
            <if test="sliderImage != null and sliderImage != ''">#{sliderImage},</if>
            <if test="productName != null">#{productName},</if>
            <if test="productInfo != null">#{productInfo},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="price != null">#{price},</if>
            <if test="otPrice != null">#{otPrice},</if>
            <if test="cost != null">#{cost},</if>
            <if test="specType != null">#{specType},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="sort != null">#{sort},</if>
            <if test="productType != null">#{productType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="isAudit != null">#{isAudit},</if>
        </trim>
    </insert>

    <update id="updateOmsProduct" parameterType="OmsProduct">
        update oms_product
        <trim prefix="SET" suffixOverrides=",">
            <if test="image != null and image != ''">image = #{image},</if>
            <if test="sliderImage != null and sliderImage != ''">slider_image = #{sliderImage},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="productInfo != null">product_info = #{productInfo},</if>
            <if test="barCode != null">bar_code = #{barCode},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="price != null">price = #{price},</if>
            <if test="otPrice != null">ot_price = #{otPrice},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="specType != null">spec_type = #{specType},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="productType != null">product_type = #{productType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="isAudit != null">is_audit = #{isAudit},</if>
        </trim>
        where product_id = #{productId}
    </update>

    <delete id="deleteOmsProductById" parameterType="Long">
        delete from oms_product where product_id = #{productId}
    </delete>

    <delete id="deleteOmsProductByIds" parameterType="String">
        delete from oms_product where product_id in
        <foreach item="productId" collection="array" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </delete>

</mapper>