|
@@ -1,8 +1,26 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.dto.RelationNodeDTO;
|
|
|
+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.UserUtils;
|
|
|
+import com.diagbot.vo.RelationContactDetailVO;
|
|
|
+import com.diagbot.vo.RelationNodeVO;
|
|
|
+import com.diagbot.vo.RemoveRelationContactVO;
|
|
|
|
|
|
/**
|
|
|
* @Description: 医学术语关联业务层
|
|
@@ -12,8 +30,145 @@ import com.diagbot.service.impl.RelationServiceImpl;
|
|
|
@Component
|
|
|
public class RelationContactFacade extends RelationServiceImpl {
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private RelationFacade relationFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("relationServiceImpl")
|
|
|
+ private RelationService relationService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医学术语关联维护/医学术语多层关联维护/化验子项维护-添加或者编辑
|
|
|
+ * @param relationNodeVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean addRelation(RelationNodeVO relationNodeVO) {
|
|
|
+ List<Relation> relationList = repairRelationDataForAdd(relationNodeVO);
|
|
|
+ String currentUser = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ relationList.forEach(i->{
|
|
|
+ i.setCreator(currentUser);
|
|
|
+ i.setGmtCreated(now);
|
|
|
+ i.setModifier(currentUser);
|
|
|
+ i.setGmtModified(now);
|
|
|
+ });
|
|
|
+ return relationService.saveOrUpdateBatch(relationList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系节点-添加或者编辑事件
|
|
|
+ * @param relationNodeVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Relation> repairRelationDataForAdd(RelationNodeVO relationNodeVO){
|
|
|
+ List<Relation> relationList = new ArrayList<>();
|
|
|
+
|
|
|
+ if(relationNodeVO.getNodeList()!=null&&relationNodeVO.getNodeList().size()>0){
|
|
|
+
|
|
|
+ QueryWrapper<Relation> relationQe = new QueryWrapper<>();
|
|
|
+ relationQe.eq("end_id", relationNodeVO.getConceptId());
|
|
|
+ if(relationNodeVO.getSonRelationId()!=null){
|
|
|
+ relationQe.eq("relation_id", relationNodeVO.getSonRelationId());
|
|
|
+ relationNodeVO.getNodeList().forEach(i->{
|
|
|
+ i.setRelationId(relationNodeVO.getSonRelationId());
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ relationQe.in("relation_id", relationNodeVO.getNodeList().stream().map(i->i.getRelationId()).distinct().collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ relationFacade.remove(relationQe);
|
|
|
+
|
|
|
+ relationNodeVO.getNodeList().forEach(i->{
|
|
|
+ i.setParentConceptId(relationNodeVO.getConceptId());
|
|
|
+ relationList.addAll(repairRelationDataForAdd(i));
|
|
|
+ });
|
|
|
+ }else if(relationNodeVO.getParentConceptId()!=null){
|
|
|
+ Relation relation = new Relation();
|
|
|
+ relation.setStartId(relationNodeVO.getConceptId());
|
|
|
+ relation.setEndId(relationNodeVO.getParentConceptId());
|
|
|
+ relation.setRelationId(relationNodeVO.getRelationId());
|
|
|
+ relationList.add(relation);
|
|
|
+ }
|
|
|
+
|
|
|
+ return relationList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医学术语关联维护/医学术语多层关联维护/化验子项维护-详情
|
|
|
+ * @param relationContactDetailVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public RelationNodeDTO relationContactDetail(RelationContactDetailVO relationContactDetailVO){
|
|
|
+ RelationNodeDTO relationNodeDTO = new RelationNodeDTO();
|
|
|
+
|
|
|
+ relationNodeDTO.setNodeList(repairRelationDataForQuery(relationContactDetailVO.getConceptId(), relationContactDetailVO.getRelationId()));
|
|
|
+
|
|
|
+ return relationNodeDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系节点-查询事件
|
|
|
+ * @param conceptId
|
|
|
+ * @param relationId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<RelationNodeDTO> repairRelationDataForQuery(Long conceptId,Long relationId){
|
|
|
+ List<RelationNodeDTO> relationNodeDTOList = relationFacade.getBaseMapper().getRelationNodeDTOs(conceptId, relationId);
|
|
|
+
|
|
|
+ relationNodeDTOList.forEach(i->{
|
|
|
+ i.setNodeList(repairRelationDataForQuery(i.getConceptId(), relationId));
|
|
|
+ });
|
|
|
+
|
|
|
+ return relationNodeDTOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医学术语关联维护/医学术语多层关联维护/化验子项维护-删除或者恢复
|
|
|
+ * @param removeRelationContactVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean removeRelationContact(RemoveRelationContactVO removeRelationContactVO){
|
|
|
+ repairRelationDataForDel(removeRelationContactVO.getConceptId(), removeRelationContactVO.getRelationId(),removeRelationContactVO.getIsDeleted());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系节点-删除/恢复事件
|
|
|
+ * @param conceptId
|
|
|
+ * @param relationId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void repairRelationDataForDel(Long conceptId,Long relationId,String isDeleted){
|
|
|
+ QueryWrapper<Relation> relationQe = new QueryWrapper<>();
|
|
|
+ relationQe.eq("end_id", conceptId);
|
|
|
+ relationQe.eq(relationId!=null,"relation_id", relationId);
|
|
|
+ List<Relation> relationList = relationFacade.list(relationQe);
|
|
|
+
|
|
|
+ if(relationList.size()==0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(relationList.stream().map(i->i.getIsDeleted()).distinct().count()>1){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,"数据异常!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String isDeleted_ = relationList.get(0).getIsDeleted();
|
|
|
+ if(isDeleted.equals(isDeleted_)){
|
|
|
+ if(isDeleted_.equals("Y")){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,"该数据已删除!");
|
|
|
+ }
|
|
|
+ if(isDeleted_.equals("N")){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,"该数据已恢复!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Relation relation = new Relation();
|
|
|
+ relation.setIsDeleted(isDeleted);
|
|
|
+ if(!relationFacade.update(relation, relationQe)){
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ relationList.forEach(i->{
|
|
|
+ repairRelationDataForDel(i.getStartId(), relationId,isDeleted);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
}
|