|
|
|
@ -1,11 +1,13 @@
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
from website import errors
|
|
|
|
|
from website.handler import APIHandler, authenticated
|
|
|
|
|
from website.db.enterprise_entity import enterprise_entity as DB_Entity
|
|
|
|
|
from website.db.enterprise_node import enterprise_node as DB_Node
|
|
|
|
|
from website.db.enterprise_busi_model import enterprise_busi_model as DB_BusiModel
|
|
|
|
|
from website.db.enterprise_busi_model import enterprise_busi_model_node_device as DB_BusiModelNodeDevice
|
|
|
|
|
from website.db.enterprise_busi_model import (
|
|
|
|
|
enterprise_busi_model_node_device as DB_BusiModelNodeDevice,
|
|
|
|
|
)
|
|
|
|
|
from website.db.enterprise_device import enterprise_device as DB_Device
|
|
|
|
|
from website.util import shortuuid
|
|
|
|
|
|
|
|
|
@ -45,18 +47,20 @@ class AddHandler(APIHandler):
|
|
|
|
|
entity_suid = db_entity.get_entity_suid(entity_id)
|
|
|
|
|
|
|
|
|
|
db_node = DB_Node.EnterpriseNodeRepository()
|
|
|
|
|
db_node.insert_node({
|
|
|
|
|
"suid": shortuuid.ShortUUID().random(length=10),
|
|
|
|
|
"entity_id": entity_id,
|
|
|
|
|
"entity_suid": entity_suid,
|
|
|
|
|
"name": name,
|
|
|
|
|
"parent": parent,
|
|
|
|
|
"addr": addr,
|
|
|
|
|
"lola": lola,
|
|
|
|
|
"contact": contact,
|
|
|
|
|
"phone": phone,
|
|
|
|
|
"comment": comment
|
|
|
|
|
})
|
|
|
|
|
db_node.insert_node(
|
|
|
|
|
{
|
|
|
|
|
"suid": shortuuid.ShortUUID().random(length=10),
|
|
|
|
|
"entity_id": entity_id,
|
|
|
|
|
"entity_suid": entity_suid,
|
|
|
|
|
"name": name,
|
|
|
|
|
"parent": parent,
|
|
|
|
|
"addr": addr,
|
|
|
|
|
"lola": lola,
|
|
|
|
|
"contact": contact,
|
|
|
|
|
"phone": phone,
|
|
|
|
|
"comment": comment,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
|
|
|
|
|
@ -92,16 +96,18 @@ class EditHandler(APIHandler):
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
|
|
|
|
|
|
|
|
|
|
db_node = DB_Node.EnterpriseNodeRepository()
|
|
|
|
|
db_node.update_node({
|
|
|
|
|
"node_id": node_id,
|
|
|
|
|
"name": name,
|
|
|
|
|
"parent": parent,
|
|
|
|
|
"addr": addr,
|
|
|
|
|
"lola": lola,
|
|
|
|
|
"contact": contact,
|
|
|
|
|
"phone": phone,
|
|
|
|
|
"comment": comment
|
|
|
|
|
})
|
|
|
|
|
db_node.update_node(
|
|
|
|
|
{
|
|
|
|
|
"node_id": node_id,
|
|
|
|
|
"name": name,
|
|
|
|
|
"parent": parent,
|
|
|
|
|
"addr": addr,
|
|
|
|
|
"lola": lola,
|
|
|
|
|
"contact": contact,
|
|
|
|
|
"phone": phone,
|
|
|
|
|
"comment": comment,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
|
|
|
|
|
@ -115,7 +121,7 @@ class TreeHandler(APIHandler):
|
|
|
|
|
>- name, string, 搜索内容
|
|
|
|
|
- 返回值:
|
|
|
|
|
```
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
"data":[
|
|
|
|
|
{
|
|
|
|
|
"id": 123,
|
|
|
|
@ -129,7 +135,7 @@ class TreeHandler(APIHandler):
|
|
|
|
|
"id": 123,
|
|
|
|
|
"name": "xxx"
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
@ -137,7 +143,7 @@ class TreeHandler(APIHandler):
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
"""
|
|
|
|
@ -151,9 +157,7 @@ class TreeHandler(APIHandler):
|
|
|
|
|
|
|
|
|
|
db_node = DB_Node.EnterpriseNodeRepository()
|
|
|
|
|
nodes = db_node.select_tree(entity_id, name)
|
|
|
|
|
self.finish({
|
|
|
|
|
"data": nodes
|
|
|
|
|
})
|
|
|
|
|
self.finish({"data": nodes})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InfoHandler(APIHandler):
|
|
|
|
@ -225,13 +229,14 @@ class BusimodelHandler(APIHandler):
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
def post(self):
|
|
|
|
|
node_id = self.get_int_argument('node_id')
|
|
|
|
|
pageNo = self.get_int_argument('pageNo', 1)
|
|
|
|
|
pageSize = self.get_int_argument('pageSize', 20)
|
|
|
|
|
node_id = self.get_int_argument("node_id")
|
|
|
|
|
pageNo = self.get_int_argument("pageNo", 1)
|
|
|
|
|
pageSize = self.get_int_argument("pageSize", 20)
|
|
|
|
|
if not node_id:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, '企业节点不能为空')
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "企业节点不能为空")
|
|
|
|
|
|
|
|
|
|
db_model_node = DB_BusiModel.EnterpriseBusiModelNodeRepository()
|
|
|
|
|
|
|
|
|
@ -240,15 +245,18 @@ class BusimodelHandler(APIHandler):
|
|
|
|
|
count = busi_models["count"]
|
|
|
|
|
models = busi_models["data"]
|
|
|
|
|
|
|
|
|
|
db_mode_node_device = DB_BusiModelNodeDevice.EnterpriseBusiModelNodeDeviceRepository()
|
|
|
|
|
db_mode_node_device = (
|
|
|
|
|
DB_BusiModelNodeDevice.EnterpriseBusiModelNodeDeviceRepository()
|
|
|
|
|
)
|
|
|
|
|
for busi_model in models:
|
|
|
|
|
deployed = db_mode_node_device.check_deployed(node_id, busi_model["busi_model_id"])
|
|
|
|
|
deployed = db_mode_node_device.check_deployed(
|
|
|
|
|
node_id, busi_model["busi_model_id"]
|
|
|
|
|
)
|
|
|
|
|
busi_model["deployed"] = deployed
|
|
|
|
|
|
|
|
|
|
self.finish({"count": count, "data": models})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BusimodelInfoHandler(APIHandler):
|
|
|
|
|
"""
|
|
|
|
|
- 描述:企业节点,业务模型部署 -> 业务模型信息
|
|
|
|
@ -272,9 +280,42 @@ class BusimodelInfoHandler(APIHandler):
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
def post(self):
|
|
|
|
|
self.finish()
|
|
|
|
|
node_id = self.get_int_argument("node_id")
|
|
|
|
|
busi_model_id = self.get_int_argument("busi_model_id")
|
|
|
|
|
|
|
|
|
|
if not node_id or not busi_model_id:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
|
|
|
|
|
|
|
|
|
|
db_busi_model = DB_BusiModel.EnterpriseBusiModelRepository()
|
|
|
|
|
busi_model = db_busi_model.get_busi_model_by_id(busi_model_id)
|
|
|
|
|
busi_model_name = busi_model.name
|
|
|
|
|
busi_model_comment = busi_model.comment
|
|
|
|
|
base_models = json.loads(busi_model.base_models)
|
|
|
|
|
base_model_names = ",".join([base_model["name"] for base_model in base_models])
|
|
|
|
|
|
|
|
|
|
db_mode_node_device = (
|
|
|
|
|
DB_BusiModelNodeDevice.EnterpriseBusiModelNodeDeviceRepository()
|
|
|
|
|
)
|
|
|
|
|
device_ids = db_mode_node_device.get_device_id(node_id, busi_model_id)
|
|
|
|
|
device_ids = list(set([item["device_id"] for item in device_ids]))
|
|
|
|
|
db_device = DB_Device.EnterpriseDeviceRepository()
|
|
|
|
|
devices = db_device.get_devices(device_ids)
|
|
|
|
|
|
|
|
|
|
devices_return = [
|
|
|
|
|
{"device_id": item["id"], "device_name": item["name"]} for item in devices
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.finish(
|
|
|
|
|
{
|
|
|
|
|
"busi_model_name": busi_model_name,
|
|
|
|
|
"busi_model_comment": busi_model_comment,
|
|
|
|
|
"base_models": base_model_names,
|
|
|
|
|
"devices": devices_return,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BusimodelDeployHandler(APIHandler):
|
|
|
|
@ -287,17 +328,18 @@ class BusimodelDeployHandler(APIHandler):
|
|
|
|
|
> - device_ids, string, 设备id, 多个id逗号分割
|
|
|
|
|
- 返回值:无
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
def post(self):
|
|
|
|
|
node_id = self.get_int_argument('node_id')
|
|
|
|
|
busi_model_id = self.get_int_argument('busi_model_id')
|
|
|
|
|
device_ids = self.get_escaped_argument('device_ids', '')
|
|
|
|
|
node_id = self.get_int_argument("node_id")
|
|
|
|
|
busi_model_id = self.get_int_argument("busi_model_id")
|
|
|
|
|
device_ids = self.get_escaped_argument("device_ids", "")
|
|
|
|
|
if not node_id or not busi_model_id:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, '参数错误')
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
|
|
|
|
|
db_node = DB_Node.EnterpriseNodeRepository()
|
|
|
|
|
node = db_node.get_node_by_id(node_id)
|
|
|
|
|
if not node:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, '节点不存在')
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "节点不存在")
|
|
|
|
|
node_suid = node["suid"]
|
|
|
|
|
|
|
|
|
|
db_busi_model = DB_BusiModel.EnterpriseBusiModelRepository()
|
|
|
|
@ -306,24 +348,28 @@ class BusimodelDeployHandler(APIHandler):
|
|
|
|
|
|
|
|
|
|
entity_suid_row = db_node.get_entity_suid_by_node_id(node_id)
|
|
|
|
|
if not entity_suid_row:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, '企业节点不存在')
|
|
|
|
|
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "企业节点不存在")
|
|
|
|
|
|
|
|
|
|
records = []
|
|
|
|
|
for device_id in device_ids.split(','):
|
|
|
|
|
for device_id in device_ids.split(","):
|
|
|
|
|
device = DB_Device.EnterpriseDeviceRepository().get_device(int(device_id))
|
|
|
|
|
if not device:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, '设备不存在')
|
|
|
|
|
|
|
|
|
|
records.append({
|
|
|
|
|
"suid": shortuuid.ShortUUID.random(length=10),
|
|
|
|
|
"entity_suid": entity_suid_row["entity_suid"],
|
|
|
|
|
"node_id": node_id,
|
|
|
|
|
"node_suid": node_suid,
|
|
|
|
|
"busi_model_id": busi_model_id,
|
|
|
|
|
"busi_model_suid": busi_model_suid,
|
|
|
|
|
"device_id": int(device_id),
|
|
|
|
|
"device_suid": device["suid"]
|
|
|
|
|
})
|
|
|
|
|
DB_BusiModelNodeDevice.EnterpriseBusiModelNodeDeviceRepository().batch_insert_record(records)
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "设备不存在")
|
|
|
|
|
|
|
|
|
|
records.append(
|
|
|
|
|
{
|
|
|
|
|
"suid": shortuuid.ShortUUID.random(length=10),
|
|
|
|
|
"entity_suid": entity_suid_row["entity_suid"],
|
|
|
|
|
"node_id": node_id,
|
|
|
|
|
"node_suid": node_suid,
|
|
|
|
|
"busi_model_id": busi_model_id,
|
|
|
|
|
"busi_model_suid": busi_model_suid,
|
|
|
|
|
"device_id": int(device_id),
|
|
|
|
|
"device_suid": device["suid"],
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
DB_BusiModelNodeDevice.EnterpriseBusiModelNodeDeviceRepository().batch_insert_record(
|
|
|
|
|
records
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
|