|
@@ -31,10 +31,13 @@ import com.diagbot.util.DateUtil;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
import com.diagbot.util.RespDTOUtil;
|
|
|
import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.DeleteRelationContactVO;
|
|
|
import com.diagbot.vo.RelationContactDetailVO;
|
|
|
import com.diagbot.vo.RelationNodeVO;
|
|
|
import com.diagbot.vo.RemoveRelationContactVO;
|
|
|
import com.diagbot.vo.SingleRelationListVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
|
|
/**
|
|
|
* @Description: 医学术语关联业务层
|
|
@@ -91,12 +94,14 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
if(relationNodeVO.getConceptId()==null){
|
|
|
throw new CommonException(CommonErrorCode.RPC_ERROR,"conceptId必填!");
|
|
|
}
|
|
|
- if(relationNodeVO.getNodeList()==null||relationNodeVO.getNodeList().size()==0){
|
|
|
+ if(ListUtil.isEmpty(relationNodeVO.getNodeList())){
|
|
|
throw new CommonException(CommonErrorCode.RPC_ERROR,"nodeList不能为空!");
|
|
|
}
|
|
|
|
|
|
- List<Long> relationIdList = repairRelationDataForDelBeforeAdd(relationNodeVO.getConceptId(), relationNodeVO.getSonRelationId());
|
|
|
+ List<Long> relationIdList = repairRelationDataForDelBeforeAdd(relationNodeVO.getConceptId(),relationNodeVO);
|
|
|
if(ListUtil.isNotEmpty(relationIdList)){
|
|
|
+ removeByIds(relationIdList);
|
|
|
+
|
|
|
QueryWrapper<RelationOrder> relationOrderQe = new QueryWrapper<>();
|
|
|
relationOrderQe.in("t_relation_id", relationIdList);
|
|
|
relationOrderFacade.remove(relationOrderQe);
|
|
@@ -105,7 +110,7 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
List<List<Relation>> relationGroupList = repairRelationDataForAdd(relationNodeVO);
|
|
|
String currentUser = UserUtils.getCurrentPrincipleID();
|
|
|
Date now = DateUtil.now();
|
|
|
- List<Relation> relationList = new ArrayList<>();
|
|
|
+ List<Relation> relationList = Lists.newArrayList();
|
|
|
relationGroupList.forEach(i->{
|
|
|
i.forEach(j->{
|
|
|
j.setCreator(currentUser);
|
|
@@ -118,7 +123,7 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
relationService.saveOrUpdateBatch(relationList);
|
|
|
|
|
|
if(relationNodeVO.getIsOrderBy()==1){
|
|
|
- List<RelationOrder> relationOrderList = new ArrayList<>();
|
|
|
+ List<RelationOrder> relationOrderList = Lists.newArrayList();
|
|
|
relationGroupList.forEach(i->{
|
|
|
int orderNo = 0;
|
|
|
for(Relation j : i){
|
|
@@ -141,30 +146,38 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
|
|
|
/**
|
|
|
* 处理关系节点-添加或者编辑前先删除掉
|
|
|
- * @param conceptId
|
|
|
- * @param relationId
|
|
|
+ * @param conceptId 当前概念id
|
|
|
+ * @param relationNodeVO
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<Long> repairRelationDataForDelBeforeAdd(Long conceptId,Long relationId){
|
|
|
- List<Long> relationIdList = new ArrayList<>();
|
|
|
+ private List<Long> repairRelationDataForDelBeforeAdd(Long conceptId,RelationNodeVO relationNodeVO){
|
|
|
+ List<Long> relationIdList = Lists.newArrayList();
|
|
|
|
|
|
QueryWrapper<Relation> relationQe = new QueryWrapper<>();
|
|
|
relationQe.eq("start_id", conceptId);
|
|
|
- relationQe.eq(relationId!=null,"relation_id", relationId);
|
|
|
+ relationQe.eq(relationNodeVO!=null&&relationNodeVO.getSonRelationId()!=null,"relation_id", relationNodeVO.getSonRelationId());
|
|
|
List<Relation> relationList = list(relationQe);
|
|
|
|
|
|
- if(relationList.size()==0){
|
|
|
- return relationIdList;
|
|
|
- }
|
|
|
-
|
|
|
- relationIdList.addAll(relationList.stream().map(i->i.getId()).collect(Collectors.toList()));
|
|
|
-
|
|
|
- relationList.forEach(i->{
|
|
|
- relationIdList.addAll(repairRelationDataForDelBeforeAdd(i.getEndId(),relationId));
|
|
|
- });
|
|
|
-
|
|
|
- if(!remove(relationQe)){
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
|
|
|
+ if(ListUtil.isNotEmpty(relationList)){
|
|
|
+ if(relationNodeVO!=null&&relationNodeVO.getSonTypeId()!=null){
|
|
|
+ List<Long> conceptIdList = conceptFacade.getCompatibleTypeConceptIds(relationNodeVO.getSonTypeId(), relationList.stream().map(i->i.getEndId()).collect(Collectors.toList()));
|
|
|
+ if(conceptIdList!=null){
|
|
|
+ relationList = relationList.stream().filter(i->conceptIdList.contains(i.getEndId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ListUtil.isNotEmpty(relationList)){
|
|
|
+ relationIdList.addAll(relationList.stream().map(i->i.getId()).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ Map<Long,RelationNodeVO> conceptIdRnMap = Maps.newHashMap();
|
|
|
+ if(relationNodeVO!=null&&ListUtil.isNotEmpty(relationNodeVO.getNodeList())){
|
|
|
+ conceptIdRnMap = relationNodeVO.getNodeList().stream().collect(Collectors.toMap(RelationNodeVO::getConceptId, i->i));
|
|
|
+ }
|
|
|
+
|
|
|
+ for(Relation i : relationList){
|
|
|
+ relationIdList.addAll(repairRelationDataForDelBeforeAdd(i.getEndId(),conceptIdRnMap.get(i.getEndId())));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return relationIdList;
|
|
@@ -176,10 +189,10 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
* @return
|
|
|
*/
|
|
|
private List<List<Relation>> repairRelationDataForAdd(RelationNodeVO relationNodeVO){
|
|
|
- List<List<Relation>> retList = new ArrayList<>();
|
|
|
+ List<List<Relation>> retList = Lists.newArrayList();
|
|
|
|
|
|
- if(relationNodeVO.getNodeList()!=null&&relationNodeVO.getNodeList().size()>0){
|
|
|
- List<Relation> relationList = new ArrayList<>();
|
|
|
+ if(ListUtil.isNotEmpty(relationNodeVO.getNodeList())){
|
|
|
+ List<Relation> relationList = Lists.newArrayList();
|
|
|
relationNodeVO.getNodeList().forEach(i->{
|
|
|
Relation relation = new Relation();
|
|
|
relation.setStartId(relationNodeVO.getConceptId());
|
|
@@ -187,7 +200,7 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
relation.setRelationId(i.getRelationId());
|
|
|
relationList.add(relation);
|
|
|
|
|
|
- if(i.getNodeList()!=null&&i.getNodeList().size()>0){
|
|
|
+ if(ListUtil.isNotEmpty(i.getNodeList())){
|
|
|
retList.addAll(repairRelationDataForAdd(i));
|
|
|
}
|
|
|
});
|
|
@@ -213,7 +226,7 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
relationNodeDTO.setConceptNameType(concept.getLibName()+"("+LexiconTypeEnum.getName(concept.getLibType().intValue())+")");
|
|
|
relationNodeDTO.setIsDeletedConcept(concept.getIsDeleted());
|
|
|
|
|
|
- relationNodeDTO.setNodeList(repairRelationDataForQuery(relationContactDetailVO.getConceptId(), relationContactDetailVO.getRelationId(),null,concept.getIsDeleted()));
|
|
|
+ relationNodeDTO.setNodeList(repairRelationDataForQuery(relationContactDetailVO.getConceptId(),relationContactDetailVO.getRelationIds(),relationContactDetailVO.getTypeIds(),null,concept.getIsDeleted()));
|
|
|
|
|
|
return relationNodeDTO;
|
|
|
}
|
|
@@ -221,18 +234,26 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
/**
|
|
|
* 处理关系节点-查询事件
|
|
|
* @param conceptId
|
|
|
- * @param relationId
|
|
|
+ * @param relationIds
|
|
|
+ * @param typeIds
|
|
|
* @param hookConceptIds
|
|
|
* @param isDeletedParent
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<RelationNodeDTO> repairRelationDataForQuery(Long conceptId,Long relationId,List<Long> hookConceptIds,String isDeletedParent){
|
|
|
+ private List<RelationNodeDTO> repairRelationDataForQuery(Long conceptId,List<Long> relationIds,List<Long> typeIds,List<Long> hookConceptIds,String isDeletedParent){
|
|
|
if(hookConceptIds==null){
|
|
|
hookConceptIds = new ArrayList<>();
|
|
|
hookConceptIds.add(conceptId);
|
|
|
}
|
|
|
|
|
|
- List<RelationNodeDTO> relationNodeDTOList = this.baseMapper.getRelationNodeDTOs(conceptId,relationId);
|
|
|
+ Long relationId = null,endTypeId = null;
|
|
|
+ if(ListUtil.isNotEmpty(relationIds)){
|
|
|
+ relationId = relationIds.remove(0);
|
|
|
+ }
|
|
|
+ if(ListUtil.isNotEmpty(typeIds)){
|
|
|
+ endTypeId = typeIds.remove(0);
|
|
|
+ }
|
|
|
+ List<RelationNodeDTO> relationNodeDTOList = this.baseMapper.getRelationNodeDTOs(conceptId,relationId,endTypeId);
|
|
|
|
|
|
for(RelationNodeDTO i : relationNodeDTOList){
|
|
|
i.setConceptTypeName(LexiconTypeEnum.getName(i.getConceptTypeId().intValue()));
|
|
@@ -245,7 +266,7 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
List<Long> hookConceptIds_ = new ArrayList<>();
|
|
|
hookConceptIds_.addAll(hookConceptIds);
|
|
|
hookConceptIds_.add(i.getConceptId());
|
|
|
- i.setNodeList(repairRelationDataForQuery(i.getConceptId(), relationId,hookConceptIds_,i.getIsDeletedConcept()));
|
|
|
+ i.setNodeList(repairRelationDataForQuery(i.getConceptId(),relationIds,typeIds,hookConceptIds_,i.getIsDeletedConcept()));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -314,8 +335,8 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
* @param removeRelationContactVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean deleteRelationContact(RemoveRelationContactVO removeRelationContactVO){
|
|
|
- repairRelationDataForDelete(removeRelationContactVO.getConceptId(), removeRelationContactVO.getRelationId());
|
|
|
+ public Boolean deleteRelationContact(DeleteRelationContactVO deleteRelationContactVO){
|
|
|
+ repairRelationDataForDelete(deleteRelationContactVO.getConceptId(), deleteRelationContactVO.getRelationIds(),deleteRelationContactVO.getTypeIds());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -324,24 +345,39 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
* @param conceptId
|
|
|
* @param relationId
|
|
|
*/
|
|
|
- private void repairRelationDataForDelete(Long conceptId,Long relationId){
|
|
|
+ private void repairRelationDataForDelete(Long conceptId,List<Long> relationIds,List<Long> typeIds){
|
|
|
+ Long relationId = null,endTypeId = null;
|
|
|
+ if(ListUtil.isNotEmpty(relationIds)){
|
|
|
+ relationId = relationIds.remove(0);
|
|
|
+ }
|
|
|
+ if(ListUtil.isNotEmpty(typeIds)){
|
|
|
+ endTypeId = typeIds.remove(0);
|
|
|
+ }
|
|
|
+
|
|
|
QueryWrapper<Relation> relationQe = new QueryWrapper<>();
|
|
|
relationQe.eq("start_id", conceptId);
|
|
|
relationQe.eq(relationId!=null,"relation_id", relationId);
|
|
|
List<Relation> relationList = list(relationQe);
|
|
|
|
|
|
- if(relationList.size()==0){
|
|
|
+ if(endTypeId!=null&&ListUtil.isNotEmpty(relationList)){
|
|
|
+ List<Long> conceptIdList = conceptFacade.getCompatibleTypeConceptIds(endTypeId,relationList.stream().map(i->i.getEndId()).collect(Collectors.toList()));
|
|
|
+ relationList = relationList.stream().filter(i->conceptIdList.contains(i.getEndId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ListUtil.isEmpty(relationList)){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ List<Long> removeRelationIds = relationList.stream().map(i->i.getId()).collect(Collectors.toList());
|
|
|
+
|
|
|
QueryWrapper<RelationOrder> relationOrderQe = new QueryWrapper<>();
|
|
|
- relationOrderQe.in("t_relation_id", relationList.stream().map(i->i.getId()).collect(Collectors.toList()));
|
|
|
- if(!remove(relationQe)||!relationOrderFacade.remove(relationOrderQe)){
|
|
|
+ relationOrderQe.in("t_relation_id", removeRelationIds);
|
|
|
+ if(!removeByIds(removeRelationIds)||!relationOrderFacade.remove(relationOrderQe)){
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
|
|
|
}
|
|
|
|
|
|
- relationList.forEach(i->{
|
|
|
- repairRelationDataForDelete(i.getEndId(), relationId);
|
|
|
+ removeRelationIds.forEach(i->{
|
|
|
+ repairRelationDataForDelete(i, relationIds, typeIds);
|
|
|
});
|
|
|
}
|
|
|
|