<?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.dgtly.system.mapper.SysRidingLanternMapper">
    
    <resultMap type="SysRidingLantern" id="SysRidingLanternResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="content"    column="content"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="userType"    column="user_type"    />
        <result property="tile"    column="tile"    />
    </resultMap>

    <sql id="selectSysRidingLanternVo">
        select id, create_by, create_time, update_by, update_time, is_delete, content, start_time, end_time, user_type, tile from sys_riding_lantern
    </sql>

    <select id="selectSysRidingLanternList" parameterType="SysRidingLantern" resultMap="SysRidingLanternResult">
        <include refid="selectSysRidingLanternVo"/>
        <where>  
            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
            <if test="content != null  and content != ''"> and content like concat('%', #{content}, '%') </if>
            <if test="startTime != null "> and start_time &gt;= #{startTime}</if>
            <if test="endTime != null "> and end_time &lt; #{endTime}</if>
            <if test="userType != null  and userType != ''"> and user_type like concat('%', #{userType}, '%') </if>
            <if test="tile != null  and tile != ''"> and tile = #{tile}</if>
        </where>
    </select>
    
    <select id="selectSysRidingLanternById" parameterType="Long" resultMap="SysRidingLanternResult">
        <include refid="selectSysRidingLanternVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSysRidingLantern" parameterType="SysRidingLantern">
        insert into sys_riding_lantern
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="isDelete != null ">is_delete,</if>
            <if test="content != null  and content != ''">content,</if>
            <if test="startTime != null ">start_time,</if>
            <if test="endTime != null ">end_time,</if>
            <if test="userType != null  and userType != ''">user_type,</if>
            <if test="tile != null  and tile != ''">tile,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="isDelete != null ">#{isDelete},</if>
            <if test="content != null  and content != ''">#{content},</if>
            <if test="startTime != null ">#{startTime},</if>
            <if test="endTime != null ">#{endTime},</if>
            <if test="userType != null  and userType != ''">#{userType},</if>
            <if test="tile != null  and tile != ''">#{tile},</if>
         </trim>
    </insert>

    <update id="updateSysRidingLantern" parameterType="SysRidingLantern">
        update sys_riding_lantern
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="isDelete != null ">is_delete = #{isDelete},</if>
            <if test="content != null  and content != ''">content = #{content},</if>
            <if test="startTime != null ">start_time = #{startTime},</if>
            <if test="endTime != null ">end_time = #{endTime},</if>
            <if test="userType != null  and userType != ''">user_type = #{userType},</if>
            <if test="tile != null  and tile != ''">tile = #{tile},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysRidingLanternById" parameterType="Long">
        delete from sys_riding_lantern where id = #{id}
    </delete>

    <delete id="deleteSysRidingLanternByIds" parameterType="String">
        delete from sys_riding_lantern where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectLanternList"  resultMap="SysRidingLanternResult">
        <include refid="selectSysRidingLanternVo"/>
        where is_delete = 0
        and  (SELECT CURDATE()) &lt;= end_time
        and end_time is  not  null
    </select>
</mapper>