Merge branch 'develop' of http://139.196.179.195:3000/chenxudong/electromagnetic-data-new into develop
This commit is contained in:
commit
cf40b68ccd
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Getter
|
||||||
|
public class Edge {
|
||||||
|
String source; // 起点
|
||||||
|
String target; // 终点
|
||||||
|
String relationId; //关系id
|
||||||
|
String relationship; //关系描述
|
||||||
|
|
||||||
|
public Edge(String source, String target, String relationId, String relationship) {
|
||||||
|
this.source = source;
|
||||||
|
this.target = target;
|
||||||
|
this.relationId = relationId;
|
||||||
|
this.relationship = relationship;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.resp;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class FIleRelationVO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关系主键id
|
|
||||||
*/
|
|
||||||
private String relationId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关系描述
|
|
||||||
*/
|
|
||||||
private String relationship;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关联文件
|
|
||||||
*/
|
|
||||||
private FileSimpleInfoVO relatedFile;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.resp;
|
package com.electromagnetic.industry.software.manage.pojo.resp;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.Edge;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -8,12 +9,12 @@ import java.util.List;
|
||||||
public class FileRelationViewVO {
|
public class FileRelationViewVO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主文件
|
* 关联文件
|
||||||
*/
|
*/
|
||||||
private FileSimpleInfoVO file;
|
List<FileSimpleInfoVO> nodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联文件关系列表
|
* 边
|
||||||
*/
|
*/
|
||||||
List<FIleRelationVO> relationList;
|
List<Edge> edges;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,11 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
public class FileSimpleInfoVO {
|
public class FileSimpleInfoVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件名称
|
* 文件名称
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,17 @@ import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.EdFileRelationMapper;
|
import com.electromagnetic.industry.software.manage.mapper.EdFileRelationMapper;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation;
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.resp.FIleRelationVO;
|
import com.electromagnetic.industry.software.manage.pojo.models.Edge;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.resp.FileRelationViewVO;
|
import com.electromagnetic.industry.software.manage.pojo.resp.FileRelationViewVO;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.resp.FileSimpleInfoVO;
|
import com.electromagnetic.industry.software.manage.pojo.resp.FileSimpleInfoVO;
|
||||||
import com.electromagnetic.industry.software.manage.service.EdFileRelationService;
|
import com.electromagnetic.industry.software.manage.service.EdFileRelationService;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper, EdFileRelation> implements EdFileRelationService {
|
public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper, EdFileRelation> implements EdFileRelationService {
|
||||||
|
|
@ -65,38 +65,71 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
* 获取关系数据
|
* 获取关系数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FileRelationViewVO listRelations (String id) {
|
@Transactional
|
||||||
|
public FileRelationViewVO listRelations(String startId) {
|
||||||
|
|
||||||
|
FileRelationViewVO fileRelationViewVO = new FileRelationViewVO();
|
||||||
|
|
||||||
|
List<Edge> visitedEdges = new ArrayList<>();
|
||||||
|
Set<String> visitedIds = new HashSet<>();
|
||||||
|
Set<String> uniqueRelationIds = new HashSet<>();
|
||||||
|
|
||||||
|
Queue<String> queue = new LinkedList<>();
|
||||||
|
|
||||||
|
// 初始化 BFS
|
||||||
|
queue.add(startId);
|
||||||
|
visitedIds.add(startId);
|
||||||
|
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
String currentId = queue.poll();
|
||||||
|
List<Edge> neighbors = getEdges(currentId);
|
||||||
|
|
||||||
|
for (Edge edge : neighbors) {
|
||||||
|
|
||||||
|
// 添加边信息
|
||||||
|
if (!uniqueRelationIds.contains(edge.getRelationId())) {
|
||||||
|
visitedEdges.add(edge);
|
||||||
|
uniqueRelationIds.add(edge.getRelationId());
|
||||||
|
}
|
||||||
|
// 如果目标节点未访问,记录边并继续搜索
|
||||||
|
if (!visitedIds.contains(edge.getTarget())) {
|
||||||
|
visitedIds.add(edge.getTarget()); // 标记目标节点为已访问
|
||||||
|
queue.add(edge.getTarget());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileRelationViewVO.setEdges(visitedEdges);
|
||||||
|
List<FileSimpleInfoVO> nodes = new ArrayList<>();
|
||||||
|
for (String id : visitedIds) {
|
||||||
|
FileSimpleInfoVO fileSimpleInfoVO = new FileSimpleInfoVO();
|
||||||
|
EdFileInfo fileInfo = edFileInfoMapper.selectById(id);
|
||||||
|
BeanUtils.copyProperties(fileInfo, fileSimpleInfoVO);
|
||||||
|
nodes.add(fileSimpleInfoVO);
|
||||||
|
}
|
||||||
|
fileRelationViewVO.setNodes(nodes);
|
||||||
|
return fileRelationViewVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Edge> getEdges(String id) {
|
||||||
LambdaQueryWrapper<EdFileRelation> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<EdFileRelation> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(EdFileRelation::getId1, id)
|
queryWrapper.eq(EdFileRelation::getId1, id)
|
||||||
.or()
|
.or()
|
||||||
.eq(EdFileRelation::getId2,id);
|
.eq(EdFileRelation::getId2, id);
|
||||||
List<EdFileRelation> list = this.list(queryWrapper);
|
List<EdFileRelation> list = this.list(queryWrapper);
|
||||||
List<FIleRelationVO> relationList = new ArrayList<>();
|
List<Edge> edges = new ArrayList<>();
|
||||||
for (EdFileRelation edFileRelation : list) {
|
for (EdFileRelation edFileRelation : list) {
|
||||||
FIleRelationVO fIleRelationVO = new FIleRelationVO();
|
|
||||||
fIleRelationVO.setRelationId(edFileRelation.getId());
|
|
||||||
fIleRelationVO.setRelationship(edFileRelation.getRelationship());
|
|
||||||
String queryId = "";
|
|
||||||
if (edFileRelation.getId1().equals(id)) {
|
if (edFileRelation.getId1().equals(id)) {
|
||||||
queryId = edFileRelation.getId2();
|
edges.add(new Edge(edFileRelation.getId1(), edFileRelation.getId2(),edFileRelation.getId(),edFileRelation.getRelationship()));
|
||||||
} else {
|
} else {
|
||||||
queryId = edFileRelation.getId1();
|
edges.add(new Edge(edFileRelation.getId2(), edFileRelation.getId1(),edFileRelation.getId(),edFileRelation.getRelationship()));
|
||||||
}
|
}
|
||||||
EdFileInfo info = edFileInfoMapper.selectById(queryId);
|
|
||||||
FileSimpleInfoVO fileSimpleInfoVO = new FileSimpleInfoVO();
|
|
||||||
BeanUtils.copyProperties(info, fileSimpleInfoVO);
|
|
||||||
fIleRelationVO.setRelatedFile(fileSimpleInfoVO);
|
|
||||||
relationList.add(fIleRelationVO);
|
|
||||||
}
|
}
|
||||||
|
return edges;
|
||||||
FileRelationViewVO fileRelationViewVO = new FileRelationViewVO();
|
|
||||||
fileRelationViewVO.setRelationList(relationList);
|
|
||||||
|
|
||||||
EdFileInfo info = edFileInfoMapper.selectById(id);
|
|
||||||
FileSimpleInfoVO fileSimpleInfoVO = new FileSimpleInfoVO();
|
|
||||||
BeanUtils.copyProperties(info, fileSimpleInfoVO);
|
|
||||||
fileRelationViewVO.setFile(fileSimpleInfoVO);
|
|
||||||
|
|
||||||
return fileRelationViewVO;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue