<?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.ruoyi.system.mapper.task.TkCommonYinhuanMapper">

    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.task.TkCommonYinhuan">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="title" column="title" jdbcType="VARCHAR"/>
            <result property="happenTime" column="happen_time" jdbcType="TIMESTAMP"/>
            <result property="address" column="address" jdbcType="VARCHAR"/>
            <result property="description" column="description" jdbcType="VARCHAR"/>
            <result property="depId" column="dep_id" jdbcType="BIGINT"/>
            <result property="dangerFlag" column="danger_flag" jdbcType="VARCHAR"/>
            <result property="creator" column="creator" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        <!--@sql select-->
        id,title,happen_time,
        address,description,dep_id,
        danger_flag,creator,create_time,
        update_time
        <!--@sql from tk_common_yinhuan-->
    </sql>

    <select id="page" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"/>
        from tk_common_yinhuan t1
        <where>
            <if test="param.dangerFlag != null and param.dangerFlag != ''">
                and danger_flag = #{param.dangerFlag}
            </if>
            <if test="param.title != null and param.title != ''">
                and title like concat('%',#{param.title},'%')
            </if>
            <if test="param.bindId != null and param.bindId != ''">
                and exists(
                    select id from tk_common_yinhuan_bind t2
                    where t1.id = t2.yinhuan_id and t2.bind_id = #{param.bindId} and t2.bind_type = #{param.bindType}
                )
            </if>
        </where>
        order by happen_time desc
    </select>
</mapper>
