소스 검색

2024/01/29 测试收费系统外网请求

wk 9 달 전
부모
커밋
4cf471ad8c
4개의 변경된 파일170개의 추가작업 그리고 39개의 파일을 삭제
  1. 8 0
      message.proto
  2. 13 5
      mytool/db_helper/db_operation.py
  3. 30 3
      指令检查节点/check_command_XmSgj.py
  4. 119 31
      指令检查节点/node.py

+ 8 - 0
message.proto

@@ -112,6 +112,14 @@ message park_table{
 
     plate_number_info car_number_info = 12;   // 车牌号信息
 }
+/*
+预约车位的表单
+*/
+message apply_table
+{
+    string car_number=1;                        //车牌号
+    string apply_end_time=2;                   //预约结束时间
+}
 
 /*
 取车表单

+ 13 - 5
mytool/db_helper/db_operation.py

@@ -19,23 +19,28 @@ class DBOperation:
     # 更新
     def update(self, sql):
         return self._db.execute_sql(sql)
+
     def query_total_empty_space(self):
         sql = "select count(*) from space where statu=0 and car_number is NULL"
         return self._db.query_all_sql(sql)
+
     def query_large_empty_space(self):
         sql = "select count(*) from space where statu=0 and car_number is NULL and height>=1.7"
         return self._db.query_all_sql(sql)
+
     def query_small_empty_space(self):
         sql = "select count(*) from space where statu=0 and car_number is NULL and height<1.7"
         return self._db.query_all_sql(sql)
 
-    def query_queue_condition(self, unit):
+    def query_queue_condition_in_unit(self, unit):
         sql = "Select * , row_number() over(order by queue_time)  from command_queue where statu <2 and unit=%s"
         return self._db.query_all_sql(sql, unit)
 
+
     def query_command_queue_count_in_unit(self, unit):
         sql = "select count(*) from command_queue where statu <2 and unit=%s"
         return self._db.query_all_sql(sql, unit)
+
     def query_parking_in_unit_tableid(self, unit, tableid):
         sql = "select * from space WHERE unit=%s and table_id=%s"
         return self._db.query_all_sql(sql, (unit, tableid))
@@ -67,12 +72,15 @@ class DBOperation:
     def query_command_all(self):
         sql = "select * from command_queue"
         return self._db.query_all_sql(sql)
-    def query_command_top_number(self,number):
+
+    def query_command_top_number(self, number):
         sql = "select *from ( select * from command_queue order by queue_time desc limit %s ) aa order by queue_time"
         return self._db.query_all_sql(sql, number)
-    def query_command_top_number_in_type(self, type,number):
+
+    def query_command_top_number_in_type(self, type, number):
         sql = "select * from ( select * from command_queue  where type=%s and statu != 4 order by queue_time desc limit %s ) aa order by queue_time"
-        return self._db.query_all_sql(sql, (type,number))
+        return self._db.query_all_sql(sql, (type, number))
+
     def query_command_in_car_number(self, car_number):
         sql = "select * from command_queue WHERE car_number=%s"
         return self._db.query_all_sql(sql, car_number)
@@ -169,7 +177,7 @@ class DBOperation:
         sql = "update space set remark=%s where id=%s"
         return self._db.execute_sql(sql, (remark, space_id))
 
-    def update_command_queue_upload_statu_in_car_number(self,car_number):
+    def update_command_queue_upload_statu_in_car_number(self, car_number):
         sql = "update command_queue set upload_statu=1 where car_number=%s"
         return self._db.execute_sql(sql, car_number)
 

+ 30 - 3
指令检查节点/check_command_XmSgj.py

@@ -536,8 +536,11 @@ class CommandChecker:
             "largeParkSurplus": large,
             "smallParkSurplus": small
         }
-        print("****************************查询排队信息****************************" + str(datetime.datetime.now()))
-        command_count = self.db.query_command_queue_count_in_unit(unit_id)[0]['count(*)']
+        if param == 'queue 1':
+            command_count = 1
+        else:
+            print("****************************查询排队信息****************************" + str(datetime.datetime.now()))
+            command_count = self.db.query_command_queue_count_in_unit(unit_id)[0]['count(*)']
         pickup_queue_dict = {
             "licenesePlate": car_number,
             "inRecordId": primary_key,
@@ -554,7 +557,7 @@ class CommandChecker:
     def push_pickqueue(self):
         while True:
             for unit in self.chnnId_in.keys():
-                res = self.db.query_queue_condition(unit)
+                res = self.db.query_queue_condition_in_unit(unit)
                 for dict in res:
                     if dict['upload_statu'] is None and dict['row_number() over(order by queue_time)'] == 2:
                         print("===============================排队为1 推送排队详情=========================" + str(datetime.datetime.now()))
@@ -592,3 +595,27 @@ class CommandChecker:
         elif unit == 3:
             return 'C'
         return ''
+    def get_unit_int(self, unit):
+        if unit == 'A1':
+            return 11
+        elif unit == 'A2':
+            return 12
+        elif unit == 'A3':
+            return 13
+        elif unit == 'A4':
+            return 14
+        elif unit == 'B1':
+            return 21
+        elif unit == 'B2':
+            return 22
+        elif unit == 'B3':
+            return 23
+        elif unit == 'B4':
+            return 24
+        elif unit == 'B5':
+            return 25
+        elif unit == 'C1':
+            return 31
+        elif unit == 'C2':
+            return 32
+        return 0

+ 119 - 31
指令检查节点/node.py

@@ -1,6 +1,7 @@
 import sys
 
 import json
+
 sys.path.append("..")
 import datetime
 import os
@@ -16,9 +17,11 @@ import check_command_ZKXY as CHE_ZKXY
 import mytool.json_helper.parse_json as parse_json
 from http.server import HTTPServer, BaseHTTPRequestHandler
 from mytool.log_helper.logger import HandleLog
+
+
 def check_park_command(body):
     # print("接收停车指令 %s  message:%s" % (datetime.datetime.now(), body))
-    log.info("接收停车指令 %s    message:%s" % (datetime.datetime.now(),body[0:260]))
+    log.info("接收停车指令 %s    message:%s" % (datetime.datetime.now(), body[0:260]))
     cmd = checker.entrance_isOK(body)
     table = message.park_table()
     table.CopyFrom(cmd)
@@ -32,14 +35,16 @@ def check_park_command(body):
         # 指令检查正常
         dispatch_key = "dispatch_park_command_%d_request_port" % cmd.unit_id
         g_rabbitmq.publish(mq_config['mq_command_exchange_name'], dispatch_key, tf.MessageToString(table, as_utf8=True))
-        log.info("停车指令 %s OK:%s    检查成功!\n" % (datetime.datetime.now(), tf.MessageToString(table, as_utf8=True)))
+        log.info(
+            "停车指令 %s OK:%s    检查成功!\n" % (datetime.datetime.now(), tf.MessageToString(table, as_utf8=True)))
     else:
         # print("---------------刷新投影-----------------" + entrance_key)
         # g_rabbitmq.publish(mq_config['mq_statu_exchange_name'], entrance_key,
         #                    tf.MessageToString(cmd, as_utf8=True))
         if cmd.statu.execute_statu == message.eWarning:
             # 给终端发送指令,刷新投影
-            log.warning("停车指令 %s  车牌号:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
+            log.warning(
+                "停车指令 %s  车牌号:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
                     datetime.datetime.now(), cmd.car_number,
                     mq_config['mq_command_exchange_name'], response_port + "," + dispatch_key,
                     tf.MessageToString(cmd, as_utf8=True)))
@@ -50,10 +55,11 @@ def check_park_command(body):
                 mq_config['mq_command_exchange_name'], response_port + "," + dispatch_key,
                 tf.MessageToString(cmd, as_utf8=True)))
         else:
-            log.critical("停车指令 %s  车牌号:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
-                datetime.datetime.now(), cmd.car_number,
-                mq_config['mq_command_exchange_name'], response_port + "," + dispatch_key,
-                tf.MessageToString(cmd, as_utf8=True)))
+            log.critical(
+                "停车指令 %s  车牌号:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
+                    datetime.datetime.now(), cmd.car_number,
+                    mq_config['mq_command_exchange_name'], response_port + "," + dispatch_key,
+                    tf.MessageToString(cmd, as_utf8=True)))
 
 
 def check_pick_command(body):
@@ -68,7 +74,8 @@ def check_pick_command(body):
         g_rabbitmq.publish(mq_config['mq_command_exchange_name'], dispatch_key, tf.MessageToString(cmd, as_utf8=True))
     else:
         if cmd.statu.execute_statu == message.eWarning:
-            log.warning("取车指令 %s  唯一码:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
+            log.warning(
+                "取车指令 %s  唯一码:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
                     datetime.datetime.now(), cmd.primary_key,
                     mq_config['mq_command_exchange_name'], response_port + "," + dispatch_key,
                     tf.MessageToString(cmd, as_utf8=True)))
@@ -78,7 +85,8 @@ def check_pick_command(body):
                 mq_config['mq_command_exchange_name'], response_port + "," + dispatch_key,
                 tf.MessageToString(cmd, as_utf8=True)))
         else:
-            log.critical("取车指令 %s  唯一码:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
+            log.critical(
+                "取车指令 %s  唯一码:%s    检查失败!\n 发送反馈    交换机:%s  发送反馈端口:%s    反馈表单:%s" % (
                     datetime.datetime.now(), cmd.primary_key,
                     mq_config['mq_command_exchange_name'], response_port + "," + dispatch_key,
                     tf.MessageToString(cmd, as_utf8=True)))
@@ -101,33 +109,111 @@ class MyHttpRequestHandler(BaseHTTPRequestHandler):
         datas = self.rfile.read(int(self.headers['content-length']))  # 固定格式,获取表单提交的数据
         self.send_response(200)  # 返回状态码
         self.end_headers()  # 返回响应头结束
+        code = 200
+        msg = "error"
+        data = "初始化"
         try:
+            # utf-8解码解析json
             st = datas.decode('utf-8')
             res = json.loads(st)
             print(res)
-            if ('data' in res.keys()) and ('InRecordId' in res['data'].keys()):
-                primary_key = res['data']['InRecordId']
+        except Exception:
+            code,msg,data = 200,"error","解析失败!"
+            self.send_write(code,msg,data)
+            return
+        # 查看是否有指令类型字段
+        if 'commandType' in res.keys():
+            # 取车指令
+            if res['commandType'] == 'PickCommand':
+                try:
+                    # 查看是否有唯一码字段
+                    primary_key = res['inRecordId']
+                except Exception:
+                    code, msg, data = 2, "error", "PickCommand,解析失败,缺少关键字段inRecordId!"
+                    self.send_write(code, msg, data)
+                    return
+                # 生成取车表单,走正常取车指令
                 table = message.pick_table()
                 table.primary_key = primary_key
-                # table.statu.table_process_mod = message.PROCESS_ONLY_TO_DISPATCH
+                # 执行取车指令
                 cmd = check_pick_command(tf.MessageToString(table, as_utf8=True))
                 if cmd.statu.execute_statu == message.eNormal:
-                    buf = {"Message": "取车成功", "Tag": 1}
+                    code, msg, data = 0, "success", "取车指令,接收成功!"
+
                 else:
-                    buf = {"Message": cmd.statu.statu_description, "Tag": 0}
-            else:
-                buf = {"Message": "取车指令缺少关键字段Data或InRecordId!", "Tag": 0}
-                # 以下是返回报文
-        except Exception as e:
-            buf = {"Message": "请求解析失败!", "Tag": 0}
-        self.wfile.write(json.dumps(buf, ensure_ascii=False).encode('utf-8'))  # 发送json格式的返回包体
-        print(buf)
+                    code, msg, data = 1, "error", "取车失败!%s" % cmd.statu.statu_description
+            # 查询排队
+            elif res['commandType'] == 'RankCommand':
+                try:
+                    garageNo = res['garageNo']
+                    unit = checker.get_unit_int(garageNo)
+                    car_number = res['licenesePlate']
+                    primary_key = res['inRecordId']
+                except Exception:
+                    code, msg, data = 2, "error", "RankCommand,解析失败,缺少关键字段!"
+                    self.send_write(code, msg, data)
+                    return
+                # 查询排队信息
+                print("%%%%%%%%%%%%%%%%%%%%%%%%%%%% 查询排队信息 %%%%%%%%%%%%%%%%%%%%%%%%%%%%" + str(datetime.datetime.now()))
+                command_list = checker.db.query_queue_condition_in_unit(unit)
+                i = 0
+                for dict in command_list:
+                    if dict['car_number'] == car_number:
+                        command_count = dict['row_number() over(order by queue_time)']-1
+                        pickup_queue_dict = {
+                            "licenesePlate": car_number,
+                            "inRecordId": primary_key,
+                            "garageNo": garageNo,
+                            "waitNum": command_count,
+                            "remainingTime": command_count * 2
+                        }
+                        code, msg, data = 0, "success",pickup_queue_dict
+                        break
+                    i = i+1
+                # 没找到对应车辆
+                if i == len(command_list):
+                    code, msg, data = 1, "error", '未查询到该车辆,车牌号:%s,单元号:%s,流水号:%s'%(car_number,garageNo,primary_key)
+            # 预约车位
+            elif res['commandType'] == 'ApplyCommand':
+                try:
 
+                    apply_table = message.apply_table()
+                    apply_table.car_number = res['licenesePlate']
+                    apply_table.apply_end_time = res['endTime']
 
+                except Exception:
+                    code, msg, data = 2, "error", "ApplyCommand,解析失败,缺少关键字段!"
+                    self.send_write(code, msg, data)
+                    return
+                #预约车位查重
+                sql = "Select *  from space where height>1.799 and wheel_base>2.899 and unit>30 and car_number is null and statu=0"
+                c_empty_space_list = checker.db.query(sql)
+                space_list = checker.db.query_space_in_car_number(apply_table.car_number)
+                if len(space_list)>0:
+                    code, msg, data = 1, "error", "预约失败,车辆已在库内!"
+                elif len(c_empty_space_list) < 0:
+                    code, msg, data = 1, "error", "预约失败,无空闲车位!"
+                else:
+                    g_rabbitmq.publish(mq_config['mq_command_exchange_name'], "dispatch_apply_command_request_port",tf.MessageToString(apply_table, as_utf8=True))
+                    code, msg, data = 0, "success", "预约成功!"
+        else:
+            code, msg, data = 2, "error", "解析失败,缺少关键字段commandType!"
+        # 发送答复
+        self.send_write(code, msg, data)
+    # 对接受到的post请求发送答复
+    def send_write(self,code,msg,data):
+        buf = {"code": code,
+               "msg": msg,
+               "data": data}
+        self.wfile.write(json.dumps(buf, ensure_ascii=False).encode('utf-8'))  # 发送json格式的返回包体
+        print(buf)
 def recv_post():
+    # 绑定IP
     ts = HTTPServer(('192.168.2.57', 8899), MyHttpRequestHandler)
+    # 启动服务
     ts.serve_forever()
 
+
 if __name__ == '__main__':
     config = parse_json.parse_json_with_comments('./config.json')
     log = HandleLog.get_logger(os.getcwd() + '_logs')
@@ -146,17 +232,19 @@ if __name__ == '__main__':
         checker = CHE_GyBhhy.CommandChecker(db_config)
     elif config['project_name'] == 'zkxy':
         checker = CHE_ZKXY.CommandChecker(db_config)
-
-    g_rabbitmq = CM.RabbitAsyncCommunicator(mq_config['mq_ip'], mq_config['mq_port'], mq_config['mq_user'], mq_config['mq_password'])
-    g_rabbitmq.Init(cmd_callbacks, mq_config['mq_statu_exchange_keys'],"checker")
-    for ex,key in mq_config['mq_statu_exchange_keys']:
+    # 初始化rabbitmq
+    g_rabbitmq = CM.RabbitAsyncCommunicator(mq_config['mq_ip'], mq_config['mq_port'], mq_config['mq_user'],
+                                            mq_config['mq_password'])
+    g_rabbitmq.Init(cmd_callbacks, mq_config['mq_statu_exchange_keys'], "checker")
+    # 绑定队列
+    for ex, key in mq_config['mq_statu_exchange_keys']:
         if key.find("dispatch") >= 0:
-            g_rabbitmq.bind_statu_callback(ex,key,checker.receive_dispatch_statu)
+            g_rabbitmq.bind_statu_callback(ex, key, checker.receive_dispatch_statu)
         if key.find("measure") >= 0:
-            g_rabbitmq.bind_statu_callback(ex,key,checker.receive_measure_info)
-
-    t1 = threading.Thread(target=recv_post)
+            g_rabbitmq.bind_statu_callback(ex, key, checker.receive_measure_info)
+    # 收费系统云端通信
+    http_community = threading.Thread(target=recv_post)
     g_rabbitmq.start()
-    t1.start()
+    http_community.start()
     g_rabbitmq.join()
-    t1.join()
+    http_community.join()