From 3e1801bfd7075122d703e1d5e642e4efff6c06df Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 21 Nov 2023 16:40:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=93=E5=AE=B6=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=B7=A5=E5=85=B7=E7=B1=BB=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=88=9B=E5=BB=BA=E4=B8=93=E5=AE=B6?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E6=A0=87=E7=AD=BE=E6=9C=AA=E4=BF=9D=E5=AD=98?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/common/util/ExpertRegisterUtil.java | 274 +++++++++++++++++++++ .../expert/assembler/ExpertInfoCmdAssembler.java | 22 +- .../com/ningdatech/pmapi/region/RegionTest.java | 27 ++ 3 files changed, 314 insertions(+), 9 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/ExpertRegisterUtil.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/ExpertRegisterUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/ExpertRegisterUtil.java new file mode 100644 index 0000000..6e60ae9 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/ExpertRegisterUtil.java @@ -0,0 +1,274 @@ +package com.ningdatech.pmapi.common.util; + +import cn.hutool.core.map.MapUtil; +import cn.hutool.json.JSONUtil; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; +import com.ningdatech.pmapi.expert.controller.ExpertController; +import com.ningdatech.pmapi.expert.model.*; +import com.ningdatech.pmapi.expert.model.req.ExpertRegistrationRequest; +import com.ningdatech.pmapi.meta.constant.DictAllTypeEnum; +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.organization.model.entity.DingOrganization; +import com.ningdatech.pmapi.organization.service.IDingOrganizationService; +import com.ningdatech.pmapi.sys.model.dto.RegionDTO; + +import java.io.File; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + *

+ * ExpertRegisterUtil + *

+ * + * @author WendyYang + * @since 10:03 2023/11/21 + */ +public class ExpertRegisterUtil { + + public static RegionCacheHelper regionCacheHelper; + public static DictionaryCache dictionaryCache; + public static IDingOrganizationService organizationService; + public static TagCache tagCache; + public static ExpertController expertController; + + private static final String FILE_PATH = "/Users/wendy/Desktop/丽水市市本级专家导入用(1).xlsx"; + + public static void registerExpertBatch() { + ExcelReader reader = ExcelUtil.getReader(new File(FILE_PATH)); + List> experts = reader.readAll(); + experts.forEach(w -> { + String rowNum = MapUtil.getStr(w, "序号"); + if (!StrUtils.isNumeric(rowNum) || Integer.parseInt(rowNum) <= 41 || Integer.parseInt(rowNum) >= 108) { + return; + } + ExpertRegistrationRequest request = new ExpertRegistrationRequest(); + ExpertBasicInfo basic = new ExpertBasicInfo(); + basic.setBank(MapUtil.getStr(w, "开户行")); + basic.setBankNo(MapUtil.getStr(w, "银行卡号")); + basic.setName(MapUtil.getStr(w, "*姓名")); + basic.setPhoneNo(MapUtil.getStr(w, "*手机")); + basic.setGender("男".equals(MapUtil.getStr(w, "性别")) ? "1" : "0"); + String expertRegion = MapUtil.getStr(w, "*专家层级"); + // 政治面貌 + basic.setPolitical(new ArrayList<>()); + String political = MapUtil.getStr(w, "政治面貌"); + List politicalDicts = dictionaryCache.getDictionaryListByDictionaryType(DictAllTypeEnum.POLITICAL.getKey()); + if (!politicalDicts.isEmpty()) { + politicalDicts.stream() + .filter(dict -> dict.getName().equals(political)) + .findFirst().ifPresent(dictionary -> { + DictionaryFieldInfo dict = new DictionaryFieldInfo(); + dict.setDictionaryName(dictionary.getName()); + dict.setDictionaryCode(dictionary.getDictionaryCode()); + dict.setDictionaryFieldName(dictionary.getDictionaryType()); + basic.getPolitical().add(dict); + }); + } + ExpertEduInfo eduInfo = new ExpertEduInfo(); + eduInfo.setSchool("暂无"); + eduInfo.setAcademicTitle("暂无"); + eduInfo.setGraduatedAt(LocalDateTime.now()); + eduInfo.setEdu(new ArrayList<>()); + eduInfo.setDegree(new ArrayList<>()); + // 学历 + String eduStr = MapUtil.getStr(w, "学历"); + List eduDicts = dictionaryCache.getDictionaryListByDictionaryType(DictAllTypeEnum.EDU.getKey()); + if (!eduDicts.isEmpty()) { + eduDicts.stream() + .filter(dict -> dict.getName().equals(eduStr)) + .findFirst().ifPresent(dictionary -> { + DictionaryFieldInfo dict = new DictionaryFieldInfo(); + dict.setDictionaryName(dictionary.getName()); + dict.setDictionaryCode(dictionary.getDictionaryCode()); + dict.setDictionaryFieldName(dictionary.getDictionaryType()); + eduInfo.getEdu().add(dict); + }); + } + // 学位 + String degreeStr = MapUtil.getStr(w, "学位"); + List degreeDicts = dictionaryCache.getDictionaryListByDictionaryType(DictAllTypeEnum.DEGREE.getKey()); + if (!degreeDicts.isEmpty()) { + degreeDicts.stream() + .filter(dict -> dict.getName().equals(degreeStr)) + .findFirst().ifPresent(dictionary -> { + DictionaryFieldInfo dict = new DictionaryFieldInfo(); + dict.setDictionaryName(dictionary.getName()); + dict.setDictionaryCode(dictionary.getDictionaryCode()); + dict.setDictionaryFieldName(dictionary.getDictionaryType()); + eduInfo.getDegree().add(dict); + }); + } + request.setEduInfo(eduInfo); + // 专家层级 + String lastRegionName = expertRegion.substring(expertRegion.lastIndexOf("-") + 1); + List regions = regionCacheHelper.all(); + Optional firstExpertRegion = regions.stream() + .filter(region -> region.getRegionLevel().equals(3) + && region.getRegionName().equals(lastRegionName)) + .findFirst(); + if (firstExpertRegion.isPresent()) { + RegionDTO dto = firstExpertRegion.get(); + ExpertRegionInfo regionInfo = new ExpertRegionInfo(); + regionInfo.setRegionCode(dto.getRegionCode()); + regionInfo.setRegionLevel(dto.getRegionLevel()); + regionInfo.setRegionName(dto.getRegionName()); + basic.setExpertRegionInfo(regionInfo); + } + // 履职意向 + String intentionRegionStr = MapUtil.getStr(w, "*履职意向"); + basic.setExpertIntentionWorkRegions(new ArrayList<>()); + for (String intentionRegion : intentionRegionStr.split("\\n")) { + String[] split = intentionRegion.split("-"); + Optional first = regions.stream() + .filter(region -> region.getRegionName().equals(split[split.length - 1]) + && region.getRegionLevel().equals(split.length)) + .findFirst(); + if (first.isPresent()) { + RegionDTO dto = first.get(); + ExpertRegionInfo regionInfo = new ExpertRegionInfo(); + regionInfo.setRegionCode(dto.getRegionCode()); + regionInfo.setRegionLevel(dto.getRegionLevel()); + regionInfo.setRegionName(dto.getRegionName()); + basic.getExpertIntentionWorkRegions().add(regionInfo); + } + } + request.setBasicInfo(basic); + // 职业信息 + ExpertJobInfo jobInfo = new ExpertJobInfo(); + jobInfo.setAddress("暂无"); + jobInfo.setExperience("暂无"); + jobInfo.setJobStatus(new ArrayList<>()); + jobInfo.setCompany(MapUtil.getStr(w, "*工作单位")); + List organizations = organizationService.list(Wrappers.lambdaQuery(DingOrganization.class) + .eq(DingOrganization::getOrganizationName, jobInfo.getCompany())); + if (organizations.size() == 1) { + jobInfo.setCompanyUniqCode(organizations.get(0).getOrganizationCode()); + } + jobInfo.setAdministrativeDuties(MapUtil.getStr(w, "行政职务")); + jobInfo.setAdministrativeRank(new ArrayList<>()); + String administrativeRankStr = MapUtil.getStr(w, "行政职级"); + List administrativeRankDicts = dictionaryCache.getDictionaryListByDictionaryType(DictAllTypeEnum.ADMINISTRATIVE_RANK.getKey()); + if (!administrativeRankDicts.isEmpty()) { + administrativeRankDicts.stream() + .filter(dict -> dict.getName().equals(administrativeRankStr)) + .findFirst().ifPresent(dictionary -> { + DictionaryFieldInfo dict = new DictionaryFieldInfo(); + dict.setDictionaryName(dictionary.getName()); + dict.setDictionaryCode(dictionary.getDictionaryCode()); + dict.setDictionaryFieldName(dictionary.getDictionaryType()); + jobInfo.getAdministrativeRank().add(dict); + }); + } + jobInfo.setCompanyAttribute(new ArrayList<>()); + String companyTypeStr = MapUtil.getStr(w, "*单位类型"); + List companyTypeDicts = dictionaryCache.getDictionaryListByDictionaryType(DictAllTypeEnum.COMPANY_ATTRIBUTE.getKey()); + if (!companyTypeDicts.isEmpty()) { + companyTypeDicts.stream() + .filter(dict -> dict.getName().equals(companyTypeStr)) + .findFirst().ifPresent(dictionary -> { + DictionaryFieldInfo dict = new DictionaryFieldInfo(); + dict.setDictionaryName(dictionary.getName()); + dict.setDictionaryCode(dictionary.getDictionaryCode()); + dict.setDictionaryFieldName(dictionary.getDictionaryType()); + jobInfo.getCompanyAttribute().add(dict); + }); + } + request.setJobInfo(jobInfo); + ExpertProfessionalInfo professionalInfo = new ExpertProfessionalInfo(); + professionalInfo.setAwards("暂无"); + professionalInfo.setIndustrySector(new ArrayList<>()); + String otherTagStr = MapUtil.getStr(w, "其他标签"); + professionalInfo.setOther(new ArrayList<>()); + Map tagMap = tagCache.getNameTagDtoMap(); + for (String othTag : otherTagStr.split(",")) { + tagMap.entrySet().stream() + .filter(tag -> tag.getValue().getParentCode().equals(ExpertTagEnum.OTHER.getKey()) + && tag.getValue().getTagName().equals(othTag)) + .forEach(tag -> { + TagFieldInfo expertTag = new TagFieldInfo(); + expertTag.setTagCode(tag.getValue().getTagCode()); + expertTag.setTagFieldName(tag.getValue().getParentCode()); + expertTag.setTagName(tag.getValue().getTagName()); + professionalInfo.getOther().add(expertTag); + }); + } + + String avoidCompanyStr = MapUtil.getStr(w, "*回避单位"); + professionalInfo.setAvoidCompanyList(new ArrayList<>()); + List avoidOrges = organizationService.list(Wrappers.lambdaQuery(DingOrganization.class) + .in(DingOrganization::getOrganizationName, avoidCompanyStr.split(","))); + if (!avoidOrges.isEmpty()) { + avoidOrges.forEach(org -> { + ExpertAvoidCompanyInfo companyInfo = new ExpertAvoidCompanyInfo(); + companyInfo.setCompanyName(org.getOrganizationName()); + companyInfo.setCompanyUniqCode(org.getOrganizationCode()); + professionalInfo.getAvoidCompanyList().add(companyInfo); + }); + } + + professionalInfo.setGoodAt(new ArrayList<>()); + String goodAtStr = MapUtil.getStr(w, "*擅长方向"); + for (String othTag : goodAtStr.split(",")) { + tagMap.entrySet().stream() + .filter(tag -> tag.getValue().getParentCode().equals(ExpertTagEnum.GOOD_AT.getKey()) + && tag.getValue().getTagName().equals(othTag)) + .forEach(tag -> { + TagFieldInfo expertTag = new TagFieldInfo(); + expertTag.setTagCode(tag.getValue().getTagCode()); + expertTag.setTagFieldName(tag.getValue().getParentCode()); + expertTag.setTagName(tag.getValue().getTagName()); + professionalInfo.getGoodAt().add(expertTag); + }); + } + professionalInfo.setTechnicalExpertise(new ArrayList<>()); + String techStr = MapUtil.getStr(w, "技术专长"); + for (String othTag : techStr.split(",|、")) { + tagMap.entrySet().stream() + .filter(tag -> tag.getValue().getParentCode().equals(ExpertTagEnum.TECHNICAL_EXPERTISE.getKey()) + && tag.getValue().getTagName().equals(othTag)) + .forEach(tag -> { + TagFieldInfo expertTag = new TagFieldInfo(); + expertTag.setTagCode(tag.getValue().getTagCode()); + expertTag.setTagFieldName(tag.getValue().getParentCode()); + expertTag.setTagName(tag.getValue().getTagName()); + professionalInfo.getTechnicalExpertise().add(expertTag); + }); + } + professionalInfo.setTitleLevel(new ArrayList<>()); + String titleLevel = MapUtil.getStr(w, "*职称级别"); + List titleLevelDicts = dictionaryCache.getDictionaryListByDictionaryType(DictAllTypeEnum.TITLE_LEVEL.getKey()); + if (!titleLevelDicts.isEmpty()) { + titleLevelDicts.stream() + .filter(dict -> dict.getName().equals(titleLevel)) + .findFirst().ifPresent(dictionary -> { + DictionaryFieldInfo dict = new DictionaryFieldInfo(); + dict.setDictionaryName(dictionary.getName()); + dict.setDictionaryCode(dictionary.getDictionaryCode()); + dict.setDictionaryFieldName(dictionary.getDictionaryType()); + professionalInfo.getTitleLevel().add(dict); + }); + } + professionalInfo.setTechnicalTitles(MapUtil.getStr(w, "技术职称")); + request.setProfessionalInfo(professionalInfo); + ExpertRecommendInfo recommendInfo = new ExpertRecommendInfo(); + recommendInfo.setRecommendedWay(new ArrayList<>()); + recommendInfo.setRecommendationProofFile(new ArrayList<>()); + request.setRecommendInfo(recommendInfo); + System.out.println(JSONUtil.toJsonStr(request)); + expertController.expertBasicInfoSubmit(request); + }); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertInfoCmdAssembler.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertInfoCmdAssembler.java index b34e3fb..b535aff 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertInfoCmdAssembler.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertInfoCmdAssembler.java @@ -1,6 +1,7 @@ package com.ningdatech.pmapi.expert.assembler; +import cn.hutool.core.collection.CollUtil; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.pmapi.common.model.FileBasicInfo; import com.ningdatech.pmapi.expert.model.*; @@ -14,6 +15,7 @@ import com.ningdatech.pmapi.meta.model.ExpertRegionInfo; import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -83,9 +85,14 @@ public class ExpertInfoCmdAssembler { List technicalExpertise = professionalInfo.getTechnicalExpertise(); List industrySector = professionalInfo.getIndustrySector(); List expertSource = basicInfo.getExpertSource(); - List other = new ArrayList<>(); + List other; if (Objects.nonNull(otherInfo)) { other = otherInfo.getOther(); + } else { + other = professionalInfo.getOther(); + } + if (other == null) { + other = Collections.emptyList(); } List tagFieldInfoList = new ArrayList<>(); assemblerTagExpertInfoFieldName(tagFieldInfoList, goodAt, ExpertTagEnum.GOOD_AT); @@ -102,14 +109,11 @@ public class ExpertInfoCmdAssembler { }).collect(Collectors.toList()); } - private static void assemblerTagExpertInfoFieldName(List allTagFieldInfoList - , List originalTagFieldInfoList, ExpertTagEnum tagExpertInfoFieldEnum) { - if (CollectionUtils.isNotEmpty(originalTagFieldInfoList)) { - originalTagFieldInfoList = originalTagFieldInfoList.stream().map(r -> { - r.setTagFieldName(tagExpertInfoFieldEnum.getKey()); - return r; - }).collect(Collectors.toList()); - allTagFieldInfoList.addAll(originalTagFieldInfoList); + private static void assemblerTagExpertInfoFieldName(List allTagList + , List targetTagList, ExpertTagEnum expertTagEnum) { + if (CollUtil.isNotEmpty(targetTagList)) { + targetTagList.forEach(r -> r.setTagFieldName(expertTagEnum.getKey())); + allTagList.addAll(targetTagList); } } diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/region/RegionTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/region/RegionTest.java index 9f42309..2a76e19 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/region/RegionTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/region/RegionTest.java @@ -1,6 +1,12 @@ package com.ningdatech.pmapi.region; import com.ningdatech.pmapi.AppTests; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; +import com.ningdatech.pmapi.common.util.ExpertRegisterUtil; +import com.ningdatech.pmapi.expert.controller.ExpertController; +import com.ningdatech.pmapi.meta.helper.DictionaryCache; +import com.ningdatech.pmapi.meta.helper.TagCache; +import com.ningdatech.pmapi.organization.service.IDingOrganizationService; import com.ningdatech.pmapi.sys.model.entity.Region; import com.ningdatech.pmapi.sys.service.IRegionService; import org.junit.Test; @@ -32,4 +38,25 @@ public class RegionTest extends AppTests { regionService.saveBatch(set); } + @Autowired + private RegionCacheHelper regionCacheHelper; + @Autowired + private IDingOrganizationService organizationService; + @Autowired + private DictionaryCache dictionaryCache; + @Autowired + private TagCache tagCache; + @Autowired + private ExpertController expertController; + + @Test + public void test1(){ + ExpertRegisterUtil.regionCacheHelper = regionCacheHelper; + ExpertRegisterUtil.tagCache = tagCache; + ExpertRegisterUtil.dictionaryCache = dictionaryCache; + ExpertRegisterUtil.organizationService = organizationService; + ExpertRegisterUtil.expertController = expertController; + ExpertRegisterUtil.registerExpertBatch(); + } + }