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

    <resultMap type="com.kmall.admin.entity.HelpTypeEntity" id="helpTypeMap">
        <result property="id" column="id"/>
        <result property="typeName" column="type_name"/>
        <result property="sort" column="sort"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.HelpTypeEntity">
		select
			`id`,
			`type_name`,
			`sort`
		from mall_help_type
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.HelpTypeEntity">
		select
    		`id`,
    		`type_name`,
    		`sort`
		from mall_help_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 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_help_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.HelpTypeEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mall_help_type(
			`type_name`,
			`sort`)
		values(
			#{typeName},
			#{sort})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.HelpTypeEntity">
		update mall_help_type
		<set>
			<if test="typeName != null">`type_name` = #{typeName}, </if>
			<if test="sort != null">`sort` = #{sort}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from mall_help_type where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mall_help_type where id in
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>