|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
from typing import List, Dict, Any
|
|
|
|
|
from typing import List, Dict, Any, Union
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
|
|
|
|
@ -33,16 +33,20 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
"insert into "
|
|
|
|
|
"enterprise_node(suid, entity_id, entity_suid, name, parent, addr, lola, contact, phone, comment) "
|
|
|
|
|
"values (:suid, :entity_id, :entity_suid, :name, :parent, :addr, :lola, :contact, :phone, :comment)"
|
|
|
|
|
), node)
|
|
|
|
|
),
|
|
|
|
|
node,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# last_insert_id = session.execute(text("SELECT LAST_INSERT_ID()")).scalar()
|
|
|
|
|
# logging.info(f"last_insert_id: {last_insert_id}")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_node(self, node: dict) -> int:
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
sql = ("update enterprise_node "
|
|
|
|
|
"set name=:name, parent=:parent, addr=:addr, lola=:lola, contact=:contact, phone=:phone, comment=:comment where id=:id")
|
|
|
|
|
sql = (
|
|
|
|
|
"update enterprise_node "
|
|
|
|
|
"set name=:name, parent=:parent, addr=:addr, lola=:lola, contact=:contact, phone=:phone, comment=:comment where id=:id"
|
|
|
|
|
)
|
|
|
|
|
param = {
|
|
|
|
|
"id": node["id"],
|
|
|
|
|
"name": node["name"],
|
|
|
|
@ -51,8 +55,8 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
"lola": node["lola"],
|
|
|
|
|
"contact": node["contact"],
|
|
|
|
|
"phone": node["phone"],
|
|
|
|
|
"comment": node["comment"]
|
|
|
|
|
}
|
|
|
|
|
"comment": node["comment"],
|
|
|
|
|
}
|
|
|
|
|
session.execute(text(sql), param)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
@ -74,14 +78,18 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
"id": node["id"],
|
|
|
|
|
"name": node["name"],
|
|
|
|
|
"suid": node["suid"],
|
|
|
|
|
"children": self.build_tree(session, node, name)
|
|
|
|
|
"children": self.build_tree(session, node, name),
|
|
|
|
|
}
|
|
|
|
|
roots.append(root)
|
|
|
|
|
# return node_list
|
|
|
|
|
return roots
|
|
|
|
|
|
|
|
|
|
def build_tree(self, session: Any, node: Dict[str, Any], name: str = "") -> List[Any]:
|
|
|
|
|
sql = "select id, name, suid from enterprise_node where del=0 and parent=:parent"
|
|
|
|
|
def build_tree(
|
|
|
|
|
self, session: Any, node: Dict[str, Any], name: str = ""
|
|
|
|
|
) -> List[Any]:
|
|
|
|
|
sql = (
|
|
|
|
|
"select id, name, suid from enterprise_node where del=0 and parent=:parent"
|
|
|
|
|
)
|
|
|
|
|
param = {"parent": node["id"]}
|
|
|
|
|
|
|
|
|
|
if name:
|
|
|
|
@ -97,17 +105,18 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
"id": node["id"],
|
|
|
|
|
"name": node["name"],
|
|
|
|
|
"suid": node["suid"],
|
|
|
|
|
"children": self.build_tree(session, node, name)
|
|
|
|
|
"children": self.build_tree(session, node, name),
|
|
|
|
|
}
|
|
|
|
|
children.append(child)
|
|
|
|
|
|
|
|
|
|
return children
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def select_node(self, node_id: int) -> Dict[str, Any]:
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
sql = ("select id, name, parent, addr, lola, contact, phone, comment, suid from enterprise_node "
|
|
|
|
|
"where id=:id and del=0")
|
|
|
|
|
sql = (
|
|
|
|
|
"select id, name, parent, addr, lola, contact, phone, comment, suid from enterprise_node "
|
|
|
|
|
"where id=:id and del=0"
|
|
|
|
|
)
|
|
|
|
|
param = {"id": node_id}
|
|
|
|
|
res = session.execute(text(sql), param)
|
|
|
|
|
node_list = to_json_list(res)
|
|
|
|
@ -116,23 +125,25 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
|
|
|
|
|
def delete_node(self, node_id: int) -> int:
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
sql = ("update enterprise_node set del=1 where id=:id")
|
|
|
|
|
sql = "update enterprise_node set del=1 where id=:id"
|
|
|
|
|
param = {"id": node_id}
|
|
|
|
|
session.execute(text(sql), param)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_node_by_id(self, node_id: int) -> dict:
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
sql = ("select suid, name from enterprise_node where id=:id")
|
|
|
|
|
sql = "select suid, name from enterprise_node where id=:id"
|
|
|
|
|
param = {"id": node_id}
|
|
|
|
|
res = session.execute(text(sql), param)
|
|
|
|
|
node = to_json(res)
|
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
|
def get_entity_suid_by_node_id(self, node_id: int) -> dict | None:
|
|
|
|
|
|
|
|
|
|
def get_entity_suid_by_node_id(self, node_id: int) -> Union[dict, None]:
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
res = session.execute(text("select entity_suid from enterprise_node where id=:id"),
|
|
|
|
|
{"id": node_id})
|
|
|
|
|
res = session.execute(
|
|
|
|
|
text("select entity_suid from enterprise_node where id=:id"),
|
|
|
|
|
{"id": node_id},
|
|
|
|
|
)
|
|
|
|
|
entity = to_json(res)
|
|
|
|
|
|
|
|
|
|
return entity if entity else None
|
|
|
|
|
|
|
|
|
|
return entity if entity else None
|
|
|
|
|