liuhairui 1 anno fa
parent
commit
295c179c28
1 ha cambiato i file con 35 aggiunte e 12 eliminazioni
  1. 35 12
      application/api/controller/Manufacture.php

+ 35 - 12
application/api/controller/Manufacture.php

@@ -989,27 +989,50 @@ class Manufacture extends Api
 
         // 按生产工序排序
         foreach ($formattedData as $yearMonth => &$processData) {
-            // 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
+            // 1. 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
             $sortedProcessData = array_fill_keys($processList, []);
 
-            // 合并原有数据
-            foreach ($processData as $process => $machines) {
-                $sortedProcessData[$process] = $machines;
-            }
-
-            // 更新排序后的数据
-            $processData = $sortedProcessData;
+            // 将原有数据合并到排序后的结构中
+            $processData = array_merge($sortedProcessData, $processData);
 
-            // 对每组内的设备日期倒序排列
+            // 2. 对每个工序下的设备组进行日期倒序排序
             foreach ($processData as $process => &$machines) {
-                foreach ($machines as $machineKey => &$dates) {
-                    rsort($dates); // 每台设备的日期倒序排序
+                if (is_array($machines)) { // 确保 $machines 是数组
+                    foreach ($machines as $machineKey => &$dates) {
+                        if (is_array($dates) && !empty($dates)) { // 确保 $dates 存在并且是非空数组
+                            rsort($dates); // 每台设备的日期倒序排序
+                        }
+                    }
                 }
             }
         }
 
-        // 返回成功结果
         $this->success('成功', $formattedData);
+
+//        // 按生产工序排序
+//        foreach ($formattedData as $yearMonth => &$processData) {
+//            // 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
+//            $sortedProcessData = array_fill_keys($processList, []);
+//
+//            // 合并原有数据
+//            foreach ($processData as $process => $machines) {
+//                $sortedProcessData[$process] = $machines;
+//            }
+//
+//            // 更新排序后的数据
+//            $processData = $sortedProcessData;
+//
+//            // 对每组内的设备日期倒序排列
+//            foreach ($processData as $process => &$machines) {
+//                foreach ($machines as $machineKey => &$dates) {
+//                    rsort($dates); // 每台设备的日期倒序排序
+//                }
+//            }
+//
+//        }
+//
+//        // 返回成功结果
+//        $this->success('成功', $formattedData);
     }