<?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.mk.store.MkStorePromTypeDao">

    <resultMap type="com.kmall.admin.entity.mk.store.MkStorePromTypeEntity" id="mkStorePromTypeMap">
        <result property="promTypeId" column="prom_type_id"/>
        <result property="title" column="title"/>
        <result property="promTypeName" column="prom_type_name"/>
        <result property="picUrl" column="pic_url"/>
        <result property="isValid" column="is_valid"/>
        <result property="note" column="note"/>
        <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.mk.store.MkStorePromTypeEntity">
		select
			`prom_type_id`,
			`title`,
			`prom_type_name`,
			`pic_url`,
			`is_valid`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`
		from mk_store_prom_type
		where prom_type_id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.mk.store.MkStorePromTypeEntity">
		select
    		`prom_type_id`,
    		`title`,
    		`prom_type_name`,
    		`pic_url`,
    		`is_valid`,
    		`note`,
    		`creater_sn`,
    		`create_time`,
    		`moder_sn`,
    		`mod_time`,
    		`tstm`
		from mk_store_prom_type
		WHERE 1=1
		<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 prom_type_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from mk_store_prom_type
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.mk.store.MkStorePromTypeEntity" useGeneratedKeys="true" keyProperty="promTypeId">
		insert into mk_store_prom_type(
			`title`,
			`prom_type_name`,
			`pic_url`,
			`is_valid`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`)
		values(
			#{title},
			#{promTypeName},
			#{picUrl},
			#{isValid},
			#{note},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.mk.store.MkStorePromTypeEntity">
		update mk_store_prom_type 
		<set>
			<if test="title != null">`title` = #{title}, </if>
			<if test="promTypeName != null">`prom_type_name` = #{promTypeName}, </if>
			<if test="picUrl != null">`pic_url` = #{picUrl}, </if>
			<if test="isValid != null">`is_valid` = #{isValid}, </if>
			<if test="note != null">`note` = #{note}, </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 prom_type_id = #{promTypeId}
	</update>
	
	<delete id="delete">
		delete from mk_store_prom_type where prom_type_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mk_store_prom_type where prom_type_id in 
		<foreach item="promTypeId" collection="array" open="(" separator="," close=")">
			#{promTypeId}
		</foreach>
	</delete>

</mapper>