<?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.web.work.mapper.ResumeDeliverMapper">
    
    <select id="selectList" resultType="com.ruoyi.web.work.domain.ResumeDeliver">
        SELECT
        d.*,
        p.title,
        p.salary,
        p.region_name,
        p.address,
        p.location,
        p.longitude,
        p.latitude,
        p.start_date,
        p.end_date
        FROM
        tb_resume_deliver d
        LEFT JOIN tb_position p ON p.id = d.position_id
        <where>
            <if test="userId != null "> and d.user_id = #{userId}</if>
            <if test="enterpriseId != null "> and d.enterprise_id = #{enterpriseId}</if>
            <if test="positionId != null "> and d.position_id = #{positionId}</if>
            <if test="state != null "> and d.state = #{state}</if>
            <if test="type != null "> and d.type = #{type}</if>
            <if test="isAccept != null "> and d.is_accept = #{isAccept}</if>
            <if test="isRead != null "> and d.is_read = #{isRead}</if>
            <if test="isContract != null "> and d.is_contract = #{isContract}</if>
            <if test="isComplete != null "> and d.is_complete = #{isComplete}</if>
        </where>
        ORDER BY d.id DESC
    </select>

    <select id="check" resultType="com.ruoyi.web.work.domain.ResumeDeliver">
        SELECT * FROM tb_resume_deliver WHERE position_id=#{positionId} AND user_id=#{userId}
    </select>

    <select id="receive" resultType="com.ruoyi.web.work.domain.vo.ReceiveVo">
        SELECT
            p.id,
            p.title,
            p.salary,
            ( SELECT COUNT( d.id ) FROM tb_resume_deliver d WHERE d.position_id = p.id ) AS total,
            ( SELECT COUNT( d.id ) FROM tb_resume_deliver d WHERE d.position_id = p.id AND d.is_read = 1 ) AS isRead
        FROM
            tb_position p
        WHERE
            p.user_id =#{enterpriseId}
            AND p.type=#{type}
        GROUP BY
            p.id
        HAVING
            total > 0
        ORDER BY total DESC
    </select>

    <select id="receiveList" resultType="com.ruoyi.web.work.domain.vo.ReceiveListVo">
        SELECT
            r.name,
            r.avatar,
            r.sex,
            r.age,
            r.experience,
            d.*
        FROM
            tb_resume r
                LEFT JOIN tb_resume_deliver d ON d.user_id = r.id
        WHERE
            d.position_id =#{positionId}
            AND d.enterprise_id =#{enterpriseId}
            AND d.type=#{type}
        <if test="state != null "> and d.state = #{state}</if>
        <if test="isAccept != null "> and d.is_accept = #{isAccept}</if>
        <if test="isRead != null "> and d.is_read = #{isRead}</if>
        <if test="min != null and max !=null">AND r.age <![CDATA[ >= ]]> #{min} AND r.age <![CDATA[ <= ]]> #{max}</if>
        ORDER BY d.id DESC
    </select>

</mapper>