Bläddra i källkod

增加任务日志

flower_bs 2 dagar sedan
förälder
incheckning
a4dddfc8ab
2 ändrade filer med 27 tillägg och 3 borttagningar
  1. 13 3
      container/views.py
  2. 14 0
      greaterwms/settings.py

+ 13 - 3
container/views.py

@@ -38,6 +38,8 @@ from collections import defaultdict
 from django.db.models import Sum
 from staff.models import ListModel as StaffListModel
 logger = logging.getLogger(__name__)
+loggertask = logging.getLogger('wms.WCSTask')
+
 
 # 托盘分类视图
 # 借助LocationContainerLink,其中
@@ -603,6 +605,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
 
 
             http_status = status.HTTP_200_OK if data_return['code'] == '200' else status.HTTP_400_BAD_REQUEST
+            loggertask.info(f"任务号:{current_task.tasknumber-20000000000},移库请求托盘:{container},起始位置:{start_location},目标位置:{target_location},返回结果:{data_return}")
             return Response(data_return, status=http_status)
 
         except Exception as e:
@@ -681,6 +684,8 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                     if batch_info['class'] == 1 or batch_info['class'] == 3:
                         self.inport_update_task(current_task.id, container_obj.id)
             http_status = status.HTTP_200_OK if data_return['code'] == '200' else status.HTTP_400_BAD_REQUEST
+            loggertask.info(f"任务号:{current_task.tasknumber-20000000000},出库请求托盘:{container},起始位置:{start_location},目标位置:{target_location},返回结果:{data_return}")
+
             return Response(data_return, status=http_status)
 
         except Exception as e:
@@ -770,6 +775,8 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
 
 
             http_status = status.HTTP_200_OK if data_return['code'] == '200' else status.HTTP_400_BAD_REQUEST
+            loggertask.info(f"任务号:{current_task.tasknumber-20000000000},入库请求托盘:{container},起始位置:{current_location},目标位置:{allocation_target_location},返回结果:{data_return}")
+
             return Response(data_return, status=http_status)
 
         except Exception as e:
@@ -992,7 +999,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
         
     def update_container_wcs(self, request, *args, **kwargs):
         data = self.request.data
-        logger.info(f"请求托盘:{data.get('container_number')}, 请求位置:{data.get('current_location')}, 任务号:{data.get('taskNumber')}")
+        loggertask.info(f"WCS返回任务: 任务号:{data.get('taskNumber')},请求托盘:{data.get('container_number')}, 请求位置:{data.get('current_location')},")
 
         try:
             # 前置校验
@@ -1013,6 +1020,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                 tasktype='inbound'
                 ).first()
             if self.is_already_at_target(container_obj, data.get('current_location')):
+                loggertask.info(f"WMS返回数据:任务号:{task.tasknumber-20000000000},托盘 {container_obj.container_code} 已在目标位置")
                 return self.handle_target_reached(container_obj, data)
             elif task:
                 data_return = {
@@ -1020,6 +1028,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                     'message': '任务已存在,重新下发',
                     'data': task.to_dict()
                 }
+                loggertask.info(f"WMS返回数据:任务号:{task.tasknumber-20000000000},入库请求托盘:{container_obj.container_code},起始位置:{data.get('current_location')},目标位置:{container_obj.target_location},返回结果:{data_return}")
                 return Response(data_return, status=status.HTTP_200_OK)
             else:
                 return self.handle_new_allocation(container_obj, data)
@@ -1056,8 +1065,8 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
 
     def is_already_at_target(self, container_obj, current_location):
         """检查是否已在目标位置"""
-        print (current_location)
-        print (str(container_obj.target_location))
+        # print (current_location)
+        # print (str(container_obj.target_location))
         return current_location == str(container_obj.target_location)
 
     def handle_target_reached(self, container_obj, data):
@@ -1790,6 +1799,7 @@ class OutboundService:
             }
             }
         }
+        loggertask.info(f"任务号:{task.tasknumber-20000000000}任务发送请求:{task.container},起始位置:{task.current_location},目标位置:{task.target_location},返回结果:{task_data}")
         
         # 创建并启动线程
         thread = threading.Thread(

+ 14 - 0
greaterwms/settings.py

@@ -230,6 +230,7 @@ REST_FRAMEWORK = {
 SERVER_LOGS_FILE = os.path.join(BASE_DIR, "logs", "server.log")
 ERROR_LOGS_FILE = os.path.join(BASE_DIR, "logs", "error.log")
 BILL_LOGS_FILE = os.path.join(BASE_DIR, "logs", "boundBill.log")
+TASK_LOGS_FILE = os.path.join(BASE_DIR, "logs", "WCSTask.log")
 if not os.path.exists(os.path.join(BASE_DIR, "logs")):
     os.makedirs(os.path.join(BASE_DIR, "logs"))
 
@@ -287,12 +288,25 @@ LOGGING = {
             "formatter": "standard",
             "encoding": "utf-8",
         },
+        'WCSTask': {
+            'level': 'INFO',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': TASK_LOGS_FILE,
+            "maxBytes": 1024 * 1024 * 100,
+            "backupCount": 30,
+            "formatter": "standard",
+            "encoding": "utf-8",
+        },
     },
     "loggers": {
         'wms.boundBill': {
             'handlers': ['boundBill'],
             'level': 'INFO',
         },
+        'wms.WCSTask': {
+            'handlers': ['WCSTask'],
+            'level': 'INFO',
+        },
         "django": {
             "handlers": ["console", "error", "file"],
             "level": "INFO",