|
@@ -1,12 +1,14 @@
|
|
|
# @Author : Rocky
|
|
|
# @File : InitController.py
|
|
|
# @Time : 2023/4/11 17:26
|
|
|
+import json
|
|
|
import ssl
|
|
|
+import time
|
|
|
|
|
|
from django.http import HttpResponse
|
|
|
from django.views import View
|
|
|
|
|
|
-from Model.models import Device_Info, SceneLog
|
|
|
+from Model.models import Device_Info, SceneLog, EquipmentInfo1
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
import redis
|
|
@@ -29,6 +31,8 @@ class InitView(View):
|
|
|
return self.health_check(request_dict)
|
|
|
elif operation == 'oci_redis_test':
|
|
|
return self.oci_redis_test(request_dict)
|
|
|
+ elif operation == 'oci_redis_test_2':
|
|
|
+ return self.oci_redis_test_2(request_dict)
|
|
|
|
|
|
@staticmethod
|
|
|
def health_check(request_dict):
|
|
@@ -66,3 +70,44 @@ class InitView(View):
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
return HttpResponse(repr(e), status=500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def oci_redis_test_2(request_dict):
|
|
|
+ try:
|
|
|
+ redis_obj = RedisObject()
|
|
|
+ response = ResponseObject()
|
|
|
+ equipment_info_kwargs = {
|
|
|
+ 'device_user_id': '163417566733313800138000',
|
|
|
+ 'event_time': int(time.time()),
|
|
|
+ 'event_type': 0,
|
|
|
+ 'device_uid': 'H47UZJ7PHY2NXKNW111A',
|
|
|
+ 'device_nick_name': 'redis_test',
|
|
|
+ 'channel': 1,
|
|
|
+ 'alarm': 'Motion',
|
|
|
+ 'is_st': 0,
|
|
|
+ 'add_time': int(time.time()),
|
|
|
+ 'storage_location': 1,
|
|
|
+ 'event_tag': '',
|
|
|
+ 'answer_status': 0
|
|
|
+ }
|
|
|
+ # 保存到redis列表
|
|
|
+ equipment_info_value = json.dumps(equipment_info_kwargs)
|
|
|
+ equipment_info_key = 'equipment_info'
|
|
|
+ redis_obj.rpush(equipment_info_key, equipment_info_value)
|
|
|
+ equipment_info_redis_list = redis_obj.lrange(equipment_info_key, 0, 99)
|
|
|
+ redis_obj.ltrim(equipment_info_key, 100, -1)
|
|
|
+
|
|
|
+ equipment_info_list = []
|
|
|
+ for equipment_info in equipment_info_redis_list:
|
|
|
+ equipment_info_data = eval(equipment_info)
|
|
|
+ # 设备昵称存在表情,解码utf-8
|
|
|
+ if equipment_info_data.get('device_nick_name') is not None:
|
|
|
+ equipment_info_data['device_nick_name'] = equipment_info_data['device_nick_name']. \
|
|
|
+ encode('UTF-8', 'ignore').decode('UTF-8')
|
|
|
+
|
|
|
+ equipment_info_list.append(EquipmentInfo1(**equipment_info_data))
|
|
|
+ EquipmentInfo1.objects.bulk_create(equipment_info_list)
|
|
|
+
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return HttpResponse(repr(e), status=500)
|