|
@@ -0,0 +1,100 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.diagbot.enums.LexiconEnum;
|
|
|
+import com.diagbot.util.ExcelUtils;
|
|
|
+import com.diagbot.vo.ImportConceptAllVO;
|
|
|
+import com.diagbot.vo.ImportConceptSubVO;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wangfeng
|
|
|
+ * @Description:
|
|
|
+ * @date 2021-05-31 13:13
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class TermImportFacade {
|
|
|
+ public void exporTermExcelAll(MultipartFile file) {
|
|
|
+ //导入处理
|
|
|
+ List<ImportConceptAllVO> conceptList = ExcelUtils.importExcel(file, 0, 1, ImportConceptAllVO.class);
|
|
|
+ //校验数据
|
|
|
+ List<Integer> sexType = Arrays.asList(1, 2, 3);
|
|
|
+ List<String> messages = new ArrayList<>();
|
|
|
+ for (ImportConceptAllVO data : conceptList) {
|
|
|
+ if (null != data.getLibName() || data.getLibName().equals("")) {
|
|
|
+ messages.add("第" + data.getRowNum() + "行标准术语为空!");
|
|
|
+ }
|
|
|
+ Integer key = LexiconEnum.getEnum(data.getLibName()).getKey();
|
|
|
+ if (null == key) {
|
|
|
+ messages.add("第" + data.getRowNum() + "行,类型错误!");
|
|
|
+ }
|
|
|
+ data.setLibType(key);
|
|
|
+ if (null != data.getSexType() && !sexType.contains(data.getSexType())) {
|
|
|
+ messages.add("第" + data.getRowNum() + "行,性别错误!");
|
|
|
+ }
|
|
|
+ if (null != data.getMinAge() && data.getMinAge() < 0.0) {
|
|
|
+ messages.add("第" + data.getRowNum() + "行,最小年龄错误!");
|
|
|
+ }
|
|
|
+ if (null != data.getMaxAge() && data.getMaxAge() > 200) {
|
|
|
+ messages.add("第" + data.getRowNum() + "行,最大年龄错误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //拆同义词
|
|
|
+ for (ImportConceptAllVO termExcelVO : conceptList) {
|
|
|
+ Integer libType = termExcelVO.getLibType();
|
|
|
+ String libName = termExcelVO.getLibName();
|
|
|
+ String synonymName = termExcelVO.getSynonymName();
|
|
|
+ List<ImportConceptSubVO> synonymsList = new ArrayList<>();
|
|
|
+ if (null != synonymName && !synonymName.equals("")) {
|
|
|
+ String[] result = synonymName.split("[\\$]");
|
|
|
+ for (String r : result) {
|
|
|
+ ImportConceptSubVO sub = new ImportConceptSubVO();
|
|
|
+ sub.setLibName(libName);
|
|
|
+ sub.setIsConcept(0);
|
|
|
+ sub.setLibType(libType);
|
|
|
+ sub.setStatus(1);
|
|
|
+ sub.setSynonymName(r.trim());
|
|
|
+ synonymsList.add(sub);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ termExcelVO.setSynonymsList(synonymsList);
|
|
|
+ }
|
|
|
+ //校验
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ //找出重复标准词
|
|
|
+ List<String> standard = conceptList.stream()
|
|
|
+ .collect(Collectors.toMap(e -> e.getLibName(), e -> 1, (a, b) -> a + b)) // 获得元素出现频率的 Map,键为元素,值为元素出现的次数
|
|
|
+ .entrySet().stream() // Set<Entry>转换为Stream<Entry>
|
|
|
+ .filter(entry -> entry.getValue() > 1) // 过滤出元素出现次数大于 1 的 entry
|
|
|
+ .map(entry -> entry.getKey()) // 获得 entry 的键(重复元素)对应的 Stream
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<ImportConceptSubVO> synonymsListNew = new ArrayList<>();
|
|
|
+ for (ImportConceptAllVO conceptData : conceptList) {
|
|
|
+ List<ImportConceptSubVO> synonymsList = conceptData.getSynonymsList();
|
|
|
+ for (ImportConceptSubVO subNew : synonymsList) {
|
|
|
+ synonymsListNew.add(subNew);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //找出重复同义词
|
|
|
+ List<String> consent = synonymsListNew.stream()
|
|
|
+ .collect(Collectors.toMap(e -> e.getSynonymName(), e -> 1, (a, b) -> a + b)) // 获得元素出现频率的 Map,键为元素,值为元素出现的次数
|
|
|
+ .entrySet().stream() // Set<Entry>转换为Stream<Entry>
|
|
|
+ .filter(entry -> entry.getValue() > 1) // 过滤出元素出现次数大于 1 的 entry
|
|
|
+ .map(entry -> entry.getKey()) // 获得 entry 的键(重复元素)对应的 Stream
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //找出标准词出现在同义词
|
|
|
+ List<String> collectAll = conceptList.stream().filter(
|
|
|
+ (ImportConceptAllVO) -> synonymsListNew.stream().map(ImportConceptSubVO::getSynonymName).collect(Collectors.toList()).contains(ImportConceptAllVO.getLibName())
|
|
|
+ ).map(entry -> entry.getSynonymName()).collect(Collectors.toList());
|
|
|
+ long endTime = System.currentTimeMillis(); //获取结束时间
|
|
|
+
|
|
|
+ }
|
|
|
+}
|