You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.7 KiB
Python

# -*- 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()