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

    <select id="queryObject" resultType="com.platform.entity.RecommendEntity">
		select * from nideshop_recommend where id = #{id} and deleted = 0
	</select>

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

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

    <select id="queryTotal" resultType="int">
		select count(*) from nideshop_recommend
		WHERE 1=1 and deleted = 0
        <if test="title != null and title.trim() != ''">
            AND name LIKE concat('%',#{title},'%')
        </if>
	</select>

    <insert id="save" parameterType="com.platform.entity.RecommendEntity" useGeneratedKeys="true" keyProperty="id">
		insert into nideshop_recommend(
			`title`,
			`image`,
			`order_num`,
			`connect_id`,
			`type`,
			`create_time`,
			`update_time`,
			`create_user_id`,
			`deleted`,
            `update_user_id`)
		values(
			#{title},
			#{image},
			#{orderNum},
			#{connectId},
			#{type},
			now(),
            now(),
			#{createUserId},
            0,
            #{updateUserId}
        )
	</insert>

    <update id="update" parameterType="com.platform.entity.RecommendEntity">
        update nideshop_recommend
        <set>
            <if test="title != null">`title` = #{title},</if>
            <if test="image != null">`image` = #{image},</if>
            <if test="orderNum != null">`order_num` = #{orderNum},</if>
            <if test="connectId != null">`connect_id` = #{connectId},</if>
            <if test="type != null">`type` = #{type},</if>
            update_time = now(),update_user_id = #{updateUserId}
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
		update nideshop_recommend set deleted = 1 where id = #{value}
	</delete>

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

</mapper>