diff --git a/controller/GraphController.py b/controller/GraphController.py index 2c4b897..2ef848b 100644 --- a/controller/GraphController.py +++ b/controller/GraphController.py @@ -1,5 +1,6 @@ import json import sys +import traceback from datetime import datetime import httpx @@ -84,6 +85,27 @@ def get_data(): ) except Exception as e: return jsonify({"error": str(e)}), 500 +@app.get("/api/getCount") +def get_data(): + try: + diseaselen = neo4j_client.count_nodes_by_label(label="Disease") + druglen = neo4j_client.count_nodes_by_label(label="Drug") + checklen = neo4j_client.count_nodes_by_label(label="Check") + data={ + "Disease":diseaselen, + "Drug":druglen, + "Check":checklen + } + + return Response( + status_code=200, + description=jsonify(data), + headers={"Content-Type": "text/plain; charset=utf-8"} + ) + except Exception as e: + error_trace = traceback.format_exc() + print(error_trace) + return jsonify({"error": str(e)}), 500 @app.post("/api/getGraph") def get_graph(req): try: @@ -110,6 +132,7 @@ def get_graph(req): return jsonify({"error": str(e)}), 500 @app.get("/api/drug-tree") def get_drug_tree(): + print(redis_get(DRUG_TREE_KEY)) return Response( status_code=200, description=redis_get(DRUG_TREE_KEY), diff --git a/util/neo4j_utils.py b/util/neo4j_utils.py index 0546253..69608b0 100644 --- a/util/neo4j_utils.py +++ b/util/neo4j_utils.py @@ -103,6 +103,12 @@ class Neo4jUtil: raw = self.execute_read(cypher) return [self._merge_id_and_props(row) for row in raw] + def count_nodes_by_label(self, label: str) -> int: + """返回指定标签的节点数量""" + # 安全校验(强烈建议保留) + cypher = f"MATCH (n:`{label}`) RETURN count(n) AS total" + result = self.execute_read(cypher) + return result[0]["total"] # Neo4j 返回结果通常是列表,取第一个记录 from typing import Optional, Dict, Any, List def find_nodes_with_element_id( diff --git a/vue/node_modules/.package-lock.json b/vue/node_modules/.package-lock.json index c5e5655..574f52d 100644 --- a/vue/node_modules/.package-lock.json +++ b/vue/node_modules/.package-lock.json @@ -7915,6 +7915,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/fuse.js": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.1.0.tgz", + "integrity": "sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==", + "engines": { + "node": ">=10" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmmirror.com/gensync/-/gensync-1.0.0-beta.2.tgz", diff --git a/vue/package-lock.json b/vue/package-lock.json index b7fb9a2..efbe5d0 100644 --- a/vue/package-lock.json +++ b/vue/package-lock.json @@ -12,6 +12,7 @@ "axios": "^1.13.2", "core-js": "^3.8.3", "element-plus": "^2.13.0", + "fuse.js": "^7.1.0", "vue": "^3.2.13", "vue-router": "^4.6.4" }, @@ -7957,6 +7958,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/fuse.js": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.1.0.tgz", + "integrity": "sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==", + "engines": { + "node": ">=10" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmmirror.com/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -19214,6 +19223,11 @@ "resolved": "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==" }, + "fuse.js": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.1.0.tgz", + "integrity": "sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==" + }, "gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmmirror.com/gensync/-/gensync-1.0.0-beta.2.tgz", diff --git a/vue/package.json b/vue/package.json index 4370f1f..2363896 100644 --- a/vue/package.json +++ b/vue/package.json @@ -12,6 +12,7 @@ "axios": "^1.13.2", "core-js": "^3.8.3", "element-plus": "^2.13.0", + "fuse.js": "^7.1.0", "vue": "^3.2.13", "vue-router": "^4.6.4" }, diff --git a/vue/src/api/graph.js b/vue/src/api/graph.js index e048c2f..54eba8e 100644 --- a/vue/src/api/graph.js +++ b/vue/src/api/graph.js @@ -13,7 +13,13 @@ export function getTestGraphData() { }); } +export function getCount() { + return request({ + url: '/api/getCount', + method: 'get' + }); +} export function getGraph(data) { return request({ url: '/api/getGraph', diff --git a/vue/src/system/GraphDemo.vue b/vue/src/system/GraphDemo.vue index 0e36d34..5113f2c 100644 --- a/vue/src/system/GraphDemo.vue +++ b/vue/src/system/GraphDemo.vue @@ -7,8 +7,8 @@
- - + +
@@ -33,7 +33,9 @@ 药品信息 检查信息
-
12种
+
{{diseaseCount.toLocaleString()}}种
+
{{ drugCount.toLocaleString() }}种
+
{{checkCount.toLocaleString()}}种
@@ -57,6 +59,7 @@ @@ -82,11 +85,12 @@