casper hace 1 mes
padre
commit
f2303cb689
Se han modificado 2 ficheros con 22 adiciones y 17 borrados
  1. 12 9
      sri-server-bg01/api/api.py
  2. 10 8
      sri-server-bg01/api/v6/code3000.py

+ 12 - 9
sri-server-bg01/api/api.py

@@ -182,20 +182,23 @@ async def download(request: Request, response: Response, tag: str):
     try:
         # --- get ---
         params = request.query_params
-        # methods.debug_log('api.download|185', f"#code: {params.get('code')} | {type(params.get('code'))}")
-        # methods.debug_log('api.download|185', f"#tag: {tag}")
+        methods.debug_log('api.download|185', f"#code: {params.get('code')} | {type(params.get('code'))}")
+        methods.debug_log('api.download|185', f"#tag: {tag}")
+        methods.debug_log('api.download|185', f"#params: {params}")
         method = _get_method_by_code(code=int(params.get('code')), tag=tag)
         result = await method(**params)
 
         # --- 是否弹框 ---
-        if True:
-            return FileResponse(result.get('file_path'),
-                                media_type="application/octet-stream", filename=result.get('file_name'))
+        if result.get('code') == 0:
+            if True:
+                return FileResponse(result.get('file_path'),
+                                    media_type="application/octet-stream", filename=result.get('file_name'))
+            else:
+                return FileResponse(result.get('file_path'))
         else:
-            return FileResponse(result.get('file_path'))
-
+            return result
     except Exception as exception:
-        methods.debug_log('api.download.249', f"#exception: {exception}")
-        methods.debug_log('api.download.249', f"#traceback: {methods.trace_log()}")
+        methods.debug_log('api.download|200', f"#exception: {exception}")
+        methods.debug_log('api.download|200', f"#traceback: {methods.trace_log()}")
         return dict(code=-1, message=f"something is wrong. [{exception.__class__.__name__}]",
                     details=f"{methods.trace_log()}")

+ 10 - 8
sri-server-bg01/api/v6/code3000.py

@@ -81,7 +81,7 @@ async def code3001(**sources):
         del item['cockpit_id']
         del item['vehicle_id']
         d1.append(item)
-        d1.append(item)
+        # d1.append(item)
 
 
     # d1 = [
@@ -164,17 +164,19 @@ async def code3002(**sources):
     """
     下载指定驾驶人员操作日志
     """
+    # --- check ---
     if not sources.get('uuid'):
-        return dict(code=1, details=f"not found uuid.")
+        return dict(code=1, details=f"not found uuid.[url中缺少uuid参数]")
+    
+    # --- get file_path ---
     # log_uuid = '671754598302fc6fd344819f'
-    # if sources.get('uuid'):
-    #     log_uuid = sources.get('uuid')
-    methods.debug_log('code3000.code3002|145:', f"#log_uuid: {sources.get('uuid')}")
-    file_path = os.path.join(save_dir, f"{sources.get('uuid')}.log")
+    log_uuid = sources.get('uuid')
+    file_path = os.path.join(save_dir, f"{log_uuid}.log")
 
     # --- get file_name ---
-    item = Global.mdb.get_one_by_id('UserWorkRecordList', sources.get('uuid'))
+    methods.debug_log('code3000.code3002|145:', f"#log_uuid: {log_uuid}")
+    item = Global.mdb.get_one_by_id('UserWorkRecordList', log_uuid)
     start_at = methods.ts_to_string(item.get('start_at'), '%Y%m%d%H%M%S')
     end_at = methods.ts_to_string(item.get('end_at'), '%Y%m%d%H%M%S')
     file_name = f"{start_at}-{end_at}.log"
-    return {'file_path': file_path, 'file_name': file_name}
+    return {'code': 0, 'file_path': file_path, 'file_name': file_name}