<?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.vetti.hotake.mapper.HotakeRolesApplyInfoMapper">
    
    <resultMap type="HotakeRolesApplyInfo" id="HotakeRolesApplyInfoResult">
        <result property="id"    column="id"    />
        <result property="candidateId"    column="candidate_id"    />
        <result property="recruiterId" column="recruiter_id" />
        <result property="roleId"    column="role_id"    />
        <result property="fullName"    column="full_name"    />
        <result property="email"    column="email"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="cvFile"    column="cv_file"    />
        <result property="cvFileSuffix" column="cv_file_suffix" />
        <result property="fileSizeShow" column="file_size_show" />
        <result property="coverLetter"    column="cover_letter"    />
        <result property="candidateStatus"    column="candidate_status"    />
        <result property="stage"    column="stage"    />
        <result property="lastContact"    column="last_contact"    />
        <result property="cvTemplateJson"    column="cv_template_json"    />
        <result property="cvScore"    column="cv_score"    />
        <result property="cvMd5"    column="cv_md5"    />
        <result property="experience"    column="experience"    />
        <result property="aiMatchScore"    column="ai_match_score"    />
        <result property="aiMatchScorePercentage"    column="ai_match_score_percentage"    />
        <result property="status" column="status" />

        <result property="aiCvScoringRankingJson" column="ai_cv_scoring_ranking_json" />
        <result property="aiCvScore" column="ai_cv_score" />
        <result property="candidateCompatibilityJson" column="candidate_compatibility_json" />
        <result property="candidateCompatibilityScore" column="candidate_compatibility_score" />

        <result property="evaluationJson" column="evaluation_json" />
        <result property="evaluationScore" column="evaluation_score" />


        <result property="aiInterviewAnalysisJson" column="ai_interview_analysis_json" />
        <result property="aiInterviewAnalysisQaJson" column="ai_interview_analysis_qa_json" />


        <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="selectHotakeRolesApplyInfoVo">
        select id, candidate_id,recruiter_id, role_id, full_name, email, phone_number, cv_file, cv_file_suffix,file_size_show,
               cover_letter, candidate_status, stage, last_contact, cv_template_json, cv_score, cv_md5, experience, ai_match_score,
               ai_match_score_percentage,status, ai_cv_scoring_ranking_json,ai_cv_score,candidate_compatibility_json,
               candidate_compatibility_score,evaluation_json,evaluation_score,ai_interview_analysis_json,ai_interview_analysis_qa_json,
               del_flag, create_by, create_time, update_by, update_time, remark from hotake_roles_apply_info
    </sql>

    <select id="selectHotakeRolesApplyInfoList" parameterType="HotakeRolesApplyInfo" resultMap="HotakeRolesApplyInfoResult">
        <include refid="selectHotakeRolesApplyInfoVo"/>
        <where>  
            <if test="candidateId != null "> and candidate_id = #{candidateId}</if>
            <if test="recruiterId != null "> and recruiter_id = #{recruiterId}</if>
            <if test="roleId != null "> and role_id = #{roleId}</if>
            <if test="fullName != null  and fullName != ''"> and full_name like concat('%', #{fullName}, '%')</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="cvFile != null  and cvFile != ''"> and cv_file = #{cvFile}</if>
            <if test="cvFileSuffix != null  and cvFileSuffix != ''"> and cv_file_suffix = #{cvFileSuffix}</if>

            <if test="coverLetter != null  and coverLetter != ''"> and cover_letter = #{coverLetter}</if>
            <if test="candidateStatus != null  and candidateStatus != ''"> and candidate_status = #{candidateStatus}</if>
            <if test="stage != null  and stage != ''"> and stage = #{stage}</if>
            <if test="lastContact != null  and lastContact != ''"> and last_contact = #{lastContact}</if>
            <if test="cvTemplateJson != null  and cvTemplateJson != ''"> and cv_template_json = #{cvTemplateJson}</if>
            <if test="cvScore != null  and cvScore != ''"> and cv_score = #{cvScore}</if>
            <if test="cvMd5 != null  and cvMd5 != ''"> and cv_md5 = #{cvMd5}</if>
            <if test="experience != null  and experience != ''"> and experience = #{experience}</if>
            <if test="aiMatchScore != null  and aiMatchScore != ''"> and ai_match_score = #{aiMatchScore}</if>
            <if test="aiMatchScorePercentage != null "> and ai_match_score_percentage = #{aiMatchScorePercentage}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectHotakeRolesApplyInfoRankingList" parameterType="HotakeRolesApplyInfo" resultMap="HotakeRolesApplyInfoResult">
        <include refid="selectHotakeRolesApplyInfoVo"/>
        <where>
            <if test="candidateId != null "> and candidate_id = #{candidateId}</if>
            <if test="recruiterId != null "> and recruiter_id = #{recruiterId}</if>
            <if test="roleId != null "> and role_id = #{roleId}</if>
            <if test="fullName != null  and fullName != ''"> and full_name like concat('%', #{fullName}, '%')</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="cvFile != null  and cvFile != ''"> and cv_file = #{cvFile}</if>
            <if test="cvFileSuffix != null  and cvFileSuffix != ''"> and cv_file_suffix = #{cvFileSuffix}</if>

            <if test="coverLetter != null  and coverLetter != ''"> and cover_letter = #{coverLetter}</if>
            <if test="candidateStatus != null  and candidateStatus != ''"> and candidate_status = #{candidateStatus}</if>
            <if test="stage != null  and stage != ''"> and stage = #{stage}</if>
            <if test="lastContact != null  and lastContact != ''"> and last_contact = #{lastContact}</if>
            <if test="cvTemplateJson != null  and cvTemplateJson != ''"> and cv_template_json = #{cvTemplateJson}</if>
            <if test="cvScore != null  and cvScore != ''"> and cv_score = #{cvScore}</if>
            <if test="cvMd5 != null  and cvMd5 != ''"> and cv_md5 = #{cvMd5}</if>
            <if test="experience != null  and experience != ''"> and experience = #{experience}</if>
            <if test="aiMatchScore != null  and aiMatchScore != ''"> and ai_match_score = #{aiMatchScore}</if>
            <if test="aiMatchScorePercentage != null "> and ai_match_score_percentage = #{aiMatchScorePercentage}</if>
            <if test="status != null "> and status = #{status}</if>

            <if test="applyRoleIdList != null ">
                and id in
                <foreach item="applyRoleId" collection="applyRoleIdList" open="(" separator="," close=")">
                    #{applyRoleId}
                </foreach>
            </if>

        </where>
        order by ai_cv_score DESC
    </select>

    <select id="selectHotakeRolesApplyInfoCompatibilityScoreList" parameterType="HotakeRolesApplyInfo" resultMap="HotakeRolesApplyInfoResult">
        <include refid="selectHotakeRolesApplyInfoVo"/>
        <where>
            <if test="candidateId != null "> and candidate_id = #{candidateId}</if>
            <if test="recruiterId != null "> and recruiter_id = #{recruiterId}</if>
            <if test="roleId != null "> and role_id = #{roleId}</if>
            <if test="fullName != null  and fullName != ''"> and full_name like concat('%', #{fullName}, '%')</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="cvFile != null  and cvFile != ''"> and cv_file = #{cvFile}</if>
            <if test="cvFileSuffix != null  and cvFileSuffix != ''"> and cv_file_suffix = #{cvFileSuffix}</if>

            <if test="coverLetter != null  and coverLetter != ''"> and cover_letter = #{coverLetter}</if>
            <if test="candidateStatus != null  and candidateStatus != ''"> and candidate_status = #{candidateStatus}</if>
            <if test="stage != null  and stage != ''"> and stage = #{stage}</if>
            <if test="lastContact != null  and lastContact != ''"> and last_contact = #{lastContact}</if>
            <if test="cvTemplateJson != null  and cvTemplateJson != ''"> and cv_template_json = #{cvTemplateJson}</if>
            <if test="cvScore != null  and cvScore != ''"> and cv_score = #{cvScore}</if>
            <if test="cvMd5 != null  and cvMd5 != ''"> and cv_md5 = #{cvMd5}</if>
            <if test="experience != null  and experience != ''"> and experience = #{experience}</if>
            <if test="aiMatchScore != null  and aiMatchScore != ''"> and ai_match_score = #{aiMatchScore}</if>
            <if test="aiMatchScorePercentage != null "> and ai_match_score_percentage = #{aiMatchScorePercentage}</if>
            <if test="status != null "> and status = #{status}</if>

            <if test="applyRoleIdList != null ">
                and id in
                <foreach item="applyRoleId" collection="applyRoleIdList" open="(" separator="," close=")">
                    #{applyRoleId}
                </foreach>
            </if>

        </where>
        order by candidate_compatibility_score DESC
    </select>


    <select id="selectHotakeRolesApplyInfoCompatibilityScoreOneList" parameterType="HotakeRolesApplyInfo" resultMap="HotakeRolesApplyInfoResult">
        <include refid="selectHotakeRolesApplyInfoVo"/>
        <where>
            <if test="candidateId != null "> and candidate_id = #{candidateId}</if>
            <if test="recruiterId != null "> and recruiter_id = #{recruiterId}</if>
            <if test="roleId != null "> and role_id = #{roleId}</if>
            <if test="fullName != null  and fullName != ''"> and full_name like concat('%', #{fullName}, '%')</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="cvFile != null  and cvFile != ''"> and cv_file = #{cvFile}</if>
            <if test="cvFileSuffix != null  and cvFileSuffix != ''"> and cv_file_suffix = #{cvFileSuffix}</if>

            <if test="coverLetter != null  and coverLetter != ''"> and cover_letter = #{coverLetter}</if>
            <if test="candidateStatus != null  and candidateStatus != ''"> and candidate_status = #{candidateStatus}</if>
            <if test="stage != null  and stage != ''"> and stage = #{stage}</if>
            <if test="lastContact != null  and lastContact != ''"> and last_contact = #{lastContact}</if>
            <if test="cvTemplateJson != null  and cvTemplateJson != ''"> and cv_template_json = #{cvTemplateJson}</if>
            <if test="cvScore != null  and cvScore != ''"> and cv_score = #{cvScore}</if>
            <if test="cvMd5 != null  and cvMd5 != ''"> and cv_md5 = #{cvMd5}</if>
            <if test="experience != null  and experience != ''"> and experience = #{experience}</if>
            <if test="aiMatchScore != null  and aiMatchScore != ''"> and ai_match_score = #{aiMatchScore}</if>
            <if test="aiMatchScorePercentage != null "> and ai_match_score_percentage = #{aiMatchScorePercentage}</if>
            <if test="status != null "> and status = #{status}</if>

            <if test="applyRoleIdList != null ">
                and id in
                <foreach item="applyRoleId" collection="applyRoleIdList" open="(" separator="," close=")">
                    #{applyRoleId}
                </foreach>
            </if>

        </where>
        order by evaluation_score DESC
    </select>
    
    <select id="selectHotakeRolesApplyInfoById" parameterType="Long" resultMap="HotakeRolesApplyInfoResult">
        <include refid="selectHotakeRolesApplyInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertHotakeRolesApplyInfo" parameterType="HotakeRolesApplyInfo" useGeneratedKeys="true" keyProperty="id">
        insert into hotake_roles_apply_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="candidateId != null">candidate_id,</if>
            <if test="recruiterId != null">recruiter_id,</if>
            <if test="roleId != null">role_id,</if>
            <if test="fullName != null">full_name,</if>
            <if test="email != null">email,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="cvFile != null">cv_file,</if>
            <if test="cvFileSuffix != null">cv_file_suffix,</if>
            <if test="fileSizeShow != null">file_size_show,</if>
            <if test="coverLetter != null">cover_letter,</if>
            <if test="candidateStatus != null">candidate_status,</if>
            <if test="stage != null">stage,</if>
            <if test="lastContact != null">last_contact,</if>
            <if test="cvTemplateJson != null">cv_template_json,</if>
            <if test="cvScore != null">cv_score,</if>
            <if test="cvMd5 != null">cv_md5,</if>
            <if test="experience != null">experience,</if>
            <if test="aiMatchScore != null">ai_match_score,</if>
            <if test="aiMatchScorePercentage != null">ai_match_score_percentage,</if>
            <if test="status != null">status,</if>

            <if test="aiCvScoringRankingJson != null">ai_cv_scoring_ranking_json,</if>
            <if test="aiCvScore != null">ai_cv_score,</if>
            <if test="candidateCompatibilityJson != null">candidate_compatibility_json,</if>
            <if test="candidateCompatibilityScore != null">candidate_compatibility_score,</if>

            <if test="evaluationJson != null">evaluation_json,</if>
            <if test="evaluationScore != null">evaluation_score,</if>

            <if test="aiInterviewAnalysisJson != null">ai_interview_analysis_json,</if>
            <if test="aiInterviewAnalysisQaJson != null">ai_interview_analysis_qa_json,</if>

            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="candidateId != null">#{candidateId},</if>
            <if test="recruiterId != null">#{recruiterId},</if>
            <if test="roleId != null">#{roleId},</if>
            <if test="fullName != null">#{fullName},</if>
            <if test="email != null">#{email},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="cvFile != null">#{cvFile},</if>
            <if test="cvFileSuffix != null">#{cvFileSuffix},</if>
            <if test="fileSizeShow != null">#{fileSizeShow},</if>
            <if test="coverLetter != null">#{coverLetter},</if>
            <if test="candidateStatus != null">#{candidateStatus},</if>
            <if test="stage != null">#{stage},</if>
            <if test="lastContact != null">#{lastContact},</if>
            <if test="cvTemplateJson != null">#{cvTemplateJson},</if>
            <if test="cvScore != null">#{cvScore},</if>
            <if test="cvMd5 != null">#{cvMd5},</if>
            <if test="experience != null">#{experience},</if>
            <if test="aiMatchScore != null">#{aiMatchScore},</if>
            <if test="aiMatchScorePercentage != null">#{aiMatchScorePercentage},</if>
            <if test="status != null">#{status},</if>

            <if test="aiCvScoringRankingJson != null">#{aiCvScoringRankingJson},</if>
            <if test="aiCvScore != null">#{aiCvScore},</if>
            <if test="candidateCompatibilityJson != null">#{candidateCompatibilityJson},</if>
            <if test="candidateCompatibilityScore != null">#{candidateCompatibilityScore},</if>

            <if test="evaluationJson != null">#{evaluationJson},</if>
            <if test="evaluationScore != null">#{evaluationScore},</if>

            <if test="aiInterviewAnalysisJson != null">#{aiInterviewAnalysisJson},</if>
            <if test="aiInterviewAnalysisQaJson != null">#{aiInterviewAnalysisQaJson},</if>

            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateHotakeRolesApplyInfo" parameterType="HotakeRolesApplyInfo">
        update hotake_roles_apply_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="candidateId != null">candidate_id = #{candidateId},</if>
            <if test="recruiterId != null">recruiter_id = #{recruiterId},</if>
            <if test="roleId != null">role_id = #{roleId},</if>
            <if test="fullName != null">full_name = #{fullName},</if>
            <if test="email != null">email = #{email},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="cvFile != null">cv_file = #{cvFile},</if>
            <if test="cvFileSuffix != null">cv_file_suffix = #{cvFileSuffix},</if>
            <if test="fileSizeShow != null">file_size_show = #{fileSizeShow},</if>
            <if test="coverLetter != null">cover_letter = #{coverLetter},</if>
            <if test="candidateStatus != null">candidate_status = #{candidateStatus},</if>
            <if test="stage != null">stage = #{stage},</if>
            <if test="lastContact != null">last_contact = #{lastContact},</if>
            <if test="cvTemplateJson != null">cv_template_json = #{cvTemplateJson},</if>
            <if test="cvScore != null">cv_score = #{cvScore},</if>
            <if test="cvMd5 != null">cv_md5 = #{cvMd5},</if>
            <if test="experience != null">experience = #{experience},</if>
            <if test="aiMatchScore != null">ai_match_score = #{aiMatchScore},</if>
            <if test="aiMatchScorePercentage != null">ai_match_score_percentage = #{aiMatchScorePercentage},</if>
            <if test="status != null">status = #{status},</if>

            <if test="aiCvScoringRankingJson != null">ai_cv_scoring_ranking_json = #{aiCvScoringRankingJson},</if>
            <if test="aiCvScore != null">ai_cv_score = #{aiCvScore},</if>
            <if test="candidateCompatibilityJson != null">candidate_compatibility_json = #{candidateCompatibilityJson},</if>
            <if test="candidateCompatibilityScore != null">candidate_compatibility_score = #{candidateCompatibilityScore},</if>

            <if test="evaluationJson != null">evaluation_json = #{evaluationJson},</if>
            <if test="evaluationScore != null">evaluation_score = #{evaluationScore},</if>

            <if test="aiInterviewAnalysisJson != null">ai_interview_analysis_json = #{aiInterviewAnalysisJson},</if>
            <if test="aiInterviewAnalysisQaJson != null">ai_interview_analysis_qa_json = #{aiInterviewAnalysisQaJson},</if>

            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteHotakeRolesApplyInfoById" parameterType="Long">
        delete from hotake_roles_apply_info where id = #{id}
    </delete>

    <delete id="deleteHotakeRolesApplyInfoByIds" parameterType="String">
        delete from hotake_roles_apply_info where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <insert id="batchInsertHotakeRolesApplyInfo">
        insert into hotake_roles_apply_info( id, candidate_id,recruiter_id, role_id, full_name, email, phone_number, cv_file, cover_letter,
                                            candidate_status, stage, last_contact, cv_template_json, cv_score, cv_md5, experience,
                                            ai_match_score, ai_match_score_percentage, del_flag, create_by, create_time, update_by, update_time, remark) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.candidateId},#{item.recruiterId}, #{item.roleId}, #{item.fullName}, #{item.email}, #{item.phoneNumber}, #{item.cvFile}, #{item.coverLetter}, #{item.candidateStatus}, #{item.stage}, #{item.lastContact}, #{item.cvTemplateJson}, #{item.cvScore}, #{item.cvMd5}, #{item.experience}, #{item.aiMatchScore}, #{item.aiMatchScorePercentage}, #{item.delFlag}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark})
        </foreach>
    </insert>

    <select id="selectByCandidateIdAndRoleId" resultMap="HotakeRolesApplyInfoResult">
        <include refid="selectHotakeRolesApplyInfoVo"/>
        where candidate_id = #{candidateId} and role_id = #{roleId}
        limit 1
    </select>
</mapper>