<?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.platform.dao.AdPositionDao">

    <resultMap type="com.platform.entity.AdPositionEntity" id="adPositionMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="width" column="width"/>
        <result property="height" column="height"/>
        <result property="desc" column="desc"/>
    </resultMap>

    <select id="queryObject" resultType="com.platform.entity.AdPositionEntity">
		select
			`id`,
			`name`,
			`width`,
			`height`,
			`desc`
		from nideshop_ad_position
		where id = #{id}
	</select>

    <select id="queryList" resultType="com.platform.entity.AdPositionEntity">
        select
        `id`,
        `name`,
        `width`,
        `height`,
        `desc`
        from nideshop_ad_position
        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 nideshop_ad_position
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>

    <insert id="save" parameterType="com.platform.entity.AdPositionEntity" useGeneratedKeys="true" keyProperty="id">
		insert into nideshop_ad_position(
			`name`,
			`width`,
			`height`,
			`desc`)
		values(
			#{name},
			#{width},
			#{height},
			#{desc})
	</insert>

    <update id="update" parameterType="com.platform.entity.AdPositionEntity">
        update nideshop_ad_position
        <set>
            <if test="name != null">`name` = #{name},</if>
            <if test="width != null">`width` = #{width},</if>
            <if test="height != null">`height` = #{height},</if>
            <if test="desc != null">`desc` = #{desc}</if>
        </set>
        where id = #{id}
    </update>

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

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

</mapper>