<?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.zhongzheng.modules.recruit.mapper.RecruitNeedsMapper">

    <resultMap type="com.zhongzheng.modules.recruit.domain.RecruitNeeds" id="RecruitNeedsResult">
        <result property="id" column="id"/>
        <result property="companyId" column="company_id"/>
        <result property="job" column="job"/>
        <result property="incomeStart" column="income_start"/>
        <result property="incomeEnd" column="income_end"/>
        <result property="duty" column="duty"/>
        <result property="requirement" column="requirement"/>
        <result property="welfare" column="welfare"/>
        <result property="jobKey" column="job_key"/>
        <result property="workingYearsDict" column="working_years_dict"/>
        <result property="workingYearsStart" column="working_years_start"/>
        <result property="workingYearsEnd" column="working_years_end"/>
        <result property="minimumEduDict" column="minimum_edu_dict"/>
        <result property="major" column="major"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="incomeType" column="income_type"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="district" column="district"/>
        <result property="address" column="address"/>
        <result property="peopleNum" column="people_num"/>
        <result property="jobNature" column="job_nature"/>
        <result property="bonusCertificate" column="bonus_certificate"/>
        <result property="isUrgent" column="is_urgent"/>
        <result property="minimumEduLabel" column="minimum_edu_label"/>
        <result property="workingYearsLabel" column="working_years_label"/>
        <result property="companyName" column="company_name"/>
        <result property="pushTime" column="push_time"/>
        <result property="linkMan" column="link_man"/>
        <result property="linkTel" column="link_tel"/>
        <result property="pushMan" column="push_man"/>
    </resultMap>

    <select id="queryRecruitNeedsList" parameterType="com.zhongzheng.modules.recruit.bo.RecruitNeedsQueryBo"  resultMap="RecruitNeedsResult">
        SELECT
        rn.*,
        dd.dict_label AS minimum_edu_label,
        dd1.dict_label AS working_years_label,
        vtc.company_name
        FROM
        recruit_needs rn
        LEFT JOIN sys_dict_data dd ON rn.minimum_edu_dict = dd.dict_code
        LEFT JOIN sys_dict_data dd1 ON rn.working_years_dict = dd1.dict_code
        LEFT JOIN v_tenant_company vtc ON rn.company_id = vtc.company_id
        WHERE
        1 = 1
        <if test="companyId != null" >
            AND rn.company_id = #{companyId}
        </if>
        <if test="city != null and city != ''">
            AND rn.city like concat('%', #{city}, '%')
        </if>
        <if test="job != null and job != ''">
            AND rn.job like concat('%', #{job}, '%')
        </if>
        <if test="jobNatures != null and jobNatures.size()!=0 ">
            AND
            <foreach collection="jobNatures" item="item"  separator="OR">
                rn.job_nature Like concat('%', #{item}, '%')
            </foreach>
        </if>
        <if test="companyName != null and companyName != ''">
            AND vtc.company_name like concat('%', #{companyName}, '%')
        </if>
        <if test="status != null and status.size()!=0 ">
            AND rn.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="minimumEduDictList != null and minimumEduDictList.size()!=0 ">
            AND rn.minimum_edu_dict in
            <foreach collection="minimumEduDictList" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="workingYearsDictList != null and workingYearsDictList.size()!=0 ">
            AND rn.working_years_dict in
            <foreach collection="workingYearsDictList" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="sizeIds != null and sizeIds.size()!=0 ">
            AND vtc.company_size_id in
            <foreach collection="sizeIds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="typeIds != null and typeIds.size()!=0 ">
            AND vtc.company_type_id in
            <foreach collection="typeIds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="pushTimeStart != null and pushTimeStart != ''">
            AND rn.push_time > #{pushTimeStart}
        </if>
        <if test="incomeListJson != null and incomeListJson.size!=0 ">
        AND
            <foreach collection="incomeListJson" item="item" separator="OR">
                ((
                #{item.incomeStart} BETWEEN rn.income_start AND rn.income_end
                OR #{item.incomeEnd} BETWEEN rn.income_start AND rn.income_end
                AND income_type = 1
                )
                OR ( #{item.incomeStart} * 12 BETWEEN rn.income_start AND rn.income_end
                OR #{item.incomeEnd} * 12 BETWEEN rn.income_start AND rn.income_end  AND income_type = 2 ) )
            </foreach>
        </if>
        <if test="pushTimeEnd != null and pushTimeEnd != ''">
            AND #{pushTimeEnd} > rn.push_time
        </if>
        ORDER BY
        rn.id DESC
    </select>

    <select id="queryRecruitNeedsListString" parameterType="com.zhongzheng.modules.recruit.bo.RecruitNeedsQueryBo"  resultMap="RecruitNeedsResult">
        SELECT
        rn.job,
        rn.id,
        rn.company_id
        FROM
        recruit_needs rn
        LEFT JOIN sys_dict_data dd ON rn.minimum_edu_dict = dd.dict_code
        LEFT JOIN sys_dict_data dd1 ON rn.working_years_dict = dd1.dict_code
        LEFT JOIN v_tenant_company vtc ON rn.company_id = vtc.company_id
        WHERE
        1 = 1
        <if test="companyId != null" >
            AND rn.company_id = #{companyId}
        </if>
        <if test="city != null and city != ''">
            AND rn.city like concat('%', #{city}, '%')
        </if>
        <if test="job != null and job != ''">
            AND rn.job like concat('%', #{job}, '%')
        </if>
        <if test="companyName != null and companyName != ''">
            AND vtc.company_name like concat('%', #{companyName}, '%')
        </if>
        <if test="status != null and status.size()!=0 ">
            AND rn.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="pushTimeStart != null and pushTimeStart != ''">
            AND rn.push_time > #{pushTimeStart}
        </if>
        <if test="pushTimeEnd != null and pushTimeEnd != ''">
            AND #{pushTimeEnd} > rn.push_time
        </if>
        ORDER BY
        rn.id DESC
    </select>

</mapper>
