浏览代码

术语关系维护修改

rgb 6 年之前
父节点
当前提交
cbc9f5a581

+ 12 - 18
knowledgeman-service/src/main/java/com/diagbot/dto/GetRelationInfoDetailDTO.java

@@ -1,9 +1,5 @@
 package com.diagbot.dto;
 
-import java.util.Date;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Getter;
 import lombok.Setter;
@@ -34,6 +30,12 @@ public class GetRelationInfoDetailDTO {
      */
 	@ApiModelProperty(value="关系起点术语名称")
     private String startName;
+	
+	/**
+     * 关系起点术语类型
+     */
+	@ApiModelProperty(value="关系起点术语类型")
+    private String startType;
     
     /**
      * 关系终点术语id
@@ -47,6 +49,12 @@ public class GetRelationInfoDetailDTO {
 	@ApiModelProperty(value="关系终点术语名称")
     private String endName;
 	
+    /**
+     * 关系终点术语类型
+     */
+	@ApiModelProperty(value="关系终点术语类型")
+    private String endType;
+	
     /**
      * 关系id
      */
@@ -59,20 +67,6 @@ public class GetRelationInfoDetailDTO {
 	@ApiModelProperty(value="关系名称")
     private String relationName;
     
-    /**
-     * 操作人
-     */
-	@ApiModelProperty(value="操作人")
-    private String operName;
-    
-    /**
-     * 操作时间
-     */
-	@JsonFormat(timezone="GMT+8",pattern ="yyyy-MM-dd HH:mm")
-	@ApiModelProperty(value="操作时间")
-    private Date operTime;
-    
-    
     
     
     

+ 12 - 0
knowledgeman-service/src/main/java/com/diagbot/dto/GetRelationInfoListDTO.java

@@ -34,6 +34,12 @@ public class GetRelationInfoListDTO {
      */
 	@ApiModelProperty(value="关系起点术语名称")
     private String startName;
+	
+	/**
+     * 关系起点术语类型
+     */
+	@ApiModelProperty(value="关系起点术语类型")
+    private String startType;
     
     /**
      * 关系终点术语id
@@ -47,6 +53,12 @@ public class GetRelationInfoListDTO {
 	@ApiModelProperty(value="关系终点术语名称")
     private String endName;
 	
+    /**
+     * 关系终点术语类型
+     */
+	@ApiModelProperty(value="关系终点术语类型")
+    private String endType;
+	
     /**
      * 关系id
      */

+ 254 - 286
knowledgeman-service/src/main/java/com/diagbot/facade/RelationFacade.java

@@ -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 "";
+        }
     }
-
+    
 
 }

+ 113 - 0
knowledgeman-service/src/main/java/com/diagbot/vo/AddRelationInfoVO.java

@@ -0,0 +1,113 @@
+package com.diagbot.vo;
+
+import javax.validation.constraints.NotBlank;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description
+ * @author rgb
+ * @time 2019-03
+ */
+@Getter
+@Setter
+public class AddRelationInfoVO {
+
+	/**
+	 * 关系起点术语名称
+	 */
+	@NotBlank(message = "关系起点术语名称必填")
+	@ApiModelProperty(value = "关系起点术语名称", required = true)
+	private String startName;
+
+	/**
+	 * 关系起点术语类型
+	 */
+	@NotBlank(message = "关系起点术语类型必填")
+	@ApiModelProperty(value = "关系起点术语类型", required = true)
+	private String startType;
+
+	/**
+	 * 关系终点术语名称
+	 */
+	@NotBlank(message = "关系终点术语名称必填")
+	@ApiModelProperty(value = "关系终点术语名称", required = true)
+	private String endName;
+
+	/**
+	 * 关系终点术语类型
+	 */
+	@NotBlank(message = "关系终点术语类型必填")
+	@ApiModelProperty(value = "关系终点术语类型", required = true)
+	private String endType;
+
+	/**
+	 * 关系名称
+	 */
+	@NotBlank(message = "关系名称必填")
+	@ApiModelProperty(value = "关系名称", required = true)
+	private String relationName;
+
+	public AddRelationInfoVO(@NotBlank(message = "关系起点术语名称必填") String startName,
+			@NotBlank(message = "关系起点术语类型必填") String startType, @NotBlank(message = "关系终点术语名称必填") String endName,
+			@NotBlank(message = "关系终点术语类型必填") String endType, @NotBlank(message = "关系名称必填") String relationName) {
+		super();
+		this.startName = startName;
+		this.startType = startType;
+		this.endName = endName;
+		this.endType = endType;
+		this.relationName = relationName;
+	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((endName == null) ? 0 : endName.hashCode());
+		result = prime * result + ((endType == null) ? 0 : endType.hashCode());
+		result = prime * result + ((relationName == null) ? 0 : relationName.hashCode());
+		result = prime * result + ((startName == null) ? 0 : startName.hashCode());
+		result = prime * result + ((startType == null) ? 0 : startType.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		AddRelationInfoVO other = (AddRelationInfoVO) obj;
+		if (endName == null) {
+			if (other.endName != null)
+				return false;
+		} else if (!endName.equals(other.endName))
+			return false;
+		if (endType == null) {
+			if (other.endType != null)
+				return false;
+		} else if (!endType.equals(other.endType))
+			return false;
+		if (relationName == null) {
+			if (other.relationName != null)
+				return false;
+		} else if (!relationName.equals(other.relationName))
+			return false;
+		if (startName == null) {
+			if (other.startName != null)
+				return false;
+		} else if (!startName.equals(other.startName))
+			return false;
+		if (startType == null) {
+			if (other.startType != null)
+				return false;
+		} else if (!startType.equals(other.startType))
+			return false;
+		return true;
+	}
+
+}

+ 18 - 40
knowledgeman-service/src/main/java/com/diagbot/web/RelationController.java

@@ -1,5 +1,6 @@
 package com.diagbot.web;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -7,7 +8,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.diagbot.annotation.SysLogger;
@@ -15,6 +18,7 @@ import com.diagbot.dto.GetRelationInfoDetailDTO;
 import com.diagbot.dto.GetRelationInfoListDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.RelationFacade;
+import com.diagbot.vo.AddRelationInfoVO;
 import com.diagbot.vo.GetRelationInfoDetailVO;
 import com.diagbot.vo.GetRelationInfoListVO;
 import com.diagbot.vo.RemoveRelationInfoVO;
@@ -61,46 +65,20 @@ public class RelationController {
         return RespDTO.onSuc(relationFacade.getRelationInfoDetail(getRelationInfoDetailVO));
     }
     
+    @ApiOperation(value = "医学术语关系添加或者编辑[by:rengb]")
+    @PostMapping("/addRelationInfo")
+    @SysLogger("addRelationInfo")
+    @Transactional
+    public RespDTO<Boolean> addRelationInfo(@Valid @RequestBody AddRelationInfoVO addRelationInfoVO) {
+        return RespDTO.onSuc(relationFacade.addRelationInfo(addRelationInfoVO));
+    }
     
+    @ApiOperation(value = "医学术语关系excel文件导入[by:rengb]")
+    @PostMapping("/relationInfoExcelIm")
+    @SysLogger("relationInfoExcelIm")
+    @Transactional
+    public RespDTO<Boolean> relationInfoExcelIm(@RequestParam("uploadfile") MultipartFile file,HttpServletRequest request) {
+        return RespDTO.onSuc(relationFacade.relationInfoExcelIm(file));
+    }
     
-
-//    @ApiOperation(value = "按标准术语查询关系",
-//            notes = "Term:术语名称, 必填<br>Type:术语类型, 必填<br>")
-//    @PostMapping("/getConceptRelation")
-//    @SysLogger("getConceptRelation")
-//    public RespDTO<List<RelationDTO>> getConceptRelation(@Valid @RequestBody RelationVo relationVo) {
-//        List<RelationDTO> data = relationFacade.getRelations(relationVo);
-//
-//        return RespDTO.onSuc(data);
-//    }
-//
-//    @ApiOperation(value = "所有术语关系查询")
-//    @PostMapping("/getAllRelation")
-//    @SysLogger("getAllRelation")
-//    public RespDTO<IPage<RelationDTO>> getAllRelation(@RequestBody AllRelationVo allrelationVo) {
-//        IPage<RelationDTO> data = relationFacade.getAllRelations(allrelationVo);
-//
-//        return RespDTO.onSuc(data);
-//    }
-//
-//    @ApiOperation(value = "标准术语关系删除",
-//            notes = "StartTerm:起始术语名称, 必填<br>StartType:起始术语类型, 必填<br>Relation:关系名称, 必填<br>" +
-//                    "EndTerm:终点术语名称, 必填<br>EndType:终点术语类型, 必填<br>")
-//    @PostMapping("/removeRelation")
-//    @SysLogger("removeRelation")
-//    public RespDTO<RelationDTO> removeRelation(@Valid @RequestBody RelationVo relationVo) {
-//        RelationDTO data = relationFacade.removeRelations(relationVo);
-//
-//        return RespDTO.onSuc(data);
-//    }
-//
-//    @ApiOperation(value = "所有关系名称查询")
-//    @PostMapping("/getRelationName")
-//    @SysLogger("getRelationName")
-//    public RespDTO<IPage<LexiconRelationship>> getAllRelationName(@RequestBody AllRelationVo allrelationVo) {
-//        IPage<LexiconRelationship> data = relationshipFacade.getRelationName(allrelationVo);
-//
-//        return RespDTO.onSuc(data);
-//    }
-
 }