package com.ningdatech.pmapi.expert.assembler;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.ningdatech.file.entity.vo.result.AttachFileVo;
import com.ningdatech.pmapi.common.enumeration.BoolDisplayEnum;
import com.ningdatech.pmapi.common.helper.RegionCacheHelper;
import com.ningdatech.pmapi.common.model.FileBasicInfo;
import com.ningdatech.pmapi.expert.constant.ExpertApplyTypeEnum;
import com.ningdatech.pmapi.expert.entity.ExpertAvoidCompany;
import com.ningdatech.pmapi.expert.entity.ExpertIntentionWorkRegion;
import com.ningdatech.pmapi.expert.entity.ExpertMetaApply;
import com.ningdatech.pmapi.expert.entity.ExpertUserFullInfo;
import com.ningdatech.pmapi.expert.model.*;
import com.ningdatech.pmapi.expert.model.dto.*;
import com.ningdatech.pmapi.expert.model.vo.ExpertFullInfoVO;
import com.ningdatech.pmapi.meta.constant.DictExpertInfoTypeEnum;
import com.ningdatech.pmapi.meta.constant.ExpertTagEnum;
import com.ningdatech.pmapi.meta.helper.DictionaryCache;
import com.ningdatech.pmapi.meta.helper.TagCache;
import com.ningdatech.pmapi.meta.model.ExpertRegionInfo;
import com.ningdatech.pmapi.meta.model.dto.DictionaryDTO;
import com.ningdatech.pmapi.meta.model.dto.TagDTO;
import com.ningdatech.pmapi.meta.model.entity.ExpertDictionary;
import com.ningdatech.pmapi.meta.model.entity.ExpertTag;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author liuxinxin
 * @date 2022/7/27 上午10:46
 */
@Component
@RequiredArgsConstructor
public class ExpertUserInfoAssembler {

    private final TagCache tagCache;
    private final DictionaryCache dictionaryCache;
    private final RegionCacheHelper regionCacheHelper;

    public ExpertFullInfoVO buildExpertFullInfoVO(List<AttachFileVo> attachFiles, ExpertFullInfoAllDTO expertFullInfoAll) {
        ExpertUserFullInfoDTO expertUserInfo = expertFullInfoAll.getExpertUserInfoDTO();
        // 字典字典段map
        Map<String, List<DictionaryFieldInfo>> dictInfoMap = buildDictInfoMap(expertFullInfoAll.getExpertDictionaryList());
        // 专家文件资料map
        Map<Long, FileBasicInfo> fileInfoMap = buildFileBasicInfoMap(attachFiles);
        // 专家标签字段map
        Map<String, List<TagFieldInfo>> tagInfoMap = buildTagFieldInfoMap(expertFullInfoAll.getExpertTagList());
        // 专家履职意向地
        List<ExpertRegionDTO> intentionWorkRegion = expertFullInfoAll.getExpertIntentionWorkRegionInfo();
        // 专家回避单位列表
        List<ExpertAvoidCompanyDTO> expertAvoidCompanyList = expertFullInfoAll.getExpertAvoidCompanyList();
        // 基本信息
        ExpertBasicInfo basicInfo = buildExpertBasicInfo(expertUserInfo, dictInfoMap, tagInfoMap, intentionWorkRegion, fileInfoMap);
        // 学历信息
        ExpertEduInfo eduInfo = buildExpertEduInfo(expertUserInfo, dictInfoMap, fileInfoMap);
        // 职业信息
        ExpertJobInfo jobInfo = buildExpertJobInfo(expertUserInfo, dictInfoMap);
        // 专业信息
        ExpertProfessionalInfo professionalInfo = buildExpertProfessionalInfo(expertUserInfo, dictInfoMap
                , tagInfoMap, fileInfoMap, expertAvoidCompanyList);
        // 推荐信息
        ExpertRecommendInfo recommendInfo = new ExpertRecommendInfo();
        recommendInfo.setRecommendedWay(dictInfoMap.get(DictExpertInfoTypeEnum.RECOMMENDED_WAY.getKey()));
        recommendInfo.setRecommendationProofFile(getFileBasicInfoList(fileInfoMap, expertUserInfo.getRecommendationProofFileIdList()));
        // 其他信息
        ExpertOtherInfo otherInfo = new ExpertOtherInfo();
        otherInfo.setOther(tagInfoMap.get(ExpertTagEnum.OTHER.getKey()));
        otherInfo.setRemark(expertUserInfo.getRemark());

        // 专家申请履职意向展示列表
        List<ExpertRegionInfo> applyIntentionWorkRegions = expertFullInfoAll.getExpertApplyIntentionWorkRegionInfo().stream().map(r -> {
            ExpertRegionInfo expertApplyIntentionWorkRegion = new ExpertRegionInfo();
            expertApplyIntentionWorkRegion.setRegionLevel(r.getRegionLevel());
            expertApplyIntentionWorkRegion.setRegionCode(r.getRegionCode());
            expertApplyIntentionWorkRegion.setRegionName(regionCacheHelper.getUnionPathStr(r.getRegionCode(), r.getRegionLevel()));
            return expertApplyIntentionWorkRegion;
        }).collect(Collectors.toList());

        if (CollUtil.isEmpty(basicInfo.getExpertIntentionWorkRegions())) {
            basicInfo.setExpertIntentionWorkRegions(applyIntentionWorkRegions);
        }
        ExpertFullInfoVO resExpertFullInfo = new ExpertFullInfoVO();
        resExpertFullInfo.setUserId(expertUserInfo.getUserId());
        resExpertFullInfo.setBasicInfo(basicInfo);
        resExpertFullInfo.setEduInfo(eduInfo);
        resExpertFullInfo.setJobInfo(jobInfo);
        resExpertFullInfo.setProfessionalInfo(professionalInfo);
        resExpertFullInfo.setRecommendInfo(recommendInfo);
        resExpertFullInfo.setExpertOtherInfo(otherInfo);
        resExpertFullInfo.setExpertApplyIntentionWorkRegions(applyIntentionWorkRegions);
        return resExpertFullInfo;
    }

    public static Map<Long, FileBasicInfo> buildFileBasicInfoMap(List<AttachFileVo> attachFiles) {
        return attachFiles.stream().map(r -> {
            FileBasicInfo fileBasicInfo = new FileBasicInfo();
            fileBasicInfo.setFileId(r.getFileId());
            fileBasicInfo.setFileName(r.getOriginalFileName());
            return fileBasicInfo;
        }).collect(Collectors.toMap(FileBasicInfo::getFileId, Function.identity()));
    }

    public Map<String, List<TagFieldInfo>> buildTagFieldInfoMap(List<ExpertTagDTO> expertTagList) {
        return expertTagList.stream().map(r -> {
            TagFieldInfo tagFieldInfo = new TagFieldInfo();
            tagFieldInfo.setTagCode(r.getTagCode());
            tagFieldInfo.setTagFieldName(r.getExpertInfoField());
            TagDTO tagDTO = tagCache.getByTagCode(r.getTagCode());
            if (Objects.nonNull(tagDTO)) {
                tagFieldInfo.setTagName(tagDTO.getTagName());
            }
            return tagFieldInfo;
        }).collect(Collectors.groupingBy(TagFieldInfo::getTagFieldName));
    }

    public Map<String, List<DictionaryFieldInfo>> buildDictInfoMap(List<ExpertDictionaryDTO> expertDictList) {
        return expertDictList.stream().map(r -> {
            DictionaryFieldInfo dictionaryFieldInfo = new DictionaryFieldInfo();
            dictionaryFieldInfo.setDictionaryFieldName(r.getExpertInfoField());
            dictionaryFieldInfo.setDictionaryCode(r.getDictionaryCode());
            DictionaryDTO dictionaryDTO = dictionaryCache.getByCode(r.getDictionaryCode());
            if (Objects.nonNull(dictionaryDTO)) {
                dictionaryFieldInfo.setDictionaryName(dictionaryDTO.getName());
            }
            return dictionaryFieldInfo;
        }).collect(Collectors.groupingBy(DictionaryFieldInfo::getDictionaryFieldName));
    }

    public static ExpertProfessionalInfo buildExpertProfessionalInfo(ExpertUserFullInfoDTO expertUserInfoDTO,
                                                                     Map<String, List<DictionaryFieldInfo>> dictInfoMap,
                                                                     Map<String, List<TagFieldInfo>> tagFieldInfoMap,
                                                                     Map<Long, FileBasicInfo> fileInfoMap,
                                                                     List<ExpertAvoidCompanyDTO> expertAvoidCompanyList) {
        ExpertProfessionalInfo professionalInfo = new ExpertProfessionalInfo();
        professionalInfo.setTechnicalTitles(expertUserInfoDTO.getTechnicalTitles());
        professionalInfo.setTitleLevel(dictInfoMap.get(DictExpertInfoTypeEnum.TITLE_LEVEL.getKey()));
        professionalInfo.setTitleCertificateFile(getFileBasicInfoList(fileInfoMap, expertUserInfoDTO.getTitleCertificateFileIdList()));
        professionalInfo.setGoodAt(tagFieldInfoMap.get(ExpertTagEnum.GOOD_AT.getKey()));
        professionalInfo.setTechnicalExpertise(tagFieldInfoMap.get(ExpertTagEnum.TECHNICAL_EXPERTISE.getKey()));
        professionalInfo.setAwards(expertUserInfoDTO.getAwards());
        professionalInfo.setIndustrySector(tagFieldInfoMap.get(ExpertTagEnum.INDUSTRY_SECTOR.getKey()));
        professionalInfo.setRecognitionReward(expertUserInfoDTO.getRecognitionReward());
        professionalInfo.setAvoidCompanyList(expertAvoidCompanyList.stream().map(r -> {
            ExpertAvoidCompanyInfo avoidCompanyInfo = new ExpertAvoidCompanyInfo();
            avoidCompanyInfo.setCompanyName(r.getCompanyName());
            avoidCompanyInfo.setCompanyUniqCode(r.getCompanyUniqCode());
            return avoidCompanyInfo;
        }).collect(Collectors.toList()));
        return professionalInfo;
    }

    public static ExpertJobInfo buildExpertJobInfo(ExpertUserFullInfoDTO expertUserInfoDTO,
                                                   Map<String, List<DictionaryFieldInfo>> dictInfoMap) {
        ExpertJobInfo jobInfo = new ExpertJobInfo();
        jobInfo.setJobStatus(dictInfoMap.get(DictExpertInfoTypeEnum.JOB_STATUS.getKey()));
        jobInfo.setRetiredAt(expertUserInfoDTO.getRetiredAt());
        jobInfo.setCompany(expertUserInfoDTO.getCompany());
        jobInfo.setCompanyUniqCode(expertUserInfoDTO.getCompanyUniqCode());
        jobInfo.setLegalEntityCode(expertUserInfoDTO.getLegalEntityCode());
        jobInfo.setAdministrativeDuties(expertUserInfoDTO.getAdministrativeDuties());
        jobInfo.setStartWorkAt(expertUserInfoDTO.getStartWorkAt());
        jobInfo.setAdministrativeRank(dictInfoMap.get(DictExpertInfoTypeEnum.ADMINISTRATIVE_RANK.getKey()));
        jobInfo.setCompanyAttribute(dictInfoMap.get(DictExpertInfoTypeEnum.COMPANY_ATTRIBUTE.getKey()));
        jobInfo.setAddress(expertUserInfoDTO.getAddress());
        jobInfo.setExperience(expertUserInfoDTO.getExperience());
        return jobInfo;
    }

    public static ExpertEduInfo buildExpertEduInfo(ExpertUserFullInfoDTO expertFullInfo,
                                                   Map<String, List<DictionaryFieldInfo>> dictInfoMap,
                                                   Map<Long, FileBasicInfo> fileInfoMap) {
        // 学历信息
        ExpertEduInfo eduInfo = new ExpertEduInfo();
        eduInfo.setSchool(expertFullInfo.getSchool());
        eduInfo.setGraduatedAt(expertFullInfo.getGraduatedAt());
        eduInfo.setAcademicTitle(expertFullInfo.getAcademicTitle());
        eduInfo.setEdu(dictInfoMap.get(DictExpertInfoTypeEnum.EDU.getKey()));
        eduInfo.setGraduationCertificateFile(getFileBasicInfoList(fileInfoMap, expertFullInfo.getGraduationCertificateFileIdList()));
        eduInfo.setDegree(dictInfoMap.get(DictExpertInfoTypeEnum.DEGREE.getKey()));
        eduInfo.setDegreeCertificateFile(getFileBasicInfoList(fileInfoMap, expertFullInfo.getDegreeCertificateFileIdList()));
        return eduInfo;
    }

    private static List<FileBasicInfo> getFileBasicInfoList(Map<Long, FileBasicInfo> fileBasicInfoMap, List<Long> fileIdList) {
        if (CollUtil.isEmpty(fileIdList)) {
            return new ArrayList<>();
        }
        List<FileBasicInfo> fileBasicInfoList = new ArrayList<>();
        for (Long fileId : fileIdList) {
            FileBasicInfo fileBasicInfo = fileBasicInfoMap.get(fileId);
            if (Objects.nonNull(fileBasicInfo)) {
                fileBasicInfoList.add(fileBasicInfo);
            }
        }
        return fileBasicInfoList;
    }

    public static FileBasicInfo getFileBasicInfo(Map<Long, FileBasicInfo> fileBasicInfoMap, Long fileId) {
        if (Objects.isNull(fileId)) {
            return null;
        }
        return fileBasicInfoMap.get(fileId);
    }

    public ExpertBasicInfo buildExpertBasicInfo(ExpertUserFullInfoDTO expertUserInfoDTO
            , Map<String, List<DictionaryFieldInfo>> dictionaryFieldInfoMap
            , Map<String, List<TagFieldInfo>> tagFieldInfoMap
            , List<ExpertRegionDTO> expertIntentionWorkRegionInfo
            , Map<Long, FileBasicInfo> fileBasicInfoMap) {
        //专家层级
        ExpertRegionInfo expertRegionInfo = new ExpertRegionInfo();
        expertRegionInfo.setRegionLevel(expertUserInfoDTO.getRegionLevel());
        expertRegionInfo.setRegionCode(expertUserInfoDTO.getRegionCode());

        // 基本信息
        ExpertBasicInfo basicInfo = new ExpertBasicInfo();
        basicInfo.setIsDingUser(expertUserInfoDTO.getIsDingUser());
        basicInfo.setPhoneNo(expertUserInfoDTO.getPhoneNo());
        basicInfo.setName(expertUserInfoDTO.getName());
        basicInfo.setAvatarFile(getFileBasicInfo(fileBasicInfoMap, expertUserInfoDTO.getAvatarFileId()));
        basicInfo.setGender(expertUserInfoDTO.getGender());
        basicInfo.setPolitical(dictionaryFieldInfoMap.get(DictExpertInfoTypeEnum.POLITICAL.getKey()));
        basicInfo.setIdCard(expertUserInfoDTO.getIdCard());
        basicInfo.setOfficePhone(expertUserInfoDTO.getPhoneNo());
        basicInfo.setBirth(expertUserInfoDTO.getBirth());
        basicInfo.setBank(expertUserInfoDTO.getBank());
        basicInfo.setBankNo(expertUserInfoDTO.getBankNo());
        basicInfo.setEmail(expertUserInfoDTO.getEmail());
        basicInfo.setHometown(expertUserInfoDTO.getHometown());
        basicInfo.setNationality(expertUserInfoDTO.getNationality());
        basicInfo.setExpertSource(tagFieldInfoMap.get(ExpertTagEnum.EXPERT_SOURCE.getKey()));
        expertRegionInfo.setRegionName(regionCacheHelper.getUnionPathStr(expertRegionInfo.getRegionCode(), expertRegionInfo.getRegionLevel()));
        basicInfo.setExpertRegionInfo(expertRegionInfo);

        basicInfo.setExpertIntentionWorkRegions(expertIntentionWorkRegionInfo.stream().map(r -> {
            ExpertRegionInfo expertIntentionWorkRegion = new ExpertRegionInfo();
            expertIntentionWorkRegion.setRegionCode(r.getRegionCode());
            expertIntentionWorkRegion.setRegionLevel(r.getRegionLevel());
            expertIntentionWorkRegion.setRegionName(regionCacheHelper.getUnionPathStr(r.getRegionCode(), r.getRegionLevel()));
            return expertIntentionWorkRegion;
        }).collect(Collectors.toList()));
        basicInfo.setExpertType(dictionaryFieldInfoMap.get(DictExpertInfoTypeEnum.EXPERT_TYPE.getKey()));
        return basicInfo;
    }

    public static ExpertFullInfoAllDTO buildExpertFullInfoAllDTO(ExpertUserFullInfo expertUserFullInfo,
                                                                 List<ExpertTag> expertTagList,
                                                                 List<ExpertDictionary> expertDictionaryList,
                                                                 List<ExpertIntentionWorkRegion> intentionWorkRegionList,
                                                                 List<ExpertMetaApply> expertMetaApplyList,
                                                                 List<ExpertAvoidCompany> expertAvoidCompanyList) {
        ExpertUserFullInfoDTO expertFullInfoDto = buildExpertUserFullInfoDTO(expertUserFullInfo);
        List<ExpertDictionaryDTO> expertDicts = buildExpertDictionaryDTOList(expertDictionaryList);
        List<ExpertTagDTO> expertTags = buildExpertTagDTOList(expertTagList);
        List<ExpertRegionDTO> intentionWorkRegions = buildExpertIntentionWorkRegionInfo(intentionWorkRegionList);

        // 专家申请履职意向展示列表
        List<ExpertRegionDTO> applyIntentionWorkRegions = buildExpertApplyIntentionWorkRegionInfo(intentionWorkRegionList, expertMetaApplyList);
        List<ExpertAvoidCompanyDTO> expertAvoidCompanyDTOList = buildExpertAvoidCompanyDTOList(expertAvoidCompanyList);
        ExpertFullInfoAllDTO expertFullInfoAll = new ExpertFullInfoAllDTO();
        expertFullInfoAll.setUserId(expertUserFullInfo.getUserId());
        expertFullInfoAll.setExpertUserInfoDTO(expertFullInfoDto);
        expertFullInfoAll.setExpertDictionaryList(expertDicts);
        expertFullInfoAll.setExpertTagList(expertTags);
        expertFullInfoAll.setExpertIntentionWorkRegionInfo(intentionWorkRegions);
        expertFullInfoAll.setExpertApplyIntentionWorkRegionInfo(applyIntentionWorkRegions);
        expertFullInfoAll.setExpertAvoidCompanyList(expertAvoidCompanyDTOList);
        return expertFullInfoAll;
    }

    private static List<ExpertRegionDTO> buildExpertApplyIntentionWorkRegionInfo(List<ExpertIntentionWorkRegion> expertIntentionWorkRegionList,
                                                                                 List<ExpertMetaApply> expertMetaApplyList) {
        Set<RegionDtoMapKey> set = new HashSet<>();
        for (ExpertIntentionWorkRegion expertIntentionWorkRegion : expertIntentionWorkRegionList) {
            RegionDtoMapKey regionDtoMapKey = new RegionDtoMapKey();
            regionDtoMapKey.setRegionCode(expertIntentionWorkRegion.getRegionCode());
            regionDtoMapKey.setRegionLevel(expertIntentionWorkRegion.getRegionLevel());
            set.add(regionDtoMapKey);
        }

        for (ExpertMetaApply expertMetaApply : expertMetaApplyList) {
            String regionCode = expertMetaApply.getRegionCode();
            Integer regionLevel = expertMetaApply.getRegionLevel();
            if (Objects.nonNull(regionLevel) && StringUtils.isNotBlank(regionCode)) {
                String applyType = expertMetaApply.getApplyType();
                RegionDtoMapKey regionDtoMapKey = new RegionDtoMapKey();
                regionDtoMapKey.setRegionCode(regionCode);
                regionDtoMapKey.setRegionLevel(regionLevel);
                ExpertApplyTypeEnum typeEnum = ExpertApplyTypeEnum.of(applyType);
                switch (typeEnum) {
                    case EXPERT_INTENTION_LEAVE: {
                        set.remove(regionDtoMapKey);
                    }
                    break;
                    case EXPERT_INTENTION_JOIN: {
                        set.add(regionDtoMapKey);
                    }
                    break;
                    default:
                        break;
                }
            }
        }
        return set.stream().map(r -> {
            ExpertRegionDTO expertRegionDTO = new ExpertRegionDTO();
            expertRegionDTO.setRegionCode(r.getRegionCode());
            expertRegionDTO.setRegionLevel(r.getRegionLevel());
            return expertRegionDTO;
        }).collect(Collectors.toList());
    }

    private static List<ExpertAvoidCompanyDTO> buildExpertAvoidCompanyDTOList(List<ExpertAvoidCompany> expertAvoidCompanyList) {
        return expertAvoidCompanyList.stream().map(r -> {
            ExpertAvoidCompanyDTO expertAvoidCompanyDTO = new ExpertAvoidCompanyDTO();
            expertAvoidCompanyDTO.setCompanyUniqCode(r.getCompanyUniqCode());
            expertAvoidCompanyDTO.setCompanyName(r.getCompanyName());
            return expertAvoidCompanyDTO;
        }).collect(Collectors.toList());
    }

    private static List<ExpertRegionDTO> buildExpertIntentionWorkRegionInfo(List<ExpertIntentionWorkRegion> expertIntentionWorkRegionList) {
        return expertIntentionWorkRegionList.stream().map(r -> {
            ExpertRegionDTO expertRegionDTO = new ExpertRegionDTO();
            expertRegionDTO.setRegionLevel(r.getRegionLevel());
            expertRegionDTO.setRegionCode(r.getRegionCode());
            return expertRegionDTO;
        }).collect(Collectors.toList());
    }

    private static List<ExpertTagDTO> buildExpertTagDTOList(List<ExpertTag> expertTagList) {
        return expertTagList.stream().map(r -> {
            ExpertTagDTO expertTagDTO = new ExpertTagDTO();
            expertTagDTO.setExpertInfoField(r.getExpertInfoField());
            expertTagDTO.setTagCode(r.getTagCode());
            return expertTagDTO;
        }).collect(Collectors.toList());
    }

    private static List<ExpertDictionaryDTO> buildExpertDictionaryDTOList(List<ExpertDictionary> expertDictionaryList) {
        return expertDictionaryList.stream().map(r -> {
            ExpertDictionaryDTO expertDictionaryDTO = new ExpertDictionaryDTO();
            expertDictionaryDTO.setExpertInfoField(r.getExpertInfoField());
            expertDictionaryDTO.setDictionaryCode(r.getDictionaryCode());
            return expertDictionaryDTO;
        }).collect(Collectors.toList());
    }

    public static ExpertUserFullInfoDTO buildExpertUserFullInfoDTO(ExpertUserFullInfo expertUserFullInfo) {
        ExpertUserFullInfoDTO expertUserFullInfoDTO = new ExpertUserFullInfoDTO();
        expertUserFullInfoDTO.setIsDingUser(BoolDisplayEnum.judgeBoolean(expertUserFullInfo.getIsDingUser()));
        expertUserFullInfoDTO.setPhoneNo(expertUserFullInfo.getPhoneNo());
        expertUserFullInfoDTO.setGender(expertUserFullInfo.getGender());
        expertUserFullInfoDTO.setName(expertUserFullInfo.getExpertName());
        expertUserFullInfoDTO.setAvatarFileId(expertUserFullInfo.getAvatarFileId());
        expertUserFullInfoDTO.setIdCard(expertUserFullInfo.getIdCard());
        expertUserFullInfoDTO.setOfficePhone(expertUserFullInfo.getOfficePhone());
        expertUserFullInfoDTO.setBirth(expertUserFullInfo.getBirth());
        expertUserFullInfoDTO.setBankNo(expertUserFullInfo.getBankNo());
        expertUserFullInfoDTO.setBank(expertUserFullInfo.getBank());
        expertUserFullInfoDTO.setEmail(expertUserFullInfo.getEmail());
        expertUserFullInfoDTO.setHometown(expertUserFullInfo.getHometown());
        expertUserFullInfoDTO.setNationality(expertUserFullInfo.getNationality());

        expertUserFullInfoDTO.setSchool(expertUserFullInfo.getSchool());
        expertUserFullInfoDTO.setGraduatedAt(expertUserFullInfo.getGraduatedAt());
        expertUserFullInfoDTO.setAcademicTitle(expertUserFullInfo.getAcademicTitle());
        if (StringUtils.isNotBlank(expertUserFullInfo.getGraduationCertificateFileIdList())) {
            expertUserFullInfoDTO.setGraduationCertificateFileIdList(JSONObject.parseArray(expertUserFullInfo.getGraduationCertificateFileIdList(), Long.class));
        }
        if (StringUtils.isNotBlank(expertUserFullInfo.getDegreeCertificateFileIdList())) {
            expertUserFullInfoDTO.setDegreeCertificateFileIdList(JSONObject.parseArray(expertUserFullInfo.getDegreeCertificateFileIdList(), Long.class));
        }
        expertUserFullInfoDTO.setRetiredAt(expertUserFullInfo.getRetiredAt());
        expertUserFullInfoDTO.setCompany(expertUserFullInfo.getCompany());
        expertUserFullInfoDTO.setCompanyUniqCode(expertUserFullInfo.getCompanyUniqCode());
        expertUserFullInfoDTO.setLegalEntityCode(expertUserFullInfo.getLegalEntityCode());
        expertUserFullInfoDTO.setAdministrativeDuties(expertUserFullInfo.getAdministrativeDuties());
        expertUserFullInfoDTO.setStartWorkAt(expertUserFullInfo.getStartWorkAt());
        expertUserFullInfoDTO.setAddress(expertUserFullInfo.getAddress());
        expertUserFullInfoDTO.setExperience(expertUserFullInfo.getExperience());

        expertUserFullInfoDTO.setTechnicalTitles(expertUserFullInfo.getTechnicalTitles());
        if (StringUtils.isNotBlank(expertUserFullInfo.getTitleCertificateFileIdList())) {
            expertUserFullInfoDTO.setTitleCertificateFileIdList(JSONObject.parseArray(expertUserFullInfo.getTitleCertificateFileIdList(), Long.class));
        }
        expertUserFullInfoDTO.setAwards(expertUserFullInfo.getAwards());
        expertUserFullInfoDTO.setRecognitionReward(expertUserFullInfo.getRecognitionReward());

        expertUserFullInfoDTO.setRegionCode(expertUserFullInfo.getRegionCode());
        expertUserFullInfoDTO.setRegionLevel(expertUserFullInfo.getRegionLevel());

        if (StringUtils.isNotBlank(expertUserFullInfo.getRecommendationProofFileIdList())) {
            expertUserFullInfoDTO.setRecommendationProofFileIdList(JSONObject.parseArray(expertUserFullInfo.getRecommendationProofFileIdList(), Long.class));
        }
        expertUserFullInfoDTO.setRemark(expertUserFullInfo.getRemark());

        return expertUserFullInfoDTO;
    }

    public static ExpertAdminExpertManageListDTO buildExpertAdminExpertManageListDTO(ExpertUserFullInfo expertUserFullInfo,
                                                                                     Map<Long, List<ExpertDictionary>> expertDictMap,
                                                                                     Map<Long, List<ExpertTag>> expertTagMap) {
        Long userId = expertUserFullInfo.getUserId();
        ExpertAdminExpertManageListDTO adminManageExpertListItem = new ExpertAdminExpertManageListDTO();
        adminManageExpertListItem.setUserId(expertUserFullInfo.getUserId());
        adminManageExpertListItem.setExpertName(expertUserFullInfo.getExpertName());
        adminManageExpertListItem.setPhoneNo(expertUserFullInfo.getPhoneNo());
        adminManageExpertListItem.setIsDingUser(BoolDisplayEnum.judgeBoolean(expertUserFullInfo.getIsDingUser()));
        adminManageExpertListItem.setCompany(expertUserFullInfo.getCompany());
        adminManageExpertListItem.setLegalEntityCode(expertUserFullInfo.getLegalEntityCode());
        adminManageExpertListItem.setExpertAccountStatus(expertUserFullInfo.getExpertAccountStatus());

        // 装配字典数据
        List<ExpertDictionary> userExpertDictList = expertDictMap.getOrDefault(userId, Collections.emptyList());
        Map<String, List<ExpertDictionary>> fieldExpertDictMap = userExpertDictList.stream().collect(Collectors.groupingBy(ExpertDictionary::getExpertInfoField));
        adminManageExpertListItem.setExpertType(
                DictionaryAssembler.toDictFieldInfoList(fieldExpertDictMap.get(DictExpertInfoTypeEnum.EXPERT_TYPE.getKey())));
        adminManageExpertListItem.setCompanyAttribute(
                DictionaryAssembler.toDictFieldInfoList(fieldExpertDictMap.get(DictExpertInfoTypeEnum.COMPANY_ATTRIBUTE.getKey())));
        adminManageExpertListItem.setTitleLevel(
                DictionaryAssembler.toDictFieldInfoList(fieldExpertDictMap.get(DictExpertInfoTypeEnum.TITLE_LEVEL.getKey())));
        // 装配标签数据
        List<ExpertTag> expertTagList = Objects.isNull(expertTagMap.get(userId)) ? new ArrayList<>() : expertTagMap.get(userId);
        Map<String, List<ExpertTag>> fieldExpertTagMap = expertTagList.stream().collect(Collectors.groupingBy(ExpertTag::getExpertInfoField));
        adminManageExpertListItem.setExpertSource(TagAssembler.toTagFieldInfoList(fieldExpertTagMap.get(ExpertTagEnum.EXPERT_SOURCE.getKey())));

        if (StrUtil.isNotBlank(expertUserFullInfo.getRegionCode()) && Objects.nonNull(expertUserFullInfo.getRegionLevel())) {
            ExpertRegionInfo expertRegionInfo = new ExpertRegionInfo();
            expertRegionInfo.setRegionLevel(expertUserFullInfo.getRegionLevel());
            expertRegionInfo.setRegionCode(expertUserFullInfo.getRegionCode());
            adminManageExpertListItem.setExpertRegionInfo(expertRegionInfo);
        }

        // 以下数据为专家excel导出使用
        adminManageExpertListItem.setGender(expertUserFullInfo.getGender());
        adminManageExpertListItem.setBirth(expertUserFullInfo.getBirth());
        adminManageExpertListItem.setHometown(expertUserFullInfo.getHometown());
        adminManageExpertListItem.setNationality(expertUserFullInfo.getNationality());
        adminManageExpertListItem.setPolitical(
                DictionaryAssembler.toDictFieldInfoList(fieldExpertDictMap.get(DictExpertInfoTypeEnum.POLITICAL.getKey())));
        adminManageExpertListItem.setIdCard(expertUserFullInfo.getIdCard());
        adminManageExpertListItem.setBankNo(expertUserFullInfo.getBankNo());
        adminManageExpertListItem.setEdu(
                DictionaryAssembler.toDictFieldInfoList(fieldExpertDictMap.get(DictExpertInfoTypeEnum.EDU.getKey())));
        adminManageExpertListItem.setRecommendedWay(
                DictionaryAssembler.toDictFieldInfoList(fieldExpertDictMap.get(DictExpertInfoTypeEnum.RECOMMENDED_WAY.getKey())));

        adminManageExpertListItem.setCreateTime(expertUserFullInfo.getCreateOn());
        return adminManageExpertListItem;
    }


}
