|
@@ -4,12 +4,12 @@ import os
|
|
import xlrd
|
|
import xlrd
|
|
from flask import request, jsonify, current_app, Response
|
|
from flask import request, jsonify, current_app, Response
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
-from sqlalchemy import select, insert, update, delete
|
|
|
|
|
|
+from sqlalchemy import select, insert, update, delete, func
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.orm import Session
|
|
from werkzeug.datastructures import FileStorage
|
|
from werkzeug.datastructures import FileStorage
|
|
|
|
|
|
from app.defines import StatesCode, Module, OperationType
|
|
from app.defines import StatesCode, Module, OperationType
|
|
-from app.modle.device import DeviceType, SecurityDevice, EnergyDeviceType
|
|
|
|
|
|
+from app.modle.device import DeviceType, SecurityDevice, EnergyDeviceType, DeviceMessage
|
|
from app.utils.jwt_util import login_required
|
|
from app.utils.jwt_util import login_required
|
|
from app.utils.save_log import save_log
|
|
from app.utils.save_log import save_log
|
|
from app.utils.util import to_dict
|
|
from app.utils.util import to_dict
|
|
@@ -150,6 +150,32 @@ class DeviceKindApi(Resource):
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
+device_kind_list = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+device_kind_list.add_argument(name='id', type=str, location='args', required=False, help='设备种类id')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@ns.route('/device_kind_list')
|
|
|
|
+class DeviceKindListApi(Resource):
|
|
|
|
+
|
|
|
|
+ @ns.doc(description='根据设备种类获取设备列表')
|
|
|
|
+ @ns.expect(device_kind_list)
|
|
|
|
+ def get(self):
|
|
|
|
+ """根据设备种类获取设备列表"""
|
|
|
|
+ device_type_id = request.args.get('id')
|
|
|
|
+ try:
|
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
|
+ stmt = select(SecurityDevice).where(SecurityDevice.device_type == device_type_id)
|
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
+
|
|
|
|
+ save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
+
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
+
|
|
|
|
+
|
|
device_list = reqparse.RequestParser(bundle_errors=True)
|
|
device_list = reqparse.RequestParser(bundle_errors=True)
|
|
device_list.add_argument(name='id', type=str, location='args', required=False, help='设备类别id')
|
|
device_list.add_argument(name='id', type=str, location='args', required=False, help='设备类别id')
|
|
# device_list.add_argument(name='name', type=str, location='args', required=False, help='过滤设备名')
|
|
# device_list.add_argument(name='name', type=str, location='args', required=False, help='过滤设备名')
|
|
@@ -180,6 +206,9 @@ class DeviceListApi(Resource):
|
|
device_ids = session.execute(stmt).scalars().first()
|
|
device_ids = session.execute(stmt).scalars().first()
|
|
|
|
|
|
if device_ids:
|
|
if device_ids:
|
|
|
|
+ count = select(func.count(SecurityDevice.id)).where(SecurityDevice.id.in_(json.loads(device_ids)))
|
|
|
|
+ count_results = session.execute(count).scalars().first()
|
|
|
|
+
|
|
stmt = select(SecurityDevice).where(SecurityDevice.id.in_(json.loads(device_ids))).offset(
|
|
stmt = select(SecurityDevice).where(SecurityDevice.id.in_(json.loads(device_ids))).offset(
|
|
page_size * (page - 1)).limit(page_size)
|
|
page_size * (page - 1)).limit(page_size)
|
|
results = session.execute(stmt).scalars().all()
|
|
results = session.execute(stmt).scalars().all()
|
|
@@ -188,7 +217,7 @@ class DeviceListApi(Resource):
|
|
|
|
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
|
|
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=to_dict(results))
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
@@ -206,18 +235,17 @@ delete_device = reqparse.RequestParser(bundle_errors=True)
|
|
delete_device.add_argument(name='device_id', type=str, location='form', required=False, help='设备id')
|
|
delete_device.add_argument(name='device_id', type=str, location='form', required=False, help='设备id')
|
|
delete_device.add_argument(name='device_type_id', type=str, location='form', required=False, help='设备类别id')
|
|
delete_device.add_argument(name='device_type_id', type=str, location='form', required=False, help='设备类别id')
|
|
|
|
|
|
-
|
|
|
|
device_details = reqparse.RequestParser(bundle_errors=True)
|
|
device_details = reqparse.RequestParser(bundle_errors=True)
|
|
device_details.add_argument(name='id', type=str, location='form', required=False, help='设备id')
|
|
device_details.add_argument(name='id', type=str, location='form', required=False, help='设备id')
|
|
device_details.add_argument(name='device_name', type=str, location='form', required=False, help='设备名称')
|
|
device_details.add_argument(name='device_name', type=str, location='form', required=False, help='设备名称')
|
|
-device_details.add_argument(name='device_id', type=str, location='form', required=False, help='设备id')
|
|
|
|
-device_details.add_argument(name='device_type', type=str, location='form', required=False, help='设备类型(1-摄像头)')
|
|
|
|
|
|
+# device_details.add_argument(name='device_id', type=str, location='form', required=False, help='设备id')
|
|
|
|
+# device_details.add_argument(name='device_type', type=str, location='form', required=False, help='设备类型(1-摄像头)')
|
|
device_details.add_argument(name='device_location', type=str, location='form', required=False, help='设备位置')
|
|
device_details.add_argument(name='device_location', type=str, location='form', required=False, help='设备位置')
|
|
-device_details.add_argument(name='loop_detail', type=str, location='form', required=False, help='回路地址')
|
|
|
|
-device_details.add_argument(name='gateway_code', type=str, location='form', required=False, help='所属单位ID')
|
|
|
|
-device_details.add_argument(name='gateway_ip', type=str, location='form', required=False, help='网关服务器')
|
|
|
|
-device_details.add_argument(name='usage', type=str, location='form', required=False, help='用途')
|
|
|
|
-device_details.add_argument(name='status', type=str, location='form', required=False, help='设备状态(1-开启)')
|
|
|
|
|
|
+# device_details.add_argument(name='loop_detail', type=str, location='form', required=False, help='回路地址')
|
|
|
|
+# device_details.add_argument(name='gateway_code', type=str, location='form', required=False, help='所属单位ID')
|
|
|
|
+# device_details.add_argument(name='gateway_ip', type=str, location='form', required=False, help='网关服务器')
|
|
|
|
+# device_details.add_argument(name='usage', type=str, location='form', required=False, help='用途')
|
|
|
|
+# device_details.add_argument(name='status', type=str, location='form', required=False, help='设备状态(1-开启)')
|
|
|
|
|
|
|
|
|
|
@ns.route('/device')
|
|
@ns.route('/device')
|
|
@@ -237,11 +265,11 @@ class DeviceApi(Resource):
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
stmt = select(SecurityDevice).where(SecurityDevice.id == device_id)
|
|
stmt = select(SecurityDevice).where(SecurityDevice.id == device_id)
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
|
-
|
|
|
|
|
|
+ results = session.execute(stmt).scalars().first().__dict__
|
|
|
|
+ del results['_sa_instance_state']
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
|
|
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=results)
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
save_log(request, Module.DEVICE, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
@@ -285,14 +313,14 @@ class DeviceApi(Resource):
|
|
|
|
|
|
id = request.form.get('id')
|
|
id = request.form.get('id')
|
|
device_name = request.form.get('device_name')
|
|
device_name = request.form.get('device_name')
|
|
- device_id = request.form.get('device_id')
|
|
|
|
- device_type = request.form.get('device_type')
|
|
|
|
|
|
+ # device_id = request.form.get('device_id')
|
|
|
|
+ # device_type = request.form.get('device_type')
|
|
device_location = request.form.get('device_location')
|
|
device_location = request.form.get('device_location')
|
|
- loop_detail = request.form.get('device_age')
|
|
|
|
- gateway_code = request.form.get('company_id')
|
|
|
|
- gateway_ip = request.form.get('user_id')
|
|
|
|
- usage = request.form.get('device_group')
|
|
|
|
- status = request.form.get('status')
|
|
|
|
|
|
+ # loop_detail = request.form.get('device_age')
|
|
|
|
+ # gateway_code = request.form.get('company_id')
|
|
|
|
+ # gateway_ip = request.form.get('user_id')
|
|
|
|
+ # usage = request.form.get('device_group')
|
|
|
|
+ # status = request.form.get('status')
|
|
|
|
|
|
if device_name is None:
|
|
if device_name is None:
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='设备名称不能为空')
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='设备名称不能为空')
|
|
@@ -300,14 +328,14 @@ class DeviceApi(Resource):
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
stmt = update(SecurityDevice).where(SecurityDevice.id == id).values(
|
|
stmt = update(SecurityDevice).where(SecurityDevice.id == id).values(
|
|
device_name=device_name,
|
|
device_name=device_name,
|
|
- device_id=device_id,
|
|
|
|
- device_type=device_type,
|
|
|
|
|
|
+ # device_id=device_id,
|
|
|
|
+ # device_type=device_type,
|
|
device_location=device_location,
|
|
device_location=device_location,
|
|
- loop_detail=loop_detail,
|
|
|
|
- gateway_code=gateway_code,
|
|
|
|
- gateway_ip=gateway_ip,
|
|
|
|
- usage=usage,
|
|
|
|
- status=status,
|
|
|
|
|
|
+ # loop_detail=loop_detail,
|
|
|
|
+ # gateway_code=gateway_code,
|
|
|
|
+ # gateway_ip=gateway_ip,
|
|
|
|
+ # usage=usage,
|
|
|
|
+ # status=status,
|
|
|
|
|
|
)
|
|
)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
@@ -377,7 +405,7 @@ class BatchDeleteDeviceApi(Resource):
|
|
device_ids = request.form.get('device_ids')
|
|
device_ids = request.form.get('device_ids')
|
|
device_type_id = request.form.get('device_type_id')
|
|
device_type_id = request.form.get('device_type_id')
|
|
|
|
|
|
- if device_ids is not None or device_type_id is not None:
|
|
|
|
|
|
+ if device_ids and device_type_id:
|
|
device_ids = json.loads(device_ids)
|
|
device_ids = json.loads(device_ids)
|
|
device_type_id = int(device_type_id)
|
|
device_type_id = int(device_type_id)
|
|
else:
|
|
else:
|
|
@@ -416,28 +444,28 @@ import_device.add_argument(name='group_id', type=str, required=True, location='f
|
|
class ImportDeviceApi(Resource):
|
|
class ImportDeviceApi(Resource):
|
|
# method_decorators = [login_required]
|
|
# method_decorators = [login_required]
|
|
|
|
|
|
- @ns.doc(id='import_device', description='导入模版下载')
|
|
|
|
- def get(self):
|
|
|
|
- """导入模版下载"""
|
|
|
|
- try:
|
|
|
|
- manage_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
- config_yml_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(manage_path))), 'config',
|
|
|
|
- 'device.xls')
|
|
|
|
-
|
|
|
|
- file_data = open(config_yml_path, 'rb')
|
|
|
|
- buf = file_data.read()
|
|
|
|
- file_data.close()
|
|
|
|
-
|
|
|
|
- response = Response(buf)
|
|
|
|
- response.headers['Content-Type'] = 'application/octet-stream'
|
|
|
|
- response.headers['Content-Disposition'] = 'attachment; filename=%s' % 'device.xls'
|
|
|
|
-
|
|
|
|
- save_log(request, Module.DEVICE, OperationType.EXPORT, StatesCode.SUCCESS)
|
|
|
|
-
|
|
|
|
- return response
|
|
|
|
- except Exception as e:
|
|
|
|
- save_log(request, Module.DEVICE, OperationType.EXPORT, StatesCode.UNKNOWN_ERROR)
|
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
+ # @ns.doc(id='import_device', description='导入模版下载')
|
|
|
|
+ # def get(self):
|
|
|
|
+ # """导入模版下载"""
|
|
|
|
+ # try:
|
|
|
|
+ # manage_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
+ # config_yml_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(manage_path))), 'config',
|
|
|
|
+ # 'device.xls')
|
|
|
|
+ #
|
|
|
|
+ # file_data = open(config_yml_path, 'rb')
|
|
|
|
+ # buf = file_data.read()
|
|
|
|
+ # file_data.close()
|
|
|
|
+ #
|
|
|
|
+ # response = Response(buf)
|
|
|
|
+ # response.headers['Content-Type'] = 'application/octet-stream'
|
|
|
|
+ # response.headers['Content-Disposition'] = 'attachment; filename=%s' % 'device.xls'
|
|
|
|
+ #
|
|
|
|
+ # save_log(request, Module.DEVICE, OperationType.EXPORT, StatesCode.SUCCESS)
|
|
|
|
+ #
|
|
|
|
+ # return response
|
|
|
|
+ # except Exception as e:
|
|
|
|
+ # save_log(request, Module.DEVICE, OperationType.EXPORT, StatesCode.UNKNOWN_ERROR)
|
|
|
|
+ # return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='import_device', description='设备导入')
|
|
@ns.doc(id='import_device', description='设备导入')
|
|
@ns.expect(import_device)
|
|
@ns.expect(import_device)
|
|
@@ -446,7 +474,7 @@ class ImportDeviceApi(Resource):
|
|
device_file = request.files.get('files')
|
|
device_file = request.files.get('files')
|
|
device_group_id = request.form.get('group_id')
|
|
device_group_id = request.form.get('group_id')
|
|
|
|
|
|
- if os.path.splitext(device_file.name)[-1] != '.xls':
|
|
|
|
|
|
+ if os.path.splitext(device_file.filename)[-1] != '.xls':
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='不支持的文件格式,仅支持 .xls 文件')
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='不支持的文件格式,仅支持 .xls 文件')
|
|
|
|
|
|
if device_group_id is None:
|
|
if device_group_id is None:
|
|
@@ -457,26 +485,49 @@ class ImportDeviceApi(Resource):
|
|
|
|
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
|
|
|
|
|
|
+ # 记录新添加的设备id
|
|
|
|
+ upload_device = []
|
|
|
|
+
|
|
for sheet in xlsx.sheets():
|
|
for sheet in xlsx.sheets():
|
|
|
|
|
|
# 添加设备数据
|
|
# 添加设备数据
|
|
for i in range(1, sheet.nrows): # 逐行打印sheet数据
|
|
for i in range(1, sheet.nrows): # 逐行打印sheet数据
|
|
value = sheet.row_values(i)
|
|
value = sheet.row_values(i)
|
|
- add_device = insert(SecurityDevice).values(
|
|
|
|
- device_name=value[0],
|
|
|
|
- device_id=value[1],
|
|
|
|
- device_type=int(value[2]) if value[2] != '' else None,
|
|
|
|
- device_location=value[3],
|
|
|
|
- device_age=int(value[4]) if value[4] != '' else None,
|
|
|
|
- company_id=value[5],
|
|
|
|
- user_id=value[6],
|
|
|
|
- device_group=device_group_id,
|
|
|
|
- status=int(value[7]) if value[7] != '' else None,
|
|
|
|
- floor_id=int(value[8]) if value[8] != '' else None,
|
|
|
|
- third_id=value[9]
|
|
|
|
- )
|
|
|
|
- session.execute(add_device)
|
|
|
|
- session.commit()
|
|
|
|
|
|
+ id = int(value[0])
|
|
|
|
+
|
|
|
|
+ # 查找设备,没有则添加有记录id
|
|
|
|
+ device_stmt = select(SecurityDevice.id).where(SecurityDevice.id == id)
|
|
|
|
+ device_id = session.execute(device_stmt).scalars().first()
|
|
|
|
+ if device_id:
|
|
|
|
+ upload_device.append(device_id)
|
|
|
|
+ else:
|
|
|
|
+ add_device = insert(SecurityDevice).values(
|
|
|
|
+ device_name=value[1],
|
|
|
|
+ device_id=value[2],
|
|
|
|
+ device_type=int(value[3]) if value[3] != '' else None,
|
|
|
|
+ device_location=value[4],
|
|
|
|
+ loop_detail=int(value[5]) if value[5] != '' else None,
|
|
|
|
+ gateway_code=value[6],
|
|
|
|
+ gateway_ip=value[7],
|
|
|
|
+ usage=value[8],
|
|
|
|
+ status=int(value[9]) if value[9] != '' else None,
|
|
|
|
+ )
|
|
|
|
+ result = session.execute(add_device)
|
|
|
|
+ session.commit()
|
|
|
|
+ upload_device.append(result.inserted_primary_key[0])
|
|
|
|
+
|
|
|
|
+ # 与设备类别做关联
|
|
|
|
+ res = session.execute(
|
|
|
|
+ select(DeviceType.device_ids).where(DeviceType.id == device_group_id)
|
|
|
|
+ ).scalars().first()
|
|
|
|
+ res = json.loads(res)
|
|
|
|
+ res.extend(upload_device)
|
|
|
|
+
|
|
|
|
+ stmt = update(DeviceType).where(DeviceType.id == device_group_id).values(
|
|
|
|
+ device_ids=json.dumps(res)
|
|
|
|
+ )
|
|
|
|
+ session.execute(stmt)
|
|
|
|
+ session.commit()
|
|
|
|
|
|
save_log(request, Module.DEVICE, OperationType.IMPORT, StatesCode.SUCCESS)
|
|
save_log(request, Module.DEVICE, OperationType.IMPORT, StatesCode.SUCCESS)
|
|
|
|
|
|
@@ -484,3 +535,69 @@ class ImportDeviceApi(Resource):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
save_log(request, Module.DEVICE, OperationType.IMPORT, StatesCode.UNKNOWN_ERROR)
|
|
save_log(request, Module.DEVICE, OperationType.IMPORT, StatesCode.UNKNOWN_ERROR)
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+device_alarm = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+device_alarm.add_argument(name='alarm_type', type=str, location='args', required=True,
|
|
|
|
+ help='告警类别(1 一般告警 2紧急告警 3重要告警)')
|
|
|
|
+device_alarm.add_argument(name='page_size', type=int, location='args', required=False, help='每页记录数量,默认:20')
|
|
|
|
+device_alarm.add_argument(name='page', type=int, location='args', required=False, help='第几页')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+delete_device_alarm = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+delete_device_alarm.add_argument(name='alarm_message_id', type=str, location='form', required=True, help='异常消息id')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@ns.route('/device_alarm')
|
|
|
|
+class DeviceAlarmApi(Resource):
|
|
|
|
+
|
|
|
|
+ @ns.doc(description='获取设备告警列表')
|
|
|
|
+ @ns.expect(device_alarm)
|
|
|
|
+ def get(self):
|
|
|
|
+ """获取设备告警列表"""
|
|
|
|
+ alarm_type = request.args.get('alarm_type')
|
|
|
|
+ page_size = int(request.args.get('page_size', 20))
|
|
|
|
+ page = int(request.args.get('page', 1))
|
|
|
|
+
|
|
|
|
+ if alarm_type is None:
|
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='告警类别不能为空')
|
|
|
|
+ try:
|
|
|
|
+
|
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
|
+ count = select(func.count(DeviceMessage.id)).where(DeviceMessage.type == alarm_type)
|
|
|
|
+ count_results = session.execute(count).scalars().first()
|
|
|
|
+
|
|
|
|
+ stmt = select(DeviceMessage).where(DeviceMessage.type == alarm_type).offset(
|
|
|
|
+ page_size * (page - 1)).limit(page_size)
|
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
+
|
|
|
|
+ save_log(request, Module.DEVICE, OperationType.IMPORT, StatesCode.SUCCESS)
|
|
|
|
+
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=to_dict(results))
|
|
|
|
+ except Exception as e:
|
|
|
|
+ save_log(request, Module.DEVICE, OperationType.IMPORT, StatesCode.UNKNOWN_ERROR)
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
+
|
|
|
|
+ @ns.doc(description='删除设备告警')
|
|
|
|
+ @ns.expect(delete_device_alarm)
|
|
|
|
+ def delete(self):
|
|
|
|
+ """删除设备告警"""
|
|
|
|
+ alarm_message_id = request.form.get('alarm_message_id')
|
|
|
|
+
|
|
|
|
+ if alarm_message_id is None:
|
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='告警消息id不能为空')
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
|
+ stmt = update(DeviceMessage).where(DeviceMessage.id == alarm_message_id).values(
|
|
|
|
+ type=None
|
|
|
|
+ )
|
|
|
|
+ session.execute(stmt)
|
|
|
|
+ session.commit()
|
|
|
|
+
|
|
|
|
+ save_log(request, Module.DEVICE, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
|
+
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
|
+ except Exception as e:
|
|
|
|
+ save_log(request, Module.DEVICE, OperationType.DELETE, StatesCode.UNKNOWN_ERROR)
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|