|
@@ -1,5 +1,27 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.apache.commons.lang.time.DateFormatUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -52,27 +74,6 @@ import com.diagbot.vo.IndexLexiconVO;
|
|
|
import com.diagbot.vo.IndexVO;
|
|
|
import com.diagbot.vo.RemoveConceptInfoVO;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import org.apache.commons.lang.time.DateFormatUtils;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
-import org.apache.poi.ss.usermodel.Cell;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import java.io.InputStream;
|
|
|
-import java.text.DecimalFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 术语查询业务层
|
|
@@ -785,14 +786,180 @@ public class ConceptFacade extends ConceptServiceImpl {
|
|
|
sbf.append("数据重复,请修改导入数据!");
|
|
|
throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
|
|
|
}
|
|
|
-
|
|
|
- addConceptInfoVOList.forEach(i -> {
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 原来的
|
|
|
+ * addConceptInfoVOList.forEach(i -> {
|
|
|
addConceptInfo(i);
|
|
|
+ });*/
|
|
|
+
|
|
|
+ ////优化后
|
|
|
+ QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
|
|
|
+ libraryInfoQe.in("name", addConceptInfoDetailVOList.stream().map(i->i.getName()).distinct().collect(Collectors.toList()));
|
|
|
+ Map<String,List<LibraryInfo>> libraryInfoListMap = libraryinfoFacade.list(libraryInfoQe).stream().collect(Collectors.groupingBy(LibraryInfo::getName));
|
|
|
+
|
|
|
+ addConceptInfoVOList.forEach(i -> {
|
|
|
+ i = checkImConceptInfo(i,libraryInfoListMap);
|
|
|
});
|
|
|
+
|
|
|
+ saveAddConceptInfoVOList(addConceptInfoVOList);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入数据插入更新前校验
|
|
|
+ * @param addConceptInfoVO
|
|
|
+ * @param libraryInfoListAllMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public AddConceptInfoVO checkImConceptInfo(AddConceptInfoVO addConceptInfoVO,Map<String,List<LibraryInfo>> libraryInfoListAllMap) {
|
|
|
+ String currentUser = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ Concept concept = new Concept();
|
|
|
+ ConceptCommon conceptCommon = new ConceptCommon();
|
|
|
+ conceptCommon.setSexType(addConceptInfoVO.getSexType());
|
|
|
+ conceptCommon.setMinAge(addConceptInfoVO.getMinAge());
|
|
|
+ conceptCommon.setMaxAge(addConceptInfoVO.getMaxAge());
|
|
|
+ conceptCommon.setGmtModified(now);
|
|
|
+ conceptCommon.setModifier(currentUser);
|
|
|
+ List<LibraryInfo> libraryInfoList = Lists.newArrayList();
|
|
|
+
|
|
|
+ String lineNumStr = "第" + addConceptInfoVO.getLineNum() + "行";
|
|
|
+
|
|
|
+ List<AddConceptInfoDetailVO> addConceptInfoDetailVOMainList = addConceptInfoVO.getDetailList().stream().filter(i -> i.getIsConcept() == 1).collect(Collectors.toList());
|
|
|
+ if (addConceptInfoDetailVOMainList.size() == 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, lineNumStr + "无标准术语!");
|
|
|
+ }
|
|
|
+ if (addConceptInfoDetailVOMainList.size() > 1) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, lineNumStr + "标准术语只能有一个!");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer typeId_ = LexiconTypeEnum.getKey(addConceptInfoVO.getType());
|
|
|
+ if (typeId_ == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, lineNumStr + "数据有误,该类型信息在数据库中不存在!");
|
|
|
+ }
|
|
|
+ Long typeId = typeId_.longValue();
|
|
|
+ concept.setLibType(typeId);
|
|
|
+ concept.setGmtModified(now);
|
|
|
+ concept.setModifier(currentUser);
|
|
|
+
|
|
|
+ List<LibraryInfo> extLibraryInfoList = Lists.newArrayList();
|
|
|
+ addConceptInfoVO.getDetailList().forEach(a->{
|
|
|
+ List<LibraryInfo> libraryInfoListAll = libraryInfoListAllMap.get(a.getName());
|
|
|
+ if(libraryInfoListAll!=null){
|
|
|
+ libraryInfoListAll = libraryInfoListAll.stream().filter(b->b.getTypeId().intValue()==typeId.intValue()).collect(Collectors.toList());
|
|
|
+ if(libraryInfoListAll!=null){
|
|
|
+ extLibraryInfoList.add(libraryInfoListAll.get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<String, LibraryInfo> extLibraryInfoMap = extLibraryInfoList.stream().collect(Collectors.toMap(LibraryInfo::getName, i -> i));
|
|
|
+
|
|
|
+ LibraryInfo libraryInfoMain = extLibraryInfoMap.get(addConceptInfoDetailVOMainList.get(0).getName());
|
|
|
+ Long conceptId = null;
|
|
|
+ if (libraryInfoMain == null) {
|
|
|
+ conceptId = -9999l;
|
|
|
+ concept.setGmtCreate(now);
|
|
|
+ concept.setCreator(currentUser);
|
|
|
+ conceptCommon.setGmtCreate(now);
|
|
|
+ conceptCommon.setCreator(currentUser);
|
|
|
+ } else {
|
|
|
+ conceptId = libraryInfoMain.getConceptId();
|
|
|
+ concept.setId(conceptId);
|
|
|
+ addConceptInfoVO.setConceptId(conceptId);
|
|
|
+
|
|
|
+ if (libraryInfoMain.getIsConcept()!=1&&extLibraryInfoList.stream().filter(i -> i.getConceptId() == libraryInfoMain.getConceptId()).count() == 1) {
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "标准术语已作为同义词被占用!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuffer sbf = new StringBuffer();
|
|
|
+ for (AddConceptInfoDetailVO i : addConceptInfoVO.getDetailList()) {
|
|
|
+ LibraryInfo libraryInfo = extLibraryInfoMap.get(i.getName());
|
|
|
+ if (libraryInfo == null) {
|
|
|
+ libraryInfo = new LibraryInfo();
|
|
|
+ libraryInfo.setTypeId(typeId);
|
|
|
+ libraryInfo.setGmtCreate(now);
|
|
|
+ libraryInfo.setCreator(currentUser);
|
|
|
+ } else if (libraryInfo.getConceptId().intValue() != conceptId.intValue()) {
|
|
|
+ sbf.append(i.getName()).append(" ");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(i, libraryInfo);
|
|
|
+ libraryInfo.setId(null);
|
|
|
+ libraryInfo.setGmtModified(now);
|
|
|
+ libraryInfo.setModifier(currentUser);
|
|
|
+ if(i.getIsConcept()==1){
|
|
|
+ libraryInfoList.add(0,libraryInfo);
|
|
|
+ }else{
|
|
|
+ libraryInfoList.add(libraryInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ if (sbf.length() > 0) {
|
|
|
+ sbf.append("已被占用");
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ addConceptInfoVO.setConcept(concept);
|
|
|
+ addConceptInfoVO.setConceptCommon(conceptCommon);
|
|
|
+ addConceptInfoVO.setLibraryInfoList(libraryInfoList);
|
|
|
+
|
|
|
+ return addConceptInfoVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入数据插入更新
|
|
|
+ * @param addConceptInfoVOList
|
|
|
+ */
|
|
|
+ private void saveAddConceptInfoVOList(List<AddConceptInfoVO> addConceptInfoVOList){
|
|
|
+ List<Long> conceptIds = addConceptInfoVOList.stream().filter(i->i.getConceptId()!=null).map(i->i.getConceptId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
|
|
|
+ libraryInfoQe.in("concept_id", conceptIds);
|
|
|
+ libraryinfoFacade.remove(libraryInfoQe);
|
|
|
+
|
|
|
+ List<LibraryInfo> saveLibraryInfoList = Lists.newArrayList();
|
|
|
+ addConceptInfoVOList.forEach(i->{
|
|
|
+ saveLibraryInfoList.addAll(i.getLibraryInfoList());
|
|
|
+ });
|
|
|
+ libraryinfoFacade.saveBatch(saveLibraryInfoList);
|
|
|
+
|
|
|
+ List<Concept> saveOrUpdateConceptList = Lists.newArrayList();
|
|
|
+ addConceptInfoVOList.forEach(i->{
|
|
|
+ i.getConcept().setLibId(i.getLibraryInfoList().get(0).getId());
|
|
|
+ i.getConcept().setLibName(i.getLibraryInfoList().get(0).getName());
|
|
|
+ saveOrUpdateConceptList.add(i.getConcept());
|
|
|
+ });
|
|
|
+ saveOrUpdateBatch(saveOrUpdateConceptList);
|
|
|
+
|
|
|
+ List<LibraryInfo> updateLibraryInfoList = Lists.newArrayList();
|
|
|
+ addConceptInfoVOList.forEach(i->{
|
|
|
+ if(i.getConceptId()==null){
|
|
|
+ i.getLibraryInfoList().forEach(j->{
|
|
|
+ j.setConceptId(i.getConcept().getId());
|
|
|
+ });
|
|
|
+ updateLibraryInfoList.addAll(i.getLibraryInfoList());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ libraryinfoFacade.updateBatchById(updateLibraryInfoList);
|
|
|
+
|
|
|
+ List<ConceptCommon> saveOrUpdateConceptCommonList = Lists.newArrayList();
|
|
|
+ QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
|
|
|
+ conceptCommonQe.in("concept_id", conceptIds);
|
|
|
+ Map<Long,ConceptCommon> conceptCommonMap = conceptCommonFacade.list(conceptCommonQe).stream().collect(Collectors.toMap(ConceptCommon::getConceptId, i->i));
|
|
|
+ addConceptInfoVOList.forEach(i->{
|
|
|
+ if(i.getConceptId()!=null){
|
|
|
+ i.getConceptCommon().setId(conceptCommonMap.get(i.getConceptId()).getId());
|
|
|
+ }
|
|
|
+ saveOrUpdateConceptCommonList.add(i.getConceptCommon());
|
|
|
+ });
|
|
|
+ conceptCommonFacade.saveOrUpdateBatch(saveOrUpdateConceptCommonList);
|
|
|
+ }
|
|
|
+
|
|
|
@SuppressWarnings("deprecation")
|
|
|
private String getValue(Cell cell) {
|
|
|
try {
|