Jelajahi Sumber

完整入库

flower_mr 1 bulan lalu
induk
melakukan
93952cbf8c

TEMPAT SAMPAH
bin/__pycache__/views.cpython-38.pyc


+ 96 - 33
bin/views.py

@@ -237,7 +237,7 @@ class LocationAllocation:
             status=1
         ).first()
         if not container_detail:
-            logger.error(f"容器 {container_code} 未组盘")
+            logger.error(f"托盘 {container_code} 未组盘")
             return None
  
         batch_container = ContainerDetailModel.objects.filter(
@@ -384,6 +384,37 @@ class LocationAllocation:
             logger.error(f"更新库位状态失败:{str(e)}")
             print(f"更新库位状态失败:{str(e)}")
             return False    
+    
+    def update_group_status_reserved(self,location_group_list):
+        """
+        更新库位组状态
+        :param location_group_list: 库位组对象列表
+        :return:
+        """
+        try:
+            for location_group in location_group_list:
+                # 1. 获取库位组
+                if not location_group:
+                    print(f"库位组获取失败!")
+                    return False
+                # 2. 更新库位组状态
+                location_group_id = location_group.split('_')[1]
+                location_group_item = LocationGroupModel.objects.filter(
+                    id=location_group_id
+                ).first()
+                if not location_group_item:
+                    print(f"库位组 {location_group} 不存在")
+                    return False
+                # 3. 更新库位组状态
+                location_group_item.status = 'reserved'
+                location_group_item.save()
+
+            return True
+        except Exception as e:       
+            logger.error(f"更新库位组状态失败:{str(e)}")
+            print(f"更新库位组状态失败:{str(e)}")
+            return False    
+    @transaction.atomic
     def update_location_group_status(self, location_code):
         """
         更新库位组状态
@@ -452,11 +483,10 @@ class LocationAllocation:
                 status=1
             ).first()
             if not container_detail:
-                print (f"容器 {container_code} 未组盘")
-                logger.error(f"容器 {container_code} 未组盘")
+                print (f"托盘 {container_code} 未组盘")
+                logger.error(f"托盘 {container_code} 未组盘")
                 return None
-            else:
-                print (f"容器 {container_code} 已组盘")
+        
             # 3. 更新批次状态
             batch = container_detail.batch
             batch.status = status
@@ -488,11 +518,10 @@ class LocationAllocation:
             status=1
         ).first()
         if not container_detail:
-            print (f"容器 {container_code} 未组盘")
-            logger.error(f"容器 {container_code} 未组盘")
+            print (f"托盘 {container_code} 未组盘")
+            logger.error(f"托盘 {container_code} 未组盘")
             return None
-        else:
-            print (f"容器 {container_code} 已组盘")
+
         batch_status = container_detail.batch.status
         return batch_status
     def get_batch(self,container_code):
@@ -516,11 +545,10 @@ class LocationAllocation:
             status=1
         ).first()
         if not container_detail:
-            print (f"容器 {container_code} 未组盘")
-            logger.error(f"容器 {container_code} 未组盘")
+            print (f"托盘 {container_code} 未组盘")
+            logger.error(f"托盘 {container_code} 未组盘")
             return None
-        else:
-            print (f"容器 {container_code} 已组盘")
+
         batch = container_detail.batch.bound_number
         return batch
     @transaction.atomic
@@ -536,7 +564,7 @@ class LocationAllocation:
         min_c_number_index=1000
          
         current_task = self.get_current_finish_task(container_code)
-        print(f"当前已完成任务: {current_task}")
+        print(f"[1]当前已完成任务: {current_task}")
         # 按压力排序
         sorted_pressure = sorted(
             [(0, current_task[0]), (1, current_task[1]), (2, current_task[2])],
@@ -544,16 +572,16 @@ class LocationAllocation:
         )
         # 交换第一和第二个元素的位置
         sorted_pressure[0], sorted_pressure[1] = sorted_pressure[1], sorted_pressure[0]
-        print(f"任务排序: {sorted_pressure}")
-        print(f"当前选择:{sorted_pressure[0][0]+1}")
+        print(f"[2]任务排序: {sorted_pressure}")
+        print(f"[3]当前选择:{sorted_pressure[0][0]+1}")
         location_type_dict = json.loads(self.divide_solution_by_layer(location_group_list))
-        print(f"库位类型分配方案: {location_type_dict}")
+        # print(f"库位类型分配方案: {location_type_dict}")
    
         for layer, _ in sorted_pressure:
             if not location_type_dict.get(str(layer+1)):
                 continue
-            print(f"当前层: {layer+1}")
-            print(f"当前层库位组: {location_type_dict[str(layer+1)].keys()}")
+            # print(f"当前层: {layer+1}")
+            # print(f"当前层库位组: {location_type_dict[str(layer+1)].keys()}")
             for group_id in location_type_dict[str(layer+1)].keys():
                 location_group = LocationGroupModel.objects.filter(
                     id=group_id,
@@ -569,8 +597,11 @@ class LocationAllocation:
                # 提取所有库位的 c_number
                 c_numbers = [loc.c_number for loc in location_list]
                 print(f"当前层库位组 {location_group.group_code} 可用库位: {c_numbers}")
+                # 更新任务完成数目
+                current_task[layer] = current_task[layer] + 1
+                self.update_current_finish_task(container_code,current_task)
                 return location_list[0]
-      
+    @transaction.atomic
     def get_location_type(self, container_code):
         """
         智能库位分配核心算法
@@ -594,7 +625,7 @@ class LocationAllocation:
             current_pressure = self.get_current_pressure()
 
             # 测试参数
-            total_pallets = 30
+            # total_pallets = 30
             # layer_capacity = [{'T1': 29, 'T2': 14, 'S4': 10, 'T4': 27, 'T5': 27}, {'T1': 0, 'T2': 0, 'S4': 0, 'T4': 0, 'T5': 21}, {'T1': 29, 'T2': 14, 'S4': 10, 'T4': 27, 'T5': 27}]
             # current_pressure = [1,0,0]
             print(f"[1]托盘数目: {total_pallets}")
@@ -678,7 +709,14 @@ class LocationAllocation:
                 batch_number=batch,
                 layer_pre_type =allocation_json
             )
-            solution_pressure = base_location.objects.get(id=1)
+            solution_pressure, created = base_location.objects.get_or_create(
+                id=1,
+                defaults={
+                    'layer1_pressure': 0,
+                    'layer2_pressure': 0, 
+                    'layer3_pressure': 0
+                }
+            )
             solution_pressure.layer1_pressure = allocation[1][0]
             solution_pressure.layer2_pressure = allocation[1][1]
             solution_pressure.layer3_pressure = allocation[1][2]
@@ -686,6 +724,7 @@ class LocationAllocation:
             solution.save()
             solution_pressure.save()
 
+
             return [loc.split('_')[1] for loc in allocation[0]]
 
         except Exception as e:
@@ -742,6 +781,19 @@ class LocationAllocation:
             return None
 
         return [solution.layer1_task_finish_number,solution.layer2_task_finish_number,solution.layer3_task_finish_number]
+    def update_current_finish_task(self,container,task_finish_number):
+        batch = self.get_batch(container) 
+
+        if not batch:
+            return None
+        solution = alloction_pre.objects.filter(batch_number=batch).first()
+        if not solution:
+            return None
+        solution.layer1_task_finish_number = task_finish_number[0]
+        solution.layer2_task_finish_number = task_finish_number[1]
+        solution.layer3_task_finish_number = task_finish_number[2]
+        solution.save()
+        return True
 
     @transaction.atomic
     def get_location_by_type(self, location_type_list, start_location, container_code):
@@ -761,6 +813,11 @@ class LocationAllocation:
         :return: 符合条件的库位列表
         """
         locations = []
+        # 检查已有分配方案
+        existing_solution = alloction_pre.objects.filter(batch_number=self.get_batch(container_code)).first()
+        if existing_solution.layer_solution_type:
+            print(f"[0]已有库位分配方案:{existing_solution.layer_solution_type}")
+            return existing_solution.layer_solution_type
 
         for layer, location_type_dict in location_type_list.items():
 
@@ -769,7 +826,7 @@ class LocationAllocation:
             # 获取库位类型列表
             location_type = list(location_type_dict.keys())
             demand_number = sum(location_type_dict.values())
-            print (f"层{layer} 需求数量: {demand_number}, 库位: {location_type}")                    
+            print (f"[1]层{layer} 需求数量: {demand_number}, 库位: {location_type}")                    
             location_groups = LocationGroupModel.objects.filter(
                 group_type__in=location_type,
                 layer=layer,
@@ -791,7 +848,10 @@ class LocationAllocation:
                     break
                 locations.append(f"{layer}_{location_group.id}")
                 number += 1
-         
+        
+        existing_solution.layer_solution_type = locations
+        existing_solution.save()
+        print(f"[2]分配方案: {locations}")
         return locations if locations else None
 
 
@@ -808,14 +868,15 @@ class LocationAllocation:
         # 
         if status == 1:
             # 2. 获取库位组
-            print (f"第一次入库")
-            self.get_location_type(container_code)
-            location_type_list = json.loads(alloction_pre.objects.filter(batch_number=self.get_batch(container_code)).first().layer_pre_type)
-            print(f"库组分配方案:{location_type_list}")
+            print(f"[1]第一次入库")
+
+            # 重新获取最新数据
+            self.get_location_type(container_code) 
+            
+            location_type_list = json.loads(alloction_pre.objects.filter(batch_number=self.get_batch(container_code)).first().layer_pre_type)            
             location_list = self.get_location_by_type(location_type_list,start_location,container_code)
-            print(f"库组列表:{location_list}")
             # 预定这些库组
-
+            self.update_group_status_reserved(location_list)
             location_min_value = self.get_location_list_remainder(location_list,container_code)
             print(f"库位安排到第{location_min_value.c_number}个库位:{location_min_value}")
             # if not location_list[location_min_index]:
@@ -824,13 +885,15 @@ class LocationAllocation:
             # else:
                 
             #     return location_list[location_min_index]
-            return 1
+            return location_min_value
       
         elif status == 2:
             # 3. 获取部分入库库位
             print (f"部分入库")
-            location_list = self.get_location_by_status_part(container_code,start_location)
-            print(f"库位列表:{location_list}")
+            location_list = alloction_pre.objects.filter(batch_number=self.get_batch(container_code)).first().layer_solution_type
+            location_min_value = self.get_location_list_remainder(location_list,container_code)
+            print(f"库位安排到第{location_min_value.c_number}个库位:{location_min_value}")
+            return location_min_value
 
             
   

TEMPAT SAMPAH
container/__pycache__/urls.cpython-38.pyc


TEMPAT SAMPAH
container/__pycache__/views.cpython-38.pyc


+ 1 - 1
container/urls.py

@@ -30,6 +30,6 @@ re_path(r'^task/(?P<pk>\d+)/$', views.TaskViewSet.as_view({
     'patch': 'partial_update',
 }), name="Task_1"),
 
-path(r'container_wcs/', views.ContainerWCSViewSet.as_view({"get": "get_container_wcs"}), name='ContainerWCS'),
+path(r'container_wcs/', views.ContainerWCSViewSet.as_view({"get": "get_container_wcs","put": "update_container_wcs"}), name='ContainerWCS'),
 
 ]

+ 181 - 3
container/views.py

@@ -13,7 +13,7 @@ import logging
 from rest_framework import status
 from .models import ContainerListModel,ContainerDetailModel,ContainerOperationModel,ContainerWCSModel,TaskModel
 from bound.models import BoundBatchModel,BoundDetailModel,BoundListModel
-
+from bin.views import LocationAllocation
 # from .files import FileListRenderCN, FileDetailRenderCN
 
 from .serializers import ContainerDetailGetSerializer,ContainerDetailPostSerializer
@@ -195,7 +195,6 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
             )
             serializer.is_valid(raise_exception=True)
             serializer.save()
-            # 库位分配
              
             # 检查是否已在目标位置
             if current_location == str(container_obj.target_location):
@@ -219,7 +218,58 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                         'data': current_task.to_dict()
                     }
                 else:
-                    self.generate_task(container, current_location, container_obj.target_location)
+                     # 库位分配
+                    container_code = container
+                    print(f"开始生成库位,托盘编码:{container_code}")
+                    allocator = LocationAllocation()  # 创建实例
+
+                    location_list_cnumber = allocator.get_location_by_status(container_code, current_location)  # 获取库位列表
+                    if not location_list_cnumber:
+                        print("❌ 通用库位获取失败,请检查托盘编码")
+                        return
+                    print(f"[1]库位:{location_list_cnumber}")
+                    
+                    update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'reserverd')  # 更新库位状态
+                    if not update_location_status:
+                        print("❌ 库位状态更新失败,请检查托盘编码")
+                        return
+                    print(f"[2]发送任务,库位状态更新成功!")
+                    update_location_group_status = allocator.update_location_group_status(location_list_cnumber.location_code)  # 更新库位组状态
+                    if not update_location_group_status:
+                        print("❌ 库位组状态更新失败,请检查托盘编码")
+                        return
+                    print(f"[3]库位组状态更新成功!")
+
+                    update_batch_status = allocator.update_batch_status(container_code, '2')  # 更新批次状态
+                    if not update_batch_status:
+                        print("❌ 批次状态更新失败,请检查批次号")
+                        return
+                    print(f"[4]批次状态更新成功!")
+
+                    update_location_group_batch = allocator.update_location_group_batch(location_list_cnumber, container_code)  # 更新库位组的批次
+                    if not update_location_group_batch:
+                        print("❌ 库位组批次更新失败,请检查托盘编码")
+                        return
+                    print(f"[5]库位组批次更新成功!")
+                    
+                    # update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'occupied')  # 更新库位状态
+                    # if not update_location_status:
+                    #     print("❌ 库位状态更新失败,请检查托盘编码")
+                    #     return
+                    # print(f"[6]WCS到位,库位状态更新成功!")
+
+                    # update_location_container_link = allocator.update_location_container_link(location_list_cnumber.location_code, container_code)  # 更新库位和托盘的关联关系
+                    # if not update_location_container_link:
+                    #     print("❌ 库位和托盘的关联关系更新失败,请检查托盘编码")
+                    #     return
+                    # print(f"[7]库位和托盘的关联关系更新成功!")
+                    allocation_target_location = (
+                            location_list_cnumber.warehouse_code + '-' 
+                            + f"{int(location_list_cnumber.row):02d}" + '-'  # 关键修改点
+                            + f"{int(location_list_cnumber.col):02d}" + '-' 
+                            + f"{int(location_list_cnumber.layer):02d}" 
+                        )
+                    self.generate_task(container, current_location, allocation_target_location)  # 生成任务
                     current_task = ContainerWCSModel.objects.get(
                         container=container, 
                         tasktype='inbound'
@@ -230,6 +280,8 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                         'message': '任务下发成功',
                         'data': current_task.to_dict()
                     }
+                    container_obj.target_location = allocation_target_location
+                    container_obj.save()
                     self.inport_update_task(current_task.id, container_obj.id)
 
 
@@ -273,6 +325,132 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
         data_tosave['tasknumber'] = f"{data_tosave['month']}{new_id}"
         ContainerWCSModel.objects.create(**data_tosave)
 
+    def update_container_wcs(self, request, *args, **kwargs):
+        data = self.request.data
+        container = data.get('container_number')
+        current_location = data.get('current_location')
+        data_return = {}
+
+        try:
+            container_obj = ContainerListModel.objects.filter(container_code=container).first()
+            if not container_obj:
+                data_return = {
+                    'code': '400',
+                    'message': '托盘编码不存在',
+                    'data': data
+                }
+                return Response(data_return, status=status.HTTP_400_BAD_REQUEST)
+
+            # 更新容器数据(部分更新)
+            serializer = ContainerListPostSerializer(
+                container_obj, 
+                data=data, 
+                partial=True  # 允许部分字段更新
+            )
+            serializer.is_valid(raise_exception=True)
+            serializer.save()
+             
+            # 检查是否已在目标位置
+            if current_location == str(container_obj.target_location):
+                logger.info(f"托盘 {container} 已在目标位置")
+                data_return = {
+                    'code': '200',
+                    'message': '当前位置已是目标位置',
+                    'data': data
+                }
+            else:
+                current_task = ContainerWCSModel.objects.filter(
+                    container=container, 
+                    tasktype='inbound'
+                ).first()
+
+                if current_task:
+                    
+                    data_return = {
+                        'code': '200',
+                        'message': '任务已存在,重新下发',
+                        'data': current_task.to_dict()
+                    }
+                else:
+                    # 库位分配
+                    container_code = container
+                    print(f"开始生成库位,托盘编码:{container_code}")
+                    allocator = LocationAllocation()  # 创建实例
+
+                    location_list_cnumber = allocator.get_location_by_status(container_code, current_location)  # 获取库位列表
+                    if not location_list_cnumber:
+                        print("❌ 通用库位获取失败,请检查托盘编码")
+                        return
+                    print(f"[1]库位:{location_list_cnumber}")
+                    
+                    update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'reserverd')  # 更新库位状态
+                    if not update_location_status:
+                        print("❌ 库位状态更新失败,请检查托盘编码")
+                        return
+                    print(f"[2]发送任务,库位状态更新成功!")
+                    update_location_group_status = allocator.update_location_group_status(location_list_cnumber.location_code)  # 更新库位组状态
+                    if not update_location_group_status:
+                        print("❌ 库位组状态更新失败,请检查托盘编码")
+                        return
+                    print(f"[3]库位组状态更新成功!")
+
+                    update_batch_status = allocator.update_batch_status(container_code, '2')  # 更新批次状态
+                    if not update_batch_status:
+                        print("❌ 批次状态更新失败,请检查批次号")
+                        return
+                    print(f"[4]批次状态更新成功!")
+
+                    update_location_group_batch = allocator.update_location_group_batch(location_list_cnumber, container_code)  # 更新库位组的批次
+                    if not update_location_group_batch:
+                        print("❌ 库位组批次更新失败,请检查托盘编码")
+                        return
+                    print(f"[5]库位组批次更新成功!")
+                    
+                    # update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'occupied')  # 更新库位状态
+                    # if not update_location_status:
+                    #     print("❌ 库位状态更新失败,请检查托盘编码")  
+                    #     return
+                    # print(f"[6]WCS到位,库位状态更新成功!")
+
+                    # update_location_container_link = allocator.update_location_container_link(location_list_cnumber.location_code, container_code)  # 更新库位和托盘的关联关系
+                    # if not update_location_container_link:
+                    #     print("❌ 库位和托盘的关联关系更新失败,请检查托盘编码")
+                    #     return
+                    # print(f"[7]库位和托盘的关联关系更新成功!")
+                    allocation_target_location = (
+                            location_list_cnumber.warehouse_code + '-' 
+                            + f"{int(location_list_cnumber.row):02d}" + '-'  # 关键修改点
+                            + f"{int(location_list_cnumber.col):02d}" + '-' 
+                            + f"{int(location_list_cnumber.layer):02d}" 
+                        )
+                    self.generate_task(container, current_location, allocation_target_location)  # 生成任务
+                    current_task = ContainerWCSModel.objects.get(
+                        container=container, 
+                        tasktype='inbound'
+                    )
+                  
+                    data_return = {
+                        'code': '200',
+                        'message': '任务下发成功',
+                        'data': current_task.to_dict()
+                    }
+                    container_obj.target_location = allocation_target_location
+                    container_obj.save()
+      
+
+                    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
+            return Response(data_return, status=http_status)
+
+        except Exception as e:
+            logger.error(f"处理请求时发生错误: {str(e)}", exc_info=True)
+            return Response(
+                {'code': '500', 'message': '服务器内部错误', 'data': None},
+                status=status.HTTP_500_INTERNAL_SERVER_ERROR
+            )
+
     @transaction.atomic
     def inport_update_task(self, wcs_id,container_id):
         try:

+ 45 - 60
data_base/inbound_task.py

@@ -23,75 +23,60 @@ def setup_django():
     django.setup()
 
 def main():
-    try:
+   
 
         from bin.views import LocationAllocation
-        container_code = "12347"
-        print(f"开始生成库位,托盘编码:{container_code}")
-        allocator = LocationAllocation()  # 创建实例
-        location_list_cnumber = allocator.get_location_by_status(container_code, 'in1', 1)  # 获取库位列表
-        if not location_list_cnumber:
-            print("❌ 通用库位获取失败,请检查托盘编码")
-            return
-        print(f"[1]库位:{location_list_cnumber}")
-        
-        update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'reserverd')  # 更新库位状态
-        if not update_location_status:
-            print("❌ 库位状态更新失败,请检查托盘编码")
-            return
-        print(f"[2]发送任务,库位状态更新成功!")
-        update_location_group_status = allocator.update_location_group_status(location_list_cnumber.location_code)  # 更新库位组状态
-        if not update_location_group_status:
-            print("❌ 库位组状态更新失败,请检查托盘编码")
-            return
-        print(f"[3]库位组状态更新成功!")
+        # code =["12346", "12345", "1", "2", "7"]
+        code =["12346", "12347"]
+        for container_code in code:
+            # container_code = "12346"
+            print(f"开始生成库位,托盘编码:{container_code}")
+            allocator = LocationAllocation()  # 创建实例
 
-        update_batch_status = allocator.update_batch_status(container_code, '2')  # 更新批次状态
-        if not update_batch_status:
-            print("❌ 批次状态更新失败,请检查批次号")
-            return
-        print(f"[4]批次状态更新成功!")
+            location_list_cnumber = allocator.get_location_by_status(container_code, 'in1')  # 获取库位列表
+            if not location_list_cnumber:
+                print("❌ 通用库位获取失败,请检查托盘编码")
+                return
+            print(f"[1]库位:{location_list_cnumber}")
+            
+            update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'reserverd')  # 更新库位状态
+            if not update_location_status:
+                print("❌ 库位状态更新失败,请检查托盘编码")
+                return
+            print(f"[2]发送任务,库位状态更新成功!")
+            update_location_group_status = allocator.update_location_group_status(location_list_cnumber.location_code)  # 更新库位组状态
+            if not update_location_group_status:
+                print("❌ 库位组状态更新失败,请检查托盘编码")
+                return
+            print(f"[3]库位组状态更新成功!")
 
-        update_location_group_batch = allocator.update_location_group_batch(location_list_cnumber, container_code)  # 更新库位组的批次
-        if not update_location_group_batch:
-            print("❌ 库位组批次更新失败,请检查托盘编码")
-            return
-        print(f"[5]库位组批次更新成功!")
-        
-        update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'occupied')  # 更新库位状态
-        if not update_location_status:
-            print("❌ 库位状态更新失败,请检查托盘编码")
-            return
-        print(f"[6]WCS到位,库位状态更新成功!")
+            update_batch_status = allocator.update_batch_status(container_code, '2')  # 更新批次状态
+            if not update_batch_status:
+                print("❌ 批次状态更新失败,请检查批次号")
+                return
+            print(f"[4]批次状态更新成功!")
 
-        update_location_container_link = allocator.update_location_container_link(location_list_cnumber.location_code, container_code)  # 更新库位和托盘的关联关系
-        if not update_location_container_link:
-            print("❌ 库位和托盘的关联关系更新失败,请检查托盘编码")
-            return
-        print(f"[7]库位和托盘的关联关系更新成功!")
+            update_location_group_batch = allocator.update_location_group_batch(location_list_cnumber, container_code)  # 更新库位组的批次
+            if not update_location_group_batch:
+                print("❌ 库位组批次更新失败,请检查托盘编码")
+                return
+            print(f"[5]库位组批次更新成功!")
+            
+            update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'occupied')  # 更新库位状态
+            if not update_location_status:
+                print("❌ 库位状态更新失败,请检查托盘编码")
+                return
+            print(f"[6]WCS到位,库位状态更新成功!")
 
+            update_location_container_link = allocator.update_location_container_link(location_list_cnumber.location_code, container_code)  # 更新库位和托盘的关联关系
+            if not update_location_container_link:
+                print("❌ 库位和托盘的关联关系更新失败,请检查托盘编码")
+                return
+            print(f"[7]库位和托盘的关联关系更新成功!")
 
-
- 
-
-        
-        # location_list = allocator.get_location_by_type(location_type, 'in2', 1)  # 获取库位列表
-        # if not location_list:
-        #     print("❌ 第一次库位获取失败,请检查库位类型")
-        #     return
-        # print(f"库位列表:{location_list}")
-        # location_list_cnumber = allocator.get_location_by_type_remainder(batch, 1)  # 获取库位列表
-        # if not location_list_cnumber:
-        #     print("❌ 剩余库位获取失败,请检查托盘编码")
-        #     return
-        # print(f"库位列表:{location_list_cnumber}")
         print("✅ 方法生成成功!")
 
-        
-    except Exception as e:
-        print(f"❌ 生成失败:{str(e)}")
-        import traceback
-        traceback.print_exc()
+
 
 if __name__ == "__main__":
     setup_django()

+ 7 - 6
data_base/test_allocation.py

@@ -28,16 +28,17 @@ def main():
         from bin.views import LocationAllocation
         
         # container_code =["12346", "12345", "1", "2", "7"]
-        container_code =["1"]
+        container_code =["12345"]
         allocator = LocationAllocation()  # 创建实例
 
         for code in container_code:  # Iterate through each container code
             print(f"开始生成库位,托盘编码:{code}")
-            location_type = allocator.get_location_by_status(code,'in1')  # 获取库位类型
-            if not location_type:
-                print("❌ 库位类型获取失败,请检查托盘数量")
-                return
-            print(f"库位类型:{location_type}")
+            allocator.get_location_type(code) 
+            # location_type = allocator.get_location_by_status(code,'in2')  # 获取库位类型
+            # if not location_type:
+            #     print("❌ 库位类型获取失败,请检查托盘数量")
+            #     return
+            # print(f"库位类型:{location_type}")
       
         
         # # 调用生成方法

TEMPAT SAMPAH
db.sqlite3


+ 2 - 0
logs/error.log

@@ -2424,3 +2424,5 @@ Traceback (most recent call last):
   File "D:\Document\code\vue\greater_wms\.\bin\views.py", line 325, in update
     handle_group_location_status(location_code,location_obj.location_group)
 NameError: name 'handle_group_location_status' is not defined
+[2025-04-21 00:14:27,894][django.request.log_response():241] [ERROR] Internal Server Error: /container/container_wcs/
+[2025-04-21 00:17:12,911][django.request.log_response():241] [ERROR] Internal Server Error: /container/container_wcs/

+ 8 - 0
logs/server.log

@@ -2685,3 +2685,11 @@ NameError: name 'handle_group_location_status' is not defined
 [2025-04-17 22:52:05,658][django.request.log_response():241] [WARNING] Not Found: /cyclecount/qtyrecorviewset/
 [2025-04-17 22:55:58,827][django.request.log_response():241] [WARNING] Not Found: /stock/list/
 [2025-04-17 22:56:10,122][django.request.log_response():241] [WARNING] Not Found: /cyclecount/manualcyclecount/
+[2025-04-21 00:14:27,894][django.request.log_response():241] [ERROR] Internal Server Error: /container/container_wcs/
+[2025-04-21 00:17:12,911][django.request.log_response():241] [ERROR] Internal Server Error: /container/container_wcs/
+[2025-04-21 00:38:32,564][django.request.log_response():241] [WARNING] Not Found: /container/
+[2025-04-21 00:43:16,704][django.request.log_response():241] [WARNING] Not Found: /dn/list/
+[2025-04-21 00:43:20,170][django.request.log_response():241] [WARNING] Not Found: /cyclecount/qtyrecorviewset/
+[2025-04-21 00:51:04,528][django.request.log_response():241] [WARNING] Not Found: /stock/list/
+[2025-04-21 00:51:16,174][django.request.log_response():241] [WARNING] Not Found: /cyclecount/qtyrecorviewset/
+[2025-04-21 00:51:59,952][django.request.log_response():241] [WARNING] Not Found: /cyclecount/qtyrecorviewset/