From 0d994fffe2528e515f7c96dc8eb219eed4d77247 Mon Sep 17 00:00:00 2001 From: icanci Date: Thu, 21 Sep 2023 21:09:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BA=A0=E5=AF=9F=E5=9B=BE=E5=85=A8?= =?UTF-8?q?=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/bic-config/dialog/node-vue-form.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/views/src/main/resources/vueboot/src/views/bic-config/dialog/node-vue-form.vue b/views/src/main/resources/vueboot/src/views/bic-config/dialog/node-vue-form.vue index 1e2588f..2c99245 100644 --- a/views/src/main/resources/vueboot/src/views/bic-config/dialog/node-vue-form.vue +++ b/views/src/main/resources/vueboot/src/views/bic-config/dialog/node-vue-form.vue @@ -7,9 +7,14 @@ :visible.sync="dialogVisible" :close-on-press-escape="false" :close-on-click-modal="false" + :fullscreen="fullScreen" width="80%" :before-close="clearForm"> - + +
+ 节点组件配置 + +
Date: Fri, 22 Sep 2023 22:00:01 +0800 Subject: [PATCH 2/2] GraphAdapter --- .../bic/biz/adapter/GraphAdapter.java | 21 ++++ .../bic/biz/adapter/GraphAdapterService.java | 95 +++++++++++++++++++ .../bic/biz/cache/GraphRepository.java | 4 + .../biz/exception/GraphAdapterException.java | 27 ++++++ .../bic/biz/service/EdgeStyleService.java | 2 + .../biz/service/UnitViewSnapshotService.java | 2 + .../service/impl/EdgeStyleServiceImpl.java | 5 + .../biz/service/impl/SnapshotServiceImpl.java | 19 +++- .../impl/UnitViewSnapshotServiceImpl.java | 9 ++ .../dal/mongo/daointerface/EdgeStyleDAO.java | 2 + .../daointerface/UnitViewSnapshotDAO.java | 2 + .../dal/mongo/mongo/MongoEdgeStyleDAO.java | 8 ++ .../mongo/mongo/MongoUnitViewSnapshotDAO.java | 10 ++ .../cn/icanci/loopstack/bic/graph/Graph.java | 21 ++++ .../loopstack/bic/graph/UnitViewGraph.java | 19 ++++ 15 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapter.java create mode 100644 biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapterService.java create mode 100644 biz/src/main/java/cn/icanci/loopstack/bic/biz/exception/GraphAdapterException.java create mode 100644 graph/src/main/java/cn/icanci/loopstack/bic/graph/Graph.java create mode 100644 graph/src/main/java/cn/icanci/loopstack/bic/graph/UnitViewGraph.java diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapter.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapter.java new file mode 100644 index 0000000..ff41c72 --- /dev/null +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapter.java @@ -0,0 +1,21 @@ +package cn.icanci.loopstack.bic.biz.adapter; + +import cn.icanci.loopstack.bic.graph.Graph; + +/** + * 本地缓存唯一Key + * + * @author icanci + * @since 1.0 Created in 2023/09/21 10:48 + */ +public interface GraphAdapter { + + /** + * 获取图 + * + * @param systemUuid 系统唯一标识 + * @param useCaseUuid 用例唯一标识 + * @return 图 + */ + Graph graph(String systemUuid, String useCaseUuid); +} diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapterService.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapterService.java new file mode 100644 index 0000000..3c151b9 --- /dev/null +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/adapter/GraphAdapterService.java @@ -0,0 +1,95 @@ +package cn.icanci.loopstack.bic.biz.adapter; + +import java.util.List; +import java.util.Optional; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import com.google.common.collect.Lists; + +import cn.icanci.loopstack.bic.biz.exception.GraphAdapterException; +import cn.icanci.loopstack.bic.biz.service.EdgeStyleService; +import cn.icanci.loopstack.bic.biz.service.NodeService; +import cn.icanci.loopstack.bic.biz.service.NodeStyleService; +import cn.icanci.loopstack.bic.biz.service.UnitViewService; +import cn.icanci.loopstack.bic.common.model.base.EdgeStyleVO; +import cn.icanci.loopstack.bic.common.model.graph.UnitEdgeVO; +import cn.icanci.loopstack.bic.common.model.graph.UnitNodeVO; +import cn.icanci.loopstack.bic.common.model.graph.UnitViewVO; +import cn.icanci.loopstack.bic.graph.Graph; +import cn.icanci.loopstack.bic.graph.edge.Edge; +import cn.icanci.loopstack.bic.graph.node.Node; + +/** + * @author icanci + * @since 1.0 Created in 2023/09/22 20:46 + */ +@Service +public class GraphAdapterService implements GraphAdapter { + @Resource + private UnitViewService unitViewService; + @Resource + private NodeService nodeService; + @Resource + private NodeStyleService nodeStyleService; + @Resource + private EdgeStyleService edgeStyleService; + + @Override + public Graph graph(String systemUuid, String useCaseUuid) { + // 查询结构图 + UnitViewVO unitView = unitViewService.queryBySystemUuidAndUseCaseUuid(systemUuid, useCaseUuid); + if (unitView == null) { + throw new GraphAdapterException("纠察图不存在"); + } + List edges = unitView.getEdges(); + List nodes = unitView.getNodes(); + return new Graph(adapterEdges(edges), adapterNodes(nodes)); + } + + private List adapterNodes(List nodes) { + List retNodes = Lists.newArrayList(); + for (UnitNodeVO node : nodes) { + retNodes.add(buildNode(node)); + } + return retNodes; + } + + private Node buildNode(UnitNodeVO node) { + Node retNode = new Node(); +// retNode.setId(); +// retNode.setShape(); +// retNode.setWidth(); +// retNode.setHeight(); +// retNode.setAttrs(); + return retNode; + } + + private List adapterEdges(List edges) { + List retEdges = Lists.newArrayList(); + for (UnitEdgeVO edge : edges) { + retEdges.add(buildEdge(edge)); + } + return retEdges; + } + + private Edge buildEdge(UnitEdgeVO edge) { + String styleUuid = edge.getStyleUuid(); + // TODO 查询样式 + String edgeStyle = Optional.ofNullable(edgeStyleService.queryByUuid(styleUuid)).map(EdgeStyleVO::getEdgeStyle).orElse(edgeStyleService.loadDefaultStyle()); + + Edge retEdge = new Edge(); +// retEdge.setSource(); +// retEdge.setTarget(); +// retEdge.setAttrs(); +// retEdge.setRouter(); +// retEdge.setConnector(); +// retEdge.setLabels(); +// retEdge.setConsumerInfo(); +// retEdge.setHistoryInfo(); + return retEdge; + + } +} diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/cache/GraphRepository.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/cache/GraphRepository.java index b2ac98d..c6597c7 100644 --- a/biz/src/main/java/cn/icanci/loopstack/bic/biz/cache/GraphRepository.java +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/cache/GraphRepository.java @@ -19,6 +19,10 @@ public final class GraphRepository implements ApplicationContextAware { } private void doGraphRepositoryReload() { + // TODO 加载所有缓存 + } + + public void refresh(String systemUuid, String useCaseUuid) { // TODO 刷新缓存 } } diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/exception/GraphAdapterException.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/exception/GraphAdapterException.java new file mode 100644 index 0000000..2b9f315 --- /dev/null +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/exception/GraphAdapterException.java @@ -0,0 +1,27 @@ +package cn.icanci.loopstack.bic.biz.exception; + +/** + * @author icanci + * @since 1.0 Created in 2023/09/22 21:46 + */ +public class GraphAdapterException extends RuntimeException { + public GraphAdapterException() { + super(); + } + + public GraphAdapterException(String message) { + super(message); + } + + public GraphAdapterException(String message, Throwable cause) { + super(message, cause); + } + + public GraphAdapterException(Throwable cause) { + super(cause); + } + + protected GraphAdapterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/EdgeStyleService.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/EdgeStyleService.java index ec533c0..34a7254 100644 --- a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/EdgeStyleService.java +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/EdgeStyleService.java @@ -30,4 +30,6 @@ public interface EdgeStyleService extends BaseService { List loadSelector(String systemUuid); String loadDefaultStyle(); + + EdgeStyleVO queryByUuid(String uuid); } diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/UnitViewSnapshotService.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/UnitViewSnapshotService.java index 2c26e5e..476f14b 100644 --- a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/UnitViewSnapshotService.java +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/UnitViewSnapshotService.java @@ -24,4 +24,6 @@ public interface UnitViewSnapshotService extends BaseService UnitViewSnapshotVO queryBySystemUuidAndUseCaseUuid(String systemUuid, String useCaseUuid); + UnitViewSnapshotVO queryBySystemUuidAndUseCaseUuidAndVersion(String systemUuid, String useCaseUuid, long version); + } diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/EdgeStyleServiceImpl.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/EdgeStyleServiceImpl.java index d632b07..2ac95a9 100644 --- a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/EdgeStyleServiceImpl.java +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/EdgeStyleServiceImpl.java @@ -99,4 +99,9 @@ public class EdgeStyleServiceImpl implements EdgeStyleService { public String loadDefaultStyle() { return TemplateFileUtils.queryDefaultEdgeStyleTemplate(); } + + @Override + public EdgeStyleVO queryByUuid(String uuid) { + return edgeStyleMapper.do2vo(edgeStyleDAO.queryByUuid(uuid)); + } } diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/SnapshotServiceImpl.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/SnapshotServiceImpl.java index f9c9377..5acb2f4 100644 --- a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/SnapshotServiceImpl.java +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/SnapshotServiceImpl.java @@ -4,10 +4,14 @@ import javax.annotation.Resource; import org.springframework.stereotype.Service; +import cn.hutool.json.JSONUtil; +import cn.icanci.loopstack.bic.biz.adapter.GraphAdapter; import cn.icanci.loopstack.bic.biz.service.SnapshotService; import cn.icanci.loopstack.bic.biz.service.UnitViewSnapshotIndexService; import cn.icanci.loopstack.bic.biz.service.UnitViewSnapshotService; import cn.icanci.loopstack.bic.common.model.snapshot.UnitViewSnapshotIndexVO; +import cn.icanci.loopstack.bic.common.model.snapshot.UnitViewSnapshotVO; +import cn.icanci.loopstack.bic.graph.Graph; /** * 快照服务 @@ -21,13 +25,24 @@ public class SnapshotServiceImpl implements SnapshotService { private UnitViewSnapshotService unitViewSnapshotService; @Resource private UnitViewSnapshotIndexService unitViewSnapshotIndexService; + @Resource + private GraphAdapter graphAdapter; // TODO 数据一致性问题 @Override public void refresh(String systemUuid, String useCaseUuid) { long version = refreshSnapshotIndex(systemUuid, useCaseUuid); - // TODO 构建数据模型 - // TODO 更新内存构建缓存 + Graph graph = graphAdapter.graph(systemUuid, useCaseUuid); + String snapshot = JSONUtil.toJsonStr(graph); + UnitViewSnapshotVO unitViewSnapshot = unitViewSnapshotService.queryBySystemUuidAndUseCaseUuid(systemUuid, useCaseUuid); + if (unitViewSnapshot == null) { + unitViewSnapshot = new UnitViewSnapshotVO(); + unitViewSnapshot.setSystemUuid(systemUuid); + unitViewSnapshot.setUseCaseUuid(useCaseUuid); + } + unitViewSnapshot.setVersion(version); + unitViewSnapshot.setSnapshot(snapshot); + unitViewSnapshotService.save(unitViewSnapshot); } /** diff --git a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/UnitViewSnapshotServiceImpl.java b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/UnitViewSnapshotServiceImpl.java index 7373270..478a3df 100644 --- a/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/UnitViewSnapshotServiceImpl.java +++ b/biz/src/main/java/cn/icanci/loopstack/bic/biz/service/impl/UnitViewSnapshotServiceImpl.java @@ -6,6 +6,7 @@ import javax.annotation.Resource; import org.springframework.stereotype.Service; +import cn.icanci.loopstack.bic.biz.cache.GraphRepository; import cn.icanci.loopstack.bic.biz.mapper.UnitViewSnapshotMapper; import cn.icanci.loopstack.bic.biz.service.UnitViewSnapshotService; import cn.icanci.loopstack.bic.common.model.snapshot.UnitViewSnapshotVO; @@ -24,6 +25,8 @@ public class UnitViewSnapshotServiceImpl implements UnitViewSnapshotService { private UnitViewSnapshotDAO unitViewSnapshotDAO; @Resource private UnitViewSnapshotMapper unitViewSnapshotMapper; + @Resource + private GraphRepository graphRepository; @Override public List queryAll() { @@ -39,6 +42,7 @@ public class UnitViewSnapshotServiceImpl implements UnitViewSnapshotService { } else { unitViewSnapshotDAO.update(unitViewSnapshotMapper.vo2do(unitViewSnapshotVO)); } + graphRepository.refresh(unitViewSnapshotVO.getSystemUuid(), unitViewSnapshotVO.getUseCaseUuid()); } @Override @@ -57,4 +61,9 @@ public class UnitViewSnapshotServiceImpl implements UnitViewSnapshotService { public UnitViewSnapshotVO queryBySystemUuidAndUseCaseUuid(String systemUuid, String useCaseUuid) { return unitViewSnapshotMapper.do2vo(unitViewSnapshotDAO.queryBySystemUuidAndUseCaseUuid(systemUuid, useCaseUuid)); } + + @Override + public UnitViewSnapshotVO queryBySystemUuidAndUseCaseUuidAndVersion(String systemUuid, String useCaseUuid, long version) { + return unitViewSnapshotMapper.do2vo(unitViewSnapshotDAO.queryBySystemUuidAndUseCaseUuidAndVersion(systemUuid, useCaseUuid, version)); + } } diff --git a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/EdgeStyleDAO.java b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/EdgeStyleDAO.java index 3f20432..7252c0e 100644 --- a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/EdgeStyleDAO.java +++ b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/EdgeStyleDAO.java @@ -16,6 +16,8 @@ public interface EdgeStyleDAO extends BaseDAO { EdgeStyleDO queryBySystemUuidAndKey(String systemUuid, String key); + EdgeStyleDO queryByUuid(String uuid); + /** 列 */ interface EdgeStyleColumn extends BaseColumn { String SYSTEM_UUID = "systemUuid"; diff --git a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/UnitViewSnapshotDAO.java b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/UnitViewSnapshotDAO.java index 3c483c5..b786411 100644 --- a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/UnitViewSnapshotDAO.java +++ b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/daointerface/UnitViewSnapshotDAO.java @@ -14,6 +14,8 @@ public interface UnitViewSnapshotDAO extends BaseDAO { UnitViewSnapshotDO queryBySystemUuidAndUseCaseUuid(String systemUuid, String useCaseUuid); + UnitViewSnapshotDO queryBySystemUuidAndUseCaseUuidAndVersion(String systemUuid, String useCaseUuid, long version); + /** 列 */ interface UnitViewSnapshotColumn extends BaseColumn { String SYSTEM_UUID = "systemUuid"; diff --git a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoEdgeStyleDAO.java b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoEdgeStyleDAO.java index ba7af7e..f2ee5c6 100644 --- a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoEdgeStyleDAO.java +++ b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoEdgeStyleDAO.java @@ -90,4 +90,12 @@ public class MongoEdgeStyleDAO extends AbstractBaseDAO implements E return mongoTemplate.findOne(query, COLLECTION_CLASS, COLLECTION_NAME); } + + @Override + public EdgeStyleDO queryByUuid(String uuid) { + Criteria criteria = Criteria.where(EdgeStyleColumn.UUID).is(uuid); + criteria.and(EdgeStyleColumn.ENV).is(DEFAULT_ENV); + Query query = new Query(criteria); + return mongoTemplate.findOne(query, COLLECTION_CLASS, COLLECTION_NAME); + } } diff --git a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoUnitViewSnapshotDAO.java b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoUnitViewSnapshotDAO.java index f01339c..b0a27cc 100644 --- a/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoUnitViewSnapshotDAO.java +++ b/dal/src/main/java/cn/icanci/loopstack/bic/dal/mongo/mongo/MongoUnitViewSnapshotDAO.java @@ -72,4 +72,14 @@ public class MongoUnitViewSnapshotDAO extends AbstractBaseDAO edges; + /** 节点 */ + List nodes; +} diff --git a/graph/src/main/java/cn/icanci/loopstack/bic/graph/UnitViewGraph.java b/graph/src/main/java/cn/icanci/loopstack/bic/graph/UnitViewGraph.java new file mode 100644 index 0000000..b028b54 --- /dev/null +++ b/graph/src/main/java/cn/icanci/loopstack/bic/graph/UnitViewGraph.java @@ -0,0 +1,19 @@ +package cn.icanci.loopstack.bic.graph; + +import java.util.List; + +import cn.icanci.loopstack.bic.graph.edge.Edge; +import cn.icanci.loopstack.bic.graph.node.UnitViewNode; +import lombok.Data; + +/** + * @author icanci + * @since 1.0 Created in 2023/09/22 20:45 + */ +@Data +public class UnitViewGraph { + /** 边 */ + List edges; + /** 节点 */ + List nodes; +} -- Gitee