添加企业设备模块

main
周平 12 months ago
parent 57ce3d896e
commit b7a3c0fb94

@ -25,7 +25,7 @@ def to_json_list(cursor: Any) -> Optional[List[Row]]:
column_names = list(cursor.keys())
result = cursor.fetchall()
if not result:
return None
return []
return [Row(itertools.zip_longest(column_names, row)) for row in result]
@ -35,7 +35,7 @@ def to_json(cursor):
result = cursor.fetchone()
if not result:
return None
return {}
return Row(itertools.zip_longest(column_names, result))

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

@ -0,0 +1,132 @@
# -*- coding: utf-8 -*-
from sqlalchemy import text
from website import errors, db
from website.handler import APIHandler, authenticated
from website.util import shortuuid
class DeviceClassificationAddHandler(APIHandler):
"""
- 描述添加设备分类
- 请求方式post
- 请求参数
>- entity_id, int, 企业id
>- name, string, 设备分类名称
- 返回值
```
{
"id": 123
}
```
"""
@authenticated
def post(self):
name = self.get_escaped_argument('name', '')
with self.app_mysql.connect() as conn:
cur = conn.execute(
text("SELECT id FROM device_classification WHERE name=:name"), {"name": name}
)
ex = cur.fetchone()
if ex:
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, '设备分类已存在')
conn.execute(
text("INSERT INTO device_classification (name, suid) VALUES (:name, :suid)"),
{"name": name, "suid": shortuuid.ShortUUID().random(10)}
)
self.finish()
class DeviceClassificationHandler(APIHandler):
"""
- 描述设备分类列表
- 请求方式post
- 请求参数
>-
- 返回值
```
{
"data": [
{
"id": 123,
"name": "xxx"
},
...
]
}
```
"""
@authenticated
def post(self):
with self.app_mysql.connect() as conn:
cur = conn.execute(
text("SELECT id, name FROM device_classification where del=0 ORDER BY id DESC")
)
res = db.to_json_list(cur)
res = res and res or []
self.finish({"data": res})
class DeviceClassificationDeleteHandler(APIHandler):
"""
- 描述删除设备分类
- 请求方式post
- 请求参数
>- id
- 返回值
"""
@authenticated
def post(self):
did = self.get_int_argument('id')
with self.app_mysql.connect() as conn:
conn.execute(
text("update device_classification set del=1 WHERE id=:id"), {"id": did}
)
self.finish()
class DeviceAddHandler(APIHandler):
"""
"""
@authenticated
def post(self):
self.finish()
class DeviceEditHandler(APIHandler):
"""
"""
@authenticated
def post(self):
self.finish()
class DeviceDeleteHandler(APIHandler):
"""
"""
@authenticated
def post(self):
self.finish()
class DeviceListHandler(APIHandler):
"""
"""
@authenticated
def post(self):
self.finish()

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from website.handlers.enterprise_device import handler
handlers = [
("/enterprise/device/classification/add", handler.DeviceClassificationAddHandler),
("/enterprise/device/classification", handler.DeviceClassificationHandler),
("/enterprise/device/classification/delete", handler.DeviceClassificationDeleteHandler),
("/enterprise/entity/nodes/device/add", handler.DeviceAddHandler),
("/enterprise/entity/nodes/device/edit", handler.DeviceEditHandler),
("/enterprise/entity/nodes/device/delete", handler.DeviceDeleteHandler),
("/enterprise/entity/nodes/device/list", handler.DeviceListHandler),
]
page_handlers = [
]

@ -2,13 +2,14 @@
import logging
from sqlalchemy import text
from website import errors
from website import settings
from website import consts
from website import db
from website.util import shortuuid, aes
from website.service import enterprise
from website import errors
from website import settings
from website.handler import APIHandler, authenticated
from website.service import enterprise
from website.util import shortuuid, aes
class EntityIndexHandler(APIHandler):
@ -77,7 +78,6 @@ class EntityIndexBasecountHandler(APIHandler):
model = enterprise.get_enterprise_model_count()
device = enterprise.get_enterprise_device_count()
self.finish({"entity": entity, "model": model, "device": device})
@ -190,7 +190,6 @@ class EntityEditHandler(APIHandler):
)
conn.commit()
self.finish()
@ -252,7 +251,6 @@ class EntityDeleteHandler(APIHandler):
self.finish()
class EntityPwdcheckHandler(APIHandler):
"""查看企业密码"""

@ -58,7 +58,7 @@ class AddHandler(APIHandler):
self.finish()
class UpdateHandler(APIHandler):
class EditHandler(APIHandler):
"""
- 描述更新企业节点
- 请求方式post

@ -3,7 +3,7 @@ from website.handlers.enterprise_node import handler
handlers = [
('/enterprise/entity/nodes/add', handler.AddHandler),
('/enterprise/entity/nodes/update', handler.UpdateHandler),
('/enterprise/entity/nodes/edit', handler.EditHandler),
('/enterprise/entity/nodes', handler.TreeHandler),
('/enterprise/entity/nodes/info', handler.InfoHandler),
('/enterprise/entity/nodes/delete', handler.DeleteHandler),

Loading…
Cancel
Save