|
@@ -0,0 +1,162 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+"""
|
|
|
+@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
|
|
|
+@AUTHOR: ASJRD019
|
|
|
+@NAME: AnsjerFormal
|
|
|
+@software: PyCharm
|
|
|
+@DATE: 2019/5/27 15:50
|
|
|
+@Version: python3.6
|
|
|
+@MODIFY DECORD:ansjer dev
|
|
|
+@file: AliPayObject.py
|
|
|
+@Contact: pzb3076@163.com
|
|
|
+"""
|
|
|
+import time
|
|
|
+import traceback
|
|
|
+
|
|
|
+import simplejson as json
|
|
|
+from django.utils.decorators import method_decorator
|
|
|
+from django.views.decorators.csrf import csrf_exempt
|
|
|
+from django.views.generic.base import View
|
|
|
+
|
|
|
+from Model.models import UidSetModel
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from Service.CommonService import CommonService
|
|
|
+from Service.ModelService import ModelService
|
|
|
+
|
|
|
+'''
|
|
|
+# 管理员获取信息
|
|
|
+http://192.168.136.39:8000/uidset/adminQuery?token=local&page=1&line=10
|
|
|
+ 管理员删除信息
|
|
|
+http://192.168.136.39:8000/uidset/adminDelete?token=local&id=2
|
|
|
+ 管理员添加信息
|
|
|
+http://192.168.136.39:8000/uidset/adminAdd?token=local&uid=JW3684H8BSHG9TTM111A
|
|
|
+ 管理员编辑信息
|
|
|
+http://192.168.136.39:8000/uidset/adminUpdate?token=local&id=6&content={"uid":"9999"}
|
|
|
+'''
|
|
|
+
|
|
|
+
|
|
|
+# 设备信息添加
|
|
|
+class UidSetView(View):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(UidSetView, self).dispatch(*args, **kwargs)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ response = ResponseObject()
|
|
|
+ if operation is None:
|
|
|
+ return response.json(444, 'error path')
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ # 设备主键uid
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if operation == 'adminDelete':
|
|
|
+ return self.do_admin_delete(request_dict, userID, response)
|
|
|
+ elif operation == 'adminQuery':
|
|
|
+ return self.do_admin_query(request_dict, userID, response)
|
|
|
+ elif operation == 'adminAdd':
|
|
|
+ return self.do_admin_add(request_dict, userID, response)
|
|
|
+ elif operation == 'adminUpdate':
|
|
|
+ return self.do_admin_update(request_dict, userID, response)
|
|
|
+ else:
|
|
|
+ return response.json(444, 'error path')
|
|
|
+
|
|
|
+ # 管理员删除
|
|
|
+ def do_admin_delete(self, request_dict, userID, response):
|
|
|
+ own_perm = ModelService.check_perm(userID, 20)
|
|
|
+ if own_perm is True:
|
|
|
+ id = request_dict.get('id')
|
|
|
+ try:
|
|
|
+ list = UidSetModel.objects.filter(id=id)
|
|
|
+ if list.exists():
|
|
|
+ list.delete()
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
+ return response.json(424, repr(e))
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+ # 管理员查询接口
|
|
|
+ def do_admin_query(self, request_dict, userID, response):
|
|
|
+ own_perm = ModelService.check_perm(userID, 20)
|
|
|
+ if own_perm is True:
|
|
|
+ page = request_dict.get('page', None)
|
|
|
+ line = request_dict.get('line', None)
|
|
|
+ page = int(page)
|
|
|
+ line = int(line)
|
|
|
+ omqs = UidSetModel.objects.all().order_by( '-id')
|
|
|
+ if not omqs.exists():
|
|
|
+ return response.json(0, [])
|
|
|
+ count = omqs.count()
|
|
|
+ order_ql = omqs[(page - 1) * line:page * line]
|
|
|
+ uidset_json = CommonService.qs_to_dict(order_ql)
|
|
|
+ uidset_json['count'] = count
|
|
|
+ return response.json(0, uidset_json)
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+ # 管理员的添加
|
|
|
+ def do_admin_add(self, request_dict, userID, response):
|
|
|
+ own_perm = ModelService.check_perm(userID=userID, permID=40)
|
|
|
+ if own_perm is not True:
|
|
|
+ return response.json(404)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ timestamp = int(time.time())
|
|
|
+ param_flag = CommonService.get_param_flag(
|
|
|
+ data=[uid])
|
|
|
+ if param_flag is not True:
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ uidset = UidSetModel(
|
|
|
+ uid=uid,
|
|
|
+ addTime=timestamp,
|
|
|
+ updTime=timestamp)
|
|
|
+ uidset.save()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(500, {'details': errorInfo})
|
|
|
+
|
|
|
+ # 管理员的编辑
|
|
|
+ def do_admin_update(self, request_dict, userID, response):
|
|
|
+ own_perm = ModelService.check_perm(userID=userID, permID=50)
|
|
|
+ if own_perm is not True:
|
|
|
+ return response.json(404)
|
|
|
+ deviceContent = request_dict.get('content', None)
|
|
|
+ id = request_dict.get('id', None)
|
|
|
+ if not deviceContent or not id:
|
|
|
+ return response.json(444, 'content,id')
|
|
|
+ try:
|
|
|
+ timestamp = int(time.time())
|
|
|
+ deviceData = json.loads(deviceContent)
|
|
|
+ uid_set = UidSetModel.objects.filter(id=id)
|
|
|
+ if uid_set.exists():
|
|
|
+ uid_set.update(updTime=timestamp, **deviceData)
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
+ except Exception:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(500, {'details': errorInfo})
|
|
|
+
|
|
|
+
|
|
|
+
|