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.

199 lines
5.5 KiB
Python

12 months ago
# -*- coding: utf-8 -*-
from website import errors
from website.handler import APIHandler, authenticated
from website.handlers.enterprise_entity import db as DB_Entity
from website.handlers.enterprise_node import db as DB_Node
from website.util import shortuuid
class AddHandler(APIHandler):
"""
- 描述添加企业节点
- 请求方式post
- 请求参数
>- entity_suid, int, 企业id, short uuid
>- name, string, 名称
>- parent, int, 上级节点id
>- addr, string, 地址
>- lola, string, 经纬度longitude and latitude
>- contact, string, 负责人
>- phone, string, 联系方式
>- comment, string, 简介
- 返回值
"""
# @authenticated
def post(self):
entity_id = self.get_int_argument("entity_suid")
entity_suid = self.get_escaped_argument("entity_suid", "")
name = self.get_escaped_argument("name", "")
parent = self.get_int_argument("parent", 0)
addr = self.get_escaped_argument("addr", "")
lola = self.get_escaped_argument("lola", "")
contact = self.get_escaped_argument("contact", "")
phone = self.get_escaped_argument("phone", "")
comment = self.get_escaped_argument("comment", "")
if not entity_id or not name:
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
db_entity = DB_Entity.EnterpriseEntityDB()
entity_suid = db_entity.select_entity_suid(entity_id)
db_node = DB_Node.EnterpriseNodeDB()
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()
class UpdateHandler(APIHandler):
"""
- 描述更新企业节点
- 请求方式post
- 请求参数
>- node_id, int, 节点id
>- name, string, 名称
>- parent, int, 上级节点id
>- addr, string, 地址
>- lola, string, 经纬度longitude and latitude
>- contact, string, 负责人
>- phone, string, 联系方式
>- comment, string, 简介
- 返回值
"""
# @authenticated
def post(self):
node_id = self.get_int_argument("node_id", 0)
name = self.get_escaped_argument("name", "")
parent = self.get_int_argument("parent", 0)
addr = self.get_escaped_argument("addr", "")
lola = self.get_escaped_argument("lola", "")
contact = self.get_escaped_argument("contact", "")
phone = self.get_escaped_argument("phone", "")
comment = self.get_escaped_argument("comment", "")
if not node_id or not name:
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
db_node = DB_Node.EnterpriseNodeDB()
db_node.update_node({
"node_id": node_id,
"name": name,
"parent": parent,
"addr": addr,
"lola": lola,
"contact": contact,
"phone": phone,
"comment": comment
})
self.finish()
class TreeHandler(APIHandler):
"""
- 描述企业节点树
- 请求方式post
- 请求参数
>- entity_id, int, 企业id
>- name, string, 搜索内容
- 返回值
```
{
"data":[
{
"id": 123,
"name": "xxx",
"children": [
{
"id": 123,
"name": "xxx"
"children": [
{
"id": 123,
"name": "xxx"
},
]
},
...
]
},
...
]
}
```
"""
@authenticated
def post(self):
entity_id = self.get_escaped_argument("entity_id", "")
name = self.get_escaped_argument("name", "")
if not entity_id:
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
db_node = DB_Node.EnterpriseNodeDB()
nodes = db_node.select_tree(entity_id, name)
self.finish({
"data": nodes
})
class InfoHandler(APIHandler):
"""
- 描述企业节点信息
- 请求方式post
- 请求参数
>- node_id, int, 节点id
- 返回值
```
{
"name": "xxx",
"parent": "xxx",
"addr": "xxx",
"lola": "xxx",
"contact": "xxx",
"phone": "xxx",
"comment": "xxx",
}
```
"""
@authenticated
def post(self):
node_id = self.get_int_argument("node_id")
if not node_id:
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
db_node = DB_Node.EnterpriseNodeDB()
node = db_node.select_node(node_id)
node = node and node or {}
self.finish(node)
class DeleteHandler(APIHandler):
@authenticated
def post(self):
node_id = self.get_int_argument("node_id")
if not node_id:
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")
db_node = DB_Node.EnterpriseNodeDB()
db_node.delete_node(node_id)
self.finish()