<?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="beilv.shopping.mapper.QmjsShoppingMallMapper">
    
    <resultMap type="QmjsShoppingMall" id="QmjsShoppingMallResult">
        <result property="id"    column="id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="goodsCode"    column="goods_code"    />
        <result property="goodsType"    column="goods_type"    />
        <result property="goodsImg"    column="goods_img"    />
        <result property="goodsDescribe"    column="goods_describe"    />
        <result property="goodsUnit"    column="goods_unit"    />
        <result property="goodsCurrentPrice"    column="goods_current_price"    />
        <result property="salePrice"    column="sale_price"    />
        <result property="suggestionPrice"    column="suggestion_price"    />
        <result property="goodsInventory"    column="goods_inventory"    />
        <result property="inventoryCost"    column="inventory_cost"    />
        <result property="goodsState"    column="goods_state"    />
    </resultMap>

    <sql id="selectQmjsShoppingMallVo">
        select id, goods_name, goods_code, goods_type, goods_img, goods_describe, goods_unit, goods_current_price, sale_price, suggestion_price, goods_inventory, inventory_cost, goods_state from qmjs_shopping_mall
    </sql>

    <select id="selectQmjsShoppingMallList" parameterType="QmjsShoppingMall" resultMap="QmjsShoppingMallResult">
        <include refid="selectQmjsShoppingMallVo"/>
        <where>  
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="goodsCode != null  and goodsCode != ''"> and goods_code = #{goodsCode}</if>
            <if test="goodsType != null  and goodsType != ''"> and goods_type = #{goodsType}</if>
            <if test="goodsImg != null  and goodsImg != ''"> and goods_img = #{goodsImg}</if>
            <if test="goodsDescribe != null  and goodsDescribe != ''"> and goods_describe = #{goodsDescribe}</if>
            <if test="goodsUnit != null  and goodsUnit != ''"> and goods_unit = #{goodsUnit}</if>
            <if test="goodsCurrentPrice != null  and goodsCurrentPrice != ''"> and goods_current_price = #{goodsCurrentPrice}</if>
            <if test="salePrice != null "> and sale_price = #{salePrice}</if>
            <if test="suggestionPrice != null "> and suggestion_price = #{suggestionPrice}</if>
            <if test="goodsInventory != null  and goodsInventory != ''"> and goods_inventory = #{goodsInventory}</if>
            <if test="inventoryCost != null "> and inventory_cost = #{inventoryCost}</if>
            <if test="goodsState != null  and goodsState != ''"> and goods_state = #{goodsState}</if>
        </where>
    </select>
    
    <select id="selectQmjsShoppingMallById" parameterType="Long" resultMap="QmjsShoppingMallResult">
        <include refid="selectQmjsShoppingMallVo"/>
        where id = #{id}
    </select>

    <insert id="insertQmjsShoppingMall" parameterType="QmjsShoppingMall" useGeneratedKeys="true" keyProperty="id">
        insert into qmjs_shopping_mall
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="goodsName != null">goods_name,</if>
            <if test="goodsCode != null">goods_code,</if>
            <if test="goodsType != null">goods_type,</if>
            <if test="goodsImg != null">goods_img,</if>
            <if test="goodsDescribe != null">goods_describe,</if>
            <if test="goodsUnit != null">goods_unit,</if>
            <if test="goodsCurrentPrice != null">goods_current_price,</if>
            <if test="salePrice != null">sale_price,</if>
            <if test="suggestionPrice != null">suggestion_price,</if>
            <if test="goodsInventory != null">goods_inventory,</if>
            <if test="inventoryCost != null">inventory_cost,</if>
            <if test="goodsState != null">goods_state,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="goodsName != null">#{goodsName},</if>
            <if test="goodsCode != null">#{goodsCode},</if>
            <if test="goodsType != null">#{goodsType},</if>
            <if test="goodsImg != null">#{goodsImg},</if>
            <if test="goodsDescribe != null">#{goodsDescribe},</if>
            <if test="goodsUnit != null">#{goodsUnit},</if>
            <if test="goodsCurrentPrice != null">#{goodsCurrentPrice},</if>
            <if test="salePrice != null">#{salePrice},</if>
            <if test="suggestionPrice != null">#{suggestionPrice},</if>
            <if test="goodsInventory != null">#{goodsInventory},</if>
            <if test="inventoryCost != null">#{inventoryCost},</if>
            <if test="goodsState != null">#{goodsState},</if>
         </trim>
    </insert>

    <update id="updateQmjsShoppingMall" parameterType="QmjsShoppingMall">
        update qmjs_shopping_mall
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="goodsCode != null">goods_code = #{goodsCode},</if>
            <if test="goodsType != null">goods_type = #{goodsType},</if>
            <if test="goodsImg != null">goods_img = #{goodsImg},</if>
            <if test="goodsDescribe != null">goods_describe = #{goodsDescribe},</if>
            <if test="goodsUnit != null">goods_unit = #{goodsUnit},</if>
            <if test="goodsCurrentPrice != null">goods_current_price = #{goodsCurrentPrice},</if>
            <if test="salePrice != null">sale_price = #{salePrice},</if>
            <if test="suggestionPrice != null">suggestion_price = #{suggestionPrice},</if>
            <if test="goodsInventory != null">goods_inventory = #{goodsInventory},</if>
            <if test="inventoryCost != null">inventory_cost = #{inventoryCost},</if>
            <if test="goodsState != null">goods_state = #{goodsState},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQmjsShoppingMallById" parameterType="Long">
        delete from qmjs_shopping_mall where id = #{id}
    </delete>

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

</mapper>