flower_bs 1 giorno fa
parent
commit
d140bd23ec
5 ha cambiato i file con 40 aggiunte e 40 eliminazioni
  1. 4 4
      bin/services.py
  2. 18 20
      bin/updates.py
  3. 7 7
      bin/views.py
  4. 3 1
      container/container_operate.py
  5. 8 8
      container/views.py

+ 4 - 4
bin/services.py

@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
 
 class AllocationService:
     @classmethod
-    @transaction.atomic
+    
     def allocate(cls, container_code, start_point):
         # logger.info(f"请求托盘:{container_code},请求位置:{start_point}")
 
@@ -34,7 +34,7 @@ class AllocationService:
         #     raise ValueError("非法的批次状态")
 
     @classmethod
-    @transaction.atomic
+    
     def _first_allocation(cls, container_code, batch_info, start_point):
         total , scatter_total = LocationQueries.get_pallet_count_by_batch(container_code)
         current_total = LocationQueries.get_pallet_count(container_code)
@@ -253,7 +253,7 @@ class AllocationService:
         else:
             return cls._execute_allocation(locations, start_point,container_code,batch_info)
 
-    @transaction.atomic
+    
     def get_location_list_remainder(location_group_list,container_code,batch_info):
         """
         获取可用库位的c_number列表
@@ -302,7 +302,7 @@ class AllocationService:
                 LocationUpdates.update_current_finish_task(container_code,current_task)
                 return location_list[0]
             
-    @transaction.atomic
+    
     def get_location_group_remainder(location_group_code):
         """
         获取可用库位的c_number列表

+ 18 - 20
bin/updates.py

@@ -14,7 +14,7 @@ class LocationUpdates:
         save_allocation_plan(batch_number, solution, pressure): 保存分配方案
     """
 
-    @transaction.atomic
+
     def link_container(location_code, container_code):
         try:
             location = LocationModel.objects.select_for_update().get(
@@ -32,7 +32,7 @@ class LocationUpdates:
         except Exception as e:
             raise RuntimeError(f"关联更新失败: {str(e)}")
         
-    @transaction.atomic
+
     def disable_link_container(location_code, container_code):
         try:
             location = LocationModel.objects.select_for_update().get(
@@ -53,7 +53,7 @@ class LocationUpdates:
             logger.error(f"关联更新失败:{str(e)}")
             return False
 
-    @transaction.atomic
+
     def update_batch_status(container_code, status):
         try:
             container = ContainerListModel.objects.get(
@@ -74,22 +74,22 @@ class LocationUpdates:
         except Exception as e:
             raise RuntimeError(f"批次状态更新失败: {str(e)}")
 
-    @transaction.atomic
+
     def save_allocation_plan(batch_number, solution, pressure):
-        with transaction.atomic():
-            base_location.objects.update_or_create(
-                id=1,
-                defaults={
-                    'layer1_pressure': pressure[0],
-                    'layer2_pressure': pressure[1],
-                    'layer3_pressure': pressure[2]
-                }
-            )
-            
-            alloction_pre.objects.update_or_create(
-                batch_number=batch_number,
-                defaults={'layer_pre_type': solution}
-            )
+   
+        base_location.objects.update_or_create(
+            id=1,
+            defaults={
+                'layer1_pressure': pressure[0],
+                'layer2_pressure': pressure[1],
+                'layer3_pressure': pressure[2]
+            }
+        )
+        
+        alloction_pre.objects.update_or_create(
+            batch_number=batch_number,
+            defaults={'layer_pre_type': solution}
+        )
 
     @staticmethod
     def update_pallet_count(batch_container_count,bound_number):
@@ -154,7 +154,6 @@ class LocationUpdates:
         return True
     
     @staticmethod
-    @transaction.atomic
     def update_location_group_status(location_code):
         """
         更新库位组状态
@@ -203,7 +202,6 @@ class LocationUpdates:
             print(f"更新库位组状态失败:{str(e)}")
 
     @staticmethod
-    @transaction.atomic
     def update_location_group_batch(location,bound_number):
         """
         :param location: 库位对象

+ 7 - 7
bin/views.py

@@ -320,7 +320,7 @@ class LocationAllocation:
     # fun:get_location_by_type: 第一次入库,根据库位类型获取库位
     # fun:get_location_by_status: 根据库位状态获取库位
 
-    @transaction.atomic
+    
     def get_pallet_count_by_batch(self, container_code):
         """
         根据托盘码查询批次下托盘总数
@@ -402,7 +402,7 @@ class LocationAllocation:
             print(f"获取库位组剩余数量失败:{str(e)}")
             return None
 
-    @transaction.atomic
+    
     def update_location_container_link(self,location_code,container_code):
         """
         更新库位和托盘的关联关系
@@ -543,7 +543,7 @@ class LocationAllocation:
             logger.error(f"更新库位组状态失败:{str(e)}")
             print(f"更新库位组状态失败:{str(e)}")
             return False    
-    @transaction.atomic
+    
     def update_location_group_status(self, location_code):
         """
         更新库位组状态
@@ -718,7 +718,7 @@ class LocationAllocation:
 
         batch = container_detail.batch.bound_number
         return batch
-    @transaction.atomic
+    
     def get_location_list_remainder(self, location_group_list,container_code):
         """
         获取可用库位的c_number列表
@@ -768,7 +768,7 @@ class LocationAllocation:
                 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):
         """
         智能库位分配核心算法
@@ -963,7 +963,7 @@ class LocationAllocation:
         solution.save()
         return True
 
-    @transaction.atomic
+    
     def get_location_by_type(self, location_type_list, start_location, container_code):
         """
         根据库位类型获取库位,先根据工作压力找出最空闲的层,看下这层有没有工作,如果有,就从里面找,如果没有,则跳过该层,继续找下一层
@@ -1023,7 +1023,7 @@ class LocationAllocation:
         return locations if locations else None
 
 
-    @transaction.atomic
+    
     def get_location_by_status(self,container_code,start_location):
         """
         根据库位状态获取库位

+ 3 - 1
container/container_operate.py

@@ -14,7 +14,7 @@ class ContainerService:
 
     """
     @staticmethod
-    @transaction.atomic
+    
     def create_container_operation(data, logger):
      
         # 初始化基础数据
@@ -137,6 +137,8 @@ class BatchStatusUpdater:
     def update_status(bound_obj, added_qty, logger):
         """批次状态管理"""
         last_qty = bound_obj.goods_in_qty
+        from decimal import Decimal
+        added_qty = Decimal(added_qty)
         bound_obj.goods_in_qty += added_qty
         
         if bound_obj.goods_in_qty >= bound_obj.goods_qty:

+ 8 - 8
container/views.py

@@ -379,7 +379,7 @@ class TaskViewSet(viewsets.ModelViewSet):
 
 # 任务回滚
 class TaskRollbackMixin:
-    @transaction.atomic
+    
     def rollback_task(self, request, task_id, *args, **kwargs):
         """
         撤销入库任务并回滚相关状态
@@ -650,7 +650,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                 status=status.HTTP_500_INTERNAL_SERVER_ERROR
             )
 
-    @transaction.atomic
+    
     # def generate_container_operate(self, container_obj, bound_number,allocation_target_location):
     def generate_container_operate(self, container_obj, allocation_target_location):
  
@@ -698,7 +698,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                 memo=f"WCS入库: 批次: {batch_obj.bound_number}, 数量: {goods_qty}"  # 使用实际容器中的数量
             )
         
-    @transaction.atomic
+    
     def generate_move_container_operate(self, container_obj, allocation_target_location):
      
         # 获取容器中所有有效的批次明细
@@ -747,7 +747,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
                 memo=f"托盘移动: 批次: {batch_obj.bound_number}, 数量: {goods_qty}"
             )
 
-    @transaction.atomic
+    
     def generate_move_container_operate_no_batch(self, container_obj, bound_number,allocation_target_location):
         ContainerOperationModel.objects.create(
             month = int(timezone.now().strftime("%Y%m")),
@@ -763,7 +763,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
             memo=f"托盘组移库:从{container_obj.current_location}移库到{allocation_target_location}"
 
         )
-    @transaction.atomic
+    
     def generate_container_operate_no_batch(self, container_obj, bound_number,allocation_target_location):
        
         ContainerOperationModel.objects.create(
@@ -780,7 +780,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
             memo=f"WCS入库: 批次: {bound_number}, 数量: 1"
 
         )
-    @transaction.atomic
+    
     def generate_task(self, container, current_location, target_location,batch_id,location_c_number):
         batch = BoundBatchModel.objects.filter(bound_number=batch_id).first()
         batch_detail = BoundDetailModel.objects.filter(bound_batch=batch).first()
@@ -1087,7 +1087,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
         self.inport_update_task(task.id, container_code)
         return task
 
-    @transaction.atomic
+    
     def inport_update_task(self, wcs_id,container_id):
         try:
             task_obj = ContainerWCSModel.objects.filter(id=wcs_id).first()
@@ -2252,7 +2252,7 @@ class OutTaskViewSet(ViewSet):
             2: 2   # 空盘最低
         }.get(goods_class, 99)
 
-    @transaction.atomic
+    
     def _update_allocation_status(self, allocate_container, allocate_qty,bound_list_id):
         """事务化更新分配状态"""
         try: