check_command_XmSgj.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. import asyncio
  2. import datetime
  3. import hashlib
  4. import json
  5. import sys
  6. import time
  7. from concurrent.futures import ThreadPoolExecutor
  8. import requests
  9. sys.path.append("..")
  10. import pymysql
  11. import logging
  12. import uuid
  13. import chardet
  14. import message_pb2 as message
  15. import google.protobuf.text_format as tf
  16. import http_client
  17. import mytool.db_helper.db_operation as spmng
  18. MeasureStatu = {"ok": message.MeasureStatu.Value('Measure_OK'),
  19. "无数据": message.MeasureStatu.Value('Measure_Empty_Clouds'),
  20. "噪声": message.MeasureStatu.Value('Measure_Failture'),
  21. "PLC超界": message.MeasureStatu.Value('Measure_Border'),
  22. "终端超界": message.MeasureStatu.Value('Measure_Terminal_Border'),
  23. "失去连接": message.MeasureStatu.Value('Lidar_Disconnect')
  24. }
  25. Range_status = {"未超界": message.Range_status.Value('Range_correct'),
  26. "前超界": message.Range_status.Value('Range_front'),
  27. "后超界": message.Range_status.Value('Range_back'),
  28. "左超界": message.Range_status.Value('Range_left'),
  29. "右超界": message.Range_status.Value('Range_right'),
  30. "底盘超界": message.Range_status.Value('Range_bottom'),
  31. "车顶超界": message.Range_status.Value('Range_top'),
  32. "车宽超界": message.Range_status.Value('Range_car_width'),
  33. "轴距超界": message.Range_status.Value('Range_car_wheelbase'),
  34. "左旋转超界": message.Range_status.Value('Range_angle_anti_clock'),
  35. "右旋转超界": message.Range_status.Value('Range_angle_clock'),
  36. "方向盘未回正": message.Range_status.Value('Range_steering_wheel_nozero'),
  37. "车辆移动": message.Range_status.Value('Range_car_moving')
  38. }
  39. class CommandChecker:
  40. def __init__(self, db_config):
  41. self.db = spmng.DBOperation(db_config['db_ip'], db_config['db_port'], db_config['db_name'],
  42. db_config['db_user'], db_config['db_password'])
  43. self._dispatch_statu = {}
  44. self._measure_statu = {}
  45. self._in_url = 'http://szdy.xmsztc.cn/Api/CarInEntry'
  46. self._query_url = 'http://szdy.xmsztc.cn/Api/GetBill'
  47. self._out_url = 'http://szdy.xmsztc.cn/Api/CarOutEntry'
  48. self._out_url_phone = 'https://sztc.xmsztc.cn/api/operateOutScene/sgjOutSceneRecord'
  49. # self._out_url_phone = 'https://sztc.smartcityxm.com/api/operateOutScene/sgjOutSceneRecord' 测试环境
  50. self._app_id_phone = '20230412151327035'
  51. self._appSecret_phone = 'Dl8gh4GGspOu9UU7YW00b55wE93ga6aF'
  52. self._secret_key = 'anzs74aph8ac8dy6tj48t05js6zpkgx5'
  53. self._parking_id = '2306041414159951342'
  54. self._app_id = 'blbc5zkpyymaicd3'
  55. self._http = 'https://sztc.smartcityxm.com/wechath5/#/pagesA/parkingBill/inrecord_parking?inRecordId='
  56. self.chnnId_in = {11: '2307241522121721333', 12: '2306041439573931681', 13: '2307241531240571925',
  57. 14: '2307241534030091638'
  58. , 21: '2307241536315471441', 22: '2307211200055462502', 23: '2307241540369691638',
  59. 24: '2307241549404491178', 25: '2307211153450762758'
  60. , 31: '2307241552306981925', 32: '2307241554369581606'}
  61. self.chnnId_out = {11: '2307241523438171745', 12: '2306041441029631932', 13: '2307241532575281334',
  62. 14: '2307241534536081930'
  63. , 21: '2307241538324701014', 22: '2307211201229402651', 23: '2307241542527281313',
  64. 24: '2307241550388621477', 25: '2307211155130692935'
  65. , 31: '2307241553191751202', 32: '2307241555230551872'}
  66. self._plate_color = {'蓝色': '1', '黑色': '2', '黄色': '3', '白色': '4', '绿色': '5', '其他': '6'}
  67. def get_in_url(self):
  68. return self._in_url
  69. def receive_dispatch_statu(self, statu, ex, key):
  70. self._dispatch_statu[key] = statu
  71. def receive_measure_info(self, statu, ex, key):
  72. self._measure_statu[key] = statu
  73. # 给收费系统推送请求
  74. def push_http_request(self, url, request, headers=None):
  75. results = ''
  76. statu = message.eError
  77. tm = time.time()
  78. # 若推送失败就重试最多2s
  79. while time.time() - tm < 2:
  80. try:
  81. print("请求地址:" + url)
  82. if url != self._in_url:
  83. print("请求内容:" + str(request))
  84. resp = requests.post(url, json=request, headers=headers,timeout=2).json()
  85. print("请求答复:"+str(resp)+'\n')
  86. if (('Tag' in resp.keys()) and resp['Tag'] == 1) or \
  87. (('code' in resp.keys()) and resp['code'] == 0):
  88. statu = message.eNormal
  89. results = resp
  90. break
  91. else:
  92. statu = message.eError
  93. results = '收费系统反馈错误!message:%s' % resp
  94. except Exception as e:
  95. statu = message.eError
  96. results = '向收费系统推送请求失败! ERROR:%s' % (str(e.args))
  97. time.sleep(0.2)
  98. return statu, results
  99. # 检查存车指令
  100. def entrance_isOK(self, park_body):
  101. # 停车表单
  102. park_table = message.park_table()
  103. try:
  104. tf.Parse(park_body, park_table)
  105. except Exception as e:
  106. park_table.statu.execute_statu = message.eError
  107. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(停车表单错误)" + str(e.args)
  108. return park_table
  109. # 检查调度状态
  110. dispatch_key = "dispatch_%d_statu_port" % park_table.unit_id
  111. if (dispatch_key in self._dispatch_statu) is False or self._dispatch_statu[dispatch_key].timeout():
  112. park_table.statu.execute_statu = message.eError
  113. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(调度)"
  114. return park_table
  115. # 获取车高信息
  116. dispatch_node_statu = message.dispatch_node_statu()
  117. try:
  118. tf.Parse(self._dispatch_statu[dispatch_key].statu, dispatch_node_statu)
  119. except Exception:
  120. park_table.statu.execute_statu = message.eError
  121. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(调度状态消息错误)"
  122. return park_table
  123. # 判断搬运器状态
  124. if dispatch_node_statu.plc_carrier_status == 0:
  125. park_table.statu.execute_statu = message.eError
  126. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(搬运器)"
  127. return park_table
  128. dispatch_plc_passway_status = dispatch_node_statu.dispatch_plc_passway_status_vector[park_table.import_id - 1]
  129. # 检查入口状态
  130. if dispatch_node_statu.plc_carrier_status == 4 or dispatch_plc_passway_status.plc_passway_enable == 2:
  131. park_table.statu.execute_statu = message.eWarning
  132. park_table.statu.statu_description = "该单元设备维护中!请前往其他入口!"
  133. return park_table
  134. if dispatch_plc_passway_status.car_height == 0:
  135. park_table.statu.execute_statu = message.eWarning
  136. park_table.statu.statu_description = "未检测到车辆!"
  137. return park_table
  138. elif dispatch_plc_passway_status.car_height == 4:
  139. park_table.statu.execute_statu = message.eWarning
  140. park_table.statu.statu_description = "车辆超高,请退出车库!"
  141. return park_table
  142. sensor_1 = dispatch_plc_passway_status.sensor_1
  143. sensor_2 = dispatch_plc_passway_status.sensor_2
  144. if park_table.unit_id != 31 and park_table.unit_id != 32:
  145. if (sensor_2 >> 3) & 0x01 != 1 or (sensor_2 >> 4) & 0x01 != 1:
  146. park_table.statu.execute_statu = message.eWarning
  147. park_table.statu.statu_description = "车辆未停到位,请根据库内指示灯挪车!"
  148. return park_table
  149. if (sensor_1 >> 2) & 0x01 != 1:
  150. park_table.statu.execute_statu = message.eWarning
  151. park_table.statu.statu_description = "车辆超限,请联系现场工作人员!"
  152. return park_table
  153. if (sensor_1 >> 3) & 0x01 != 1:
  154. park_table.statu.execute_statu = message.eWarning
  155. park_table.statu.statu_description = "车辆后超界,请往前!"
  156. return park_table
  157. if (sensor_1 >> 4) & 0x01 != 1:
  158. park_table.statu.execute_statu = message.eWarning
  159. park_table.statu.statu_description = "车辆前超界,请往后!"
  160. return park_table
  161. if (sensor_1 >> 5) & 0x01 != 1:
  162. park_table.statu.execute_statu = message.eWarning
  163. park_table.statu.statu_description = "车辆左超界,请往右!"
  164. return park_table
  165. if (sensor_1 >> 6) & 0x01 != 1:
  166. park_table.statu.execute_statu = message.eWarning
  167. park_table.statu.statu_description = "车辆右超界,请往左!"
  168. return park_table
  169. measure_buffer = message.measure_buffer()
  170. measure_info_to_terminal = message.measure_info()
  171. measure_info_to_plc_reverse = message.measure_info()
  172. measure_info_to_plc_forward = message.measure_info()
  173. if park_table.unit_id == 31 or park_table.unit_id == 32:
  174. measure_key = "measure_%d_statu_port" % park_table.terminal_id
  175. if (measure_key in self._measure_statu) is False or self._measure_statu[measure_key].timeout():
  176. park_table.statu.execute_statu = message.eError
  177. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(雷达)"
  178. return park_table
  179. # 获取车高信息
  180. try:
  181. tf.Parse(self._measure_statu[measure_key].statu, measure_buffer)
  182. measure_info_to_terminal.CopyFrom(measure_buffer.measure_info_to_terminal)
  183. measure_info_to_plc_reverse.CopyFrom(measure_buffer.measure_info_to_plc_reverse)
  184. measure_info_to_plc_forward.CopyFrom(measure_buffer.measure_info_to_plc_forward)
  185. except Exception:
  186. park_table.statu.execute_statu = message.eError
  187. park_table.statu.statu_description = "设备故障,请联系管理员!" + "(雷达状态消息错误)"
  188. return park_table
  189. # 获取雷达信息
  190. tm = time.time()
  191. while time.time() - tm < 2:
  192. park_table.entrance_measure_info.CopyFrom(measure_buffer)
  193. # 没有超界。车为静止状态。
  194. # if measure_info.border_statu == MeasureStatu["ok"] and measure_info.ground_status == 0 and measure_info.motion_statu == 1:
  195. if measure_info_to_terminal.border_statu == Range_status["未超界"] and \
  196. measure_info_to_terminal.ground_status == MeasureStatu["ok"] and \
  197. measure_info_to_plc_reverse.border_statu == Range_status["未超界"] and \
  198. measure_info_to_plc_reverse.ground_status == MeasureStatu["ok"] and \
  199. measure_info_to_plc_forward.border_statu == Range_status["未超界"] and \
  200. measure_info_to_plc_forward.ground_status == MeasureStatu["ok"]:
  201. park_table.statu.execute_statu = message.eNormal
  202. break
  203. else:
  204. park_table.statu.execute_statu = message.eError
  205. if self._measure_statu[measure_key].statu is not None and self._measure_statu[
  206. measure_key].timeout() is False:
  207. try:
  208. measure_buffer = message.measure_buffer()
  209. measure_info_to_terminal = message.measure_info()
  210. tf.Parse(self._measure_statu[measure_key].statu, measure_buffer)
  211. measure_info_to_terminal.CopyFrom(measure_buffer.measure_info_to_terminal)
  212. measure_info_to_plc_reverse.CopyFrom(measure_buffer.measure_info_to_plc_reverse)
  213. measure_info_to_plc_forward.CopyFrom(measure_buffer.measure_info_to_plc_forward)
  214. # print("check measure info again:", measure_info)
  215. except:
  216. print("parse exception:\n" + self._measure_statu[measure_key].statu)
  217. time.sleep(0.1)
  218. if park_table.statu.execute_statu == message.eError:
  219. if measure_info_to_terminal.ground_status == MeasureStatu["ok"] or \
  220. measure_info_to_plc_reverse.ground_status == MeasureStatu["ok"] or \
  221. measure_info_to_plc_forward.ground_status == MeasureStatu["ok"]:
  222. park_table.statu.statu_description = "雷达状态异常!"
  223. elif measure_info_to_terminal.ground_status == MeasureStatu["终端超界"] or \
  224. measure_info_to_plc_reverse.ground_status == MeasureStatu["PLC超界"] or \
  225. measure_info_to_plc_forward.ground_status == MeasureStatu["PLC超界"]:
  226. park_table.statu.statu_description = "请按提示调整!"
  227. elif measure_info_to_terminal.ground_status == MeasureStatu["失去连接"] or \
  228. measure_info_to_plc_reverse.ground_status == MeasureStatu["失去连接"] or \
  229. measure_info_to_plc_forward.ground_status == MeasureStatu["失去连接"]:
  230. park_table.statu.statu_description = "设备故障,请联系管理员! (雷达)"
  231. else:
  232. park_table.statu.statu_description = "请检查库内是否有异物!"
  233. print(" MeasureInfo:\n " + tf.MessageToString(measure_info_to_terminal, as_utf8=True))
  234. return park_table
  235. # 填写车高信息
  236. height = dispatch_plc_passway_status.car_height
  237. # 赋值唯一码
  238. uid = str(uuid.uuid1())
  239. park_table.primary_key = uid
  240. # 查询黑名单
  241. print("----------------------------查询黑名单-----------------------------" + str(datetime.datetime.now()))
  242. blacklist_res = self.db.query_blacklist_in_car_number(park_table.car_number)
  243. blacklist_count = len(blacklist_res)
  244. if blacklist_count > 0:
  245. park_table.statu.execute_statu = message.eWarning
  246. park_table.statu.statu_description = "车辆 :%s 车辆超限,请退出!" % park_table.car_number
  247. return park_table
  248. # 查询车位表和指令表是否有该车
  249. print("----------------------------查询车位表-----------------------------" + str(datetime.datetime.now()))
  250. space_res = self.db.query_space_in_car_number(park_table.car_number)
  251. space_count = len(space_res)
  252. if space_count > 0:
  253. park_table.statu.execute_statu = message.eWarning
  254. park_table.statu.statu_description = "车辆 :%s 已在库内!" % park_table.car_number
  255. return park_table
  256. print("----------------------------查询指令表-----------------------------" + str(datetime.datetime.now()))
  257. command_res = self.db.query_command_in_car_number(park_table.car_number)
  258. command_count = len(command_res)
  259. if command_count > 0:
  260. park_table.statu.execute_statu = message.eWarning
  261. park_table.statu.statu_description = "指令正在执行中!请稍等!"
  262. return park_table
  263. # 车辆不在库内 查询是否有对应大小空车位
  264. print("----------------------------查询空车位-----------------------------" + str(datetime.datetime.now()))
  265. space_empty_res = self.db.query_space_in_height_level_wheel_base_unit_and_empty(height,
  266. measure_info_to_terminal.wheelbase,
  267. park_table.unit_id)
  268. space_empty_count = len(space_empty_res)
  269. if space_empty_count <= 0:
  270. park_table.statu.execute_statu = message.eWarning
  271. park_table.statu.statu_description = "没有空余的合适车位,车牌号:%s 高度等级:%d 轴距:%.3fm!" % (
  272. park_table.car_number, height, measure_info_to_terminal.wheelbase)
  273. else:
  274. # 查询是否在白名单
  275. print("----------------------------查询白名单-----------------------------" + str(datetime.datetime.now()))
  276. whitelist_res = self.db.query_whitelist_in_car_number(park_table.car_number)
  277. if len(whitelist_res) <= 0:
  278. # 向收费系统推送入场信息
  279. print("----------------------------推送入场-----------------------------" + str(datetime.datetime.now()))
  280. request = self.get_request_data(park_table, 'in')
  281. statu, response = self.push_http_request(self._in_url, request)
  282. if statu != message.eNormal:
  283. park_table.statu.execute_statu = statu
  284. park_table.statu.statu_description = response
  285. else:
  286. if ('Data' in response.keys()) and ('InPicUrl' in response['Data'].keys()):
  287. park_table.car_number_info.plate_full_image = response['Data']['InPicUrl']
  288. park_table.car_number_info.plate_clip_image = response['Data']['InPlateUrl']
  289. else:
  290. park_table.statu.execute_statu = message.eError
  291. park_table.statu.statu_description = "收费系统答复错误!请联系管理员!"
  292. else:
  293. print("----------------------------白名单车辆-----------------------------" + str(datetime.datetime.now()))
  294. return park_table
  295. # 检查取车指令
  296. def exit_isOK(self, pick_body):
  297. pick_table = message.pick_table()
  298. try:
  299. tf.Parse(pick_body, pick_table)
  300. except Exception as e:
  301. pick_table.statu.execute_statu = message.eError
  302. pick_table.statu.statu_description = "设备故障,请联系管理员!" + "(取车表单错误)" + str(e.args)
  303. return pick_table
  304. if pick_table.primary_key is None or pick_table.primary_key == '':
  305. pick_table.statu.execute_statu = message.eWarning
  306. pick_table.statu.statu_description = " 唯一码不能为空!"
  307. else:
  308. # 查询车位表和指令表是否有该车
  309. print("****************************查询车位表****************************" + str(datetime.datetime.now()))
  310. space_res = self.db.query_space_in_primary_key(pick_table.primary_key)
  311. space_count = len(space_res)
  312. print("****************************查询停车指令表****************************" + str(datetime.datetime.now()))
  313. command_res_park = self.db.query_park_command_in_primary_key(pick_table.primary_key)
  314. command_count_park = len(command_res_park)
  315. if space_count <= 0 and command_count_park <= 0:
  316. pick_table.statu.execute_statu = message.eWarning
  317. pick_table.statu.statu_description = "车辆信息不存在!"
  318. return pick_table
  319. print("****************************查询取车指令表****************************" + str(datetime.datetime.now()))
  320. command_res = self.db.query_pick_command_in_primary_key(pick_table.primary_key)
  321. command_count = len(command_res)
  322. if command_count > 0:
  323. pick_table.unit_id = space_res[0]['unit']
  324. t_unit_str = self.get_unit_str(pick_table.unit_id)
  325. # 重复取车,提示成功,流程失败!
  326. pick_table.statu.execute_statu = message.eWarning
  327. pick_table.statu.statu_description = "取车成功!请前往 << %s >> 单元出口等待车辆,观看大屏幕提示取车!" % t_unit_str
  328. return pick_table
  329. pick_table.statu.execute_statu = message.eNormal
  330. pick_table.statu.statu_description = "取车成功,请观看大屏幕提示取车!"
  331. # 完善表单信息
  332. try:
  333. try:
  334. pick_table.car_number = space_res[0]['car_number']
  335. pick_table.unit_id = space_res[0]['unit']
  336. except Exception as e:
  337. pick_table.car_number = command_res_park[0]['car_number']
  338. pick_table.unit_id = command_res_park[0]['unit']
  339. print("车为表未找到,使用指令表结果")
  340. pick_table.car_number_info.plate_color = space_res[0]['plate_color']
  341. pick_table.car_number_info.plate_type = space_res[0]['plate_type']
  342. pick_table.car_number_info.plate_confidence = space_res[0]['plate_confidence']
  343. pick_table.car_number_info.recognition_time = space_res[0]['recognition_time']
  344. pick_table.car_number_info.plate_full_image = ''
  345. pick_table.car_number_info.plate_clip_image = ''
  346. except Exception as e:
  347. print("数据库信息不全,缺失号牌颜色等信息!")
  348. # 强制取车 或 虚拟取车
  349. if pick_table.statu.table_process_mod == message.PROCESS_ONLY_TO_DISPATCH or pick_table.statu.table_process_mod == message.PROCESS_ONLY_TO_PAY:
  350. # if pick_table.unit_id != 31 and pick_table.unit_id != 32:
  351. # 直接向收费系统发送出场
  352. print("****************************收费系统推送出场****************************" + str(datetime.datetime.now()))
  353. request, request2,headers = self.get_request_data(pick_table, 'out')
  354. self.push_http_request(self._out_url, request)
  355. print("\n")
  356. print("****************************手机端推送出场****************************" + str(datetime.datetime.now()))
  357. self.push_http_request(self._out_url_phone, request2,headers)
  358. print('强制取车')
  359. else:
  360. print("****************************查询白名单****************************" + str(datetime.datetime.now()))
  361. whitelist_res = self.db.query_whitelist_in_car_number(pick_table.car_number)
  362. if len(whitelist_res) <= 0:
  363. # 向收费系统查询缴费情况
  364. print("****************************查询缴费情况****************************" + str(datetime.datetime.now()))
  365. request = self.get_request_data(pick_table, 'query')
  366. statu, response = self.push_http_request(self._query_url, request)
  367. if statu == message.eNormal:
  368. if ('Data' in response.keys()) and ('UnpaidMoney' in response['Data'].keys()):
  369. if response['Data']['UnpaidMoney'] == 0:
  370. # 向收费系统推送车辆离场
  371. print("****************************收费系统推送出场****************************" + str(datetime.datetime.now()))
  372. request, request2,headers = self.get_request_data(pick_table, 'out')
  373. statu, response = self.push_http_request(self._out_url, request)
  374. print("****************************手机端推送出场****************************" + str(datetime.datetime.now()))
  375. self.push_http_request(self._out_url_phone, request2, headers)
  376. if statu != message.eNormal:
  377. pick_table.statu.execute_statu = statu
  378. pick_table.statu.statu_description = response
  379. else:
  380. unit_str = self.get_unit_str(pick_table.unit_id)
  381. pick_table.statu.execute_statu = message.eNormal
  382. pick_table.statu.statu_description = "取车成功,请前往 << %s >> 单元出口等待车辆,观看大屏幕提示取车!" % unit_str
  383. else:
  384. pick_table.statu.execute_statu = message.eWarning
  385. pick_table.statu.statu_description = ("您有待缴费用,请您微信扫码缴费%.2f元;" % (
  386. response['Data']['UnpaidMoney'])) + self._http + pick_table.primary_key
  387. else:
  388. pick_table.statu.execute_statu = message.eError
  389. pick_table.statu.statu_description = "收费系统答复错误!请联系管理员!"
  390. else:
  391. pick_table.statu.execute_statu = statu
  392. pick_table.statu.statu_description = response
  393. else:
  394. unit_str = self.get_unit_str(pick_table.unit_id)
  395. pick_table.statu.execute_statu = message.eNormal
  396. pick_table.statu.statu_description = "取车成功,请前往 << %s >> 单元出口等待车辆,观看大屏幕提示取车!" % unit_str
  397. return pick_table
  398. def get_request_data(self, table, param):
  399. print(param+":")
  400. # 创建请求
  401. msgId = str(uuid.uuid1()) + '@' + table.car_number
  402. AppId = self._app_id
  403. time = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
  404. sign = msgId + AppId + time + self._secret_key
  405. hl = hashlib.md5()
  406. hl.update(sign.encode(encoding='utf-8'))
  407. sign = hl.hexdigest()
  408. color = self._plate_color[
  409. table.car_number_info.plate_color] if table.car_number_info.plate_color in self._plate_color.keys() else \
  410. self._plate_color['其他']
  411. if param == 'in':
  412. data = http_client.HttpRequest.InDate(self._parking_id, table.car_number,
  413. str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')),
  414. self.chnnId_in[table.unit_id],
  415. table.car_number_info.plate_type, color,
  416. table.car_number_info.plate_full_image,
  417. table.car_number_info.plate_clip_image, table.primary_key)
  418. elif param == 'query':
  419. data = http_client.HttpRequest.QueryData(table.primary_key, self._parking_id)
  420. elif param == 'out':
  421. data = http_client.HttpRequest.OutDate(self._parking_id, table.car_number,
  422. table.primary_key,
  423. str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')),
  424. self.chnnId_out[table.unit_id],
  425. table.car_number_info.plate_type, color,
  426. table.car_number_info.plate_full_image,
  427. table.car_number_info.plate_clip_image)
  428. appid_iphone = self._app_id_phone
  429. time_iphone = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
  430. sign_iphone = appid_iphone + time_iphone + self._appSecret_phone
  431. hl_iphone = hashlib.md5()
  432. hl_iphone.update(sign_iphone.encode(encoding='utf-8'))
  433. sign_iphone = hl_iphone.hexdigest()
  434. headers = {
  435. "Appid": appid_iphone,
  436. "Time": time_iphone,
  437. "Sign": sign_iphone
  438. }
  439. data2 = {
  440. "parkId": self._parking_id,
  441. "licenesePlate": table.car_number,
  442. "inRecordId": table.primary_key
  443. }
  444. request = http_client.HttpRequest(msgId, AppId, time, sign, data)
  445. if param == 'out':
  446. return request.__dict__, data2,headers
  447. return request.__dict__
  448. def get_unit_str(self, unit):
  449. if unit == 11:
  450. return 'A1'
  451. elif unit == 12:
  452. return 'A2'
  453. elif unit == 13:
  454. return 'A3'
  455. elif unit == 14:
  456. return 'A4'
  457. elif unit == 21:
  458. return 'B1'
  459. elif unit == 22:
  460. return 'B2'
  461. elif unit == 23:
  462. return 'B3'
  463. elif unit == 24:
  464. return 'B4'
  465. elif unit == 25:
  466. return 'B5'
  467. elif unit == 31:
  468. return 'C1'
  469. elif unit == 32:
  470. return 'C2'
  471. elif unit == 1:
  472. return 'A'
  473. elif unit == 2:
  474. return 'B'
  475. elif unit == 3:
  476. return 'C'
  477. return ''