|
@@ -16,10 +16,13 @@ import com.diagbot.client.UserServiceClient;
|
|
|
import com.diagbot.dto.RelationContactListDTO;
|
|
|
import com.diagbot.dto.RelationNodeDTO;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.entity.Concept;
|
|
|
import com.diagbot.entity.Relation;
|
|
|
+import com.diagbot.entity.RelationOrder;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.RelationService;
|
|
|
+import com.diagbot.service.impl.RelationOrderServiceImpl;
|
|
|
import com.diagbot.service.impl.RelationServiceImpl;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
import com.diagbot.util.RespDTOUtil;
|
|
@@ -37,10 +40,17 @@ import com.diagbot.vo.RemoveRelationContactVO;
|
|
|
@Component
|
|
|
public class RelationContactFacade extends RelationServiceImpl {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ConceptFacade conceptFacade;
|
|
|
+ @Autowired
|
|
|
+ private RelationOrderFacade relationOrderFacade;
|
|
|
@Autowired
|
|
|
@Qualifier("relationServiceImpl")
|
|
|
private RelationService relationService;
|
|
|
@Autowired
|
|
|
+ @Qualifier("relationOrderServiceImpl")
|
|
|
+ private RelationOrderServiceImpl relationOrderServiceImpl;
|
|
|
+ @Autowired
|
|
|
private UserServiceClient userServiceClient;
|
|
|
|
|
|
/**
|
|
@@ -67,16 +77,84 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean addRelation(RelationNodeVO relationNodeVO) {
|
|
|
- List<Relation> relationList = repairRelationDataForAdd(relationNodeVO);
|
|
|
+ if(relationNodeVO.getConceptId()==null){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,"conceptId必填!");
|
|
|
+ }
|
|
|
+ if(relationNodeVO.getNodeList()==null||relationNodeVO.getNodeList().size()==0){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,"nodeList不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> relationIdList = repairRelationDataForDelBeforeAdd(relationNodeVO.getConceptId(), relationNodeVO.getSonRelationId());
|
|
|
+ QueryWrapper<RelationOrder> relationOrderQe = new QueryWrapper<>();
|
|
|
+ relationOrderQe.in("t_relation_id", relationIdList);
|
|
|
+ relationOrderFacade.remove(relationOrderQe);
|
|
|
+
|
|
|
+ List<List<Relation>> relationGroupList = 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);
|
|
|
+ List<Relation> relationList = new ArrayList<>();
|
|
|
+ relationGroupList.forEach(i->{
|
|
|
+ i.forEach(j->{
|
|
|
+ j.setCreator(currentUser);
|
|
|
+ j.setGmtCreated(now);
|
|
|
+ j.setModifier(currentUser);
|
|
|
+ j.setGmtModified(now);
|
|
|
+ relationList.add(j);
|
|
|
+ });
|
|
|
});
|
|
|
- return relationService.saveOrUpdateBatch(relationList);
|
|
|
+ relationService.saveOrUpdateBatch(relationList);
|
|
|
+
|
|
|
+ if(relationNodeVO.getIsOrderBy()==1){
|
|
|
+ List<RelationOrder> relationOrderList = new ArrayList<>();
|
|
|
+ relationGroupList.forEach(i->{
|
|
|
+ int orderNo = 0;
|
|
|
+ for(Relation j : i){
|
|
|
+ orderNo++;
|
|
|
+ RelationOrder relationOrder = new RelationOrder();
|
|
|
+ relationOrder.setOrderNo(orderNo);
|
|
|
+ relationOrder.settRelationId(j.getId());
|
|
|
+ relationOrder.setGmtCreate(now);
|
|
|
+ relationOrder.setGmtModified(now);
|
|
|
+ relationOrder.setCreator(currentUser);
|
|
|
+ relationOrder.setModifier(currentUser);
|
|
|
+ relationOrderList.add(relationOrder);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ relationOrderServiceImpl.saveBatch(relationOrderList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系节点-添加或者编辑前先删除掉
|
|
|
+ * @param conceptId
|
|
|
+ * @param relationId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Long> repairRelationDataForDelBeforeAdd(Long conceptId,Long relationId){
|
|
|
+ List<Long> relationIdList = new ArrayList<>();
|
|
|
+
|
|
|
+ QueryWrapper<Relation> relationQe = new QueryWrapper<>();
|
|
|
+ relationQe.eq("end_id", conceptId);
|
|
|
+ relationQe.eq(relationId!=null,"relation_id", relationId);
|
|
|
+ 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.getStartId(),relationId));
|
|
|
+ });
|
|
|
+
|
|
|
+ if(!remove(relationQe)){
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ return relationIdList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -84,36 +162,26 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
* @param relationNodeVO
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<Relation> repairRelationDataForAdd(RelationNodeVO relationNodeVO){
|
|
|
- List<Relation> relationList = new ArrayList<>();
|
|
|
+ private List<List<Relation>> repairRelationDataForAdd(RelationNodeVO relationNodeVO){
|
|
|
+ List<List<Relation>> retList = 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()));
|
|
|
- }
|
|
|
- remove(relationQe);
|
|
|
-
|
|
|
+ List<Relation> relationList = new ArrayList<>();
|
|
|
relationNodeVO.getNodeList().forEach(i->{
|
|
|
- i.setParentConceptId(relationNodeVO.getConceptId());
|
|
|
- relationList.addAll(repairRelationDataForAdd(i));
|
|
|
+ Relation relation = new Relation();
|
|
|
+ relation.setStartId(i.getConceptId());
|
|
|
+ relation.setEndId(relationNodeVO.getConceptId());
|
|
|
+ relation.setRelationId(i.getRelationId());
|
|
|
+ relationList.add(relation);
|
|
|
+
|
|
|
+ if(i.getNodeList()!=null&&i.getNodeList().size()>0){
|
|
|
+ retList.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);
|
|
|
+ retList.add(relationList);
|
|
|
}
|
|
|
|
|
|
- return relationList;
|
|
|
+ return retList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -124,6 +192,10 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
public RelationNodeDTO relationContactDetail(RelationContactDetailVO relationContactDetailVO){
|
|
|
RelationNodeDTO relationNodeDTO = new RelationNodeDTO();
|
|
|
|
|
|
+ Concept concept = conceptFacade.getById(relationContactDetailVO.getConceptId());
|
|
|
+ relationNodeDTO.setConceptId(concept.getId());
|
|
|
+ relationNodeDTO.setConceptName(concept.getLibName());
|
|
|
+
|
|
|
relationNodeDTO.setNodeList(repairRelationDataForQuery(relationContactDetailVO.getConceptId(), relationContactDetailVO.getRelationId()));
|
|
|
|
|
|
return relationNodeDTO;
|
|
@@ -151,7 +223,9 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean removeRelationContact(RemoveRelationContactVO removeRelationContactVO){
|
|
|
- repairRelationDataForDel(removeRelationContactVO.getConceptId(), removeRelationContactVO.getRelationId(),removeRelationContactVO.getIsDeleted());
|
|
|
+ String currentUser = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ repairRelationDataForDel(removeRelationContactVO.getConceptId(), removeRelationContactVO.getRelationId(),removeRelationContactVO.getIsDeleted(),currentUser,now);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -159,9 +233,11 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
* 处理关系节点-删除/恢复事件
|
|
|
* @param conceptId
|
|
|
* @param relationId
|
|
|
- * @return
|
|
|
+ * @param isDeleted
|
|
|
+ * @param currentUser 操作人
|
|
|
+ * @param now 操作时间
|
|
|
*/
|
|
|
- private void repairRelationDataForDel(Long conceptId,Long relationId,String isDeleted){
|
|
|
+ private void repairRelationDataForDel(Long conceptId,Long relationId,String isDeleted,String currentUser,Date now){
|
|
|
QueryWrapper<Relation> relationQe = new QueryWrapper<>();
|
|
|
relationQe.eq("end_id", conceptId);
|
|
|
relationQe.eq(relationId!=null,"relation_id", relationId);
|
|
@@ -187,12 +263,14 @@ public class RelationContactFacade extends RelationServiceImpl {
|
|
|
|
|
|
Relation relation = new Relation();
|
|
|
relation.setIsDeleted(isDeleted);
|
|
|
+ relation.setGmtModified(now);
|
|
|
+ relation.setModifier(currentUser);
|
|
|
if(!update(relation, relationQe)){
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
|
|
|
}
|
|
|
|
|
|
relationList.forEach(i->{
|
|
|
- repairRelationDataForDel(i.getStartId(), relationId,isDeleted);
|
|
|
+ repairRelationDataForDel(i.getStartId(), relationId,isDeleted,currentUser,now);
|
|
|
});
|
|
|
}
|
|
|
|