casper 1 ay önce
ebeveyn
işleme
b96219cb9d

+ 2 - 0
sri-server-bg01/api/v6/code1000.py

@@ -69,6 +69,8 @@ async def code1002(**sources):
     size = sources.get('size', 10)
     for item in Global.mdb.get_all('UserInfo', sort_field=[('allow_at', -1)]):
 
+        # methods.debug_log('code1000|72', f"#item: {item.get('name')}")
+
         # --- check ---
         if sources.get('name') and sources.get('name') not in str(item.get('name')):
             continue

+ 11 - 79
sri-server-bg01/api/v6/code3000.py

@@ -38,6 +38,11 @@ async def code3001(**sources):
         ipv4 = int(f"{item.get('host_address').replace('.', '')}")
         d2[ipv4] = item.get('pid')
 
+    cockpit_name_dict = {
+        '': '1号舱',
+        '': '2号舱',
+    }
+
     # --- fill d1 ---
     """
     UserWorkRecordList: 用户操作记录
@@ -61,18 +66,20 @@ async def code3001(**sources):
         item['uuid'] = uuid
         item['start_time_at'] = item.get('start_at')
         item['end_time_at'] = item.get('end_at')
-        item['cockpit_name'] = item.get('cockpit_id')
 
-        # --- check ---
+        # --- update driver_name ---
         item['driver_name'] = item.get('user_uuid')
         if len('67174cf9cd36d7a6def99cae') == len(item.get('user_uuid')):
             item['driver_name'] = Global.mdb.get_one_by_id('UserInfo', item.get('user_uuid')).get('name')
 
-        # --- check ---
+        # --- update pid ---
         item['pid'] = item.get('vehicle_id')
         if int(item.get('vehicle_id')) in d2:
             item['pid'] = d2.get(int(item.get('vehicle_id')))
 
+        # --- update cockpit_name ---
+        item['cockpit_name'] = item.get('cockpit_id')
+
         # --- update --
         del item['_id']
         del item['user_uuid']
@@ -81,82 +88,7 @@ async def code3001(**sources):
         del item['cockpit_id']
         del item['vehicle_id']
         d1.append(item)
-        # d1.append(item)
-
-
-    # d1 = [
-    #     {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',  # 车牌号
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '张三',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }, {
-    #         'uuid': '65dbe96949fbe311a3a01d30',
-    #         'pid': 'AA112233',
-    #         'start_time_at': methods.now_ts(),
-    #         'end_time_at': methods.now_ts() + (3600 * 8),
-    #         'driver_name': '李四',
-    #         'cockpit_name': '1号舱',
-    #     }
-    # ]
+
     return dict(code=0, data=d1[(page - 1) * size: page * size], total=len(d1), page=page, size=size)
 
 

+ 11 - 11
sri-server-bg01/test/test-1000.py

@@ -53,17 +53,17 @@ print(response.json())
 
 # --- test 1002 查询用户列表 ---
 # url = 'http://58.34.94.177:29101/v6/api'
-# url = 'http://127.0.0.1:9000/v6/api'
-# data = {
-#     'code': 1002,  # 接口号
-#     'page': 1,  # 页码
-#     'size': 3,  # 每页条数
-#     'name': 'a',  # 模糊姓名(可选项)
-#     'phone': '',  # 手机号(可选项)
-#     'role_type': ['2'],  # 角色类型(可选项) 1 超级管理员 2 普通管理员 3 普通用户(默认值)
-# }
-# response = requests.post(url=url, json=data, headers={'authorization': token})
-# print(response.json())
+url = 'http://127.0.0.1:9000/v6/api'
+data = {
+    'code': 1002,  # 接口号
+    'page': 1,  # 页码
+    'size': 3,  # 每页条数
+    'name': '张',  # 模糊姓名(可选项)
+    'phone': '',  # 手机号(可选项)
+    'role_type': ['1'],  # 角色类型(可选项) 1 超级管理员 2 普通管理员 3 普通用户(默认值)
+}
+response = requests.post(url=url, json=data, headers={'authorization': token})
+print(response.json())
 # """
 # {
 #   'code': 0,

+ 3 - 2
sri-server-bg02/hub.py

@@ -8,8 +8,9 @@ methods = importlib.import_module(f"xlib")
 
 class Global(object):
     # --- 中间件服务器 ---
-    emqx = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
-
+    emqx001 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
+    emqx002 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
+    
     aps = importlib.import_module(f"xpip.xapscheduler").APS(db_type='mongo',
                                                             db_host='127.0.0.1',
                                                             db_port=47017,

+ 7 - 11
sri-server-bg02/lib/JobManage.py

@@ -24,12 +24,12 @@ class JobManage(object):
         # Global.aps.create_job(func=cls.job101, trigger='date', run_date='2022-02-23 18:54:00')  # 定时测试
         # Global.aps.create_job(func=cls.job301, trigger='interval', seconds=60)  # 循环测试
         # Global.aps.create_job(func=cls.job20102, trigger='date', run_date='2022-07-28 17:15:30')  # 定时测试
-
-        # --- release ---
         # Global.aps.create_job(func=cls.job101, trigger='cron', hour=22)  # 每天晚10点 
-        Global.aps.create_job(func=cls.job101, trigger='interval', seconds=600)  # 每10分钟 
+        # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=60)  # 每1分钟 
         # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=300)  # 每5分钟 
-        # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3600)  # 每1小时 
+
+        # --- release ---
+        Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3600)  # 每1小时 
 
     @classmethod
     def end(cls):
@@ -39,14 +39,10 @@ class JobManage(object):
     @staticmethod
     def job101():
         """
-        每日22点清理7天之前的日志
-
-        每日22点清理1天之前的日志(测试)
-
-        todo 根据UserWorkRecordList.start_at来判断过去7天的数据
+        每1小时清理7*24小时之前的日志
         """
         # --- log ---
-        methods.debug_log("JobManage|49", f"------------------------------ start")
+        methods.debug_log("JobManage|49", f"------------------------------ start job101")
 
         # --- get log_file_uuid_list ---
         log_file_list = methods.get_file_path_list(save_dir)
@@ -58,7 +54,7 @@ class JobManage(object):
             
             # --- check ---
             file_path = os.path.join(save_dir, f"{log_file_uuid}.log")
-            item = Global.mdb.updage_one_by_id('UserWorkRecordList', log_file_uuid)
+            item = Global.mdb.get_one_by_id('UserWorkRecordList', log_file_uuid)
             if not item:
                 methods.remove_file(file_path)
 

+ 4 - 4
sri-server-bg02/lib/MessageListenerC001.py

@@ -72,7 +72,7 @@ def method_c001(client, userdata, message):
         'vehicleID': '0538'
     }
     """
-    # --- print ---
+    # --- check ---
     # methods.debug_log(f"method_c001|75", f"#message.payload: {message.payload}")
     try:
         log_dict = json.loads(message.payload)
@@ -89,7 +89,7 @@ def method_c001(client, userdata, message):
     vehicle_id = log_dict.get('vehicleID')
     cockpit_id = log_dict.get('cockpitID')
     log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
-    methods.debug_log(f"method_c001|92", f"user_uuid: {user_uuid}, log_time: {log_time}")
+    # methods.debug_log(f"method_c001|92", f"user_uuid: {user_uuid}, log_time: {log_time}")
     if not log_uuid:
         return
 
@@ -155,13 +155,13 @@ def method_c001(client, userdata, message):
 
     # --- save ---
     log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
-    methods.debug_log(f"MessageListener|149", f"#log_list: {log_list}")
+    methods.debug_log(f"MessageListenerC001|158", f"#log_list: {log_list}")
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 
 def subscribe_c001():
     """"""
-    Global.emqx.start_subscribe_loop(
+    Global.emqx001.start_subscribe_loop(
         decorate_method=method_c001,
         subscribe_topic='Cockpit/CanBus/CanId001/Cop001'
     )

+ 2 - 2
sri-server-bg02/lib/MessageListenerV001.py

@@ -109,13 +109,13 @@ def method_v001(client, userdata, message):
 
     # --- save ---
     log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
-    methods.debug_log(f"MessageListener24", f"#log_list: {log_list}")
+    methods.debug_log(f"MessageListenerV001|113", f"#log_list: {log_list}")
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 
 def subscribe_v001():
     """"""
-    Global.emqx.start_subscribe_loop(
+    Global.emqx002.start_subscribe_loop(
         decorate_method=method_v001,
         subscribe_topic='Vehicle/ControlVehicle/Veh001'
     )