|
@@ -0,0 +1,260 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.dto.RelationNodeDTO;
|
|
|
+import com.diagbot.entity.KlConcept;
|
|
|
+import com.diagbot.entity.KlRelation;
|
|
|
+import com.diagbot.entity.KlRelationOrder;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.enums.LexiconEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.KlRelationService;
|
|
|
+import com.diagbot.service.impl.KlRelationOrderServiceImpl;
|
|
|
+import com.diagbot.service.impl.KlRelationServiceImpl;
|
|
|
+import com.diagbot.util.CryptUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.KlRelationNodeVO;
|
|
|
+import com.diagbot.vo.RelationContactDetailVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.management.relation.Relation;
|
|
|
+import javax.management.relation.RelationService;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author kwz
|
|
|
+ * @date 2021/3/3
|
|
|
+ * @time 15:42
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class RelationContactFacade extends KlRelationServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ private KlConceptFacade klConceptFacade;
|
|
|
+ @Autowired
|
|
|
+ private KlRelationOrderFacade klRelationOrderFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("klRelationServiceImpl")
|
|
|
+ private KlRelationService klRelationService;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("klRelationOrderServiceImpl")
|
|
|
+ private KlRelationOrderServiceImpl klRelationOrderServiceImpl;
|
|
|
+
|
|
|
+ public RelationNodeDTO relationContactDetail(RelationContactDetailVO relationContactDetailVO) {
|
|
|
+ RelationNodeDTO relationNodeDTO = new RelationNodeDTO();
|
|
|
+
|
|
|
+ KlConcept klConcept = klConceptFacade.getById(relationContactDetailVO.getConceptId());
|
|
|
+ relationNodeDTO.setConceptId(klConcept.getId());
|
|
|
+ relationNodeDTO.setConceptName(klConcept.getLibName());
|
|
|
+ relationNodeDTO.setIsDeletedConcept(klConcept.getIsDeleted());
|
|
|
+ relationNodeDTO.setConceptTypeId(new Long(klConcept.getLibType()));
|
|
|
+
|
|
|
+ relationNodeDTO.setNodeList(repairRelationDataForQuery(relationContactDetailVO.getConceptId(),
|
|
|
+ relationContactDetailVO.getRelationIds(), relationContactDetailVO.getTypeIds(),
|
|
|
+ null, klConcept.getIsDeleted()));
|
|
|
+
|
|
|
+ return relationNodeDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系节点-查询事件
|
|
|
+ *
|
|
|
+ * @param conceptId
|
|
|
+ * @param relationIds
|
|
|
+ * @param typeIds
|
|
|
+ * @param hookConceptIds
|
|
|
+ * @param isDeletedParent
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long relationId = null, endTypeId = null;
|
|
|
+ if (ListUtil.isNotEmpty(relationIds)) {
|
|
|
+ relationId = relationIds.remove(0);
|
|
|
+ }
|
|
|
+ if (relationId == null) {
|
|
|
+ relationId = -999999l;
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(typeIds)) {
|
|
|
+ endTypeId = typeIds.remove(0);
|
|
|
+ }
|
|
|
+ List<RelationNodeDTO> relationNodeDTOList = this.baseMapper.getRelationNodeDTOs(conceptId, relationId, endTypeId);
|
|
|
+
|
|
|
+ for (RelationNodeDTO i : relationNodeDTOList) {
|
|
|
+ i.setConceptName(i.getConceptName());
|
|
|
+ i.setParentConceptName(i.getParentConceptName());
|
|
|
+ i.setConceptTypeName(LexiconEnum.getName(i.getConceptTypeId().intValue()));
|
|
|
+ i.setConceptNameType(i.getConceptName() + "(" + LexiconEnum.getName(i.getConceptTypeId().intValue()) + ")");
|
|
|
+ i.setParentConceptTypeName(LexiconEnum.getName(i.getParentConceptTypeId().intValue()));
|
|
|
+ i.setParentConceptNameType(i.getParentConceptName() + "("
|
|
|
+ + LexiconEnum.getName(i.getParentConceptTypeId().intValue()) + ")");
|
|
|
+ i.setIsDeletedConcept(
|
|
|
+ isDeletedParent.equals(IsDeleteEnum.Y.getKey()) ? IsDeleteEnum.Y.getKey() : i.getIsDeletedConcept()
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!hookConceptIds.contains(i.getConceptId())) {
|
|
|
+ List<Long> hookConceptIds_ = new ArrayList<>();
|
|
|
+ hookConceptIds_.addAll(hookConceptIds);
|
|
|
+ hookConceptIds_.add(i.getConceptId());
|
|
|
+ i.setNodeList(repairRelationDataForQuery(i.getConceptId(),
|
|
|
+ Lists.newArrayList(relationIds), Lists.newArrayList(typeIds),
|
|
|
+ hookConceptIds_, i.getIsDeletedConcept()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return relationNodeDTOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医学术语关联维护/医学术语多层关联维护-添加或者编辑
|
|
|
+ *
|
|
|
+ * @param klRelationNodeVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean addRelation(KlRelationNodeVO klRelationNodeVO) {
|
|
|
+ if (klRelationNodeVO.getConceptId() == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR, "conceptId必填!");
|
|
|
+ }
|
|
|
+ if (ListUtil.isEmpty(klRelationNodeVO.getNodeList())) {
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR, "nodeList不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //先删除
|
|
|
+ List<Long> relationIdList = repairRelationDataForDelBeforeAdd(klRelationNodeVO.getConceptId(), klRelationNodeVO);
|
|
|
+ if (ListUtil.isNotEmpty(relationIdList)) {
|
|
|
+ removeByIds(relationIdList);
|
|
|
+
|
|
|
+ QueryWrapper<KlRelationOrder> relationOrderQe = new QueryWrapper<>();
|
|
|
+ relationOrderQe.in("t_relation_id", relationIdList);
|
|
|
+ klRelationOrderFacade.remove(relationOrderQe);
|
|
|
+ }
|
|
|
+
|
|
|
+ //后添加
|
|
|
+ List<List<KlRelation>> relationGroupList = repairRelationDataForAdd(klRelationNodeVO);
|
|
|
+ String currentUser = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ List<KlRelation> relationList = Lists.newArrayList();
|
|
|
+ relationGroupList.forEach(i -> {
|
|
|
+ i.forEach(j -> {
|
|
|
+ j.setCreator(currentUser);
|
|
|
+ j.setGmtCreate(now);
|
|
|
+ j.setModifier(currentUser);
|
|
|
+ j.setGmtModified(now);
|
|
|
+ relationList.add(j);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ klRelationService.saveOrUpdateBatch(relationList);
|
|
|
+
|
|
|
+ if (klRelationNodeVO.getIsOrderBy() == 1) {
|
|
|
+ List<KlRelationOrder> relationOrderList = Lists.newArrayList();
|
|
|
+ relationGroupList.forEach(i -> {
|
|
|
+ int orderNo = 0;
|
|
|
+ for (KlRelation j : i) {
|
|
|
+ orderNo++;
|
|
|
+ KlRelationOrder relationOrder = new KlRelationOrder();
|
|
|
+ relationOrder.setOrderNo(orderNo);
|
|
|
+ relationOrder.settRelationId(j.getId());
|
|
|
+ relationOrder.setGmtCreate(now);
|
|
|
+ relationOrder.setGmtModified(now);
|
|
|
+ relationOrder.setCreator(currentUser);
|
|
|
+ relationOrder.setModifier(currentUser);
|
|
|
+ relationOrderList.add(relationOrder);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ klRelationOrderServiceImpl.saveBatch(relationOrderList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系节点-添加或者编辑前先删除掉
|
|
|
+ *
|
|
|
+ * @param conceptId 当前概念id
|
|
|
+ * @param klRelationNodeVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Long> repairRelationDataForDelBeforeAdd(Long conceptId, KlRelationNodeVO klRelationNodeVO) {
|
|
|
+ List<Long> relationIdList = Lists.newArrayList();
|
|
|
+ QueryWrapper<KlRelation> relationQe = new QueryWrapper<>();
|
|
|
+ relationQe.eq("start_id", conceptId);
|
|
|
+ if (klRelationNodeVO != null && klRelationNodeVO.getSonRelationId() != null) {
|
|
|
+ relationQe.eq("relation_id", klRelationNodeVO.getSonRelationId());
|
|
|
+ } else {
|
|
|
+ relationQe.eq("relation_id", -999999l);
|
|
|
+ }
|
|
|
+ List<KlRelation> relationList = this.list(relationQe);
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(relationList)) {
|
|
|
+ if (klRelationNodeVO != null && klRelationNodeVO.getSonTypeId() != null) {
|
|
|
+ List<Long> conceptIdList = klConceptFacade.getCompatibleTypeConceptIds(klRelationNodeVO.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, KlRelationNodeVO> conceptIdRnMap = Maps.newHashMap();
|
|
|
+ if (klRelationNodeVO != null && ListUtil.isNotEmpty(klRelationNodeVO.getNodeList())) {
|
|
|
+ conceptIdRnMap = klRelationNodeVO.getNodeList()
|
|
|
+ .stream().collect(Collectors.toMap(KlRelationNodeVO::getConceptId, i -> i));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KlRelation i : relationList) {
|
|
|
+ relationIdList.addAll(repairRelationDataForDelBeforeAdd(i.getEndId(),
|
|
|
+ conceptIdRnMap.get(i.getEndId())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return relationIdList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系节点-添加或者编辑事件
|
|
|
+ *
|
|
|
+ * @param klRelationNodeVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<List<KlRelation>> repairRelationDataForAdd(KlRelationNodeVO klRelationNodeVO) {
|
|
|
+ List<List<KlRelation>> retList = Lists.newArrayList();
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(klRelationNodeVO.getNodeList())) {
|
|
|
+ List<KlRelation> relationList = Lists.newArrayList();
|
|
|
+ klRelationNodeVO.getNodeList().forEach(i -> {
|
|
|
+ KlRelation relation = new KlRelation();
|
|
|
+ relation.setStartId(klRelationNodeVO.getConceptId());
|
|
|
+ relation.setEndId(i.getConceptId());
|
|
|
+ relation.setRelationId(Integer.parseInt(String.valueOf(i.getRelationId())));
|
|
|
+ relationList.add(relation);
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(i.getNodeList())) {
|
|
|
+ retList.addAll(repairRelationDataForAdd(i));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ retList.add(relationList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|