<?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.cms.mapper.JobFairMapper">
    
    <resultMap type="JobFair" id="JobFairResult">
        <result property="jobFairId"    column="job_fair_id"    />
        <result property="name"    column="name"    />
        <result property="jobFairType"    column="job_fair_type"    />
        <result property="location"    column="location"    />
        <result property="latitude"    column="latitude"    />
        <result property="longitude"    column="longitude"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="delFlag"    column="del_flag"    />
        <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="remark"    column="remark"    />
        <result property="description"    column="description"    />
        <result property="address"    column="address"    />
    </resultMap>

    <sql id="selectJobFairVo">
        select job_fair_id, name, job_fair_type, location, latitude, longitude, start_time, end_time, del_flag, create_by, create_time, update_by, update_time, remark,address,description from job_fair
    </sql>

    <select id="selectJobFairList" parameterType="JobFair" resultMap="JobFairResult">
        <include refid="selectJobFairVo"/>
        <where>  del_flag = '0'
            <if test="name != null  and name != ''"> and name like concat('%', cast(#{name, jdbcType=VARCHAR} as varchar), '%')</if>
            <if test="jobFairType != null  and jobFairType != ''"> and job_fair_type = #{jobFairType}</if>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
        </where>
    </select>
    <select id="appList" resultType="com.ruoyi.cms.domain.JobFair" parameterType="com.ruoyi.cms.domain.JobFair">
        <include refid="selectJobFairVo"/>
        <where>  del_flag = '0'
            <if test="jobFairType != null  and jobFairType != ''"> and job_fair_type = #{jobFairType}</if>
            <if test="queryDate != null "> and start_time &gt;= #{queryDate} and end_time &lt;= #{queryDate}</if>
        </where>
    </select>
    <select id="selectAppList" resultType="com.ruoyi.cms.domain.JobFair">
        select j.*
        from job_fair as j
        inner join fair_collection as f on f.fair_id = j.job_fair_id and f.USER_ID = #{userId}
        where j.DEL_FLAG = '0' and f.DEL_FLAG = '0'
        <if test="type!=null and type==1">
            -- 未开始
            and j.START_TIME &gt; now()
        </if>
        <if test="type!=null and type==2">
            -- 进行中
            and j.START_TIME &lt; NOW() AND  J.END_TIME &gt; NOW()
        </if>
        <if test="type!=null and type==3">
            -- 已结束
            and j.END_TIME &lt; now()
        </if>
        order by j.START_TIME desc
    </select>
</mapper>