DetectController.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: AnsjerFormal
  7. @software: PyCharm
  8. @DATE: 2019/1/14 15:57
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: DetectController.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. import json
  15. import os
  16. import time
  17. import urllib
  18. import apns2
  19. import jpush as jpush
  20. import oss2
  21. import requests
  22. from django.utils.decorators import method_decorator
  23. from django.views.decorators.csrf import csrf_exempt
  24. from django.views.generic.base import View
  25. from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
  26. from Ansjer.config import BASE_DIR
  27. from Ansjer.config import SERVER_DOMAIN
  28. from Model.models import Device_Info, VodHlsModel, Equipment_Info, UidSetModel, UidPushModel
  29. from Object.ResponseObject import ResponseObject
  30. from Object.TokenObject import TokenObject
  31. from Object.UidTokenObject import UidTokenObject
  32. from django.http import JsonResponse
  33. from Object.RedisObject import RedisObject
  34. from django.db import transaction
  35. # http://192.168.136.40:8077/detect/changeStatus?uid=JW3684H8BSHG9TTM111A&token_val=18071adc03536302f34&appBundleId=com.ansjer.zccloud_ab&push_type=2&token=local&status=1&app_type=1
  36. class DetectControllerView(View):
  37. @method_decorator(csrf_exempt)
  38. def dispatch(self, *args, **kwargs):
  39. return super(DetectControllerView, self).dispatch(*args, **kwargs)
  40. def get(self, request, *args, **kwargs):
  41. request.encoding = 'utf-8'
  42. operation = kwargs.get('operation')
  43. return self.validation(request.GET, operation)
  44. def post(self, request, *args, **kwargs):
  45. request.encoding = 'utf-8'
  46. operation = kwargs.get('operation')
  47. return self.validation(request.POST, operation)
  48. def validation(self, request_dict, operation):
  49. response = ResponseObject()
  50. if operation is None:
  51. return response.json(444, 'error path')
  52. token = request_dict.get('token', None)
  53. tko = TokenObject(token)
  54. if tko.code == 0:
  55. userID = tko.userID
  56. # 修改推送设置
  57. if operation == 'changeStatus':
  58. return self.do_change_status(userID, request_dict, response)
  59. # 查询推送信息
  60. elif operation == 'queryInfo':
  61. return self.do_query(request_dict, response, userID)
  62. # 更新推送延迟
  63. elif operation == 'updateInterval':
  64. return self.do_update_interval(userID, request_dict, response)
  65. else:
  66. return response.json(414)
  67. else:
  68. return response.json(tko.code)
  69. def do_query(self, request_dict, response, userID):
  70. page = int(request_dict.get('page', None))
  71. line = int(request_dict.get('line', None))
  72. nowTime = int(time.time())
  73. if not page or not line:
  74. return response.json(444, 'page,line')
  75. qs = Equipment_Info.objects.filter(userID_id=userID, eventTime__gte=nowTime - 3600 * 24 * 27)
  76. uid = request_dict.get('uid', None)
  77. if uid:
  78. qs = qs.filter(devUid=uid)
  79. dvqs = Device_Info.objects.filter(UID=uid).values('Type', 'NickName')
  80. uid_type_dict = {uid: {'type': dvqs[0]['Type'], 'NickName': dvqs[0]['NickName']}}
  81. else:
  82. dvqs = Device_Info.objects.filter(userID_id=userID).values('UID', 'Type', 'NickName')
  83. uid_type_dict = {}
  84. for dv in dvqs:
  85. uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
  86. print(uid_type_dict)
  87. if not qs.exists():
  88. return response.json(0, {'datas': [], 'count': 0})
  89. qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
  90. 'receiveTime', 'is_st')
  91. count = qs.count()
  92. qr = qs[(page - 1) * line:page * line]
  93. res = []
  94. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  95. img_bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  96. # vod_time_list = []
  97. for p in qr:
  98. devUid = p['devUid']
  99. eventTime = p['eventTime']
  100. channel = p['Channel']
  101. if p['is_st'] == 1:
  102. p['img'] = img_bucket.sign_url('GET', '{uid}/{channel}/{time}.jpeg'.
  103. format(uid=devUid, channel=p['Channel'], time=eventTime), 300)
  104. p['img_list'] = [img_bucket.sign_url('GET', '{uid}/{channel}/{time}.jpeg'.
  105. format(uid=devUid, channel=channel, time=eventTime), 300)]
  106. elif p['is_st'] == 2:
  107. # 列表装载回放时间戳标记
  108. vodqs = VodHlsModel.objects.filter(uid=devUid, channel=channel, time=int(eventTime)) \
  109. .values("bucket__bucket", "bucket__endpoint")
  110. print(vodqs)
  111. if vodqs.exists():
  112. bucket_name = vodqs[0]['bucket__bucket']
  113. endpoint = vodqs[0]['bucket__endpoint']
  114. bucket = oss2.Bucket(auth, endpoint, bucket_name)
  115. ts = '{uid}/vod{channel}/{etime}/ts0.ts'.format(uid=devUid, channel=p['Channel'], etime=eventTime)
  116. thumb0 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_0000,w_700'})
  117. thumb1 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_1000,w_700'})
  118. thumb2 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_2000,w_700'})
  119. # thumb3 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_3000,w_700'})
  120. p['img_list'] = [thumb0, thumb1, thumb2]
  121. if devUid in uid_type_dict.keys():
  122. p['uid_type'] = uid_type_dict[devUid]['type']
  123. p['devNickName'] = uid_type_dict[devUid]['NickName']
  124. else:
  125. p['uid_type'] = ''
  126. res.append(p)
  127. return response.json(0, {'datas': res, 'count': count})
  128. def do_change_status(self, userID, request_dict, response):
  129. uid = request_dict.get('uid', None)
  130. token_val = request_dict.get('token_val', None)
  131. appBundleId = request_dict.get('appBundleId', None)
  132. app_type = request_dict.get('app_type', None)
  133. push_type = request_dict.get('push_type', None)
  134. status = request_dict.get('status', None)
  135. m_code = request_dict.get('m_code', None)
  136. # interval = request_dict.get('interval', None)
  137. print('status:' + status)
  138. if not status:
  139. return response.json(444, 'status')
  140. # 关闭推送
  141. if not all([appBundleId, app_type, token_val, uid, m_code]):
  142. return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
  143. dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
  144. status = int(status)
  145. if dvqs.exists():
  146. nowTime = int(time.time())
  147. uid_set_qs = UidSetModel.objects. \
  148. filter(uid=uid, uidpushmodel__userID_id=userID, uidpushmodel__m_code=m_code)
  149. # 判断是否有曾经开启过
  150. if uid_set_qs.exists():
  151. uid_push_update_dict = {
  152. 'appBundleId': appBundleId,
  153. 'app_type': app_type,
  154. 'push_type': push_type,
  155. 'token_val': token_val,
  156. 'updTime': nowTime
  157. }
  158. uid_set_qs.update(detect_status=status, updTime=nowTime)
  159. UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
  160. update(**uid_push_update_dict)
  161. utko = UidTokenObject()
  162. # right
  163. utko.generate(data={'uid': uid})
  164. detectUrl = "{SERVER_DOMAIN}notify/push?uidToken={uidToken}". \
  165. format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN)
  166. return response.json(0, {'detectUrl': detectUrl})
  167. else:
  168. uid_set_qs = UidSetModel.objects.filter(uid=uid)
  169. # 判断uid push是否绑定
  170. if not uid_set_qs.exists():
  171. uid_set_create_dict = {
  172. 'uid': uid,
  173. 'addTime': nowTime,
  174. 'updTime': nowTime,
  175. 'detect_status': status
  176. }
  177. # 添加设备配置
  178. uid_set_qs = UidSetModel.objects.create(**uid_set_create_dict)
  179. uid_set_id = uid_set_qs.id
  180. else:
  181. uid_set_id = uid_set_qs[0].id
  182. uid_push_create_dict = {
  183. 'uid_set_id': uid_set_id,
  184. 'userID_id': userID,
  185. 'appBundleId': appBundleId,
  186. 'app_type': app_type,
  187. 'push_type': push_type,
  188. 'token_val': token_val,
  189. 'm_code': m_code,
  190. 'addTime': nowTime,
  191. 'updTime': nowTime
  192. }
  193. # 绑定设备推送
  194. UidPushModel.objects.create(**uid_push_create_dict)
  195. utko = UidTokenObject()
  196. utko.generate(data={'uid': uid})
  197. detectUrl = "{SERVER_DOMAIN}notify/push?uidToken={uidToken}". \
  198. format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN)
  199. return response.json(0, {'detectUrl': detectUrl})
  200. else:
  201. return response.json(14)
  202. def do_update_interval(self, userID, request_dict, response):
  203. uid = request_dict.get('uid', None)
  204. interval = request_dict.get('interval', None)
  205. dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
  206. if dvqs.exists():
  207. uid_set_qs = UidSetModel.objects. \
  208. filter(uid=uid, uidpushmodel__userID_id=userID)
  209. if uid_set_qs.exists():
  210. uid_set_qs.update(interval=int(interval))
  211. else:
  212. return response.json(173)
  213. else:
  214. return response.json(0)
  215. # http://192.168.136.40:8077/notify/push?uidToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJUTjdNUEUzMjExVUU3NkFQMTExQSJ9.k501567VdnhFpn_ygzGRDat3Kqlz5CsEA9jAC2dDk_g&obj=12341234&n_time=1234561234
  216. # http://test.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
  217. # 移动侦测接口
  218. class NotificationView(View):
  219. def get(self, request, *args, **kwargs):
  220. request.encoding = 'utf-8'
  221. # operation = kwargs.get('operation')
  222. return self.validation(request.GET)
  223. def post(self, request, *args, **kwargs):
  224. request.encoding = 'utf-8'
  225. # operation = kwargs.get('operation')
  226. return self.validation(request.POST)
  227. def validation(self, request_dict):
  228. response = ResponseObject()
  229. uidToken = request_dict.get('uidToken', None)
  230. channel = request_dict.get('channel', None)
  231. n_time = request_dict.get('n_time', None)
  232. event_type = request_dict.get('event_type', None)
  233. is_st = request_dict.get('is_st', None)
  234. if not all([uidToken, channel, n_time]):
  235. return JsonResponse(status=200, data={
  236. 'code': 444,
  237. 'msg': 'param is wrong'})
  238. # return response.json(444)
  239. utko = UidTokenObject(uidToken)
  240. uid = utko.UID
  241. uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
  242. if uid_set_qs.exists():
  243. uid_set_id = uid_set_qs[0].id
  244. uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
  245. values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName')
  246. if uid_set_qs.exists():
  247. redisObj = RedisObject(db=6)
  248. pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
  249. if redisObj.get_data(key=pkey):
  250. res_data = {'code': 0, 'msg': 'success,!'}
  251. return JsonResponse(status=200, data=res_data)
  252. else:
  253. detect_interval = uid_set_qs[0].detect_interval
  254. if detect_interval:
  255. redisObj.set_data(key=pkey, val=1, expire=detect_interval)
  256. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  257. bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  258. for up in uid_push_qs:
  259. push_type = up['push_type']
  260. # ios apns
  261. if push_type == 0:
  262. self.do_apns(request_dict, up, response, uid)
  263. # android gcm
  264. elif push_type == 1:
  265. self.do_gmc(request_dict, up, response, uid)
  266. # android jpush
  267. elif push_type == 2:
  268. self.do_jpush(request_dict, up, response, uid)
  269. # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
  270. # 需求不一样,所以这么做的
  271. self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
  272. if is_st == '0' or is_st == '2':
  273. return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
  274. else:
  275. # Endpoint以杭州为例,其它Region请按实际情况填写。
  276. obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  277. # 设置此签名URL在60秒内有效。
  278. url = bucket.sign_url('PUT', obj, 7200)
  279. res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
  280. return JsonResponse(status=200, data=res_data)
  281. else:
  282. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  283. else:
  284. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  285. def do_jpush(self, request_dict, uaql, response, uid):
  286. event_type = request_dict.get('event_type', None)
  287. jpush_config = {
  288. 'com.ansjer.accloud_ab': {
  289. 'Key': 'f0dc047e5e53fd14199de5b0',
  290. 'Secret': 'aa7f7db33e9f0a7f3871aa1c'},
  291. 'com.ansjer.adcloud_ab': {
  292. 'Key': '76d97b535185114985608234',
  293. 'Secret': 'c9a92b301043cc9c52778692'},
  294. 'com.ansjer.zccloud_ab': {
  295. 'Key': 'd9924f56d3cc7c6017965130',
  296. 'Secret': '869d832d126a232f158b5987'},
  297. 'com.ansjer.loocamccloud_ab': {
  298. 'Key': 'd1cc44797b4642b0e05304fe',
  299. 'Secret': 'c3e8b4ca8c576de61401e56a'},
  300. 'com.ansjer.loocamdcloud_ab': {
  301. 'Key': '76d97b535185114985608234',
  302. 'Secret': 'c9a92b301043cc9c52778692'},
  303. 'com.ansjer.zccloud_a': {
  304. 'Key': '57de2a80d68bf270fd6bdf5a',
  305. 'Secret': '3d354eb6a0b49c2610decf42'},
  306. 'com.ansjer.accloud_a': {
  307. 'Key': 'ff95ee685f49c0dc4013347b',
  308. 'Secret': 'de2c20959f5516fdeeafe78e'},
  309. 'com.ansjer.adcloud_a': {
  310. 'Key': '2e47eb1aee9b164460df3668',
  311. 'Secret': 'b9137d8d684bc248f1809b6d'},
  312. 'com.ansjer.loocamccloud_a': {
  313. 'Key': '23c9213215c7ca0ec945629b',
  314. 'Secret': '81e4b1e859cc8387e2e6c431'},
  315. 'com.ansjer.loocamdcloud_a': {
  316. 'Key': '1dbdd60a16e9892d6f68a073',
  317. 'Secret': '80a97690e7e043109059b403'},
  318. 'com.ansjer.customizedb_a': {
  319. 'Key': '9d79630aa49adfa291fe2568',
  320. 'Secret': '4d8ff52f88136561875a0212'},
  321. }
  322. n_time = request_dict.get('n_time', None)
  323. appBundleId = uaql['appBundleId']
  324. token_val = uaql['token_val']
  325. response = ResponseObject()
  326. app_key = jpush_config[appBundleId]['Key']
  327. master_secret = jpush_config[appBundleId]['Secret']
  328. # 此处换成各自的app_key和master_secre
  329. _jpush = jpush.JPush(app_key, master_secret)
  330. push = _jpush.create_push()
  331. # if you set the logging level to "DEBUG",it will show the debug logging.
  332. _jpush.set_logging("DEBUG")
  333. # push.audience = jpush.all_
  334. push.audience = jpush.registration_id(token_val)
  335. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  336. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1"}
  337. push.message = jpush.message('Motion', extras=push_data, title='KPNS', content_type='text')
  338. push.platform = jpush.all_
  339. try:
  340. res = push.send()
  341. print(res)
  342. except Exception as e:
  343. print("Exception")
  344. print(repr(e))
  345. return response.json(10, repr(e))
  346. else:
  347. return response.json(0)
  348. def do_gmc(self, request_dict, uaql, response, uid):
  349. n_time = request_dict.get('n_time')
  350. appBundleId = uaql['appBundleId']
  351. token_val = uaql['token_val']
  352. gcm_config = {
  353. 'com.ansjer.zccloud_a': 'AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I',
  354. 'com.ansjer.loocamccloud_a': 'AAAAb9YP3rk:APA91bFCgd-kbVmpK4EVpfdHH_PJZQCYTkOGnTZdIuBWEz2r7aMRsJYHOH3sB-rwcbaRWgnufTyjX9nGQxb6KxQbWVk4ah_H-M3IqGh6Mb60WQQAuR33V6g_Jes5pGL6ViuIxGHqVMaR',
  355. 'com.ansjer.loocamdcloud_a': 'AAAAb9YP3rk:APA91bGw2I2KMD4i-5T7nZO_wB8kuAOuqgyqe5rxmY-W5qkpYEx9IL2IfmC_qf6B_xOyjIDDSjckvMo-RauN__SEoxvAkis7042GRkoKpw7cjZ_H8lC-d50PC0GclPzccrOGFusyKbFY',
  356. 'com.ansjer.customizedb_a': 'AAAAb9YP3rk:APA91bE7kI4vcm-9h_CJNFlOZfc-xwP4Btn6AnjOrwoKV6fgYN7fdarkO76sYxVZiAbDnxsFfOJyP7vQfwyan6mdjuyD5iHdt_XgO22VqniC0vA1V4GJiCS8Tp7LxIX8JVKZl9I_Powt',
  357. 'com.ansjer.customizeda_a': 'AAAAb9YP3rk:APA91bF0HzizVWDc6dKzobY9fsaKDK4veqkOZehDXshVXs8pEEvNWjR_YWbhP60wsRYCHCal8fWN5cECVOWNMMzDsfU88Ty2AUl8S5FtZsmeDTkoGntQOswBr8Ln7Fm_LAp1VqTf9CpM',
  358. }
  359. serverKey = gcm_config[appBundleId]
  360. event_type = request_dict.get('event_type', None)
  361. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  362. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1"}
  363. json_data = {
  364. "collapse_key": "WhatYouWant",
  365. "data": push_data,
  366. "delay_while_idle": False,
  367. "time_to_live": 3600,
  368. "registration_ids": [token_val]
  369. }
  370. url = 'https://android.googleapis.com/gcm/send'
  371. # serverKey = "AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I"
  372. data = json.dumps(json_data).encode('utf-8')
  373. headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % serverKey}
  374. req = requests.post(url, data, headers=headers)
  375. return response.json(0)
  376. def do_apns(self, request_dict, uaql, response, uid):
  377. token_val = uaql['token_val']
  378. n_time = request_dict.get('n_time')
  379. appBundleId = uaql['appBundleId']
  380. apns_config = {
  381. 'appbundleId': {'pem_path': 'xxxx', 'topic': 'topic', 'password': 'password'}
  382. }
  383. try:
  384. # daytime = time.strftime("%Y%m%d%H%M", time.localtime(1547256103))
  385. # print(daytime)
  386. pem_path = os.path.join(BASE_DIR, apns_config[appBundleId]['topic'])
  387. # pem_path = os.path.join(BASE_DIR, 'Ansjer/file/apns-dev.pem')
  388. cli = apns2.APNSClient(mode="dev", client_cert=pem_path, password='111111')
  389. body = json.dumps({'uid': uid, 'n_time': n_time})
  390. alert = apns2.PayloadAlert(body="body!", title="title!")
  391. payload = apns2.Payload(alert=alert)
  392. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  393. res = cli.push(n=n, device_token=token_val, topic=apns_config[appBundleId]['pem_path'])
  394. # assert res.status_code == 200, res.reason
  395. # assert res.apns_id
  396. if res.status_code == 200:
  397. return response.json(0)
  398. else:
  399. return response.json(404, res.reason)
  400. except Exception as e:
  401. return response.json(10, repr(e))
  402. def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
  403. #
  404. qs_list = []
  405. nowTime = int(time.time())
  406. # 设备昵称
  407. for dv in uaqs:
  408. add_data = {
  409. 'userID_id': dv["userID_id"],
  410. 'eventTime': n_time,
  411. 'eventType': event_type,
  412. 'devUid': uid,
  413. 'devNickName': uid,
  414. 'Channel': channel,
  415. 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
  416. 'is_st': int(is_st),
  417. 'receiveTime': n_time,
  418. 'addTime': nowTime
  419. }
  420. qs_list.append(Equipment_Info(**add_data))
  421. if qs_list:
  422. print(1)
  423. Equipment_Info.objects.bulk_create(qs_list)
  424. return True
  425. else:
  426. return False