|
@@ -1,6 +1,10 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.dto.RelationNameDTO;
|
|
|
+import com.diagbot.dto.RelationNamesDTO;
|
|
|
import com.diagbot.dto.RelationNodeDTO;
|
|
|
import com.diagbot.entity.KlConcept;
|
|
|
import com.diagbot.entity.KlRelation;
|
|
@@ -12,20 +16,22 @@ 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.KlRelationSaveVO;
|
|
|
+import com.diagbot.vo.KlRelationVO;
|
|
|
import com.diagbot.vo.RelationContactDetailVO;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
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 javax.validation.constraints.NotNull;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -66,6 +72,15 @@ public class RelationContactFacade extends KlRelationServiceImpl {
|
|
|
return relationNodeDTO;
|
|
|
}
|
|
|
|
|
|
+ public RelationNodeDTO relationContactDetail(KlRelationVO klRelationVO) {
|
|
|
+ RelationNamesDTO relationNamesDTO = new RelationNamesDTO();
|
|
|
+ RelationNodeDTO relationNodeDTO = new RelationNodeDTO();
|
|
|
+ List<RelationNameDTO> relationNameDTOs_first = this.getRelationNameDTOs(klRelationVO.getConceptIds(), klRelationVO.getRelationId());
|
|
|
+
|
|
|
+
|
|
|
+ return relationNodeDTO;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理关系节点-查询事件
|
|
|
*
|
|
@@ -120,6 +135,130 @@ public class RelationContactFacade extends KlRelationServiceImpl {
|
|
|
|
|
|
return relationNodeDTOList;
|
|
|
}
|
|
|
+ @DS("med")
|
|
|
+ @DSTransactional
|
|
|
+ public Boolean addRelation(List<KlRelationSaveVO> klRelationSaveVOs) {
|
|
|
+ if (ListUtil.isNotEmpty(klRelationSaveVOs)) {
|
|
|
+ KlRelationSaveVO klRelationSaveVO = klRelationSaveVOs.get(0);
|
|
|
+ Long sid = klRelationSaveVO.getSid();
|
|
|
+ List<Long> conceptid = Lists.newArrayList(sid);
|
|
|
+ Integer rid = klRelationSaveVO.getRid();
|
|
|
+ List<Long> sids = new ArrayList<>();
|
|
|
+ List<RelationNameDTO> relationNameDTOs = this.getRelationNameDTOs(conceptid, rid);
|
|
|
+ if (ListUtil.isNotEmpty(relationNameDTOs)) {
|
|
|
+ for (RelationNameDTO red : relationNameDTOs) {
|
|
|
+ Long startId = red.getStartId();
|
|
|
+ Long medId = red.getEndId();
|
|
|
+ if (!sids.contains(startId)) {
|
|
|
+ sids.add(startId);
|
|
|
+ }
|
|
|
+ if (!sids.contains(medId)) {
|
|
|
+ sids.add(medId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<KlRelation> relationList = this.list(new QueryWrapper<KlRelation>()
|
|
|
+ .in("start_id", sids)
|
|
|
+ .eq("relation_id", rid));
|
|
|
+ List<Long> ids = relationList.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
+ //先删除
|
|
|
+ if (ListUtil.isNotEmpty(ids)) {
|
|
|
+ this.removeByIds(ids);
|
|
|
+
|
|
|
+ QueryWrapper<KlRelationOrder> relationOrderQe = new QueryWrapper<>();
|
|
|
+ relationOrderQe.in("t_relation_id", ids);
|
|
|
+ klRelationOrderFacade.remove(relationOrderQe);
|
|
|
+ }
|
|
|
+ List<List<KlRelation>> relationGroupList = relationDataForAdd(klRelationSaveVOs);
|
|
|
+
|
|
|
+// String currentUser = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ List<KlRelation> relationLists = Lists.newArrayList();
|
|
|
+ relationGroupList.forEach(i -> {
|
|
|
+ i.forEach(j -> {
|
|
|
+// j.setCreator(currentUser);
|
|
|
+ j.setGmtCreate(now);
|
|
|
+// j.setModifier(currentUser);
|
|
|
+ j.setGmtModified(now);
|
|
|
+ relationLists.add(j);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ klRelationService.saveBatch(relationLists);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<List<KlRelation>> relationDataForAdd(List<KlRelationSaveVO> klRelationSaveVOs) {
|
|
|
+ List<List<KlRelation>> relationList = Lists.newArrayList();
|
|
|
+ Map<String, List<KlRelation>> relationMap = Maps.newHashMap();
|
|
|
+ if (ListUtil.isNotEmpty(klRelationSaveVOs)) {
|
|
|
+
|
|
|
+ for (KlRelationSaveVO kls : klRelationSaveVOs) {
|
|
|
+ Long sid = kls.getSid();
|
|
|
+ Integer rid = kls.getRid();
|
|
|
+ Long eid = kls.getEid();
|
|
|
+ Integer srid = kls.getSrid();
|
|
|
+ List<Long> eids = kls.getEids();
|
|
|
+ if(relationMap.containsKey(sid.toString()+"&"+rid.toString())){
|
|
|
+ List<KlRelation> klRelations_big = relationMap.get(sid.toString() + "&" + rid.toString());
|
|
|
+ KlRelation klRelation = new KlRelation();
|
|
|
+ klRelation.setStartId(sid);
|
|
|
+ klRelation.setRelationId(rid);
|
|
|
+ klRelation.setEndId(eid);
|
|
|
+ klRelation.setStatus(1);
|
|
|
+ klRelations_big.add(klRelation);
|
|
|
+ relationMap.put(sid.toString() + "&" + rid.toString(),klRelations_big);
|
|
|
+ }else {
|
|
|
+ List<KlRelation> klRelations_big = Lists.newArrayList();
|
|
|
+ KlRelation klRelation = new KlRelation();
|
|
|
+ klRelation.setStartId(sid);
|
|
|
+ klRelation.setRelationId(rid);
|
|
|
+ klRelation.setEndId(eid);
|
|
|
+ klRelation.setStatus(1);
|
|
|
+ klRelations_big.add(klRelation);
|
|
|
+ relationMap.put(sid.toString() + "&" + rid.toString(),klRelations_big);
|
|
|
+ }
|
|
|
+ if(srid != null && ListUtil.isNotEmpty(eids)){
|
|
|
+ List<KlRelation> klRelations_sub = Lists.newArrayList();
|
|
|
+ for (Long id:eids) {
|
|
|
+ KlRelation klRelation = new KlRelation();
|
|
|
+ klRelation.setStartId(eid);
|
|
|
+ klRelation.setRelationId(srid);
|
|
|
+ klRelation.setEndId(id);
|
|
|
+ klRelation.setStatus(1);
|
|
|
+ klRelations_sub.add(klRelation);
|
|
|
+ }
|
|
|
+ relationMap.put(eid.toString() + "&" + srid.toString(),klRelations_sub);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(MapUtils.isNotEmpty(relationMap)){
|
|
|
+ relationMap.forEach((x,y)->{
|
|
|
+ relationList.add(y);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return relationList;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 医学术语关联维护/医学术语多层关联维护-添加或者编辑
|
|
@@ -186,20 +325,16 @@ public class RelationContactFacade extends KlRelationServiceImpl {
|
|
|
/**
|
|
|
* 处理关系节点-添加或者编辑前先删除掉
|
|
|
*
|
|
|
- * @param conceptId 当前概念id
|
|
|
+ * @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);
|
|
|
+ List<KlRelation> relationList = this.list(new QueryWrapper<KlRelation>()
|
|
|
+ .eq("start_id", conceptId)
|
|
|
+ .eq("relation_id", klRelationNodeVO != null && klRelationNodeVO.getSonRelationId() != null ?
|
|
|
+ klRelationNodeVO.getSonRelationId() : -999999l));
|
|
|
|
|
|
if (ListUtil.isNotEmpty(relationList)) {
|
|
|
if (klRelationNodeVO != null && klRelationNodeVO.getSonTypeId() != null) {
|