main_window.py 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. import ctypes
  2. import inspect
  3. import os
  4. import signal
  5. import sys
  6. sys.path.append('..')
  7. import datetime
  8. import json
  9. import threading
  10. import time
  11. import traceback
  12. from functools import partial
  13. from django.core.serializers.json import DjangoJSONEncoder
  14. import requests
  15. from PyQt5.QtCore import QSize, QDateTime
  16. from PyQt5.QtCore import pyqtSignal, QTimer, Qt
  17. from PyQt5.QtGui import QFont, QIcon, QPixmap, QCursor, QColor
  18. from PyQt5.QtWidgets import QMessageBox, QListWidgetItem, QMainWindow, QMenu, QPushButton, QGridLayout, QListWidget, \
  19. QLabel, QHeaderView, QTableWidgetItem, QAbstractItemView, QSizePolicy, QApplication
  20. import google.protobuf.text_format as tf
  21. import ui.spaceUi as sui
  22. from window_controller.pickup_passwd_window import PickupWindow, ResultReturn
  23. import message.message_pb2 as message
  24. from window_controller.reparking_window import ReparkingWindow
  25. from window_controller.full_car_window import FullcarWindow
  26. from window_controller.led import Led
  27. import copy
  28. import async_communication as cmt
  29. import mytool.db_helper.db_operation as spmng
  30. class MainWindow(QMainWindow, sui.Ui_MainWindow):
  31. # # 取车界面信号
  32. # signal_dict = pyqtSignal(dict)
  33. def __init__(self, parking_config, mq_config, db_config, parent=None):
  34. super(MainWindow, self).__init__(parent)
  35. self.command_dict = {}
  36. self.unit_space_dict = None
  37. self.setupUi(self)
  38. self.parking_config = parking_config
  39. self.label.setText(self.parking_config['process_title'])
  40. # 数据存储
  41. # 全矩阵
  42. self.btn_positions = [(i, j) for i in range(self.parking_config['row'] - 1, -1, -1) for j in
  43. range(self.parking_config['column'])]
  44. # # 奇数矩阵
  45. # self.btn_positions1 = [(i, j) for i in range(self.parking_config['row']-1, -1, -1) for j in
  46. # range(1,self.parking_config['column'],2)]
  47. # # 偶数矩阵
  48. # self.btn_positions2 = [(i, j) for i in range(self.parking_config['row']-1, -1, -1) for j in
  49. # range(2,self.parking_config['column']+2,2)]
  50. self._dispatch_statu = {}
  51. self.unit_space_is_init = False
  52. self.process_is_init = False
  53. self.parking_unit_list = self.parking_config['parking_unit_list']
  54. self.process_unit_list = self.parking_config['process_unit_list']
  55. self.db_unit_list = self.parking_config['db_unit_list']
  56. self.label_dict = {}
  57. self.list_widget_dict = {}
  58. self.setWindowTitle(self.parking_config['window_title'])
  59. # 锁
  60. self.data_lock = threading.Lock()
  61. # 配置导入初始化数据库和rabbitmq
  62. self.db = spmng.DBOperation(db_config['db_ip'], db_config['db_port'], db_config['db_name'],
  63. db_config['db_user'], db_config['db_password'])
  64. self.rabbitmq = cmt.RabbitAsyncCommunicator(mq_config['mq_ip'], mq_config['mq_port'], mq_config['mq_user'],
  65. mq_config['mq_password'])
  66. try:
  67. self.rabbitmq.Init(None, mq_config['mq_statu_exchange_keys'])
  68. for ex, key in mq_config['mq_statu_exchange_keys']:
  69. self.rabbitmq.bind_statu_callback(ex, key, self.receive_dispatch_statu)
  70. self.rabbitmq.start()
  71. except Exception as e:
  72. print('rabbitmq启动失败!' + str(e.args))
  73. self.out_date = None
  74. self.in_date = None
  75. # 拓展功能
  76. self.action_queryBlacklist.triggered.connect(self.btn_query_blacklist)
  77. self.action_addBlacklist.triggered.connect(self.btn_add_blacklist)
  78. self.action_deleteBlacklist.triggered.connect(self.btn_delete_blacklist)
  79. self.action_queryWhitelist.triggered.connect(self.btn_query_whitelist)
  80. self.action_addWhitelist.triggered.connect(self.btn_add_whitelist)
  81. self.action_deleteWhitelist.triggered.connect(self.btn_delete_whitelist)
  82. # 记录表单元号,流程表单元号,车位表单元号
  83. self.unit_comboBox.addItems(list(self.parking_unit_list.keys()))
  84. self.process_comboBox.addItems(list(self.process_unit_list.keys()))
  85. self.db_comboBox.addItems(list(self.db_unit_list.keys()))
  86. self.parking_unit = self.parking_config['init_parking_unit']
  87. self.process_unit = self.parking_config['init_process_unit']
  88. self.db_unit = self.parking_config['init_db_unit_list']
  89. self.unit_comboBox.setCurrentText(self.parking_unit)
  90. self.process_comboBox.setCurrentText(self.process_unit)
  91. self.db_comboBox.setCurrentText(self.db_unit)
  92. self.updata_record_btn.clicked.connect(self.updata_record)
  93. # 调度状态指示灯
  94. self.plc_statu_led = Led()
  95. self.plc_statu_led.setEnabled(False) # 设置为不使能状态,如果需要切换可以设置为True。则可以实现点击切换指示灯颜色的效果
  96. self.plc_statu_led.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
  97. self.plc_statu_led.setChecked(False) # 设置状态
  98. self.dispatch_heart_timer = cmt.TimeStatu(1, 0.1)
  99. self.horizontalLayout_11.addWidget(self.plc_statu_led)
  100. self.db_statu_led = Led()
  101. self.db_statu_led.setEnabled(False) # 设置为不使能状态,如果需要切换可以设置为True。则可以实现点击切换指示灯颜色的效果
  102. self.db_statu_led.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
  103. self.db_statu_led.setChecked(False) # 设置状态
  104. self.horizontalLayout_11.addWidget(self.db_statu_led)
  105. # 是否输入过密码 密码保护默认五分钟
  106. self.t_time = time.time()
  107. self.is_pwd = False
  108. # 数据历史记录默认设置
  109. self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
  110. self.tableWidget.itemClicked.connect(self.show_car_image)
  111. self.tableWidget.setHorizontalHeaderLabels(self.parking_config['record_title'])
  112. now = datetime.datetime.now()
  113. zero_today = now - datetime.timedelta(hours=now.hour, minutes=now.minute, seconds=now.second,
  114. microseconds=now.microsecond)
  115. last_today = zero_today + datetime.timedelta(hours=23, minutes=59, seconds=59)
  116. self.in_dateTimeEdit.setDateTime(zero_today)
  117. self.out_dateTimeEdit.setDateTime(last_today)
  118. self.in_dateTimeEdit_2.setDateTime(zero_today)
  119. self.out_dateTimeEdit_2.setDateTime(last_today)
  120. self.db_find_Button.clicked.connect(self.db_record_find)
  121. # 车位显示模式
  122. self.show_model = self.car_number_rbtn_2.isChecked()
  123. # 切换库位按钮关联函数
  124. self.find_btn.clicked.connect(self.find_btn_click)
  125. self.update_unit_btn.clicked.connect(self.update_btn_click)
  126. self.update_unit_btn_2.clicked.connect(self.update_process_unit_btn_click)
  127. # 初始化显示库位高度
  128. font = QFont()
  129. font.setFamily('宋体')
  130. font.setBold(False)
  131. font.setPointSize(15)
  132. self.parking_listWidget.setFont(font)
  133. # 数据缓存
  134. self.space_dict = {}
  135. self.record_all_unit_park_dict = {}
  136. self.record_all_unit_pick_dict = {}
  137. self.db_unit_park_dict = {}
  138. self.db_unit_pick_dict = {}
  139. self.record_total_unit_park_dict = {11: {}, 12: {}, 13: {}, 14: {}, 21: {}, 22: {}, 23: {}, 24: {}, 25: {},
  140. 31: {}, 32: {}}
  141. self.record_total_unit_pick_dict = {11: {}, 12: {}, 13: {}, 14: {}, 21: {}, 22: {}, 23: {}, 24: {}, 25: {},
  142. 31: {}, 32: {}}
  143. self.last_command_dict = {}
  144. self.unit_label.setText(self.parking_unit)
  145. self.pushButton_grade1.setIcon(QIcon(QPixmap("./images/grade1.png")))
  146. self.pushButton_grade2.setIcon(QIcon(QPixmap("./images/grade2.png")))
  147. self.pushButton_grade3.setIcon(QIcon(QPixmap("./images/grade3.png")))
  148. self.pushButton_grade1.setText("车高等级:" + str(self.parking_config['grade1']))
  149. self.pushButton_grade2.setText("车高等级:" + str(self.parking_config['grade2']))
  150. self.pushButton_grade3.setText("车高等级:" + str(self.parking_config['grade3']))
  151. # 数据库更新时间
  152. self.db_update_time = time.time() - 3
  153. self.db_connect_statu = False
  154. # 数据库查询线程
  155. self.db_query = threading.Thread(target=self.db_query)
  156. self.db_query_isClose = False
  157. self.db_query.start()
  158. # 启动界面刷新定时器
  159. self.timer = QTimer()
  160. self.timer.timeout.connect(self.Switch)
  161. self.timer.start(200)
  162. # # 临时
  163. # self.show_unit_box.setVisible(False)
  164. # self.groupBox_2.setVisible(False)
  165. # self.db_unit_label.setVisible(False)
  166. # self.db_comboBox.setVisible(False)
  167. def receive_dispatch_statu(self, statu, ex, key):
  168. # 调度状态接收
  169. self._dispatch_statu[key] = statu
  170. def db_query(self):
  171. while self.db_query_isClose is False:
  172. # 查询车位
  173. self.data_lock.acquire()
  174. self.space_dict = self.db.query_space_in_unit(self.parking_unit_list[self.parking_unit])
  175. # 查询指令表
  176. for unit in self.process_unit_list[self.process_unit]:
  177. self.last_command_dict[unit] = self.db.query_command_all_in_unit_and_sort(unit)
  178. self.data_lock.release()
  179. # 数据库更新时间
  180. self.db_update_time = time.time()
  181. time.sleep(0.1)
  182. # 界面刷新定时器
  183. def Switch(self):
  184. # 200毫秒刷新一次,同时检查密码定时器是否超过五分钟
  185. time_now = time.time()
  186. if self.is_pwd is True and time_now - self.t_time > 300:
  187. self.is_pwd = False
  188. self.t_time = time_now
  189. self.in_date = self.in_dateTimeEdit_2.dateTime().toPyDateTime().strftime("%Y-%m-%d %H:%M:%S")
  190. self.out_date = self.out_dateTimeEdit_2.dateTime().toPyDateTime().strftime("%Y-%m-%d %H:%M:%S")
  191. # 更新记录表单元号,流程表单元号,车位表单元号
  192. self.db_unit = self.db_comboBox.currentText()
  193. # 检查连接
  194. self.db_connect_statu = self.check_connect_statu()
  195. if self.db_connect_statu:
  196. self.data_lock.acquire()
  197. unit = self.parking_unit_list[self.parking_unit]
  198. # 车位管理
  199. self.parkspace_show(self.parking_unit, self.parking_config["in_occupy_space"][str(unit)],
  200. self.parking_config["out_occupy_space"][str(unit)],
  201. self.parking_config["controlroom_occupy_space"][str(unit)])
  202. # # 流程监控
  203. self.process_monitoring(self.process_unit_list[self.process_unit])
  204. self.data_lock.release()
  205. def updata_record(self):
  206. # 当前选中时间段内所有单元记录表数据
  207. self.data_lock.acquire()
  208. self.record_all_unit_park_dict = self.db.query_park_count_in_time(self.in_date, self.out_date)
  209. self.record_all_unit_pick_dict = self.db.query_pick_count_out_time(self.in_date, self.out_date)
  210. # 当前选中时间内指定单元记录数据
  211. if len(self.db_unit) != 1 and self.db_unit_list[self.db_unit] is not None:
  212. self.db_unit_park_dict = self.db.query_park_count_in_time_and_unit(self.in_date, self.out_date,
  213. self.db_unit_list[self.db_unit])
  214. self.db_unit_pick_dict = self.db.query_pick_count_out_time_and_unit(self.in_date, self.out_date,
  215. self.db_unit_list[
  216. self.db_unit])
  217. # 当前选中时间内指定总单元记录数据
  218. if len(self.db_unit) == 1:
  219. for unit in self.db_unit_list[self.db_unit]:
  220. self.record_total_unit_park_dict[unit] = self.db.query_park_count_in_time_and_unit(self.in_date,
  221. self.out_date,
  222. unit)
  223. self.record_total_unit_pick_dict[unit] = self.db.query_pick_count_out_time_and_unit(self.in_date,
  224. self.out_date,
  225. unit)
  226. # # 停车数量记录
  227. self.show_parkingData()
  228. self.data_lock.release()
  229. # 检查数据库连接
  230. def check_connect_statu(self):
  231. # 检查调度连接
  232. key = "dispatch_%d_statu_port" % self.parking_unit_list[self.parking_unit]
  233. if (key in self._dispatch_statu) is False or self._dispatch_statu[key].timeout():
  234. self.plc_statu_led.setChecked(False)
  235. else:
  236. statu = self._dispatch_statu[key].statu
  237. dispatch_node_statu = message.dispatch_node_statu()
  238. try:
  239. tf.Parse(statu, dispatch_node_statu)
  240. except Exception:
  241. pass
  242. if self.dispatch_heart_timer.statu != dispatch_node_statu.plc_heartbeat:
  243. self.dispatch_heart_timer = cmt.TimeStatu(dispatch_node_statu.plc_heartbeat)
  244. self.plc_statu_led.setChecked(True)
  245. if self.dispatch_heart_timer.timeout():
  246. self.plc_statu_led.setChecked(False)
  247. # 检查数据库连接
  248. if time.time() - self.db_update_time > 3:
  249. self.db_statu_led.setChecked(False)
  250. else:
  251. self.db_statu_led.setChecked(True)
  252. return self.db_statu_led.isChecked()
  253. # 车位显示
  254. def parkspace_show(self, unit, in_occupy_space, out_occupy_space, controlroom_occupy_space):
  255. # 绘制车位按钮
  256. if self.space_dict is None:
  257. return
  258. is_show_car_number = self.car_number_rbtn_2.isChecked()
  259. if self.unit_space_dict != self.space_dict:
  260. self.unit_label.setText(unit)
  261. print('有修改')
  262. if self.unit_space_is_init == False:
  263. self.unit_space_dict = copy.deepcopy(self.space_dict)
  264. self.unit_space_is_init = True
  265. is_drawIn = False
  266. is_drawOut = False
  267. is_drawControlRoom = False
  268. for park, position in zip(self.space_dict, self.btn_positions):
  269. btn = QPushButton()
  270. font, text_str, stylesheet, tool_tip = self.get_btn_show(park)
  271. btn.setFont(font)
  272. btn.setLayout(QGridLayout())
  273. btn.setText(text_str)
  274. btn.setStyleSheet(stylesheet)
  275. btn.setToolTip(tool_tip)
  276. btn.setObjectName(str(park["table_id"]))
  277. if text_str == "入 口" and is_drawIn is False:
  278. self.unit_gridLayout.addWidget(btn, *position, 1, in_occupy_space)
  279. is_drawIn = True
  280. elif text_str == "出 口" and is_drawOut is False:
  281. self.unit_gridLayout.addWidget(btn, *position, 1, out_occupy_space)
  282. is_drawOut = True
  283. elif text_str == " 控制室 " and is_drawControlRoom is False:
  284. self.unit_gridLayout.addWidget(btn, *position, 1, controlroom_occupy_space)
  285. is_drawControlRoom = True
  286. elif text_str != "出 口" and text_str != "入 口" and text_str != " 控制室 ":
  287. btn.setContextMenuPolicy(Qt.CustomContextMenu)
  288. btn.customContextMenuRequested.connect(self.park_btn_right_click)
  289. btn.clicked.connect(self.park_btn_left_click)
  290. self.unit_gridLayout.addWidget(btn, *position)
  291. else:
  292. temp1 = copy.deepcopy(self.unit_space_dict)
  293. temp2 = copy.deepcopy(self.space_dict)
  294. merged = zip(temp1, temp2)
  295. for last_space,space in merged:
  296. if last_space.values() != space.values():
  297. font, text_str, stylesheet, tool_tip = self.get_btn_show(space)
  298. results = self.findChild(QPushButton, str(space["table_id"]))
  299. if results is None:
  300. return
  301. results.setFont(font)
  302. results.setText(text_str)
  303. results.setStyleSheet(stylesheet)
  304. results.setToolTip(tool_tip)
  305. self.unit_space_dict = copy.deepcopy(self.space_dict)
  306. if self.show_model != is_show_car_number:
  307. self.show_model = is_show_car_number
  308. for park in self.unit_space_dict:
  309. if park["statu"] == 2:
  310. font, text_str, stylesheet, tool_tip = self.get_btn_show(park)
  311. results = self.findChild(QPushButton, str(park["table_id"]))
  312. results.setFont(font)
  313. results.setText(text_str)
  314. results.setStyleSheet(stylesheet)
  315. results.setToolTip(tool_tip)
  316. # 流程监控
  317. def process_monitoring(self, process_unit_list):
  318. if self.process_is_init is False:
  319. for i in process_unit_list:
  320. self.list_widget_dict[i] = QListWidget(self)
  321. self.list_widget_dict[i].setContextMenuPolicy(Qt.CustomContextMenu)
  322. self.list_widget_dict[i].customContextMenuRequested.connect(self.custom_right_menu)
  323. self.list_widget_dict[i].setStyleSheet("border:5px solid #014F84;")
  324. self.list_widget_dict[i].setObjectName(('list_widget_%d' % (i + 1)))
  325. self.process_horizontalLayout.addWidget(self.list_widget_dict[i])
  326. self.label_dict[i] = QLabel(self)
  327. # 临时
  328. # self.label_dict[i].setText(unit_char + "-" + str((i % 10)))
  329. self.label_dict[i].setText(self.get_unit(i))
  330. # self.label_dict[i].setText("停取流程")
  331. self.label_dict[i].setAlignment(Qt.AlignCenter)
  332. self.label_dict[i].setFont(QFont("华文楷体", 60, QFont.Bold))
  333. self.command_dict[i] = []
  334. self.unit_horizontalLayout.addWidget(self.label_dict[i])
  335. self.process_is_init = True
  336. for i in process_unit_list:
  337. if (i in self.last_command_dict.keys()) is False or self.last_command_dict[i] is None:
  338. return
  339. else:
  340. last_command_dict = copy.deepcopy(self.last_command_dict[i])
  341. if self.command_dict[i] != last_command_dict:
  342. self.command_dict[i] = copy.deepcopy(last_command_dict)
  343. self.list_widget_dict[i].clear()
  344. for dict in self.command_dict[i]:
  345. if dict['statu'] != 3:
  346. self.list_widget_dict[i].addItem(self.get_listWidget_item(dict))
  347. for dict in self.command_dict[i]:
  348. if dict['statu'] == 3:
  349. self.list_widget_dict[i].addItem(self.get_listWidget_item(dict))
  350. # 刷新停车数据
  351. def show_parkingData(self):
  352. # 有一个数据是空就直接返回
  353. if self.record_all_unit_park_dict is None or self.record_all_unit_pick_dict is None or self.db_unit_park_dict is None or \
  354. self.db_unit_pick_dict is None or self.record_total_unit_park_dict is None or self.record_total_unit_pick_dict is None:
  355. return
  356. record_all_unit_park_dict, record_all_unit_pick_dict, db_unit_park_dict, db_unit_pick_dict, record_total_unit_park_dict, record_total_unit_pick_dict = \
  357. copy.deepcopy(self.record_all_unit_park_dict), copy.deepcopy(self.record_all_unit_pick_dict), copy.deepcopy(
  358. self.db_unit_park_dict), copy.deepcopy(self.db_unit_pick_dict), copy.deepcopy(
  359. self.record_total_unit_park_dict), copy.deepcopy(self.record_total_unit_pick_dict)
  360. unit_park_count = unit_pick_count = 0
  361. all_park_count, all_pick_count = record_all_unit_park_dict[0]['count(*)'], record_all_unit_pick_dict[0]['count(*)']
  362. # 当前选中时间内指定总单元记录数据
  363. if len(self.db_unit) == 1:
  364. for unit in self.db_unit_list[self.db_unit]:
  365. unit_park_count = unit_park_count + record_total_unit_park_dict[unit][0]['count(*)']
  366. unit_pick_count = unit_pick_count + record_total_unit_pick_dict[unit][0]['count(*)']
  367. # 当前选中时间内指定单元记录数据
  368. elif len(self.db_unit) != 1 and isinstance(self.db_unit_list[self.db_unit],list) is False:
  369. unit_park_count, unit_pick_count = db_unit_park_dict[0]['count(*)'], db_unit_pick_dict[0]['count(*)']
  370. else:
  371. unit_park_count, unit_pick_count = all_park_count, all_pick_count
  372. self.unit_park_count_label.setText("该单元停车{value}次".format(value=unit_park_count))
  373. self.unit_pick_count_label.setText("该单元取车{value}次".format(value=unit_pick_count))
  374. self.all_park_count_label.setText("所有库停车{value}次".format(value=all_park_count))
  375. self.all_pick_count_label.setText("所有库取车{value}次".format(value=all_pick_count))
  376. def show_parking_details(self, park_dict):
  377. self.parking_listWidget.clear()
  378. for poit in park_dict.items():
  379. item = QListWidgetItem()
  380. item.setSizeHint(QSize(50, 39))
  381. name = self.get_name(poit[0])
  382. if name == '未知':
  383. continue
  384. value = poit[1]
  385. if name == '楼层':
  386. value = value - self.parking_config['floor_minus']
  387. item.setText(name + ":" + str(value))
  388. item.setToolTip(str(value))
  389. self.parking_listWidget.addItem(item)
  390. res = self.db.query_space_in_car_number(park_dict['car_number'])
  391. self.plate_full_image_label.setPixmap(QPixmap(""))
  392. self.plate_clip_image_label.setPixmap(QPixmap(""))
  393. if len(res) > 0:
  394. try:
  395. rep = requests.get(res[0]['plate_full_image'])
  396. pix = QPixmap()
  397. pix.loadFromData(rep.content)
  398. pix = pix.scaled(self.plate_full_image_label.size(), Qt.KeepAspectRatio)
  399. self.plate_full_image_label.setPixmap(pix)
  400. except Exception as e:
  401. print('全景图:' + str(e.args))
  402. try:
  403. rep = requests.get(res[0]['plate_clip_image'])
  404. pix = QPixmap()
  405. pix.loadFromData(rep.content)
  406. pix = pix.scaled(self.plate_clip_image_label.size(), Qt.KeepAspectRatio)
  407. self.plate_clip_image_label.setPixmap(pix)
  408. except Exception as e:
  409. print('特写图:' + str(e.args))
  410. def find_btn_click(self):
  411. text = self.find_lineEdit.text()
  412. if text == '':
  413. QMessageBox.question(None, "提示", "请输入要查询的内容",
  414. QMessageBox.Ok)
  415. return
  416. if self.car_number_rbtn.isChecked():
  417. park_dict = self.db.query_space_in_car_number(text)
  418. if len(park_dict) > 0:
  419. self.show_parking_details(park_dict[0])
  420. else:
  421. QMessageBox.question(None, "查询结果", "车牌号:" + text + " 未查询到数据!",
  422. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  423. elif self.key_rbtn.isChecked():
  424. park_dict = self.db.query_space_in_primary_key(text)
  425. if len(park_dict) > 0:
  426. self.show_parking_details(park_dict[0])
  427. else:
  428. QMessageBox.question(None, "查询结果", "唯一码:" + text + " 未查询到数据!",
  429. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  430. # elif self.parking_rbtn.isChecked():
  431. # park_dict = self.db.query_space_in_unit_and_table_id(self.unit, text)
  432. # if len(park_dict) > 0:
  433. # self.show_parking_details(park_dict[0])
  434. #
  435. # else:
  436. # QMessageBox.question(None, "查询结果", "车位id:" + text + " 未查询到数据!",
  437. # QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  438. return
  439. def update_process_unit_btn_click(self):
  440. self.process_unit = self.process_comboBox.currentText()
  441. for i in range(self.process_horizontalLayout.count()):
  442. self.process_horizontalLayout.itemAt(i).widget().deleteLater()
  443. for i in range(self.unit_horizontalLayout.count()):
  444. self.unit_horizontalLayout.itemAt(i).widget().deleteLater()
  445. self.process_is_init = False
  446. def update_btn_click(self):
  447. parking_unit = self.unit_comboBox.currentText()
  448. if self.parking_unit_list[self.parking_unit] == self.parking_unit_list[parking_unit]:
  449. return
  450. self.parking_unit = parking_unit
  451. unit = self.parking_unit_list[self.parking_unit]
  452. for i in range(self.unit_gridLayout.count()):
  453. self.unit_gridLayout.itemAt(i).widget().deleteLater()
  454. self.data_lock.acquire()
  455. self.space_dict = self.db.query_space_in_unit(unit)
  456. self.data_lock.release()
  457. self.unit_space_is_init = False
  458. def park_btn_left_click(self):
  459. if self.db_connect_statu:
  460. sender = self.sender()
  461. tool_tip = sender.toolTip()
  462. dict = json.loads(tool_tip)
  463. self.show_parking_details(dict)
  464. else:
  465. QMessageBox.critical(None, "提示", "数据库连接断开!", QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  466. def park_btn_right_click(self):
  467. if self.db_connect_statu:
  468. menu = QMenu(self)
  469. sender = self.sender()
  470. tool_tip = sender.toolTip()
  471. dict = json.loads(tool_tip)
  472. action = menu.addAction('启用车位')
  473. action.triggered.connect(partial(self.btn_opeSpace, dict, 0))
  474. action = menu.addAction('停用车位')
  475. action.triggered.connect(partial(self.btn_disableSpace, dict, 10))
  476. action = menu.addAction('清除车位')
  477. action.triggered.connect(partial(self.btn_clearSpace, dict))
  478. action = menu.addAction('正常取车')
  479. action.triggered.connect(partial(self.btn_pickUp, dict, message.PROCESS_NORMAL))
  480. action = menu.addAction('强制取车')
  481. action.triggered.connect(partial(self.btn_pickUp, dict, message.PROCESS_ONLY_TO_DISPATCH))
  482. action = menu.addAction('虚拟取车')
  483. action.triggered.connect(partial(self.btn_pickUp, dict, message.PROCESS_ONLY_TO_PAY))
  484. # action = menu.addAction('更换车位')
  485. # action.triggered.connect(partial(self.btn_replace_parking, dict))
  486. action = menu.addAction('填充车位')
  487. action.triggered.connect(partial(self.btn_fill_parking, dict))
  488. action = menu.addAction('增加备注')
  489. action.triggered.connect(partial(self.btn_add_remarks, dict))
  490. menu.exec_(QCursor.pos())
  491. else:
  492. QMessageBox.critical(None, "提示", "数据库连接断开!", QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  493. def btn_disableSpace(self, dict, statu):
  494. if self.is_input_pwd() is True:
  495. res = self.db.update_space_status_in_space_id(dict["id"], statu)
  496. if res == 0:
  497. QMessageBox.question(None, '提示', '更新车位失败!请检查是否点击错误!',
  498. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  499. def btn_opeSpace(self, dict, statu):
  500. if self.is_input_pwd() is True:
  501. res = self.db.update_space_status_in_space_id(dict["id"], statu)
  502. if res == 0:
  503. QMessageBox.question(None, '提示', '更新车位失败!请检查是否点击错误!',
  504. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  505. def btn_clearSpace(self, dict):
  506. if self.is_input_pwd() is True:
  507. res = self.db.clear_space_data(dict["id"])
  508. if res == 0:
  509. QMessageBox.question(None, '提示', '更新车位失败!请检查是否点击错误!',
  510. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  511. def btn_pickUp(self, dict, table_process_mod):
  512. if self.is_input_pwd() is True:
  513. table = message.pick_table()
  514. table.statu.table_process_mod = table_process_mod
  515. table.primary_key = dict["primary_key"]
  516. self.rabbitmq.publish("command_ex", "user_pick_command_request_port",
  517. tf.MessageToString(table, as_utf8=True))
  518. QMessageBox.question(None, '提示', '取车消息发送成功!',
  519. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  520. # def btn_replace_parking(self, dict):
  521. # if self.is_input_pwd() is True:
  522. # if dict['car_number'] == 'None' or dict['primary_key'] == 'None':
  523. # QMessageBox.question(None, '提示', '没有车牌号或唯一码,不符合更换车位条件!',
  524. # QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  525. # return
  526. # repwind = ReparkingWindow()
  527. # repwind.exec()
  528. # res = repwind.get_results()
  529. # if res is True:
  530. # target_parking = self.db.query_parking_in_unit_tableid(dict['unit'], repwind.get_park_tableid())[0]
  531. # if target_parking['car_number'] is not None:
  532. # QMessageBox.question(None, '提示', '目标车位不为空!',
  533. # QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  534. # return
  535. # parking = self.db.query_space_in_car_number(dict['car_number'])[0]
  536. #
  537. # space_info_sql = "NULL"
  538. # measure_info_sql = "NULL"
  539. # plate_color_sql = "NULL"
  540. # plate_type_sql = "NULL"
  541. # plate_confidence_sql = "NULL"
  542. # recognition_time_sql = "NULL"
  543. # plate_full_image_sql = "NULL"
  544. # plate_clip_image_sql = "NULL"
  545. #
  546. # if parking['space_info'] is not None:
  547. # space_info_sql = "'%s'" % parking['space_info']
  548. #
  549. # if parking['measure_info'] is not None:
  550. # measure_info_sql = "'%s'" % parking['measure_info']
  551. #
  552. # if parking['plate_color'] is not None:
  553. # plate_color_sql = "'%s'" % parking['plate_color']
  554. #
  555. # if parking['plate_type'] is not None:
  556. # plate_type_sql = "'%s'" % parking['plate_type']
  557. #
  558. # if parking['plate_confidence'] is not None:
  559. # plate_confidence_sql = "%d" % parking['plate_confidence']
  560. #
  561. # if parking['recognition_time'] is not None:
  562. # recognition_time_sql = "'%s'" % parking['recognition_time']
  563. #
  564. # if parking['plate_full_image'] is not None:
  565. # plate_full_image_sql = "'%s'" % parking['plate_full_image']
  566. #
  567. # if parking['plate_clip_image'] is not None:
  568. # plate_clip_image_sql = "'%s'" % parking['plate_clip_image']
  569. #
  570. # sql2 = "update space set car_number='%s', primary_key='%s', statu=%d , space_info=%s , measure_info=%s ,\
  571. # plate_color=%s , plate_type=%s , plate_confidence=%s , recognition_time=%s , plate_full_image=%s , plate_clip_image=%s where id=%d" \
  572. # % (parking['car_number'], parking['primary_key'], parking['statu'], space_info_sql,
  573. # measure_info_sql,
  574. # plate_color_sql, \
  575. # plate_type_sql, plate_confidence_sql, recognition_time_sql, plate_full_image_sql,
  576. # plate_clip_image_sql, target_parking['id'])
  577. # # print(sql2)
  578. #
  579. # res = self.db.update(sql2)
  580. # if res == 0:
  581. # QMessageBox.question(None, '提示', '执行失败!',
  582. # QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  583. # return
  584. # res = self.db.clear_space_data(parking['id'])
  585. # if res > 0:
  586. # QMessageBox.question(None, '提示', '车位交换成功!',
  587. # QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  588. def btn_fill_parking(self, dict):
  589. if self.is_input_pwd() is True:
  590. fullcar = FullcarWindow()
  591. fullcar.exec()
  592. if fullcar.get_results() is True:
  593. car_number = fullcar.get_text()
  594. res = self.db.update_space_status_car_number_in_space_id(dict['id'], car_number, 2)
  595. if res > 0:
  596. QMessageBox.question(None, '提示', '车位填充成功!',
  597. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  598. def btn_query_blacklist(self):
  599. if self.is_input_pwd() is True:
  600. res = self.db.query_blacklist()
  601. if res is not None and len(res) > 0:
  602. blacklist = ""
  603. for dict in res:
  604. blacklist = blacklist + str(dict) + "\n\n"
  605. QMessageBox.question(None, '提示', blacklist,
  606. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  607. else:
  608. QMessageBox.question(None, '提示', '没有黑名单!',
  609. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  610. def btn_add_blacklist(self):
  611. if self.is_input_pwd() is True:
  612. fullcar = FullcarWindow()
  613. fullcar.exec()
  614. if fullcar.get_results() is True:
  615. car_number = fullcar.get_text()
  616. res = self.db.add_blacklist_in_car_number(car_number, datetime.datetime.now(), None, None)
  617. if res is not None and res > 0:
  618. QMessageBox.question(None, '提示', '黑名单添加成功!',
  619. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  620. else:
  621. QMessageBox.question(None, '提示', '黑名单添加失败!',
  622. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  623. def btn_delete_blacklist(self):
  624. if self.is_input_pwd() is True:
  625. fullcar = FullcarWindow()
  626. fullcar.exec()
  627. if fullcar.get_results() is True:
  628. car_number = fullcar.get_text()
  629. res = self.db.delete_blacklist_in_car_number(car_number)
  630. if res is not None and res > 0:
  631. QMessageBox.question(None, '提示', '黑名单删除成功!',
  632. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  633. else:
  634. QMessageBox.question(None, '提示', '黑名单删除失败!',
  635. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  636. def btn_query_whitelist(self):
  637. if self.is_input_pwd() is True:
  638. res = self.db.query_whitelist()
  639. if res is not None and len(res) > 0:
  640. whitelist = ""
  641. for dict in res:
  642. whitelist = whitelist + str(dict) + "\n\n"
  643. QMessageBox.question(None, '提示', whitelist,
  644. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  645. else:
  646. QMessageBox.question(None, '提示', '没有白名单!',
  647. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  648. def btn_add_whitelist(self):
  649. if self.is_input_pwd() is True:
  650. fullcar = FullcarWindow()
  651. fullcar.exec()
  652. if fullcar.get_results() is True:
  653. car_number = fullcar.get_text()
  654. res = self.db.add_whitelist_in_car_number(car_number, datetime.datetime.now(), None, None)
  655. if res is not None and res > 0:
  656. QMessageBox.question(None, '提示', '白名单添加成功!',
  657. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  658. else:
  659. QMessageBox.question(None, '提示', '黑名单删除失败!',
  660. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  661. def btn_delete_whitelist(self):
  662. if self.is_input_pwd() is True:
  663. fullcar = FullcarWindow()
  664. fullcar.exec()
  665. if fullcar.get_results() is True:
  666. car_number = fullcar.get_text()
  667. res = self.db.delete_whitelist_in_car_number(car_number)
  668. if res is not None and res > 0:
  669. QMessageBox.question(None, '提示', '白名单删除成功!',
  670. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  671. else:
  672. QMessageBox.question(None, '提示', '黑名单删除失败!',
  673. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  674. def btn_add_remarks(self, dict):
  675. if self.is_input_pwd() is True:
  676. fullcar = FullcarWindow()
  677. fullcar.exec()
  678. if fullcar.get_results() is True:
  679. remark = fullcar.get_text()
  680. res = self.db.update_space_remark_in_space_id(dict['id'], remark)
  681. if res > 0:
  682. QMessageBox.question(None, '提示', '车位添加备注成功!',
  683. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  684. def get_btn_show(self, park):
  685. font = QFont()
  686. font.setFamily('宋体')
  687. font.setPointSize(21)
  688. if park["statu"] == 6:
  689. text_str = "入 口"
  690. font.setBold(True)
  691. elif park["statu"] == 7:
  692. text_str = "出 口"
  693. font.setBold(True)
  694. elif park["statu"] == 8:
  695. text_str = " 控制室 "
  696. font.setBold(True)
  697. # elif park["statu"] == 10 and park["remark"] is not None:
  698. # text_str = park["remark"][0:4]
  699. # font.setPointSize(20)
  700. elif 0 < park["statu"] < 6 and park["car_number"] is not None and self.car_number_rbtn_2.isChecked():
  701. text_str = park["car_number"]
  702. font.setPointSize(20)
  703. else:
  704. text_str = "车位:%d\n楼层:%d" % (park["table_id"], (park["floor"] - self.parking_config['floor_minus']))
  705. font.setPointSize(10)
  706. background_color = ""
  707. background_image = ""
  708. # 设置背景图
  709. if park["height_level"] == self.parking_config['grade1']:
  710. background_image = "background-image: url(./images/grade1.png);"
  711. elif park["height_level"] == self.parking_config['grade2']:
  712. background_image = "background-image: url(./images/grade2.png);"
  713. elif park["height_level"] == self.parking_config['grade3']:
  714. background_image = "background-image: url(./images/grade3.png);"
  715. elif park["height_level"] == self.parking_config['grade4']:
  716. background_image = "background-image: url(./images/grade1.png);"
  717. # 故障
  718. if park["statu"] == 10:
  719. background_color = "background-color:rgb(255,130,130);"
  720. # 空闲
  721. elif park["statu"] == 0:
  722. background_color = "background-color:rgb(195,195,195);"
  723. # 存车中
  724. elif park["statu"] == 1:
  725. background_color = "background-color:rgb(140,100,220);"
  726. # 占用
  727. elif park["statu"] == 2:
  728. background_color = "background-color:rgb(248,239,71);"
  729. # 已锁定
  730. elif park["statu"] == 3:
  731. background_color = "background-color:rgb(0,100,255);"
  732. # 取车中
  733. elif park["statu"] == 4:
  734. background_color = "background-color:rgb(102,255,255);"
  735. # 已预约
  736. elif park["statu"] == 5:
  737. background_color = "background-color:rgb(0,255,0);"
  738. # 出入口
  739. elif park["statu"] == 6 or park["statu"] == 7 or park["statu"] == 8:
  740. background_color = "background-color:rgb(0,162,232);"
  741. background_image = ""
  742. # elif park["statu"] == 0 and park["remark"] is not None:
  743. # background_color = "background-color:rgb(255,130,130);"
  744. stylesheet = background_color + "pressed{padding-top:2px;padding-left:2px;};" + background_image + "background-repeat:no-repeat;"
  745. for key in park.keys():
  746. if park[key] is None:
  747. park[key] = ''
  748. tool_tip = json.dumps(park, cls=DjangoJSONEncoder)
  749. return font, text_str, stylesheet, tool_tip
  750. # 显示车辆图片
  751. def show_car_image(self, Item):
  752. try:
  753. row = Item.row() # 获取行数
  754. col = self.tableWidget.columnCount() # 获取列数 注意是column而不是col哦
  755. plate_full_image = self.tableWidget.item(row, col - 2)
  756. plate_clip_image = self.tableWidget.item(row, col - 1)
  757. self.plate_full_image_label_2.setPixmap(QPixmap(""))
  758. self.plate_clip_image_label_2.setPixmap(QPixmap(""))
  759. if plate_full_image is not None:
  760. rep = requests.get(plate_full_image.text())
  761. pix = QPixmap()
  762. pix.loadFromData(rep.content)
  763. pix = pix.scaled(self.plate_full_image_label_2.size(), Qt.KeepAspectRatio)
  764. self.plate_full_image_label_2.setPixmap(pix)
  765. if plate_clip_image is not None:
  766. rep = requests.get(plate_clip_image.text())
  767. pix = QPixmap()
  768. pix.loadFromData(rep.content)
  769. pix = pix.scaled(self.plate_clip_image_label_2.size(), Qt.KeepAspectRatio)
  770. self.plate_clip_image_label_2.setPixmap(pix)
  771. except Exception as e:
  772. traceback.print_exc()
  773. # 查询历史记录
  774. def db_record_find(self):
  775. if self.db_connect_statu is False:
  776. QMessageBox.critical(None, "提示", "数据库连接断开!", QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  777. return
  778. if self.db_unit_list[self.db_unit] == 0:
  779. unit_sql = ""
  780. elif type(self.db_unit_list[self.db_unit]) != int:
  781. unit_sql = "and ("
  782. for i in self.db_unit_list[self.db_unit]:
  783. unit_sql = unit_sql + "unit_id=%d or " % i
  784. unit_sql = unit_sql[:-3] + ")"
  785. else:
  786. unit_sql = "and (unit_id = %s)" % self.db_unit_list[self.db_unit]
  787. in_datatime = self.in_dateTimeEdit.dateTime().toPyDateTime()
  788. out_datatime = self.out_dateTimeEdit.dateTime().toPyDateTime()
  789. car_number = self.car_number_lineEdit.text()
  790. in_time_sql = "(in_time_start >= '%s' and in_time_start <= '%s') " % (in_datatime, out_datatime)
  791. out_time_sql = "(out_time_start >= '%s' and out_time_start <= '%s') " % (in_datatime, out_datatime)
  792. in_and_out_time_sql = "(" + in_time_sql + " or " + out_time_sql + ")"
  793. if self.park_radioButton.isChecked():
  794. time_sql = in_time_sql
  795. elif self.pick_radioButton.isChecked():
  796. time_sql = out_time_sql
  797. else:
  798. time_sql = in_and_out_time_sql
  799. car_number_sql = ""
  800. if car_number != "":
  801. car_number_sql = "and car_number like '%{}%'".format(car_number)
  802. sql = "select * from record where %s %s %s " % (time_sql, unit_sql, car_number_sql)
  803. print(sql)
  804. results = self.db.query(sql)
  805. self.tableWidget.clearContents()
  806. self.tableWidget.setRowCount(0)
  807. for i in range(len(results)):
  808. row_count = self.tableWidget.rowCount() # 返回当前行数(尾部)
  809. self.tableWidget.insertRow(row_count) # 尾部插入一行
  810. for j, value in zip(range(0, len(results[i])), results[i].values()):
  811. self.tableWidget.setItem(i, j, QTableWidgetItem(str(value)))
  812. # print(results)
  813. def custom_right_menu(self, pos):
  814. sender = self.sender()
  815. menu = QMenu()
  816. opt1 = menu.addAction("恢复排队")
  817. opt2 = menu.addAction("设为故障")
  818. opt3 = menu.addAction("删除任务")
  819. try:
  820. hitIndex = sender.indexAt(pos).row()
  821. # print(hitIndex)
  822. if hitIndex > -1:
  823. # 获取item内容
  824. car_number = sender.item(hitIndex).toolTip()
  825. action = menu.exec_(sender.mapToGlobal(pos))
  826. if action is None:
  827. return
  828. if self.is_input_pwd() is True:
  829. self.is_pwd = False
  830. if self.is_input_pwd('该操作存在风险,请再次输入密码!') is True:
  831. if action == opt1:
  832. res = self.db.update_command_status_in_car_number(car_number, 0)
  833. if action == opt2:
  834. res = self.db.update_command_status_in_car_number(car_number, 3)
  835. if action == opt3:
  836. res = self.db.delete_command(car_number)
  837. if res > 0:
  838. QMessageBox.question(None, '提示', '指令修改成功!',
  839. QMessageBox.Ok) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  840. except Exception as e:
  841. pass
  842. def is_input_pwd(self, tipstr=None):
  843. if self.is_pwd is False:
  844. # 组装显示信息
  845. # 实例取车窗口,并以模态窗口形式显示
  846. pickup_window = PickupWindow(tipstr,self.parking_config['passwd'])
  847. pickup_window.exec_()
  848. res = pickup_window.getResult()
  849. if res is ResultReturn.OK:
  850. self.is_pwd = True
  851. self.t_time = time.time()
  852. return True
  853. else:
  854. return False
  855. return True
  856. def get_listWidget_item(self, dict):
  857. item = QListWidgetItem()
  858. item.setFont(QFont('微软雅黑', 14, QFont.Bold))
  859. item.setToolTip(dict['car_number'])
  860. parkspace = message.parkspace_info()
  861. try:
  862. tf.Parse(dict['space_info'], parkspace)
  863. except Exception:
  864. parkspace.table_id = -1
  865. show_str = ""
  866. if dict['type'] == 1: # 存车指令
  867. item.setBackground(QColor(185, 240, 240))
  868. if (dict['statu'] == 0): # 排队
  869. item.setForeground(QColor(80, 80, 80))
  870. show_str = dict['car_number'] + " 排队中"
  871. elif (dict['statu'] == 1): # 工作
  872. item.setForeground(QColor('blue'))
  873. show_str = dict['car_number'] + " 存车中"
  874. elif (dict['statu'] == 2): # 已完成
  875. item.setForeground(QColor('green'))
  876. show_str = dict['car_number'] + " 已完成"
  877. elif (dict['statu'] == 3): # 已完成
  878. item.setForeground(QColor('red'))
  879. show_str = dict['car_number'] + " 故障!"
  880. show_str = "存 %d入 %d出 %d号车位 %s %s " % (
  881. dict["import_id"], dict["export_id"], parkspace.table_id, show_str, str(dict["queue_time"].time()))
  882. elif dict['type'] == 2: # 取车指令
  883. item.setBackground(QColor(250, 240, 200))
  884. if (dict['statu'] == 0): # 排队
  885. item.setForeground(QColor(80, 80, 80))
  886. show_str = dict['car_number'] + " 排队中"
  887. elif (dict['statu'] == 1): # 工作
  888. item.setForeground(QColor('blue'))
  889. show_str = dict['car_number'] + " 取车中"
  890. elif (dict['statu'] == 2): # 已完成
  891. item.setForeground(QColor('green'))
  892. show_str = dict['car_number'] + " 已完成"
  893. elif (dict['statu'] == 3): # 已完成
  894. item.setForeground(QColor('red'))
  895. show_str = dict['car_number'] + " 故障!"
  896. show_str = "取 %d入 %d出 %d号车位 %s %s " % (
  897. dict["import_id"], dict["export_id"], parkspace.table_id, show_str, str(dict["queue_time"].time()))
  898. item.setText(show_str)
  899. return item
  900. def closeEvent(self, event):
  901. results = QMessageBox.question(self, '退出', '你确定要退出吗?', QMessageBox.Yes | QMessageBox.No,
  902. QMessageBox.No) # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
  903. if results == QMessageBox.Yes:
  904. self.db_query_isClose = True
  905. self.db_query.join()
  906. self.rabbitmq.close()
  907. event.accept() # 接受关闭事件
  908. # 强制结束进程
  909. pid = os.getpid()
  910. os.kill(pid, signal.SIGTERM)
  911. else:
  912. event.ignore() # 忽略关闭事件
  913. def get_name(self, key):
  914. if key == 'id':
  915. return '总车位号'
  916. elif key == 'table_id':
  917. return '表编号'
  918. elif key == 'floor':
  919. return '楼层'
  920. elif key == 'height_level':
  921. return '限高等级'
  922. elif key == 'height':
  923. return '限高'
  924. elif key == 'wheel_base_level':
  925. return '限制轴距等级'
  926. elif key == 'wheel_base':
  927. return '限制轴距'
  928. elif key == 'car_number':
  929. return '车牌号'
  930. elif key == 'statu':
  931. return '车位状态'
  932. elif key == 'plate_color':
  933. return '号牌颜色'
  934. elif key == 'plate_type':
  935. return '号牌类型'
  936. elif key == 'plate_confidence':
  937. return '号牌可信度'
  938. elif key == 'recognition_time':
  939. return '识别时间'
  940. elif key == 'primary_key':
  941. return '唯一码'
  942. elif key == 'plate_full_image':
  943. return '号牌全景图'
  944. elif key == 'plate_clip_image':
  945. return '号牌特写图'
  946. elif key == 'remark':
  947. return '备注'
  948. elif key == 'remark_time':
  949. return '备注时间'
  950. elif key == 'apply_end_time':
  951. return '预约结束时间'
  952. else:
  953. return '未知'
  954. def get_unit(self, unit):
  955. if unit == 1:
  956. return 'A'
  957. elif unit == 2:
  958. return 'B'
  959. elif unit == 11:
  960. return 'A'
  961. elif unit == 12:
  962. return 'A2'
  963. elif unit == 13:
  964. return 'A3'
  965. elif unit == 14:
  966. return 'A4'
  967. elif unit == 21:
  968. return 'B'
  969. elif unit == 22:
  970. return 'B2'
  971. elif unit == 23:
  972. return 'B3'
  973. elif unit == 24:
  974. return 'B4'
  975. elif unit == 25:
  976. return 'B5'
  977. elif unit == 31:
  978. return 'C1'
  979. elif unit == 32:
  980. return 'C2'
  981. return '未知'