package com.vetti.hotake.service.impl;

import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.json.JSONUtil;
import com.vetti.common.ai.gpt.ChatGPTClient;
import com.vetti.common.core.service.BaseServiceImpl;
import com.vetti.common.enums.CandidateStatusEnum;
import com.vetti.common.enums.FillTypeEnum;
import com.vetti.common.enums.MinioBucketNameEnum;
import com.vetti.common.enums.StageEnum;
import com.vetti.common.utils.DateUtils;
import com.vetti.common.utils.SecurityUtils;
import com.vetti.common.utils.readFile.FileContentUtil;
import com.vetti.hotake.domain.*;
import com.vetti.hotake.domain.dto.*;
import com.vetti.hotake.domain.dto.VcDto.*;
import com.vetti.hotake.domain.vo.*;
import com.vetti.hotake.mapper.HotakeCvInfoMapper;
import com.vetti.hotake.mapper.HotakeRolesApplyInfoMapper;
import com.vetti.hotake.mapper.HotakeRolesInfoMapper;
import com.vetti.hotake.service.IHotakeAiCommonToolsService;
import com.vetti.hotake.service.IHotakeRolesApplyOperRecordService;
import io.minio.GetObjectArgs;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vetti.hotake.mapper.HotakeInitScreQuestionsReplyRecordInfoMapper;
import com.vetti.hotake.service.IHotakeInitScreQuestionsReplyRecordInfoService;

/**
 * 初步筛选问题回答记录信息Service业务层处理
 *
 * @author wangxiangshun
 * @date 2025-12-14
 */
@Slf4j
@SuppressWarnings("all")
@Service
public class HotakeInitScreQuestionsReplyRecordInfoServiceImpl extends BaseServiceImpl implements IHotakeInitScreQuestionsReplyRecordInfoService {
    @Autowired
    private HotakeInitScreQuestionsReplyRecordInfoMapper hotakeInitScreQuestionsReplyRecordInfoMapper;

    @Autowired
    private HotakeRolesApplyInfoMapper hotakeRolesApplyInfoMapper;

    @Autowired
    private HotakeRolesInfoMapper hotakeRolesInfoMapper;

    @Autowired
    private HotakeCvInfoMapper hotakeCvInfoMapper;

    @Autowired
    private IHotakeAiCommonToolsService aiCommonToolsService;

    @Autowired
    private MinioClient minioClient;

    @Autowired
    private ChatGPTClient chatGPTClient;

    @Autowired
    private IHotakeRolesApplyOperRecordService rolesApplyOperRecordService;


    /**
     * 查询初步筛选问题回答记录信息
     *
     * @param id 初步筛选问题回答记录信息主键
     * @return 初步筛选问题回答记录信息
     */
    @Transactional(readOnly = true)
    @Override
    public HotakeInitScreQuestionsReplyRecordInfo selectHotakeInitScreQuestionsReplyRecordInfoById(Long id) {
        return hotakeInitScreQuestionsReplyRecordInfoMapper.selectHotakeInitScreQuestionsReplyRecordInfoById(id);
    }

    /**
     * 查询初步筛选问题回答记录信息列表
     *
     * @param hotakeInitScreQuestionsReplyRecordInfo 初步筛选问题回答记录信息
     * @return 初步筛选问题回答记录信息
     */
    @Transactional(readOnly = true)
    @Override
    public List<HotakeInitScreQuestionsReplyRecordInfo> selectHotakeInitScreQuestionsReplyRecordInfoList(HotakeInitScreQuestionsReplyRecordInfo hotakeInitScreQuestionsReplyRecordInfo) {
        return hotakeInitScreQuestionsReplyRecordInfoMapper.selectHotakeInitScreQuestionsReplyRecordInfoList(hotakeInitScreQuestionsReplyRecordInfo);
    }

    /**
     * 新增初步筛选问题回答记录信息
     *
     * @param hotakeInitScreQuestionsReplyRecordInfo 初步筛选问题回答记录信息
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertHotakeInitScreQuestionsReplyRecordInfo(HotakeInitScreQuestionsReplyRecordInfo hotakeInitScreQuestionsReplyRecordInfo) {
        hotakeInitScreQuestionsReplyRecordInfo.setCreateTime(DateUtils.getNowDate());
        return hotakeInitScreQuestionsReplyRecordInfoMapper.insertHotakeInitScreQuestionsReplyRecordInfo(hotakeInitScreQuestionsReplyRecordInfo);
    }

    /**
     * 修改初步筛选问题回答记录信息
     *
     * @param hotakeInitScreQuestionsReplyRecordInfo 初步筛选问题回答记录信息
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateHotakeInitScreQuestionsReplyRecordInfo(HotakeInitScreQuestionsReplyRecordInfo hotakeInitScreQuestionsReplyRecordInfo) {
        hotakeInitScreQuestionsReplyRecordInfo.setUpdateTime(DateUtils.getNowDate());
        return hotakeInitScreQuestionsReplyRecordInfoMapper.updateHotakeInitScreQuestionsReplyRecordInfo(hotakeInitScreQuestionsReplyRecordInfo);
    }

    /**
     * 批量删除初步筛选问题回答记录信息
     *
     * @param ids 需要删除的初步筛选问题回答记录信息主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteHotakeInitScreQuestionsReplyRecordInfoByIds(Long[] ids) {
        return hotakeInitScreQuestionsReplyRecordInfoMapper.deleteHotakeInitScreQuestionsReplyRecordInfoByIds(ids);
    }

    /**
     * 删除初步筛选问题回答记录信息信息
     *
     * @param id 初步筛选问题回答记录信息主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteHotakeInitScreQuestionsReplyRecordInfoById(Long id) {
        return hotakeInitScreQuestionsReplyRecordInfoMapper.deleteHotakeInitScreQuestionsReplyRecordInfoById(id);
    }

    /**
     * 批量新增初步筛选问题回答记录信息
     *
     * @param hotakeInitScreQuestionsReplyRecordInfoList 初步筛选问题回答记录信息列表
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int batchInsertHotakeInitScreQuestionsReplyRecordInfo(List<HotakeInitScreQuestionsReplyRecordInfo> hotakeInitScreQuestionsReplyRecordInfoList) {
        return hotakeInitScreQuestionsReplyRecordInfoMapper.batchInsertHotakeInitScreQuestionsReplyRecordInfo(hotakeInitScreQuestionsReplyRecordInfoList);
    }

    /**
     * 初步筛选问题回答记录信息批量保存
     *
     * @param initScreQuestionsReplyRecordInfoList 初步筛选问题回答记录信息数据集合
     * @return
     */
    @Override
    public int saveHotakeInitScreQuestionsReplyRecordInfo(HotakeInitScreQuestionsReplyRecordInfoVo initScreQuestionsReplyRecordInfoVo) {
        log.info("===:{}",JSONUtil.toJsonStr(initScreQuestionsReplyRecordInfoVo));
        //先删除对应问题答案记录数据
        hotakeInitScreQuestionsReplyRecordInfoMapper.deleteHotakeInitScreQuestionsReplyRecordInfoByRoleApplyId(initScreQuestionsReplyRecordInfoVo.getRoleApplyId());
        //批量保存数据
        if (CollectionUtil.isNotEmpty(initScreQuestionsReplyRecordInfoVo.getInitScreQuestionsReplyRecordInfoList())) {
            for (HotakeInitScreQuestionsReplyRecordInfo recordInfo : initScreQuestionsReplyRecordInfoVo.getInitScreQuestionsReplyRecordInfoList()) {
                recordInfo.setCandidateId(SecurityUtils.getUserId()).setRoleId(initScreQuestionsReplyRecordInfoVo.getRoleApplyId());
                recordInfo.setRoleApplyId(initScreQuestionsReplyRecordInfoVo.getRoleApplyId());
                fill(FillTypeEnum.INSERT.getCode(), recordInfo);
            }
            batchInsertHotakeInitScreQuestionsReplyRecordInfo(initScreQuestionsReplyRecordInfoVo.getInitScreQuestionsReplyRecordInfoList());
        }
        //获取申请的简历数据
        HotakeRolesApplyInfo applyInfo = hotakeRolesApplyInfoMapper.selectHotakeRolesApplyInfoById(initScreQuestionsReplyRecordInfoVo.getRoleApplyId());
        if (applyInfo != null) {
            HotakeRolesInfo rolesInf = hotakeRolesInfoMapper.selectHotakeRolesInfoById(initScreQuestionsReplyRecordInfoVo.getRoleId());
            //获取初步筛选问题评分
            HotakeInitialQuestionEliminationScoreVo eliminationScoreVo = new HotakeInitialQuestionEliminationScoreVo();
            eliminationScoreVo.setRoleId(rolesInf.getId());
            eliminationScoreVo.setRoleName(rolesInf.getRoleName());
            eliminationScoreVo.setInitScreQuestionsReplyRecordInfoList(initScreQuestionsReplyRecordInfoVo.getInitScreQuestionsReplyRecordInfoList());
            HotakeInitialQuestionEliminationScoreDto eliminationScoreDto = aiCommonToolsService.getInitialQuestionEliminationScore(eliminationScoreVo);

            try {
                applyInfo.setAiMatchScorePercentage(new BigDecimal(eliminationScoreDto.getScore()).
                        divide(new BigDecimal(100)).setScale(2, 4));
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (applyInfo.getAiMatchScorePercentage() != null) {
                if (applyInfo.getAiMatchScorePercentage().compareTo(new BigDecimal(0.85)) >= 0) {
                    applyInfo.setCandidateStatus(CandidateStatusEnum.HOT.getCode());
                } else if (applyInfo.getAiMatchScorePercentage().compareTo(new BigDecimal(0.85)) < 0
                        && applyInfo.getAiMatchScorePercentage().compareTo(new BigDecimal(0.6)) >= 0) {
                    applyInfo.setCandidateStatus(CandidateStatusEnum.WARM.getCode());
                } else if (applyInfo.getAiMatchScorePercentage().compareTo(new BigDecimal(0.6)) < 0
                        && applyInfo.getAiMatchScorePercentage().compareTo(new BigDecimal(0.3)) >= 0) {
                    applyInfo.setCandidateStatus(CandidateStatusEnum.COLD.getCode());
                } else {
                    applyInfo.setCandidateStatus(CandidateStatusEnum.PENDING.getCode());
                }
            }
            //解析简历数据
            //查询候选人的当前最新简历信息
            HotakeCvInfo queryCv = new HotakeCvInfo();
            queryCv.setUserId(SecurityUtils.getUserId());
            queryCv.setCvFileType("cv");
            List<HotakeCvInfo> cvInfos = hotakeCvInfoMapper.selectHotakeCvInfoList(queryCv);
            HotakeCvInfo cvInfo = null;
            if(CollectionUtil.isNotEmpty(cvInfos)) {
                cvInfo = cvInfos.get(0);
            }
            //解析简历内容以及获取简历对应的评分数据
            log.info("开始处理简历");
            try {
                InputStream inputStream = minioClient.getObject(
                        GetObjectArgs.builder()
                                .bucket(MinioBucketNameEnum.CV.getCode())
                                .object(applyInfo.getCvFile())
                                .build());
                String contents = FileContentUtil.readFileContent(inputStream, applyInfo.getCvFileSuffix());
                log.info("简历信息:{}", contents);
                //验证文件内容是否改变,如果未改变不进行模型解析直接返回原有结果
                String md5Hash = MD5.create().digestHex16(contents);
                String scoreStr = "";
                if (StrUtil.isNotEmpty(md5Hash) && cvInfo != null && md5Hash.equals(cvInfo.getCvMd5())) {
                    //直接获取简历表中的简历解析的详细数据
                    applyInfo.setCvScore(cvInfo.getCvScore());
                    applyInfo.setCvTemplateJson(cvInfo.getCvTemplateJson());
                    applyInfo.setCvMd5(md5Hash);
                    applyInfo.setExperience(cvInfo.getExperience());
                } else {
                    //生成简历模版数据信息
                    HotakeCvInfoDto cvInfoDto = handleAnalysisCvInfo(contents);
                    //生成对应的简历评分
                    applyInfo.setCvTemplateJson(JSONUtil.toJsonStr(cvInfoDto));
                    applyInfo.setCvMd5(md5Hash);
                    applyInfo.setExperience(cvInfoDto.getExperienceYear());
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
            //AI简历评分和排名系统-直接传到简历系统中
            HotakeAiCvScoringRankingRoleApplyVo roleApplyVo = new HotakeAiCvScoringRankingRoleApplyVo();
            roleApplyVo.setApplyInfo(applyInfo);
            roleApplyVo.setCvTemplateJson(applyInfo.getCvTemplateJson());
            HotakeAiCvScoringRankingDto scoringRankingDto = aiCommonToolsService.handleAiCvScoringRanking(roleApplyVo);

            applyInfo.setAiCvScoringRankingJson(JSONUtil.toJsonStr(scoringRankingDto));
            applyInfo.setAiCvScore(scoringRankingDto.getOverallScore());

            //招聘者查看候选人匹配度
//            HotakeCandidateCompatibilityVo compatibilityVo = new HotakeCandidateCompatibilityVo();
//            compatibilityVo.setPosition(rolesInf.getRoleName());
//            HotakeCvInfoDto cvInfoDto = JSONUtil.toBean(applyInfo.getCvTemplateJson(), HotakeCvInfoDto.class);
//            compatibilityVo.setCurrentPosition(cvInfoDto.getPosition());
//            compatibilityVo.setOverallRating(scoringRankingDto.getOverallScore().toString());
//            compatibilityVo.setWorkExperience(cvInfoDto.getExperienceYear());
//            List<String> skills = new ArrayList<>();
//            if(CollectionUtil.isNotEmpty(cvInfoDto.getSkillsTools())){
//                for (VcSkillsToolsDto toolsDto : cvInfoDto.getSkillsTools()){
//                    skills.add(toolsDto.getContent());
//                }
//            }
//            compatibilityVo.setSkills(skills);
//
//
//
//            HotakeCandidateCompatibilityDto compatibilityDto = aiCommonToolsService.handleCandidateCompatibility(compatibilityVo);
//            applyInfo.setCandidateCompatibilityJson(JSONUtil.toJsonStr(compatibilityDto));
//            applyInfo.setCandidateCompatibilityScore(compatibilityDto.getOverallScore());
            try{
                //候选人面试综合评估
                HotakeCandidateInterviewEvaluationVo evaluationVo = new HotakeCandidateInterviewEvaluationVo();

                evaluationVo.setTitle(rolesInf.getRoleName());
                evaluationVo.setDescription(rolesInf.getAboutRole());
                evaluationVo.setRequiredSkills(rolesInf.getRequiredSkillsJson());
                evaluationVo.setPreferredSkills(rolesInf.getNiceToHaveSkillsJson());
                evaluationVo.setExperienceRequired(rolesInf.getJobExperience());
                HotakeCvInfoDto cvInfoDto = JSONUtil.toBean(applyInfo.getCvTemplateJson(), HotakeCvInfoDto.class);
                evaluationVo.setName(cvInfoDto.getName());
                evaluationVo.setCurrentPosition(cvInfoDto.getPosition());
                evaluationVo.setEmail(cvInfoDto.getEmail());
                evaluationVo.setWorkExperience(JSONUtil.toJsonStr(cvInfoDto.getExperience()));
                evaluationVo.setSkills(JSONUtil.toJsonStr(cvInfoDto.getSkillsTools()));
                evaluationVo.setEducation(JSONUtil.toJsonStr(cvInfoDto.getEducation()));
                evaluationVo.setCertifications("");
                evaluationVo.setInterviewData("");
                evaluationVo.setQuestions("");
                evaluationVo.setAnswers("");
                evaluationVo.setTechnical("");
                evaluationVo.setCommunication("");
                evaluationVo.setSafetyAwareness("");
                evaluationVo.setProblemSolving("");

                HotakeCandidateInterviewEvaluationDto evaluationDto = aiCommonToolsService.getCandidateInterviewEvaluation(evaluationVo);
                applyInfo.setEvaluationJson(JSONUtil.toJsonStr(evaluationDto));
                applyInfo.setEvaluationScore(new BigDecimal(evaluationDto.getOverallScore()));
            }catch (Exception e){
                e.printStackTrace();
            }

            applyInfo.setRecruiterId(rolesInf.getRecruiterId());
            applyInfo.setStage(StageEnum.APPLIED.getCode());
            hotakeRolesApplyInfoMapper.updateHotakeRolesApplyInfo(applyInfo);

            //记录第一次申请记录
            HotakeRolesApplyOperRecord hotakeRolesApplyOperRecord = new HotakeRolesApplyOperRecord();
            hotakeRolesApplyOperRecord.setApplyStage(StageEnum.APPLIED.getCode());
            hotakeRolesApplyOperRecord.setRoleApplyId(applyInfo.getId());
            hotakeRolesApplyOperRecord.setRoleId(rolesInf.getId());
            rolesApplyOperRecordService.insertHotakeRolesApplyOperRecord(hotakeRolesApplyOperRecord);
        }
        return 0;
    }


    /**
     * 简历解析数据
     *
     * @param contents
     * @return
     */
    private HotakeCvInfoDto handleAnalysisCvInfo(String contents) {
        log.info("开始简历解析");
        try {
            List<Map<String, String>> list = new LinkedList();
            Map<String, String> entity = new HashMap<>();
            entity.put("role", "user");
            // TODO: 修复工作年限计算错误 - Bug修复说明
            // 问题：之前的提示词中"experienceYear（根据工作经验计算出来的工作年限）"描述不够明确，
            // 导致AI可能会将教育时间也计算在内，或者简单地用最早年份到最新年份的差值，
            // 例如：2006年上大学到2025年工作 = 19年（错误），实际应该是2010年毕业后开始工作约15年
            // 
            // 修复方案：在提示词中明确工作年限的计算规则：
            // 1. 只计算experience（工作经历）中的时间段，不包括education（教育经历）
            // 2. 累加所有工作经历的实际工作时长（年）
            // 3. 如果工作结束时间是"Present"、"Current"、"至今"等，使用当前年份(2026)计算
            // 4. 计算公式：总工作年限 = Σ(每段工作的结束年份 - 开始年份)
            // 5. 结果保留整数，向下取整
            // 
            // 修改日期：2026-02-04
            // 修改人：sxc
            entity.put("content", "从下面提供的文本中提取所有能识别到的简历信息，只提取原文中存在的内容，不要补充、不推测、不总结。需要提取的字段包括：name（姓名或人名）、phone（电话号码）、email（电子邮件地址）、experienceYear（工作年限，重要：只计算experience工作经历中的实际工作时长，不包括education教育时间。计算方法：累加所有工作经历的年数，如果结束时间是Present/Current/至今则用2026年计算，例如：2018-01到2020-06工作2年+2021-03到Present工作5年=总共7年工作经验）、position（岗位或者简历中自己期望的职位等）、location（地点或者地址、家庭住址）、links（所有链接地址）、currentWork(当前工作公司)、about（关于我/自我介绍）、skills_tools（关键资格（许可证、注册/会员资格、认证））、languages（语言能力,主要就是Languages下面的语言）、experience（工作经历,除了title、company、location、durationStart、durationEnd,其他的都放到description里面,并且description里面要根据换行符分成不同的content),日期要拆分成开始时间(durationStart)和结束时间(durationEnd)）、education（教育经历,日期要拆分成开始时间(durationStart)和结束时间(durationEnd)）。请将提取结果以结构化 JSON 格式返回，格式如下：{ \\\"name\\\": \\\"\\\", \\\"phone\\\": \\\"\\\", \\\"currentWork\\\": \\\"\\\", \\\"position\\\": \\\"\\\", \\\"location\\\": \\\"\\\", \\\"email\\\": \\\"\\\", \\\"experienceYear\\\": \\\"\\\", \\\"links\\\": [{\\\"content\\\":\\\"\\\"}], \\\"about\\\": \\\"\\\", \\\"skillsTools\\\": [{\\\"content\\\":\\\"\\\"}], \\\"languages\\\": [{\\\"content\\\":\\\"\\\"}], \\\"experience\\\": [{\\\"title\\\": \\\"\\\", \\\"company\\\": \\\"\\\",\\\"location\\\": \\\"\\\",\\\"durationStart\\\": \\\"\\\",\\\"durationEnd\\\": \\\"\\\",\\\"description\\\": [{\\\"content\\\":\\\"\\\"}]}], \\\"education\\\": [{\\\"degree\\\": \\\"\\\",\\\"institution\\\": \\\"\\\",\\\"durationStart\\\": \\\"\\\",\\\"durationEnd\\\": \\\"\\\"}] }。字段不存在则返回 null 或空数组。只返回标准可解析的 JSON结构 ,不要多余的```json等信息，不要解释说明，不要改写内容。以下为待处理文本：" + contents);
            //根据AI做
            list.add(entity);
            String resultCv = chatGPTClient.handleAiChat(JSONUtil.toJsonStr(list), "JX");
            log.info("开始返回简历解析结果:{}", resultCv);
            HotakeCvInfoDto cvInfoDto = JSONUtil.toBean(resultCv, HotakeCvInfoDto.class);
            //数据添加默认值
            if (cvInfoDto != null) {
                if (StrUtil.isEmpty(cvInfoDto.getName())) {
                    cvInfoDto.setName("-");
                }
                if (StrUtil.isEmpty(cvInfoDto.getPhone())) {
                    cvInfoDto.setPhone("-");
                }
                if (StrUtil.isEmpty(cvInfoDto.getEmail())) {
                    cvInfoDto.setEmail("-");
                }
                if (StrUtil.isEmpty(cvInfoDto.getPosition())) {
                    cvInfoDto.setPosition("-");
                }
                if (StrUtil.isEmpty(cvInfoDto.getLocation())) {
                    cvInfoDto.setLocation("-");
                }
                if (StrUtil.isEmpty(cvInfoDto.getExperienceYear())) {
                    cvInfoDto.setExperienceYear("-");
                }
                if (StrUtil.isEmpty(cvInfoDto.getAbout())) {
                    cvInfoDto.setAbout("-");
                }
                if (StrUtil.isEmpty(cvInfoDto.getCurrentWork())) {
                    cvInfoDto.setCurrentWork("-");
                }
                if (CollectionUtil.isNotEmpty(cvInfoDto.getSkillsTools())) {
                    for (VcSkillsToolsDto toolsDto : cvInfoDto.getSkillsTools()) {
                        if (StrUtil.isEmpty(toolsDto.getContent())) {
                            toolsDto.setContent("-");
                        }
                    }
                }
                if (CollectionUtil.isNotEmpty(cvInfoDto.getLinks())) {
                    for (VcLinksDto linksDto : cvInfoDto.getLinks()) {
                        if (StrUtil.isEmpty(linksDto.getContent())) {
                            linksDto.setContent("-");
                        }
                    }
                }

                if (CollectionUtil.isNotEmpty(cvInfoDto.getLanguages())) {
                    for (VcLanguagesDto languagesDto : cvInfoDto.getLanguages()) {
                        if (StrUtil.isEmpty(languagesDto.getContent())) {
                            languagesDto.setContent("-");
                        }
                    }
                }

                if (CollectionUtil.isNotEmpty(cvInfoDto.getExperience())) {
                    for (VcExperienceDto experienceDto : cvInfoDto.getExperience()) {
                        if (StrUtil.isEmpty(experienceDto.getTitle())) {
                            experienceDto.setTitle("-");
                        }
                        if (StrUtil.isEmpty(experienceDto.getCompany())) {
                            experienceDto.setCompany("-");
                        }
                        if (StrUtil.isEmpty(experienceDto.getLocation())) {
                            experienceDto.setLocation("-");
                        }
                        if (StrUtil.isEmpty(experienceDto.getDurationStart())) {
                            experienceDto.setDurationStart("-");
                        }
                        if (StrUtil.isEmpty(experienceDto.getDurationEnd())) {
                            experienceDto.setDurationEnd("-");
                        }
                        if (CollectionUtil.isNotEmpty(experienceDto.getDescription())) {
                            for (VcExperienceDescriptionDto descriptionDto : experienceDto.getDescription()) {
                                if (StrUtil.isEmpty(descriptionDto.getContent())) {
                                    descriptionDto.setContent("-");
                                }

                            }
                        }
                    }
                }

                if (CollectionUtil.isNotEmpty(cvInfoDto.getEducation())) {
                    for (VcEducationDto educationDto : cvInfoDto.getEducation()) {
                        if (StrUtil.isEmpty(educationDto.getDegree())) {
                            educationDto.setDegree("-");
                        }
                        if (StrUtil.isEmpty(educationDto.getInstitution())) {
                            educationDto.setInstitution("-");
                        }
                        if (StrUtil.isEmpty(educationDto.getDurationStart())) {
                            educationDto.setDurationStart("-");
                        }
                        if (StrUtil.isEmpty(educationDto.getDurationEnd())) {
                            educationDto.setDurationEnd("-");
                        }
                        if (educationDto.getCertificate() != null) {
                            if (StrUtil.isEmpty(educationDto.getCertificate().getFileName())) {
                                educationDto.getCertificate().setFileName("-");
                            }
                            if (StrUtil.isEmpty(educationDto.getCertificate().getFileSuffix())) {
                                educationDto.getCertificate().setFileSuffix("-");
                            }
                            if (StrUtil.isEmpty(educationDto.getCertificate().getFileUrl())) {
                                educationDto.getCertificate().setFileUrl("-");
                            }
                            if (StrUtil.isEmpty(educationDto.getCertificate().getFileSizeShow())) {
                                educationDto.getCertificate().setFileSizeShow("-");
                            }
                        }
                    }
                }
            }

            return cvInfoDto;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HotakeCvInfoDto();
    }


    /**
     * 处理简历信息
     *
     * @param hotakeCvInfo 简历信息
     * @return
     */
    private String handleHotakeCvInfoScore(HotakeCvInfoDto cvInfoDto) {
        String resultMsg = "";
        try {
            //调用AI大模型
            List<Map<String, String>> list = new LinkedList();
            Map<String, String> mapEntity = new HashMap<>();
            mapEntity.put("role", "system");
            mapEntity.put("content", "You are a construction industry HR expert. Evaluate resumes and provide scores and recommendations for construction management positions.");
            list.add(mapEntity);
            Map<String, String> mapEntityOne = new HashMap<>();
            mapEntityOne.put("role", "user");
            mapEntityOne.put("content", "Position: Construction Labourer" +
                    "\\nCandidate: " + cvInfoDto.getName() +
                    "\\nResume Summary: " + JSONUtil.toJsonStr(cvInfoDto.getAbout()) +
                    "\\nSkills: " + JSONUtil.toJsonStr(cvInfoDto.getSkillsTools()) +
                    "\\nExperience: " + JSONUtil.toJsonStr(cvInfoDto.getExperience()) +
                    "\\nEducation: " + JSONUtil.toJsonStr(cvInfoDto.getEducation()) +
                    "\\nCertifications: " + JSONUtil.toJsonStr(cvInfoDto.getSkillsTools()));
            list.add(mapEntityOne);
            String promptText = JSONUtil.toJsonStr(list);
            resultMsg = chatGPTClient.handleAiChat(promptText, "CV");
            log.info("返回简历评分数据:{}", resultMsg);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultMsg;
    }
}
