<?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.kmall.api.dao.ApiBrandMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.kmall.api.entity.BrandVo" id="brandMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="list_pic_url" column="list_pic_url"/>
        <result property="simple_desc" column="simple_desc"/>
        <result property="pic_url" column="pic_url"/>
        <result property="sort_order" column="sort_order"/>
        <result property="is_show" column="is_show"/>
        <result property="floor_price" column="floor_price"/>
        <result property="app_list_pic_url" column="app_list_pic_url"/>
        <result property="is_new" column="is_new"/>
        <result property="new_pic_url" column="new_pic_url"/>
        <result property="new_sort_order" column="new_sort_order"/>
    </resultMap>

    <select id="queryObject" resultMap="brandMap">
		select * from mall_brand where id = #{value}
	</select>

    <select id="queryList" resultMap="brandMap">
        select
        <if test="fields != null and fields != ''">
            ${fields}
        </if>
        <if test="fields == null or fields == ''">
            *
        </if>
        from mall_brand
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
		select count(*) from mall_brand
	</select>

    <insert id="save" parameterType="com.kmall.api.entity.BrandVo" useGeneratedKeys="true" keyProperty="id">
		insert into mall_brand
		(
			`name`, 
			`list_pic_url`, 
			`simple_desc`, 
			`pic_url`, 
			`sort_order`, 
			`is_show`, 
			`floor_price`, 
			`app_list_pic_url`, 
			`is_new`, 
			`new_pic_url`, 
			`new_sort_order`
		)
		values
		(
			#{name}, 
			#{list_pic_url}, 
			#{simple_desc}, 
			#{pic_url}, 
			#{sort_order}, 
			#{is_show}, 
			#{floor_price}, 
			#{app_list_pic_url}, 
			#{is_new}, 
			#{new_pic_url}, 
			#{new_sort_order}
		)
	</insert>

    <update id="update" parameterType="com.kmall.api.entity.BrandVo">
        update mall_brand
        <set>
            <if test="name != null">`name` = #{name},</if>
            <if test="list_pic_url != null">`list_pic_url` = #{list_pic_url},</if>
            <if test="simple_desc != null">`simple_desc` = #{simple_desc},</if>
            <if test="pic_url != null">`pic_url` = #{pic_url},</if>
            <if test="sort_order != null">`sort_order` = #{sort_order},</if>
            <if test="is_show != null">`is_show` = #{is_show},</if>
            <if test="floor_price != null">`floor_price` = #{floor_price},</if>
            <if test="app_list_pic_url != null">`app_list_pic_url` = #{app_list_pic_url},</if>
            <if test="is_new != null">`is_new` = #{is_new},</if>
            <if test="new_pic_url != null">`new_pic_url` = #{new_pic_url},</if>
            <if test="new_sort_order != null">`new_sort_order` = #{new_sort_order}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
		delete from mall_brand where id = #{value}
	</delete>

    <delete id="deleteBatch">
        delete from mall_brand where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>