|
|
|
@ -63,11 +63,21 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
def select_tree(self, entity_id: int, name: str = "") -> List[Dict[str, Any]]:
|
|
|
|
|
roots = []
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
sql = "select id, name, suid from enterprise_node where entity_id=:entity_id and del=0 and parent=0 "
|
|
|
|
|
# sql = "select id, name, suid, parent from enterprise_node where entity_id=:entity_id and del=0 and parent=0 "
|
|
|
|
|
|
|
|
|
|
sql = (
|
|
|
|
|
"""
|
|
|
|
|
SELECT
|
|
|
|
|
n.id, n.name, n.parent, p.name AS parent_name, n.suid
|
|
|
|
|
FROM enterprise_node n
|
|
|
|
|
LEFT JOIN enterprise_node p ON n.parent = p.id
|
|
|
|
|
WHERE n.entity_id=:entity_id AND n.del=0 and n.parent=0
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
param = {"entity_id": entity_id}
|
|
|
|
|
|
|
|
|
|
if name:
|
|
|
|
|
sql += " and name like :name"
|
|
|
|
|
sql += " and n.name like :name"
|
|
|
|
|
param["name"] = f"%{name}%"
|
|
|
|
|
|
|
|
|
|
res = session.execute(text(sql), param)
|
|
|
|
@ -78,6 +88,8 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
"id": node["id"],
|
|
|
|
|
"name": node["name"],
|
|
|
|
|
"suid": node["suid"],
|
|
|
|
|
"parent": node["parent"],
|
|
|
|
|
"parent_name": node["parent_name"],
|
|
|
|
|
"children": self.build_tree(session, node, name),
|
|
|
|
|
}
|
|
|
|
|
roots.append(root)
|
|
|
|
@ -87,13 +99,24 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
def build_tree(
|
|
|
|
|
self, session: Any, node: Dict[str, Any], name: str = ""
|
|
|
|
|
) -> List[Any]:
|
|
|
|
|
# sql = (
|
|
|
|
|
# "select id, name, suid, parent from enterprise_node where del=0 and parent=:parent"
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
|
sql = (
|
|
|
|
|
"select id, name, suid from enterprise_node where del=0 and parent=:parent"
|
|
|
|
|
"""
|
|
|
|
|
SELECT
|
|
|
|
|
n.id, n.name, n.parent, p.name AS parent_name, n.suid
|
|
|
|
|
FROM enterprise_node n
|
|
|
|
|
LEFT JOIN enterprise_node p ON n.parent = p.id
|
|
|
|
|
WHERE n.parent=:parent AND n.del=0
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
param = {"parent": node["id"]}
|
|
|
|
|
|
|
|
|
|
if name:
|
|
|
|
|
sql += " and name like :name"
|
|
|
|
|
sql += " and n.name like :name"
|
|
|
|
|
param["name"] = f"%{name}%"
|
|
|
|
|
|
|
|
|
|
res = session.execute(text(sql), param)
|
|
|
|
@ -105,6 +128,8 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
"id": node["id"],
|
|
|
|
|
"name": node["name"],
|
|
|
|
|
"suid": node["suid"],
|
|
|
|
|
"parent": node["parent"],
|
|
|
|
|
"parent_name": node["parent_name"],
|
|
|
|
|
"children": self.build_tree(session, node, name),
|
|
|
|
|
}
|
|
|
|
|
children.append(child)
|
|
|
|
@ -113,9 +138,18 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
"""
|
|
|
|
|
SELECT
|
|
|
|
|
n.id, n.name, n.parent, p.name AS parent_name, n.addr, n.lola, n.contact, n.phone, n.comment, n.suid
|
|
|
|
|
FROM enterprise_node n
|
|
|
|
|
LEFT JOIN enterprise_node p ON n.parent = p.id
|
|
|
|
|
WHERE n.id=:id AND n.del=0
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
param = {"id": node_id}
|
|
|
|
|
res = session.execute(text(sql), param)
|
|
|
|
@ -128,6 +162,7 @@ class EnterpriseNodeRepository(object):
|
|
|
|
|
sql = "update enterprise_node set del=1 where id=:id"
|
|
|
|
|
param = {"id": node_id}
|
|
|
|
|
session.execute(text(sql), param)
|
|
|
|
|
session.commit()
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def get_node_by_id(self, node_id: int) -> dict:
|
|
|
|
|