|
|
@ -1,6 +1,7 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import copy
|
|
|
|
import copy
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
from sqlalchemy import Column, Integer, String, DateTime, func
|
|
|
|
from sqlalchemy import Column, Integer, String, DateTime, func
|
|
|
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
|
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
|
@ -48,22 +49,22 @@ CREATE TABLE `enterprise_busi_model_node` (
|
|
|
|
class EnterpriseBusiModel(Base):
|
|
|
|
class EnterpriseBusiModel(Base):
|
|
|
|
__tablename__ = 'enterprise_busi_model'
|
|
|
|
__tablename__ = 'enterprise_busi_model'
|
|
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
suid = Column(String(10), nullable=False, default='')
|
|
|
|
suid = Column(String(10), nullable=False, default='', comment='short uuid')
|
|
|
|
entity_id = Column(Integer, nullable=False)
|
|
|
|
entity_id = Column(Integer, nullable=False, comment='企业id')
|
|
|
|
entity_suid = Column(String(10), nullable=False)
|
|
|
|
entity_suid = Column(String(10), nullable=False, comment='企业uuid')
|
|
|
|
name = Column(String(255), nullable=False)
|
|
|
|
name = Column(String(255), nullable=False)
|
|
|
|
comment = Column(String(255))
|
|
|
|
comment = Column(String(255), nullable=True, default='')
|
|
|
|
basemodel_ids = Column(String(255), nullable=False)
|
|
|
|
base_models = Column(String(255), nullable=False, comment='关联的基础模型,json list, [{"id":123,"suid":"xxx"},...]')
|
|
|
|
business_logic = Column(String(32))
|
|
|
|
business_logic = Column(String(32), nullable=True, comment='业务代码压缩包的md5')
|
|
|
|
business_conf_file = Column(String(32))
|
|
|
|
business_conf_file = Column(String(32), nullable=True, comment='业务配置参数压缩包的文件md5')
|
|
|
|
business_conf_param = Column(String(255))
|
|
|
|
business_conf_param = Column(String(255), nullable=True, comment='业务配置的参数,json字符串,eg: ''{"a":1, "b":2}''')
|
|
|
|
delete = Column(Integer, default=0)
|
|
|
|
delete = Column(Integer, default=0)
|
|
|
|
create_time = Column(DateTime, default=func.current_timestamp())
|
|
|
|
create_time = Column(DateTime, nullable=False, default=func.now(), onupdate=func.now())
|
|
|
|
update_time = Column(DateTime, default=func.current_timestamp(), onupdate=func.current_timestamp())
|
|
|
|
update_time = Column(DateTime, nullable=False, default=func.now(), onupdate=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
def __repr__(self):
|
|
|
|
return f'<EnterpriseBusiModel(id={self.id}, suid={self.suid})>'
|
|
|
|
return f"EnterpriseBusiModel(id={self.id}, suid='{self.suid}', name='{self.name}')"
|
|
|
|
|
|
|
|
|
|
|
|
class EnterpriseBusiModelNode(Base):
|
|
|
|
class EnterpriseBusiModelNode(Base):
|
|
|
|
__tablename__ = 'enterprise_busi_model_node'
|
|
|
|
__tablename__ = 'enterprise_busi_model_node'
|
|
|
@ -83,7 +84,10 @@ class EnterpriseBusiModelNode(Base):
|
|
|
|
class EnterpriseBusiModelRepository(object):
|
|
|
|
class EnterpriseBusiModelRepository(object):
|
|
|
|
|
|
|
|
|
|
|
|
def get_by_id(self, id: int) -> Optional[EnterpriseBusiModel]:
|
|
|
|
def get_by_id(self, id: int) -> Optional[EnterpriseBusiModel]:
|
|
|
|
return self.db.query(EnterpriseBusiModel).filter(EnterpriseBusiModel.id == id).first()
|
|
|
|
with get_session() as session:
|
|
|
|
|
|
|
|
model = session.query(EnterpriseBusiModel).filter(EnterpriseBusiModel.id == id).first()
|
|
|
|
|
|
|
|
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def insert_busi_model(self, data: Dict):
|
|
|
|
def insert_busi_model(self, data: Dict):
|
|
|
|
entity_suid = EnterpriseEntityRepository().get_entity_suid(data['entity_id'])
|
|
|
|
entity_suid = EnterpriseEntityRepository().get_entity_suid(data['entity_id'])
|
|
|
@ -99,7 +103,7 @@ class EnterpriseBusiModelRepository(object):
|
|
|
|
'id': base_model_id,
|
|
|
|
'id': base_model_id,
|
|
|
|
'suid': base_model_suid
|
|
|
|
'suid': base_model_suid
|
|
|
|
})
|
|
|
|
})
|
|
|
|
data['basemodel_ids'] = json.dumps(base_model)
|
|
|
|
data['base_models'] = json.dumps(base_model)
|
|
|
|
new_data = copy.copy(data)
|
|
|
|
new_data = copy.copy(data)
|
|
|
|
|
|
|
|
|
|
|
|
with get_session() as session:
|
|
|
|
with get_session() as session:
|
|
|
@ -109,6 +113,27 @@ class EnterpriseBusiModelRepository(object):
|
|
|
|
|
|
|
|
|
|
|
|
return model.id, model.suid
|
|
|
|
return model.id, model.suid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def edit_busi_model(self, data: Dict):
|
|
|
|
|
|
|
|
base_model_ids = [int(model_id) for model_id in data['basemodel_ids'].split(',')]
|
|
|
|
|
|
|
|
base_model_db = DB_alg_model.ModelRepositry()
|
|
|
|
|
|
|
|
base_model = []
|
|
|
|
|
|
|
|
for base_model_id in base_model_ids:
|
|
|
|
|
|
|
|
base_model_suid = base_model_db.get_suid(base_model_id)
|
|
|
|
|
|
|
|
base_model.append({
|
|
|
|
|
|
|
|
'id': base_model_id,
|
|
|
|
|
|
|
|
'suid': base_model_suid
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data['base_models'] = json.dumps(base_model)
|
|
|
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
session.query(EnterpriseBusiModel).filter(EnterpriseBusiModel.id == data['id']).update(data)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
logging.error("Failed to edit device")
|
|
|
|
|
|
|
|
session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_busi_model_by_id(self, id: int) -> Optional[EnterpriseBusiModel]:
|
|
|
|
def get_busi_model_by_id(self, id: int) -> Optional[EnterpriseBusiModel]:
|
|
|
|
with get_session() as session:
|
|
|
|
with get_session() as session:
|
|
|
@ -116,6 +141,45 @@ class EnterpriseBusiModelRepository(object):
|
|
|
|
return model
|
|
|
|
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def list_enterprise_busi_model(self, entity_id: int, page_no: int, page_size: int) -> Dict[Any, Any]:
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
获取企业部署的业务模型列表
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
session (Session): SQLAlchemy 数据库会话
|
|
|
|
|
|
|
|
entity_id (int): 企业 ID
|
|
|
|
|
|
|
|
page_no (int): 页码
|
|
|
|
|
|
|
|
page_size (int): 每页数量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
dict: 包含总数和数据列表的字典
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
|
|
|
total_count = session.query(func.count(EnterpriseBusiModel.id)).filter(EnterpriseBusiModel.entity_id == entity_id).scalar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
models = (
|
|
|
|
|
|
|
|
session.query(
|
|
|
|
|
|
|
|
EnterpriseBusiModel.id.label("model_id"),
|
|
|
|
|
|
|
|
EnterpriseBusiModel.name.label("model_name"),
|
|
|
|
|
|
|
|
EnterpriseBusiModel.create_time
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.filter(EnterpriseBusiModel.entity_id == entity_id)
|
|
|
|
|
|
|
|
.offset((page_no - 1) * page_size)
|
|
|
|
|
|
|
|
.limit(page_size)
|
|
|
|
|
|
|
|
.all()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
"count": total_count,
|
|
|
|
|
|
|
|
"data": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"model_id": model.model_id,
|
|
|
|
|
|
|
|
"model_name": model.model_name,
|
|
|
|
|
|
|
|
"create_time": model.create_time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for model in models
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class EnterpriseBusiModelNodeRepository(object):
|
|
|
|
class EnterpriseBusiModelNodeRepository(object):
|
|
|
|
# def get_by_id(self, id: int) -> Optional[EnterpriseBusiModelNode]:
|
|
|
|
# def get_by_id(self, id: int) -> Optional[EnterpriseBusiModelNode]:
|
|
|
@ -142,3 +206,13 @@ class EnterpriseBusiModelNodeRepository(object):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_nodes_by_busi_model(self, busi_model_id: int) -> List[EnterpriseBusiModelNode]:
|
|
|
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
|
|
|
nodes = session.query(EnterpriseBusiModelNode).filter(EnterpriseBusiModelNode.busi_model_id == busi_model_id).all()
|
|
|
|
|
|
|
|
return nodes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_by_busi_model_id(self, busi_model_id: int) -> None:
|
|
|
|
|
|
|
|
with get_session() as session:
|
|
|
|
|
|
|
|
session.query(EnterpriseBusiModelNode).filter(EnterpriseBusiModelNode.busi_model_id == busi_model_id).delete()
|
|
|
|
|
|
|
|
session.commit()
|