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

    <resultMap type="JobApply" id="JobApplyResult">
        <result property="id"    column="id"    />
        <result property="jobId"    column="job_id"    />
        <result property="userId"    column="user_id"    />
        <result property="matchingDegree"    column="matching_degree"    />
        <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"    />
    </resultMap>

    <sql id="selectJobApplyVo">
        select id, job_id, user_id, matching_degree, del_flag, create_by, create_time, update_by, update_time, remark from job_apply
    </sql>

    <select id="selectJobApplyList" parameterType="JobApply" resultMap="JobApplyResult">
        <include refid="selectJobApplyVo"/>
        <where>  del_flag = '0'
            <if test="jobId != null "> and job_id = #{jobId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="matchingDegree != null "> and matching_degree = #{matchingDegree}</if>
        </where>
    </select>
    <select id="applyJob" resultType="com.ruoyi.cms.domain.Job">
        SELECT ja.create_time AS applyTime, j.*
        FROM job j
                 INNER JOIN job_apply ja ON j.job_id = ja.job_id
        WHERE j.del_flag = '0'
          AND j.is_publish = 1
          AND ja.del_flag = '0'
          AND ja.user_id = #{userId}
        ORDER BY ja.create_time DESC
    </select>
    <select id="candidates" resultType="com.ruoyi.cms.domain.vo.CandidateVO">
        SELECT au.*,jc.create_time as apply_date,jc.matching_degree,jc.id as applyId
        from job_apply as jc
                 inner join app_user as au on jc.user_id = au.user_id
        where jc.job_id = #{jobId} and jc.del_flag = '0' and au.del_flag ='0'
    </select>

    <select id="trendChart" resultType="java.util.HashMap" parameterType="JobApply">
        select a.job_title as name,count(b.job_id) sl from job a left join job_apply b
            on a.job_id=b.job_id where a.del_flag='0' and b.del_flag='0'
         <if test="jobId!=null and jobId!=''">
             and a.job_id=#{jobId}
         </if>
          group by a.job_title
    </select>

    <sql id="selectAppUserVo">
        select user_id, name, age, sex, birth_date, education, political_affiliation, phone, avatar, salary_min, salary_max, area, status, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, remark,job_title_id,is_recommend,id_card,hire from app_user
    </sql>

    <select id="selectAppUserList" parameterType="com.ruoyi.cms.domain.Job" resultType="com.ruoyi.cms.domain.vo.CandidateVO">
        select b.job_title jobName,l.name companyName,e.* from job_apply a
                INNER join job b on a.job_id=b.job_id and b.del_flag='0'
                INNER join app_user e on a.user_id =e.user_id and e.del_flag='0'
                INNER join company l on b.company_id =l.company_id and l.del_flag='0'
        where a.del_flag='0' and a.hire='0'
        <if test="jobTitle != null  and jobTitle != ''"> and b.job_title like concat('%', cast(#{jobTitle, jdbcType=VARCHAR} as varchar), '%')</if>
        <if test="education != null  and education != ''"> and b.education = #{education}</if>
        <if test="experience != null  and experience != ''"> and b.experience = #{experience}</if>
        <if test="companyName != null  and companyName != ''"> and b.company_name like concat('%', cast(#{companyName, jdbcType=VARCHAR} as varchar), '%')</if>
        <if test="jobLocation != null  and jobLocation != ''"> and b.job_location = #{jobLocation}</if>
        <if test="postingDate != null and postingDate!=''"> and b.posting_date = #{postingDate}</if>
        <if test="vacancies != null "> and b.vacancies = #{vacancies}</if>
        <if test="latitude != null "> and b.latitude = #{latitude}</if>
        <if test="longitude != null "> and b.longitude = #{longitude}</if>
        <if test="view != null "> and b."view" = #{view}</if>
        <if test="companyId != null "> and b.company_id = #{companyId}</if>
        <if test="isHot != null "> and b.is_hot = #{isHot}</if>
        <if test="applyNum != null "> and b.apply_num = #{applyNum}</if>
        <if test="code != null "> and b.company_id in(select company_id from company where code=#{code})</if>
        <if test="compensation!=null ">
            <if test="compensation==0 ">
                and b.min_salary &lt; 1750
            </if>
            <if test="compensation==1 ">
                and b.max_salary &lt; 2000 and b.min_salary &gt;= 1750
            </if>
            <if test="compensation==2 ">
                and b.max_salary &lt; 3000 and b.min_salary &gt;= 2000
            </if>
            <if test="compensation==3 ">
                and b.max_salary &lt; 4000 and b.min_salary &gt;= 3000
            </if>
            <if test="compensation==4 ">
                and b.max_salary &lt; 5000 and b.min_salary &gt;= 4000
            </if>
            <if test="compensation==5 ">
                and b.min_salary &gt; 5000
            </if>
        </if>
    </select>

</mapper>