|
@@ -71,48 +71,41 @@ class EquipmentInfo(View):
|
|
|
own_device = ModelService.check_own_device(userID, UID=devUid)
|
|
|
if own_device is not True:
|
|
|
return response.json(14)
|
|
|
+ device_info = Device_Info.objects.filter(UID=devUid, userID_id=userID)
|
|
|
+ if not device_info.exists():
|
|
|
+ return response.json(14)
|
|
|
try:
|
|
|
- device_info = Device_Info.objects.filter(UID=devUid, userID_id=userID)
|
|
|
+ equipment_info = Equipment_Info(
|
|
|
+ userID=Device_User.objects.get(userID=userID),
|
|
|
+ devUid=devUid,
|
|
|
+ Channel=Channel,
|
|
|
+ eventType=eventType,
|
|
|
+ receiveTime=receiveTime,
|
|
|
+ eventTime=eventTime,
|
|
|
+ viewPwd=device_info[0].View_Password,
|
|
|
+ devNickName=device_info[0].NickName,
|
|
|
+ viewAccont=device_info[0].View_Account,
|
|
|
+ alarm=alarm
|
|
|
+ )
|
|
|
+ equipment_info.save()
|
|
|
except Exception:
|
|
|
errorInfo = traceback.format_exc()
|
|
|
print(errorInfo)
|
|
|
- return response.json(424, errorInfo)
|
|
|
+ return response.json(500, errorInfo)
|
|
|
else:
|
|
|
- if device_info.exists():
|
|
|
- try:
|
|
|
- equipment_info = Equipment_Info(
|
|
|
- userID=Device_User.objects.get(userID=userID),
|
|
|
- devUid=devUid,
|
|
|
- Channel=Channel,
|
|
|
- eventType=eventType,
|
|
|
- receiveTime=receiveTime,
|
|
|
- eventTime=eventTime,
|
|
|
- viewPwd=device_info[0].View_Password,
|
|
|
- devNickName=device_info[0].NickName,
|
|
|
- viewAccont=device_info[0].View_Account,
|
|
|
- alarm=alarm
|
|
|
- )
|
|
|
- equipment_info.save()
|
|
|
- except Exception:
|
|
|
- errorInfo = traceback.format_exc()
|
|
|
- print(errorInfo)
|
|
|
- return response.json(500, errorInfo)
|
|
|
- else:
|
|
|
- if equipment_info.id:
|
|
|
- return response.json(0, {'infoID': equipment_info.id,
|
|
|
- 'devUid': devUid,
|
|
|
- 'Channel': Channel,
|
|
|
- 'alarm': alarm,
|
|
|
- 'eventType': eventType,
|
|
|
- 'eventTime': eventTime,
|
|
|
- 'receiveTime': receiveTime,
|
|
|
- 'viewPwd': equipment_info.viewPwd,
|
|
|
- 'devNickName': equipment_info.devNickName,
|
|
|
- 'viewAccont': equipment_info.viewAccont})
|
|
|
- else:
|
|
|
- return response.json(500)
|
|
|
+ if equipment_info.id:
|
|
|
+ return response.json(0, {'infoID': equipment_info.id,
|
|
|
+ 'devUid': devUid,
|
|
|
+ 'Channel': Channel,
|
|
|
+ 'alarm': alarm,
|
|
|
+ 'eventType': eventType,
|
|
|
+ 'eventTime': eventTime,
|
|
|
+ 'receiveTime': receiveTime,
|
|
|
+ 'viewPwd': equipment_info.viewPwd,
|
|
|
+ 'devNickName': equipment_info.devNickName,
|
|
|
+ 'viewAccont': equipment_info.viewAccont})
|
|
|
else:
|
|
|
- return response.json(14)
|
|
|
+ return response.json(500)
|
|
|
|
|
|
def query_info(self, request_dict, userID,response):
|
|
|
page = int(request_dict.get('page', None))
|
|
@@ -176,63 +169,267 @@ class EquipmentInfo(View):
|
|
|
endTime = request_dict.get('endTime')
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
- param_flag = CommonService.get_param_flag(data=[startTime, endTime, page, line])
|
|
|
- if param_flag is True:
|
|
|
- uid_list = Device_Info.objects.filter(userID_id=userID).values_list('UID', flat=True)
|
|
|
- if len(uid_list):
|
|
|
- equipment_info_queryset = Equipment_Info.objects.filter(userID_id=userID,
|
|
|
- eventTime__range=(startTime, endTime)).order_by(
|
|
|
- '-id')
|
|
|
- if equipment_info_queryset.exists():
|
|
|
- equipment_info_count = equipment_info_queryset.count()
|
|
|
- equipment_info_res = equipment_info_queryset[(page - 1) * line:page * line]
|
|
|
- send_json = CommonService.qs_to_dict(equipment_info_res)
|
|
|
- send_json['count'] = equipment_info_count
|
|
|
- return response.json(0,send_json)
|
|
|
- return response.json(0,{'datas': [], 'count': 0})
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
+ if not startTime or not endTime or not page or not line:
|
|
|
+ return response.json(444,'startTime, endTime, page, line')
|
|
|
+ uid_list = Device_Info.objects.filter(userID_id=userID).values_list('UID', flat=True)
|
|
|
+ if not len(uid_list):
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID,
|
|
|
+ eventTime__range=(startTime, endTime)).order_by('-id')
|
|
|
+ if qs.exists():
|
|
|
+ count = qs.count()
|
|
|
+ res = qs[(page - 1) * line:page * line]
|
|
|
+ send_json = CommonService.qs_to_dict(res)
|
|
|
+ send_json['count'] = count
|
|
|
+ return response.json(0, send_json)
|
|
|
+
|
|
|
|
|
|
def query_all_info(self, request_dict, userID,response):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
userID_id = request_dict.get('userID_id', None)
|
|
|
- param_flag = CommonService.get_param_flag(data=[page, line])
|
|
|
- if param_flag is True:
|
|
|
- check_perm = ModelService.check_permission(userID=userID, permID=30)
|
|
|
- if check_perm is True:
|
|
|
- uid_list = Device_Info.objects.filter(userID_id=userID_id).values_list('UID', flat=True)
|
|
|
- if len(uid_list):
|
|
|
- equipment_info_queryset = Equipment_Info.objects.filter(userID_id=userID_id).order_by(
|
|
|
- '-id')
|
|
|
- if equipment_info_queryset.exists():
|
|
|
- equipment_info_count = equipment_info_queryset.count()
|
|
|
- equipment_info_res = equipment_info_queryset[(page - 1) * line:page * line]
|
|
|
- send_json = CommonService.qs_to_dict(equipment_info_res)
|
|
|
- send_json['count'] = equipment_info_count
|
|
|
- return response.json(0,send_json)
|
|
|
- return response.json(0,{'datas': [], 'count': 0})
|
|
|
- else:
|
|
|
- return response.json(404)
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
+ if not page or not line:
|
|
|
+ return response.json(444,'page,line')
|
|
|
+ check_perm = ModelService.check_permission(userID=userID, permID=30)
|
|
|
+ if not check_perm:
|
|
|
+ return response.json(404)
|
|
|
+ uid_list = Device_Info.objects.filter(userID_id=userID_id).values_list('UID', flat=True)
|
|
|
+ if not len(uid_list):
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID_id).order_by('-id')
|
|
|
+ if not qs.exists():
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ count = qs.count()
|
|
|
+ res = qs[(page - 1) * line:page * line]
|
|
|
+ send_json = CommonService.qs_to_dict(res)
|
|
|
+ send_json['count'] = count
|
|
|
+ return response.json(0, send_json)
|
|
|
+
|
|
|
|
|
|
def delete_by_admin(self, request_dict, userID,response):
|
|
|
id_list = request_dict.getlist('id', None)
|
|
|
+ if not len(id_list):
|
|
|
+ return response.json(444,'id is None or not list')
|
|
|
+ check_perm = ModelService.check_permission(userID=userID, permID=10)
|
|
|
+ if check_perm is True:
|
|
|
+ try:
|
|
|
+ is_delete = Equipment_Info.objects.filter(id__in=id_list).delete()
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(424, {'details': repr(e)})
|
|
|
+ else:
|
|
|
+ return response.json(0, {'delete_count': is_delete[0]})
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+
|
|
|
+class EquipmentInfo(View):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(EquipmentInfo, self).dispatch(*args, **kwargs)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.validation(request_dict=request.GET)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.validation(request_dict=request.POST)
|
|
|
+
|
|
|
+ def validation(self, request_dict, *args, **kwargs):
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ response = ResponseObject()
|
|
|
+ tko = TokenObject(token)
|
|
|
+ tko.valid()
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ operation = request_dict.get('operation', None)
|
|
|
+ if not userID:
|
|
|
+ return response.json(444, 'operation')
|
|
|
+ if operation == 'query':
|
|
|
+ return self.query_info(request_dict, userID, response)
|
|
|
+ elif operation == 'add':
|
|
|
+ return self.add_info(request_dict, userID, response)
|
|
|
+ elif operation == 'update':
|
|
|
+ return self.update_info(request_dict, userID, response)
|
|
|
+ elif operation == 'delete':
|
|
|
+ return self.delete_info(request_dict, userID, response)
|
|
|
+ elif operation == 'findByTime':
|
|
|
+ return self.findByTime_info(request_dict, userID, response)
|
|
|
+ if operation == 'queryByAdmin':
|
|
|
+ return self.query_all_info(request_dict, userID, response)
|
|
|
+ if operation == 'deleteByAdmin':
|
|
|
+ return self.delete_by_admin(request_dict, userID, response)
|
|
|
+ else:
|
|
|
+ return response.json(444, 'operation')
|
|
|
+
|
|
|
+ def add_info(self, request_dict, userID,response):
|
|
|
+ devUid = request_dict.get('devUid', None)
|
|
|
+ Channel = request_dict.get('Channel', None)
|
|
|
+ eventType = request_dict.get('eventType', None)
|
|
|
+ eventTime = request_dict.get('eventTime', None)
|
|
|
+ receiveTime = request_dict.get('receiveTime', None)
|
|
|
+ alarm = request_dict.get('alarm', None)
|
|
|
+ if not devUid or not Channel or not eventType or not eventTime or not alarm or not receiveTime:
|
|
|
+ return response.json(444,'devUid, Channel, eventType, eventTime, alarm, receiveTime')
|
|
|
+ own_device = ModelService.check_own_device(userID, UID=devUid)
|
|
|
+ if own_device is not True:
|
|
|
+ return response.json(14)
|
|
|
+ device_info = Device_Info.objects.filter(UID=devUid, userID_id=userID)
|
|
|
+ if not device_info.exists():
|
|
|
+ return response.json(14)
|
|
|
+ try:
|
|
|
+ equipment_info = Equipment_Info(
|
|
|
+ userID=Device_User.objects.get(userID=userID),
|
|
|
+ devUid=devUid,
|
|
|
+ Channel=Channel,
|
|
|
+ eventType=eventType,
|
|
|
+ receiveTime=receiveTime,
|
|
|
+ eventTime=eventTime,
|
|
|
+ viewPwd=device_info[0].View_Password,
|
|
|
+ devNickName=device_info[0].NickName,
|
|
|
+ viewAccont=device_info[0].View_Account,
|
|
|
+ alarm=alarm
|
|
|
+ )
|
|
|
+ equipment_info.save()
|
|
|
+ except Exception:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(500, errorInfo)
|
|
|
+ else:
|
|
|
+ if equipment_info.id:
|
|
|
+ return response.json(0, {'infoID': equipment_info.id,
|
|
|
+ 'devUid': devUid,
|
|
|
+ 'Channel': Channel,
|
|
|
+ 'alarm': alarm,
|
|
|
+ 'eventType': eventType,
|
|
|
+ 'eventTime': eventTime,
|
|
|
+ 'receiveTime': receiveTime,
|
|
|
+ 'viewPwd': equipment_info.viewPwd,
|
|
|
+ 'devNickName': equipment_info.devNickName,
|
|
|
+ 'viewAccont': equipment_info.viewAccont})
|
|
|
+ else:
|
|
|
+ return response.json(500)
|
|
|
+
|
|
|
+ def query_info(self, request_dict, userID,response):
|
|
|
+ page = int(request_dict.get('page', None))
|
|
|
+ line = int(request_dict.get('line', None))
|
|
|
+ if not page or not line:
|
|
|
+ return response.json(444,'page,line')
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ if uid:
|
|
|
+ qs.filter(uid=uid)
|
|
|
+ if not qs.exists():
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ count = qs.count()
|
|
|
+ res = qs[(page - 1) * line:page * line]
|
|
|
+ send_json = CommonService.qs_to_dict(res)
|
|
|
+ send_json['count'] = count
|
|
|
+ return response.json(0, send_json)
|
|
|
+
|
|
|
+ def update_info(self, request_dict, userID, response):
|
|
|
+ id_list = request_dict.getlist('id[]', None)
|
|
|
+ if id_list is None or len(id_list) < 1:
|
|
|
+ id_list = request_dict.getlist('id', None)
|
|
|
param_flag = CommonService.get_param_flag(data=[id_list])
|
|
|
if param_flag is True:
|
|
|
- check_perm = ModelService.check_permission(userID=userID, permID=10)
|
|
|
- if check_perm is True:
|
|
|
+ count = 0
|
|
|
+ for id in id_list:
|
|
|
try:
|
|
|
- is_delete = Equipment_Info.objects.filter(id__in=id_list).delete()
|
|
|
+ eq = Equipment_Info.objects.filter(id=int(id))
|
|
|
+ if eq.exists():
|
|
|
+ own_dev = ModelService.check_own_device(userID, eq[0].devUid)
|
|
|
+ if own_dev is True:
|
|
|
+ count += 1
|
|
|
+ eq.update(status=1)
|
|
|
except Exception as e:
|
|
|
- errorInfo = traceback.format_exc()
|
|
|
- print(errorInfo)
|
|
|
- return response.json(424,{'details': repr(e)})
|
|
|
- else:
|
|
|
- return response.json(0,{'delete_count': is_delete[0]})
|
|
|
+ print(repr(e))
|
|
|
+ return response.json(0,{'update_success': count})
|
|
|
+ else:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ def delete_info(self, request_dict, userID, response):
|
|
|
+ id_list = request_dict.getlist('id[]', None)
|
|
|
+ if id_list is None or len(id_list) < 1:
|
|
|
+ id_list = request_dict.getlist('id', None)
|
|
|
+ param_flag = CommonService.get_param_flag(data=[id_list])
|
|
|
+ if param_flag is True:
|
|
|
+ try:
|
|
|
+ for id in id_list:
|
|
|
+ eq = Equipment_Info.objects.filter(id=id)
|
|
|
+ if eq.exists():
|
|
|
+ own_dev = ModelService.check_own_device(userID, eq[0].devUid)
|
|
|
+ if own_dev is True:
|
|
|
+ eq.delete()
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(424,repr(e))
|
|
|
else:
|
|
|
- return response.json(404)
|
|
|
+ return response.json(0)
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
|
|
|
+ def findByTime_info(self, request_dict, userID,response):
|
|
|
+ startTime = request_dict.get('startTime')
|
|
|
+ endTime = request_dict.get('endTime')
|
|
|
+ page = int(request_dict.get('page', None))
|
|
|
+ line = int(request_dict.get('line', None))
|
|
|
+ if not startTime or not endTime or not page or not line:
|
|
|
+ return response.json(444,'startTime, endTime, page, line')
|
|
|
+ uid_list = Device_Info.objects.filter(userID_id=userID).values_list('UID', flat=True)
|
|
|
+ if not len(uid_list):
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID,
|
|
|
+ eventTime__range=(startTime, endTime)).order_by('-id')
|
|
|
+ if qs.exists():
|
|
|
+ count = qs.count()
|
|
|
+ res = qs[(page - 1) * line:page * line]
|
|
|
+ send_json = CommonService.qs_to_dict(res)
|
|
|
+ send_json['count'] = count
|
|
|
+ return response.json(0, send_json)
|
|
|
+
|
|
|
+
|
|
|
+ def query_all_info(self, request_dict, userID,response):
|
|
|
+ page = int(request_dict.get('page', None))
|
|
|
+ line = int(request_dict.get('line', None))
|
|
|
+ userID_id = request_dict.get('userID_id', None)
|
|
|
+ if not page or not line:
|
|
|
+ return response.json(444,'page,line')
|
|
|
+ check_perm = ModelService.check_permission(userID=userID, permID=30)
|
|
|
+ if not check_perm:
|
|
|
+ return response.json(404)
|
|
|
+ uid_list = Device_Info.objects.filter(userID_id=userID_id).values_list('UID', flat=True)
|
|
|
+ if not len(uid_list):
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID_id).order_by('-id')
|
|
|
+ if not qs.exists():
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ count = qs.count()
|
|
|
+ res = qs[(page - 1) * line:page * line]
|
|
|
+ send_json = CommonService.qs_to_dict(res)
|
|
|
+ send_json['count'] = count
|
|
|
+ return response.json(0, send_json)
|
|
|
+
|
|
|
+
|
|
|
+ def delete_by_admin(self, request_dict, userID,response):
|
|
|
+ id_list = request_dict.getlist('id', None)
|
|
|
+ if not len(id_list):
|
|
|
+ return response.json(444,'id is None or not list')
|
|
|
+ check_perm = ModelService.check_permission(userID=userID, permID=10)
|
|
|
+ if check_perm is True:
|
|
|
+ try:
|
|
|
+ is_delete = Equipment_Info.objects.filter(id__in=id_list).delete()
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(424, {'details': repr(e)})
|
|
|
+ else:
|
|
|
+ return response.json(0, {'delete_count': is_delete[0]})
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+
|