<?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="org.dromara.main.mapper.MainBackCandidateMapper">

    <select id="selectPostCandidatePage" resultType="org.dromara.main.domain.vo.MainPostCandidateVo">
        SELECT
            c.id,
            c.post_id AS postId,
            c.student_id AS studentId,
            s.name AS name,
            CASE s.gender
                WHEN '0' THEN '男'
                WHEN '1' THEN '女'
                ELSE '--'
            END AS gender,
            s.mobile AS phone,
            COALESCE(NULLIF(c.status, ''), 'pending') AS status,
            CASE COALESCE(NULLIF(c.status, ''), 'pending')
                WHEN 'adopted' THEN '录用'
                WHEN 'rejected' THEN '不录用'
                WHEN 'closed' THEN '学员已拒绝'
                ELSE '待回复'
            END AS statusText,
            CASE COALESCE(NULLIF(c.status, ''), 'pending')
                WHEN 'adopted' THEN 'success'
                WHEN 'rejected' THEN 'danger'
                WHEN 'closed' THEN 'danger'
                ELSE 'warning'
            END AS statusType,
            DATE_FORMAT(COALESCE(c.update_time, c.create_time), '%Y-%m-%d %H:%i:%s') AS evaluateTime,
            s.resume_file AS resumeFile,
            c.remark
        FROM main_back_candidate c
        LEFT JOIN main_student s ON c.student_id = s.id AND IFNULL(s.del_flag, '0') = '0'
        WHERE IFNULL(c.del_flag, '0') = '0'
          AND c.post_id = #{bo.postId}
        <if test="bo.keyword != null and bo.keyword != ''">
            AND (
                s.name LIKE CONCAT('%', #{bo.keyword}, '%')
                OR s.mobile LIKE CONCAT('%', #{bo.keyword}, '%')
            )
        </if>
        <if test="bo.status != null and bo.status != ''">
            AND COALESCE(NULLIF(c.status, ''), 'pending') = #{bo.status}
        </if>
        ORDER BY c.create_time DESC, c.id DESC
    </select>

</mapper>
