91 lines
2.8 KiB
Plaintext
91 lines
2.8 KiB
Plaintext
from PDAPI import *
|
|
import datetime
|
|
|
|
STATUS_MAP = {0: "待处理", 1: "处理中", 2: "已解决", 3: "已关闭", -1: "已拒绝"}
|
|
|
|
__metadata__ = {
|
|
"methods": ["POST"],
|
|
"blueprint": "GERP",
|
|
"permission": 1.0,
|
|
"attributes": ["admin:workorder_write"],
|
|
"limit": "30 per minute",
|
|
"route": "{DEFAULT_ROUTE}/<order_uuid>",
|
|
}
|
|
|
|
def HandleRequest(_CleanedData):
|
|
current_user = UGM.GetELTUser()
|
|
if not current_user:
|
|
return {"code": 401, "msg": "未登录"}, 401
|
|
|
|
order_uuid_str = _CleanedData["params"].get("order_uuid", "").strip()
|
|
if not order_uuid_str:
|
|
return {"code": 1, "msg": "缺少工单ID"}, 400
|
|
|
|
try:
|
|
order_uuid = UUIDObj(order_uuid_str)
|
|
except:
|
|
return {"code": 1, "msg": "无效的工单ID"}, 400
|
|
|
|
order = GERPWorkOrder.query.filter(GERPWorkOrder.OrderUUID == order_uuid).first()
|
|
if not order:
|
|
return {"code": 1, "msg": "工单不存在"}, 404
|
|
|
|
data = flask.request.get_json(silent=True) or {}
|
|
|
|
if "status" in data:
|
|
new_status = data["status"]
|
|
if new_status not in [0, 1, 2, 3, -1]:
|
|
return {"code": 1, "msg": "无效的状态值"}, 400
|
|
order.Status = new_status
|
|
if new_status in [2, 3, -1] and not order.CloseTime:
|
|
order.CloseTime = datetime.datetime.utcnow()
|
|
if new_status == 1 and not order.AssigneeUUID:
|
|
order.AssigneeUUID = current_user.UserUUID
|
|
|
|
if "priority" in data:
|
|
if data["priority"] not in [0, 1, 2, 3]:
|
|
return {"code": 1, "msg": "无效的优先级"}, 400
|
|
order.Priority = data["priority"]
|
|
|
|
if "category" in data:
|
|
valid_categories = ["bug", "feature", "question", "account", "other"]
|
|
if data["category"] not in valid_categories:
|
|
return {"code": 1, "msg": "无效的分类"}, 400
|
|
order.Category = data["category"]
|
|
|
|
if "assigneeUUID" in data:
|
|
try:
|
|
order.AssigneeUUID = UUIDObj(data["assigneeUUID"])
|
|
except:
|
|
order.AssigneeUUID = None
|
|
|
|
if "resolution" in data:
|
|
order.Resolution = data["resolution"][:4096]
|
|
|
|
if "title" in data:
|
|
title = data["title"].strip()
|
|
if not title:
|
|
return {"code": 1, "msg": "标题不能为空"}, 400
|
|
order.Title = title[:256]
|
|
|
|
if "description" in data:
|
|
order.Description = data["description"][:4096]
|
|
|
|
order.UpdateTime = datetime.datetime.utcnow()
|
|
|
|
try:
|
|
db.session.commit()
|
|
except:
|
|
db.session.rollback()
|
|
return {"code": 1, "msg": "更新失败"}, 200
|
|
|
|
return {
|
|
"code": 0,
|
|
"msg": "更新成功",
|
|
"data": {
|
|
"orderUUID": UUIDObj(order.OrderUUID).UpperStr,
|
|
"status": order.Status,
|
|
"statusDisplay": STATUS_MAP.get(order.Status, "未知"),
|
|
}
|
|
}, 200
|