|
@@ -1,36 +1,46 @@
|
|
|
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.springframework.beans.BeanUtils;
|
|
|
+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.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.client.UserServiceClient;
|
|
|
import com.diagbot.dto.GetRelationInfoDetailDTO;
|
|
|
import com.diagbot.dto.GetRelationInfoListDTO;
|
|
|
-import com.diagbot.dto.RelationDTO;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
import com.diagbot.entity.LexiconRelationship;
|
|
|
import com.diagbot.entity.LibraryInfo;
|
|
|
import com.diagbot.entity.Relation;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.RelationService;
|
|
|
import com.diagbot.service.impl.RelationServiceImpl;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.util.UserUtils;
|
|
|
-import com.diagbot.vo.AllRelationVo;
|
|
|
-import com.diagbot.vo.AmendTermVo;
|
|
|
+import com.diagbot.vo.AddRelationInfoVO;
|
|
|
import com.diagbot.vo.GetRelationInfoDetailVO;
|
|
|
import com.diagbot.vo.GetRelationInfoListVO;
|
|
|
-import com.diagbot.vo.RelationVo;
|
|
|
import com.diagbot.vo.RemoveRelationInfoVO;
|
|
|
|
|
|
/**
|
|
@@ -41,16 +51,15 @@ import com.diagbot.vo.RemoveRelationInfoVO;
|
|
|
@Component
|
|
|
public class RelationFacade extends RelationServiceImpl {
|
|
|
|
|
|
-// @Autowired
|
|
|
-// private ConceptFacade conceptFacade;
|
|
|
@Autowired
|
|
|
private LibraryInfoFacade libraryInfoFacade;
|
|
|
@Autowired
|
|
|
- private RelationshipFacade relationshipFacade;
|
|
|
- @Autowired
|
|
|
private UserServiceClient userServiceClient;
|
|
|
@Autowired
|
|
|
private LexiconRelationshipFacade lexiconRelationshipFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("relationServiceImpl")
|
|
|
+ private RelationService relationService;
|
|
|
|
|
|
/**
|
|
|
* 获取医学术语关系列表
|
|
@@ -65,8 +74,24 @@ public class RelationFacade extends RelationServiceImpl {
|
|
|
throw new CommonException(CommonErrorCode.RPC_ERROR,
|
|
|
"获取用户信息失败");
|
|
|
}
|
|
|
+
|
|
|
+ List<Long> libraryInfoIds = new ArrayList<>();
|
|
|
+ libraryInfoIds.addAll(ipage.getRecords().stream().map(i->i.getStartId()).collect(Collectors.toList()));
|
|
|
+ libraryInfoIds.addAll(ipage.getRecords().stream().map(i->i.getEndId()).collect(Collectors.toList()));
|
|
|
+ libraryInfoIds = libraryInfoIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
|
|
|
+ libraryInfoQe.eq("is_deleted", "N");
|
|
|
+ libraryInfoQe.in("id", libraryInfoIds);
|
|
|
+ Map<Long,LibraryInfo> libraryInfoMap = libraryInfoFacade.list(libraryInfoQe).stream().collect(Collectors.toMap(LibraryInfo::getId, i->i));
|
|
|
+
|
|
|
ipage.getRecords().forEach(i->{
|
|
|
i.setOperName(respDTO.data.get(i.getOperName()));
|
|
|
+ if(i.getStartId()!=null&&libraryInfoMap.get(i.getStartId())!=null){
|
|
|
+ i.setStartType(libraryInfoMap.get(i.getStartId()).getType());
|
|
|
+ }
|
|
|
+ if(i.getEndId()!=null&&libraryInfoMap.get(i.getEndId())!=null){
|
|
|
+ i.setEndType(libraryInfoMap.get(i.getEndId()).getType());
|
|
|
+ }
|
|
|
});
|
|
|
return ipage;
|
|
|
}
|
|
@@ -100,17 +125,20 @@ public class RelationFacade extends RelationServiceImpl {
|
|
|
}
|
|
|
|
|
|
GetRelationInfoDetailDTO getRelationInfoDetailDTO = new GetRelationInfoDetailDTO();
|
|
|
+ getRelationInfoDetailDTO.setId(relation.getId());
|
|
|
|
|
|
LibraryInfo startLibraryInfo = libraryInfoFacade.getById(relation.getStartId());
|
|
|
if(startLibraryInfo!=null&&startLibraryInfo.getIsDeleted().equals("N")){
|
|
|
getRelationInfoDetailDTO.setStartId(startLibraryInfo.getId());
|
|
|
getRelationInfoDetailDTO.setStartName(startLibraryInfo.getName());
|
|
|
+ getRelationInfoDetailDTO.setStartType(startLibraryInfo.getType());
|
|
|
}
|
|
|
|
|
|
LibraryInfo endLibraryInfo = libraryInfoFacade.getById(relation.getEndId());
|
|
|
if(endLibraryInfo!=null&&endLibraryInfo.getIsDeleted().equals("N")){
|
|
|
getRelationInfoDetailDTO.setEndId(endLibraryInfo.getId());
|
|
|
getRelationInfoDetailDTO.setEndName(endLibraryInfo.getName());
|
|
|
+ getRelationInfoDetailDTO.setEndType(endLibraryInfo.getType());
|
|
|
}
|
|
|
|
|
|
LexiconRelationship lexiconRelationship = lexiconRelationshipFacade.getById(relation.getRelationId());
|
|
@@ -122,298 +150,238 @@ public class RelationFacade extends RelationServiceImpl {
|
|
|
return getRelationInfoDetailDTO;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- *
|
|
|
- * 获取所有医学术语的关系
|
|
|
- *
|
|
|
- * @param allrelationVo
|
|
|
- * @result IPage<RelationDTO>
|
|
|
- */
|
|
|
- public IPage<RelationDTO> getAllRelations(AllRelationVo allrelationVo) {
|
|
|
-
|
|
|
- return getAllRelation(allrelationVo);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取指定医学术语的关联关系
|
|
|
- *
|
|
|
- * @param relation
|
|
|
- *
|
|
|
- * @return List<RelationDTO>
|
|
|
- */
|
|
|
- public List<RelationDTO> getRelationInfo(RelationDTO relation) {
|
|
|
- List<RelationDTO> rellist = new ArrayList<>();
|
|
|
-
|
|
|
- rellist = getRelation(relation);
|
|
|
-
|
|
|
- return rellist;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- *
|
|
|
- * 获取指定医学术语的所有上级关系
|
|
|
- *
|
|
|
- * @param relationVo
|
|
|
- * @result List<Relation>
|
|
|
- */
|
|
|
- public List<RelationDTO> getRelations(RelationVo relationVo) {
|
|
|
- List<RelationDTO> relationDTOs = new ArrayList<>();
|
|
|
- RelationDTO relationDTO = new RelationDTO();
|
|
|
- Long concept_id = 0l;
|
|
|
-
|
|
|
- if (relationVo.getStart_term().length() > 0 && relationVo.getEnd_term().length() > 0) {
|
|
|
- QueryWrapper<LibraryInfo> query = new QueryWrapper<>();
|
|
|
- query.eq("name", relationVo.getStart_term());
|
|
|
- query.eq("type", relationVo.getStart_type());
|
|
|
-
|
|
|
- LibraryInfo libraryInfo = libraryInfoFacade.getOne(query);
|
|
|
-
|
|
|
- if (libraryInfo == null) {
|
|
|
- relationDTO.setMsg("术语 \"" + relationVo.getStart_term() + "\" 不存在!");
|
|
|
- relationDTOs.add(relationDTO);
|
|
|
-
|
|
|
- return relationDTOs;
|
|
|
- }
|
|
|
- concept_id = (libraryInfo == null) ? 0l : libraryInfo.getConceptId();
|
|
|
- }
|
|
|
- else if (relationVo.getStart_concept_id() > 0) {
|
|
|
- concept_id = relationVo.getStart_concept_id();
|
|
|
- }
|
|
|
-
|
|
|
- if (concept_id > 0) {
|
|
|
- List<Relation> relations = new ArrayList<>();
|
|
|
- relations = getList(relations, concept_id, -1);
|
|
|
- relationDTOs.addAll(ConvertListtoDTO(relations));
|
|
|
- }
|
|
|
-
|
|
|
- return relationDTOs;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public List<RelationDTO> ConvertListtoDTO (List<Relation> src) {
|
|
|
- List<RelationDTO> dest = new ArrayList<>();
|
|
|
- RelationDTO relationDTO;
|
|
|
-
|
|
|
- for (Relation relation:src) {
|
|
|
- relationDTO = new RelationDTO();
|
|
|
- BeanUtils.copyProperties(relation, relationDTO);
|
|
|
-
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("concept_id", relationDTO.getStartId());
|
|
|
- LibraryInfo libraryInfo = libraryInfoFacade.getLibraryInfor(map);
|
|
|
-
|
|
|
- relationDTO.setStartName(libraryInfo.getName());
|
|
|
-
|
|
|
- map.put("concept_id", relationDTO.getEndId());
|
|
|
- libraryInfo = libraryInfoFacade.getLibraryInfor(map);
|
|
|
-
|
|
|
- relationDTO.setEndName(libraryInfo.getName());
|
|
|
-
|
|
|
- LexiconRelationship lexiconRelationship = relationshipFacade.getLexiconRelationship(relationDTO);
|
|
|
- relationDTO.setRelationName(lexiconRelationship.getName());
|
|
|
-
|
|
|
- dest.add(relationDTO);
|
|
|
- }
|
|
|
-
|
|
|
- return dest;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取关系列表
|
|
|
- * @param relations 关系列表
|
|
|
- * @param con_id 起始术语id
|
|
|
- * @param direct -1:向上, 1:向下
|
|
|
- * @result List<Relation>
|
|
|
- */
|
|
|
- public List<Relation> getList(List<Relation> relations, Object con_id, int direct) {
|
|
|
- List<Relation> rel_list = new ArrayList<>();
|
|
|
-
|
|
|
-
|
|
|
- if (con_id != null && con_id instanceof Integer) {
|
|
|
- QueryWrapper<Relation> wrapper = new QueryWrapper<>();
|
|
|
-
|
|
|
- if (direct == -1) {
|
|
|
- wrapper.eq("start_id", con_id);
|
|
|
- rel_list = this.list(wrapper);
|
|
|
- } else if (direct == 1) {
|
|
|
- wrapper.eq("end_id", con_id);
|
|
|
- rel_list = this.list(wrapper);
|
|
|
- }
|
|
|
-
|
|
|
- for (Relation item:rel_list) {
|
|
|
- if (!isExist(relations, item))
|
|
|
- relations.add(item);
|
|
|
- else {
|
|
|
- System.out.println("Conflicted items:\t" + JSON.toJSONString(item));
|
|
|
- return relations;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (rel_list.size() > 0) {
|
|
|
- for (Relation rel : rel_list) {
|
|
|
- getList(relations, rel.getEndId(), direct);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return relations;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询关系是否有循环,即新加关系的起点和终点与原有关系的终点和起点相等
|
|
|
- *
|
|
|
- * @param
|
|
|
+ * 医学术语关系添加或者编辑
|
|
|
+ * @param addRelationInfoVO
|
|
|
+ * @return
|
|
|
*/
|
|
|
- public Boolean isExist(List<Relation> relations, Relation relation) {
|
|
|
- Boolean Exist = false;
|
|
|
-
|
|
|
- for (Relation item:relations) {
|
|
|
-
|
|
|
- if (item.getEndId().intValue() == relation.getStartId().intValue()
|
|
|
- && item.getStartId().intValue() == relation.getEndId().intValue()
|
|
|
- && item.getRelationId().intValue() == relation.getRelationId().intValue()) {
|
|
|
- Exist = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return Exist;
|
|
|
+ public Boolean addRelationInfo(AddRelationInfoVO addRelationInfoVO){
|
|
|
+ Map<String,Object> ckMap = checkAddRelationInfoVO(addRelationInfoVO);
|
|
|
+ Object message = ckMap.get("message");
|
|
|
+ if(message!=null){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,message.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ckMap.get("relation")!=null){
|
|
|
+ return saveOrUpdate((Relation)(ckMap.get("relation")));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新或添加医学术语关系信息
|
|
|
- *
|
|
|
- * @param amendTermVo
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验即将添加的数据
|
|
|
+ * @param addRelationInfoVO
|
|
|
+ * @return 返回map中,包含2个字段:message和relation,message-为空时,表示正常,取relation-relation可能为空,表示已经有了,并且无需更新
|
|
|
+ */
|
|
|
+ private Map<String,Object> checkAddRelationInfoVO(AddRelationInfoVO addRelationInfoVO){
|
|
|
+ Map<String,Object> retMap = new HashMap<>();
|
|
|
+
|
|
|
+ QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
|
|
|
+ libraryInfoQe.eq("is_deleted", "N");
|
|
|
+ libraryInfoQe.eq("name", addRelationInfoVO.getStartName());
|
|
|
+ libraryInfoQe.eq("type", addRelationInfoVO.getStartType());
|
|
|
+ LibraryInfo startLibraryInfo = libraryInfoFacade.getOne(libraryInfoQe);
|
|
|
+ if(startLibraryInfo==null){
|
|
|
+ retMap.put("message", "关系起点术语不存在");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ libraryInfoQe.eq("name", addRelationInfoVO.getEndName());
|
|
|
+ libraryInfoQe.eq("type", addRelationInfoVO.getEndType());
|
|
|
+ LibraryInfo endLibraryInfo = libraryInfoFacade.getOne(libraryInfoQe);
|
|
|
+ if(endLibraryInfo==null){
|
|
|
+ retMap.put("message", "关系终点术语不存在");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<LexiconRelationship> lexiconRelationshipQe = new QueryWrapper<>();
|
|
|
+ lexiconRelationshipQe.eq("is_deleted", "N");
|
|
|
+ lexiconRelationshipQe.eq("name", addRelationInfoVO.getRelationName());
|
|
|
+ LexiconRelationship lexiconRelationship = lexiconRelationshipFacade.getOne(lexiconRelationshipQe);
|
|
|
+ if(lexiconRelationship==null){
|
|
|
+ retMap.put("message", "术语关系不存在");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<Relation> relationQe = new QueryWrapper<>();
|
|
|
+ relationQe.eq("start_id", startLibraryInfo.getId());
|
|
|
+ relationQe.eq("end_id", endLibraryInfo.getId());
|
|
|
+ relationQe.eq("relation_id", lexiconRelationship.getId());
|
|
|
+ Relation relation = getOne(relationQe);
|
|
|
+ if(relation!=null&&relation.getIsDeleted().equals("N")){
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ String currentUser = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ if(relation==null){
|
|
|
+ relation = new Relation();
|
|
|
+ relation.setStartId(startLibraryInfo.getId());
|
|
|
+ relation.setEndId(endLibraryInfo.getId());
|
|
|
+ relation.setRelationId(lexiconRelationship.getId());
|
|
|
+ relation.setCreator(currentUser);
|
|
|
+ relation.setGmtCreated(now);
|
|
|
+ }else if(relation.getIsDeleted().equals("Y")){
|
|
|
+ relation.setIsDeleted("N");
|
|
|
+ relation.setModifier(currentUser);
|
|
|
+ relation.setGmtModified(now);
|
|
|
+ }
|
|
|
+ retMap.put("relation", relation);
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医学术语关系excel文件导入
|
|
|
+ * @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public void upsertRelationInfo(AmendTermVo amendTermVo) {
|
|
|
- Relation relation = new Relation();
|
|
|
- RelationDTO relnodeDTO;
|
|
|
- RelationDTO relationDTO;
|
|
|
- List<RelationDTO> rellist;
|
|
|
- boolean updated = false;
|
|
|
- int rel_id = 0;
|
|
|
-
|
|
|
- if (amendTermVo.getRelations() != null && amendTermVo.getRelations().size() > 0) {
|
|
|
- for (int i=0; i<amendTermVo.getRelations().size(); i++) {
|
|
|
- updated = false;
|
|
|
- relnodeDTO = amendTermVo.getRelations().get(i);
|
|
|
- if (relnodeDTO.getStartId() > 0 && relnodeDTO.getEndId() > 0
|
|
|
- && relnodeDTO.getStartId() != relnodeDTO.getEndId()) {
|
|
|
- relationDTO = amendTermVo.getRelations().get(i);
|
|
|
- rel_id = relationDTO.getRelationId();
|
|
|
-
|
|
|
- rellist = getRelationInfo(relationDTO);
|
|
|
-
|
|
|
- if (rellist.size() > 0) {
|
|
|
- for (RelationDTO reldto:rellist) {
|
|
|
- if (reldto.getRelationId() == rel_id) {
|
|
|
- updated = true;
|
|
|
-
|
|
|
- break;
|
|
|
+ public Boolean relationInfoExcelIm(MultipartFile file) {
|
|
|
+ List<AddRelationInfoVO> addRelationInfoVOList = new ArrayList<>();
|
|
|
+ StringBuffer sbf = new StringBuffer();
|
|
|
+ InputStream inputStream = null;
|
|
|
+ Workbook wb = null;
|
|
|
+ try {
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ inputStream = file.getInputStream();
|
|
|
+ if (inputStream.available() > 512000) {
|
|
|
+ sbf.append("文件最大支持500KB!").append("<br/>");
|
|
|
+ } else {
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ if (fileName.lastIndexOf(".") != -1) {
|
|
|
+ String type = fileName.substring(fileName.lastIndexOf("."));
|
|
|
+ if (type.equals(".xls")) {
|
|
|
+ wb = new HSSFWorkbook(inputStream);
|
|
|
+ } else if (type.equals(".xlsx")) {
|
|
|
+ wb = new XSSFWorkbook(inputStream);
|
|
|
+ }
|
|
|
+ if (wb != null) {
|
|
|
+
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ int count = 0;
|
|
|
+ String startName, startType, endName, endType, relationName;
|
|
|
+ for (Row row : sheet) {
|
|
|
+ count++;
|
|
|
+ if (count == 1 || row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ startName = getValue(row.getCell(0)).trim().replace(" ", "");
|
|
|
+ startType = getValue(row.getCell(1)).trim().replace(" ", "");
|
|
|
+ endName = getValue(row.getCell(2)).trim().replace(" ", "");
|
|
|
+ endType = getValue(row.getCell(3)).trim().replace(" ", "");
|
|
|
+ relationName = getValue(row.getCell(4)).trim().replace(" ", "");
|
|
|
+ if(StringUtil.isEmpty(startName) && StringUtil.isEmpty(startType)
|
|
|
+ && StringUtil.isEmpty(endName) && StringUtil.isEmpty(endType)
|
|
|
+ && StringUtil.isEmpty(relationName)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(startName) || StringUtil.isEmpty(startType)
|
|
|
+ || StringUtil.isEmpty(endName) || StringUtil.isEmpty(endType)
|
|
|
+ || StringUtil.isEmpty(relationName)) {
|
|
|
+ sbf.append("第" + count + "行数据不完整;").append("<br/>");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ addRelationInfoVOList.add(new AddRelationInfoVO(startName,startType,endName,endType,relationName));
|
|
|
}
|
|
|
+ } else {
|
|
|
+ sbf.append("非excel文件无法解析!").append("<br/>");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ sbf.append("未知文件无法解析!").append("<br/>");
|
|
|
}
|
|
|
-
|
|
|
- if (!updated) {
|
|
|
- BeanUtils.copyProperties(relationDTO, relation);
|
|
|
- this.saveOrUpdate(relation);
|
|
|
- }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ sbf.append("无文件上传!").append("<br/>");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ sbf.append("解析失败!").append("<br/>");
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (wb != null) {
|
|
|
+ wb.close();
|
|
|
+ }
|
|
|
+ if (inputStream != null) {
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 删除指定医学术语的关系
|
|
|
- *
|
|
|
- * @param relationVo
|
|
|
- * @result RelationDTO
|
|
|
- */
|
|
|
- public RelationDTO removeRelations(RelationVo relationVo) {
|
|
|
- RelationDTO relationDTO = new RelationDTO();
|
|
|
- QueryWrapper<Relation> query;
|
|
|
-
|
|
|
- Long startid = relationVo.getStart_concept_id();
|
|
|
- Long relationid = relationVo.getRelation_id();
|
|
|
- Long endid = relationVo.getEnd_concept_id();
|
|
|
- String startname = relationVo.getStart_term().trim();
|
|
|
- String relationname = relationVo.getRelation_name().trim();
|
|
|
- String endname = relationVo.getEnd_term().trim();
|
|
|
-
|
|
|
- if (startid > 0 && relationid > 0 && endid > 0) {
|
|
|
- query = new QueryWrapper<>();
|
|
|
- query.eq("start_id", startid);
|
|
|
- query.eq("relation_id", relationid);
|
|
|
- query.eq("end_id", endid);
|
|
|
-
|
|
|
- relationDTO.setMsg(String.valueOf(remove(query)));
|
|
|
+
|
|
|
+ /*****************excel文件本身问题提醒************************/
|
|
|
+ if(sbf.length()>0){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,sbf.toString());
|
|
|
}
|
|
|
- else if (startname.length() > 0 && endname.length() > 0 && relationname.length() > 0) {
|
|
|
- relationDTO = getRelationbyName(relationVo);
|
|
|
-
|
|
|
- if (relationDTO != null) {
|
|
|
- int id = relationDTO.getId();
|
|
|
- query = new QueryWrapper<>();
|
|
|
- query.eq("id", id);
|
|
|
-
|
|
|
- relationDTO.setMsg(String.valueOf(remove(query)));
|
|
|
- }
|
|
|
- else {
|
|
|
- relationDTO.setMsg("此关系不存在!");
|
|
|
- }
|
|
|
+
|
|
|
+ /****************excel文件中数据存在重复提示---数据一模一样即重复***********************/
|
|
|
+ Map<String,List<AddRelationInfoVO>> addRelationInfoVOListMap = addRelationInfoVOList.stream().collect(Collectors.groupingBy(i->{
|
|
|
+ AddRelationInfoVO addRelationInfoVO = (AddRelationInfoVO)i;
|
|
|
+ return addRelationInfoVO.getStartName()+"-"+addRelationInfoVO.getStartType()+"-"+addRelationInfoVO.getEndName()+"-"+addRelationInfoVO.getEndType()+"-"+addRelationInfoVO.getRelationName();
|
|
|
+ }));
|
|
|
+ for(String key : addRelationInfoVOListMap.keySet()){
|
|
|
+ if(addRelationInfoVOListMap.get(key).size()>1){
|
|
|
+ sbf.append(key).append(" ");
|
|
|
+ }
|
|
|
}
|
|
|
- else {
|
|
|
- relationDTO.setMsg("此关系不存在!");
|
|
|
+ if(sbf.length()>0){
|
|
|
+ sbf.append("(存在重复)");
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,sbf.toString());
|
|
|
}
|
|
|
-
|
|
|
- return relationDTO;
|
|
|
+
|
|
|
+ /**************校验每一组数据,同时组装*************************/
|
|
|
+ List<Relation> saveOrUpdateRelationList = new ArrayList<>();
|
|
|
+ Map<String,Object> ckMap = null;
|
|
|
+ Object message = null;
|
|
|
+ int count = 0;
|
|
|
+ for(AddRelationInfoVO i : addRelationInfoVOList){
|
|
|
+ count++;
|
|
|
+ ckMap = checkAddRelationInfoVO(i);
|
|
|
+ message = ckMap.get("message");
|
|
|
+ if(message!=null){
|
|
|
+ sbf.append(message.toString()).append("(第").append(count).append("行)").append("<br/>");
|
|
|
+ }else if(ckMap.get("relation")!=null){
|
|
|
+ saveOrUpdateRelationList.add((Relation)(ckMap.get("relation")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(sbf.length()>0){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,sbf.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return relationService.saveOrUpdateBatch(saveOrUpdateRelationList);
|
|
|
}
|
|
|
+
|
|
|
+ @SuppressWarnings("deprecation")
|
|
|
+ private String getValue(Cell cell) {
|
|
|
+ try {
|
|
|
+ Object obj = null;
|
|
|
+ switch (cell.getCellTypeEnum()) {
|
|
|
+ case BOOLEAN:
|
|
|
+ obj = cell.getBooleanCellValue();
|
|
|
+ break;
|
|
|
+ case ERROR:
|
|
|
+ obj = cell.getErrorCellValue();
|
|
|
+ break;
|
|
|
+ case NUMERIC:
|
|
|
+ if (HSSFDateUtil.isCellDateFormatted(cell)) {
|
|
|
+ Date date = cell.getDateCellValue();
|
|
|
+ obj = DateFormatUtils.format(date, "yyyy-MM-dd");
|
|
|
+ } else {
|
|
|
+ obj = cell.getNumericCellValue();
|
|
|
+ DecimalFormat df = new DecimalFormat("0");
|
|
|
+ obj = df.format(obj);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 清空医学术语关系表
|
|
|
- *
|
|
|
- */
|
|
|
- public void deleteRelation() {
|
|
|
- truncateRelation();
|
|
|
+ break;
|
|
|
+ case STRING:
|
|
|
+ obj = cell.getStringCellValue();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return obj.toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|