<?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.sf.service.mapper.GoodsMessagesMapper">
    
    <resultMap type="GoodsMessages" id="GoodsMessagesResult">
        <result property="id"    column="id"    />
        <result property="goodsCode"    column="goods_code"    />
        <result property="stockId"    column="stock_id"    />
        <result property="reviewStatus"    column="review_status"    />
        <result property="productTitle"    column="product_title"    />
        <result property="productPicture"    column="product_picture"    />
        <result property="originalPrice"    column="original_price"    />
        <result property="productDesc"    column="product_desc"    />
        <result property="goodsType"    column="goods_type"    />
        <result property="goodsSpec"    column="goods_spec"    />
        <result property="orderNum"    column="order_num"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="created"    column="created"    />
        <result property="modified"    column="modified"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="goodsModel"    column="goods_model"    />
    </resultMap>

    <sql id="selectGoodsMessagesVo">
        select id, goods_code, stock_id, review_status, product_title, product_picture, original_price, product_desc, goods_type, goods_spec, order_num, is_delete, created, modified, create_time, update_time, goods_name, goods_model from GOODS_MESSAGES
    </sql>

    <select id="selectGoodsMessagesList" parameterType="GoodsMessages" resultMap="GoodsMessagesResult">
        <include refid="selectGoodsMessagesVo"/>
        <where>  
            <if test="goodsCode != null  and goodsCode != ''"> and goods_code = #{goodsCode}</if>
            <if test="reviewStatus != null "> and review_status = #{reviewStatus}</if>
            <if test="productTitle != null  and productTitle != ''"> and product_title like concat('%', #{productTitle}, '%')</if>
            <if test="params.beginOriginalPrice != null and params.beginOriginalPrice != '' and params.endOriginalPrice != null and params.endOriginalPrice != ''"> and original_price between #{params.beginOriginalPrice} and #{params.endOriginalPrice}</if>
            <if test="goodsType != null "> and goods_type = #{goodsType}</if>
            <if test="goodsSpec != null  and goodsSpec != ''"> and goods_spec = #{goodsSpec}</if>
            <if test="goodsModel != null  and goodsModel != ''"> and goods_model = #{goodsModel}</if>
        </where>
    </select>
    
    <select id="selectGoodsMessagesById" parameterType="Long" resultMap="GoodsMessagesResult">
        <include refid="selectGoodsMessagesVo"/>
        where id = #{id}
    </select>
    <select id="selectGoodsMessagesByCode"  parameterType="String" resultMap="GoodsMessagesResult">
        <include refid="selectGoodsMessagesVo"/>
        where goods_code = #{goodsCode}
    </select>

    <insert id="insertGoodsMessages" parameterType="GoodsMessages" useGeneratedKeys="true" keyProperty="id">
        insert into GOODS_MESSAGES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="goodsCode != null and goodsCode != ''">goods_code,</if>
            <if test="stockId != null">stock_id,</if>
            <if test="reviewStatus != null">review_status,</if>
            <if test="productTitle != null and productTitle != ''">product_title,</if>
            <if test="productPicture != null and productPicture != ''">product_picture,</if>
            <if test="originalPrice != null">original_price,</if>
            <if test="productDesc != null">product_desc,</if>
            <if test="goodsType != null">goods_type,</if>
            <if test="goodsSpec != null and goodsSpec != ''">goods_spec,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="created != null">created,</if>
            <if test="modified != null">modified,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="goodsName != null and goodsName != ''">goods_name,</if>
            <if test="goodsModel != null">goods_model,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="goodsCode != null and goodsCode != ''">#{goodsCode},</if>
            <if test="stockId != null">#{stockId},</if>
            <if test="reviewStatus != null">#{reviewStatus},</if>
            <if test="productTitle != null and productTitle != ''">#{productTitle},</if>
            <if test="productPicture != null and productPicture != ''">#{productPicture},</if>
            <if test="originalPrice != null">#{originalPrice},</if>
            <if test="productDesc != null">#{productDesc},</if>
            <if test="goodsType != null">#{goodsType},</if>
            <if test="goodsSpec != null and goodsSpec != ''">#{goodsSpec},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="created != null">#{created},</if>
            <if test="modified != null">#{modified},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="goodsName != null and goodsName != ''">#{goodsName},</if>
            <if test="goodsModel != null">#{goodsModel},</if>
         </trim>
    </insert>

    <update id="updateGoodsMessages" parameterType="GoodsMessages">
        update GOODS_MESSAGES
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsCode != null and goodsCode != ''">goods_code = #{goodsCode},</if>
            <if test="stockId != null">stock_id = #{stockId},</if>
            <if test="reviewStatus != null">review_status = #{reviewStatus},</if>
            <if test="productTitle != null and productTitle != ''">product_title = #{productTitle},</if>
            <if test="productPicture != null and productPicture != ''">product_picture = #{productPicture},</if>
            <if test="originalPrice != null">original_price = #{originalPrice},</if>
            <if test="productDesc != null">product_desc = #{productDesc},</if>
            <if test="goodsType != null">goods_type = #{goodsType},</if>
            <if test="goodsSpec != null and goodsSpec != ''">goods_spec = #{goodsSpec},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="created != null">created = #{created},</if>
            <if test="modified != null">modified = #{modified},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
            <if test="goodsModel != null">goods_model = #{goodsModel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGoodsMessagesById" parameterType="Long">
        delete from GOODS_MESSAGES where id = #{id}
    </delete>

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