133 lines
2.7 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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