瀏覽代碼

增加专家导入工具类、修复管理员创建专家其他标签未保存bug

tags/24080901
WendyYang 1 年之前
父節點
當前提交
3e1801bfd7
共有 3 個文件被更改,包括 314 次插入9 次删除
  1. +274
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/util/ExpertRegisterUtil.java
  2. +13
    -9
      pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertInfoCmdAssembler.java
  3. +27
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/region/RegionTest.java

+ 274
- 0
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;

/**
* <p>
* ExpertRegisterUtil
* </p>
*
* @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<Map<String, Object>> 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<DictionaryDTO> 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<DictionaryDTO> 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<DictionaryDTO> 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<RegionDTO> regions = regionCacheHelper.all();
Optional<RegionDTO> 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<RegionDTO> 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<DingOrganization> 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<DictionaryDTO> 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<DictionaryDTO> 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<String, TagDTO> 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<DingOrganization> 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<DictionaryDTO> 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);
});
}

}

+ 13
- 9
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<TagFieldInfo> technicalExpertise = professionalInfo.getTechnicalExpertise();
List<TagFieldInfo> industrySector = professionalInfo.getIndustrySector();
List<TagFieldInfo> expertSource = basicInfo.getExpertSource();
List<TagFieldInfo> other = new ArrayList<>();
List<TagFieldInfo> other;
if (Objects.nonNull(otherInfo)) {
other = otherInfo.getOther();
} else {
other = professionalInfo.getOther();
}
if (other == null) {
other = Collections.emptyList();
}
List<TagFieldInfo> tagFieldInfoList = new ArrayList<>();
assemblerTagExpertInfoFieldName(tagFieldInfoList, goodAt, ExpertTagEnum.GOOD_AT);
@@ -102,14 +109,11 @@ public class ExpertInfoCmdAssembler {
}).collect(Collectors.toList());
}

private static void assemblerTagExpertInfoFieldName(List<TagFieldInfo> allTagFieldInfoList
, List<TagFieldInfo> 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<TagFieldInfo> allTagList
, List<TagFieldInfo> targetTagList, ExpertTagEnum expertTagEnum) {
if (CollUtil.isNotEmpty(targetTagList)) {
targetTagList.forEach(r -> r.setTagFieldName(expertTagEnum.getKey()));
allTagList.addAll(targetTagList);
}
}



+ 27
- 0
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();
}

}

Loading…
取消
儲存