<?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.admin.dao.BrandDao">

    <resultMap type="com.kmall.admin.entity.BrandEntity" id="brandMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="storeId" column="store_id"/>
        <result property="merchSn" column="merch_sn"/>
        <result property="listPicUrl" column="list_pic_url"/>
        <result property="simpleDesc" column="simple_desc"/>
        <result property="picUrl" column="pic_url"/>
        <result property="sortOrder" column="sort_order"/>
        <result property="isShow" column="is_show"/>
        <result property="floorPrice" column="floor_price"/>
        <result property="appListPicUrl" column="app_list_pic_url"/>
        <result property="isNew" column="is_new"/>
        <result property="newPicUrl" column="new_pic_url"/>
        <result property="newSortOrder" column="new_sort_order"/>
    </resultMap>

    <select id="queryObject" resultType="com.kmall.admin.entity.BrandEntity">
		select
			`id`,
			`name`,
			`store_id`,
			`merch_sn`,
			`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`
		from mall_brand
		where id = #{id}
	</select>

    <select id="queryObjectByName" resultType="com.kmall.admin.entity.BrandEntity">
        select
        `id`,
        `name`,
        `store_id`,
		`merch_sn`,
        `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`
        from mall_brand
        where `name` = #{brandName}
        <if test="merchSn != null and merchSn.trim() != ''">
            AND merch_sn = #{merchSn}
        </if>
    </select>

    <select id="queryList" resultType="com.kmall.admin.entity.BrandEntity">
        select
        `id`,
        `name`,
        `store_id`,
        `merch_sn`,
        `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`
        from mall_brand
        WHERE 1=1
        <if test="storeId != null and storeId != ''">
            AND store_id = #{storeId}
        </if>
        <if test="merchSn != null and merchSn.trim() != ''">
            AND merch_sn = #{merchSn}
        </if>
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
        <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
        WHERE 1=1
        <if test="storeId != null and storeId != ''">
            AND store_id = #{storeId}
        </if>
        <if test="merchSn != null and merchSn.trim() != ''">
            AND merch_sn = #{merchSn}
        </if>
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
    </select>

    <insert id="save" parameterType="com.kmall.admin.entity.BrandEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mall_brand(
			`name`,
			`store_id`,
			`merch_sn`,
			`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},
			#{storeId},
			#{merchSn},
			#{listPicUrl},
			#{simpleDesc},
			#{picUrl},
			#{sortOrder},
			#{isShow},
			#{floorPrice},
			#{appListPicUrl},
			#{isNew},
			#{newPicUrl},
			#{newSortOrder})
	</insert>

    <update id="update" parameterType="com.kmall.admin.entity.BrandEntity">
        update mall_brand
        <set>
            <if test="name != null">`name` = #{name},</if>
            <if test="storeId != null">`store_id` = #{storeId}, </if>
            <if test="merchSn != null">`merch_sn` = #{merchSn}, </if>
            <if test="listPicUrl != null">`list_pic_url` = #{listPicUrl},</if>
            <if test="simpleDesc != null">`simple_desc` = #{simpleDesc},</if>
            <if test="picUrl != null">`pic_url` = #{picUrl},</if>
            <if test="sortOrder != null">`sort_order` = #{sortOrder},</if>
            <if test="isShow != null">`is_show` = #{isShow},</if>
            <if test="floorPrice != null">`floor_price` = #{floorPrice},</if>
            <if test="appListPicUrl != null">`app_list_pic_url` = #{appListPicUrl},</if>
            <if test="isNew != null">`is_new` = #{isNew},</if>
            <if test="newPicUrl != null">`new_pic_url` = #{newPicUrl},</if>
            <if test="newSortOrder != null">`new_sort_order` = #{newSortOrder}</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>