Compare commits
No commits in common. "7151243618a0d13189da032879830be43f95f068" and "dd13bf76e3763c2e9431ebe36cc9aa7ab530fdfa" have entirely different histories.
7151243618
...
dd13bf76e3
|
|
@ -1,40 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.models;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Getter
|
|
||||||
public class Edge {
|
|
||||||
String source; // 起点
|
|
||||||
String target; // 终点
|
|
||||||
|
|
||||||
public Edge(String source, String target) {
|
|
||||||
this.source = source;
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return source + " -- " + target;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) return true;
|
|
||||||
if (obj == null || getClass() != obj.getClass()) return false;
|
|
||||||
Edge edge = (Edge) obj;
|
|
||||||
// 无向边,两个方向都相等即认为是同一条边
|
|
||||||
return (Objects.equals(source, edge.source) && Objects.equals(target, edge.target)) ||
|
|
||||||
(Objects.equals(source, edge.target) && Objects.equals(target, edge.source));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
// 无向边需要对 source 和 target 排序后计算哈希值
|
|
||||||
return Objects.hash(Math.min(source.hashCode(), target.hashCode()),
|
|
||||||
Math.max(source.hashCode(), target.hashCode()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
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,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -9,12 +8,12 @@ import java.util.List;
|
||||||
public class FileRelationViewVO {
|
public class FileRelationViewVO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联文件
|
* 主文件
|
||||||
*/
|
*/
|
||||||
List<FileSimpleInfoVO> nodes;
|
private FileSimpleInfoVO file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 边
|
* 关联文件关系列表
|
||||||
*/
|
*/
|
||||||
List<Edge> edges;
|
List<FIleRelationVO> relationList;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,6 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
public class FileSimpleInfoVO {
|
public class FileSimpleInfoVO {
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键id
|
|
||||||
*/
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件名称
|
* 文件名称
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ 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.models.Edge;
|
import com.electromagnetic.industry.software.manage.pojo.resp.FIleRelationVO;
|
||||||
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;
|
||||||
|
|
@ -18,7 +18,8 @@ import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper, EdFileRelation> implements EdFileRelationService {
|
public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper, EdFileRelation> implements EdFileRelationService {
|
||||||
|
|
@ -64,69 +65,38 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
* 获取关系数据
|
* 获取关系数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FileRelationViewVO listRelations(String startId) {
|
public FileRelationViewVO listRelations (String id) {
|
||||||
|
|
||||||
FileRelationViewVO fileRelationViewVO = new FileRelationViewVO();
|
|
||||||
|
|
||||||
List<Edge> visitedEdges = new ArrayList<>();
|
|
||||||
Set<String> visitedIds = new HashSet<>();
|
|
||||||
Set<Edge> uniqueEdges = 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 (!uniqueEdges.contains(edge)) {
|
|
||||||
visitedEdges.add(edge);
|
|
||||||
uniqueEdges.add(edge);
|
|
||||||
}
|
|
||||||
// 如果目标节点未访问,记录边并继续搜索
|
|
||||||
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<Edge> edges = new ArrayList<>();
|
List<FIleRelationVO> relationList = 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)) {
|
||||||
edges.add(new Edge(edFileRelation.getId1(), edFileRelation.getId2()));
|
queryId = edFileRelation.getId2();
|
||||||
} else {
|
} else {
|
||||||
edges.add(new Edge(edFileRelation.getId2(), edFileRelation.getId1()));
|
queryId = edFileRelation.getId1();
|
||||||
}
|
}
|
||||||
|
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