<?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.ApiRecommendMapper">
    <select id="queryObject" resultType="com.platform.entity.RecommendEntity">
		select * from nideshop_recommend where id = #{value}
	</select>

    <select id="queryList" resultType="com.platform.entity.RecommendEntity">
        select * from nideshop_recommend
        <where>
            deleted = 0
            <if test="title != null and title.trim() != ''">
                AND title LIKE concat('%',#{title},'%')
            </if>
            <if test="type != null">
                AND type = #{type}
            </if>
        </where>
        order by order_num asc ,create_time desc
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
		select count(*) from nideshop_recommend 
	</select>

    <insert id="save" parameterType="com.platform.entity.RecommendEntity" useGeneratedKeys="true" keyProperty="id">
		insert into nideshop_recommend
		(
			`ad_position_id`, 
			`media_type`, 
			`name`, 
			`link`, 
			`image_url`, 
			`content`, 
			`end_time`, 
			`enabled`
		)
		values
		(
			#{ad_position_id},
			#{media_type},
			#{name}, 
			#{link}, 
			#{image_url},
			#{content}, 
			#{end_time},
			#{enabled}
		)
	</insert>

    <update id="update" parameterType="com.platform.entity.RecommendEntity">
        update nideshop_recommend
        <set>
            <if test="ad_position_id != null">`ad_position_id` = #{adPositionId},</if>
            <if test="media_type != null">`media_type` = #{mediaType},</if>
            <if test="name != null">`name` = #{name},</if>
            <if test="link != null">`link` = #{link},</if>
            <if test="image_url != null">`image_url` = #{imageUrl},</if>
            <if test="content != null">`content` = #{content},</if>
            <if test="end_time != null">`end_time` = #{endTime},</if>
            <if test="enabled != null">`enabled` = #{enabled}</if>
        </set>
        where id = #{id}
    </update>

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

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

</mapper>