<?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.MerchDao">

    <resultMap type="com.kmall.admin.entity.MerchEntity" id="merchMap">
        <result property="id" column="id"/>
        <result property="merchSn" column="merch_sn"/>
        <result property="merchName" column="merch_name"/>
        <result property="merchShortName" column="merch_short_name"/>
        <result property="merchImg" column="merch_img"/>
        <result property="sortOrder" column="sort_order"/>
		<result property="isShow" column="is_show"/>
        <result property="remark" column="remark"/>
        <result property="createrSn" column="creater_sn"/>
        <result property="createTime" column="create_time"/>
        <result property="moderSn" column="moder_sn"/>
        <result property="modTime" column="mod_time"/>
        <result property="tstm" column="tstm"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.MerchEntity">
		select
			`id`,
			`merch_sn`,
			`merch_name`,
			`merch_short_name`,
			`merch_img`,
			`sort_order`,
			`is_show`,
			`remark`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,
			`is_show` as `show`
		from mall_merch
		where id = #{id}
	</select>

	<select id="findByMerchSn" resultType="com.kmall.admin.entity.MerchEntity">
		select
			`id`,
			`merch_sn`,
			`merch_name`,
			`merch_short_name`,
			`merch_img`,
			`sort_order`,
			`is_show`,
			`remark`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,
			`is_show` as `show`
		from mall_merch
		where merch_sn = #{merchSn}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.MerchEntity">
		select
    		`id`,
    		`merch_sn`,
    		`merch_name`,
    		`merch_short_name`,
    		`merch_img`,
    		`sort_order`,
			`is_show`,
    		`remark`,
    		`creater_sn`,
    		`create_time`,
    		`moder_sn`,
    		`mod_time`,
    		`tstm`,
			`is_show` as `show`
		from mall_merch
		WHERE 1=1
		<if test="roleMerchSn != null and roleMerchSn.trim() != ''">
			AND merch_sn = #{roleMerchSn}
		</if>
		<if test="merchName != null and merchName.trim() != ''">
			AND merch_name LIKE concat('%',#{merchName},'%')
		</if>
		<if test="merchSn != null and merchSn.trim() != ''">
			AND merch_sn LIKE concat('%',#{merchSn},'%')
		</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_merch
		WHERE 1=1
		<if test="roleMerchSn != null and roleMerchSn.trim() != ''">
			AND merch_sn = #{roleMerchSn}
		</if>
		<if test="merchName != null and merchName.trim() != ''">
			AND merch_name LIKE concat('%',#{merchName},'%')
		</if>
		<if test="merchSn != null and merchSn.trim() != ''">
			AND merch_sn LIKE concat('%',#{merchSn},'%')
		</if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.MerchEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mall_merch(
			`merch_sn`,
			`merch_name`,
			`merch_short_name`,
			`merch_img`,
			`sort_order`,
			`is_show`,
			`remark`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`)
		values(
			#{merchSn},
			#{merchName},
			#{merchShortName},
			#{merchImg},
			#{sortOrder},
			#{isShow},
			#{remark},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.MerchEntity">
		update mall_merch 
		<set>
			<if test="merchSn != null">`merch_sn` = #{merchSn}, </if>
			<if test="merchName != null">`merch_name` = #{merchName}, </if>
			<if test="merchShortName != null">`merch_short_name` = #{merchShortName}, </if>
			<if test="merchImg != null">`merch_img` = #{merchImg}, </if>
			<if test="sortOrder != null">`sort_order` = #{sortOrder}, </if>
			<if test="isShow != null">`is_show` = #{isShow}, </if>
			<if test="remark != null">`remark` = #{remark}, </if>
			<if test="createrSn != null">`creater_sn` = #{createrSn}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
			<if test="modTime != null">`mod_time` = #{modTime}, </if>
			<if test="tstm != null">`tstm` = #{tstm}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from mall_merch where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mall_merch where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>