ソースを参照

决策支持优化

15168162575 11 ヶ月 前
コミット
f0d318aed0
1 ファイル変更27 行追加16 行削除
  1. 27 16
      application/api/controller/Decision.php

+ 27 - 16
application/api/controller/Decision.php

@@ -131,21 +131,24 @@ class Decision extends Api
 //    }
     public function MachineProduction()
     {
+        // 验证请求方式
         if ($this->request->isGet() === false) {
             $this->error('请求错误');
         }
 
+        // 获取请求参数
         $param = $this->request->param();
         if (empty($param['mouth'])) {
             $this->error('参数错误');
         }
 
+        // 初始化查询条件
         $where = [];
         if (!empty($param['sist'])) {
-            $where['设备编组'] = $param['sist'];
+            $where['a.设备编组'] = $param['sist'];
         }
 
-        // 将参数转换成标准日期格式
+        // 转换日期格式
         $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
 
         // 使用单个查询获取所有需要的数据
@@ -158,20 +161,20 @@ class Decision extends Api
                 'a.sczl_jtbh',
                 'a.sczl_bzdh',
                 'DATE_FORMAT(a.sczl_rq, "%Y-%m-%d") as day',
-                'SUM(a.sczl_cl) as total_cl',
-                'c.yj_yjmc as 印件名称',
-                'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")") as 工序名称',
-                'RTRIM(d.印刷方式) as 印刷方式',
-                'RTRIM(d.版距) as 版距'
+                'SUM(a.sczl_cl) AS total_cl',
+                'c.yj_yjmc AS 印件名称',
+                'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")") AS 工序名称',
+                'RTRIM(d.印刷方式) AS 印刷方式',
+                'RTRIM(d.版距) AS 版距'
             ])
             ->where('a.sczl_rq', 'like', $mouth . '%')
             ->where('b.sys_sbID', '<>', '')
             ->where($where)
-            ->group('a.sczl_bzdh, day, a.sczl_jtbh, c.yj_yjmc, d.Gy0_gxmc')
+            ->group('a.sczl_jtbh, a.sczl_bzdh, day, c.yj_yjmc, d.Gy0_gxmc')
             ->order('a.sczl_jtbh, a.sczl_bzdh, day')
             ->select();
 
-        // 处理数据
+        // 数据处理
         $data = [];
         // 获取唯一日期并排序
         $data['head'] = array_unique(array_column($results, 'day'));
@@ -181,6 +184,7 @@ class Decision extends Api
             return strtotime($a) - strtotime($b);
         });
 
+        // 准备按设备和班组整理的数据
         $total_by_machine = [];
 
         foreach ($results as $item) {
@@ -189,11 +193,14 @@ class Decision extends Api
             $day = $item['day'];
             $printed_type = $item['印刷方式'];
 
+            // 初始化设备和班组
             if (!isset($total_by_machine[$machine_id])) {
                 $total_by_machine[$machine_id] = [];
             }
             if (!isset($total_by_machine[$machine_id][$group_id])) {
                 $total_by_machine[$machine_id][$group_id] = [
+                    '机台编号' => $machine_id,
+                    '班组编号' => $group_id,
                     '印件名称' => $item['印件名称'],
                     '工序名称' => $item['工序名称'],
                     'total_cl' => 0,
@@ -201,19 +208,18 @@ class Decision extends Api
                 ];
             }
 
-            // 更新数量
+            // 更新累计数量
             if ($printed_type === '卷对卷') {
                 $total_by_machine[$machine_id][$group_id]['total_cl'] += round($item['total_cl'] / $item['版距'] * 1000);
             } else {
                 $total_by_machine[$machine_id][$group_id]['total_cl'] += $item['total_cl'];
             }
 
-            // 按天汇总
+            // 更新每日总计
             if (!isset($total_by_machine[$machine_id][$group_id]['day_total'][$day])) {
                 $total_by_machine[$machine_id][$group_id]['day_total'][$day] = 0;
             }
 
-            // 日总数
             if ($printed_type === '卷对卷') {
                 $total_by_machine[$machine_id][$group_id]['day_total'][$day] += round($item['total_cl'] / $item['版距'] * 1000);
             } else {
@@ -222,9 +228,13 @@ class Decision extends Api
         }
 
         // 格式化输出数据
-        $data['total'] = array_values(array_map(function ($machine) {
-            return array_values($machine);
-        }, $total_by_machine));
+        $data['total'] = [];
+
+        foreach ($total_by_machine as $machine_group) {
+            foreach ($machine_group as $group_data) {
+                $data['total'][] = $group_data;
+            }
+        }
 
         $this->success('成功', $data);
     }
@@ -405,7 +415,7 @@ class Decision extends Api
             ->alias('a')
             ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
             ->join('工单_印件资料 c', 'b.sczl_gdbh = c.Yj_Gdbh AND b.sczl_yjno = c.yj_Yjno')
-            ->join('工单_工艺资料 d', 'b.sczl_gdbh = d.Gy0_gdbh AND b.sczl_yjno = d.GY0_yjno AND b.sczl_gxh = d.Gy0_gxh')
+            ->join('工单_工艺资料 d', 'b.sczl_gdbh = d.Gy0_gdbh AND b.sczl_yjno = d.Gy0_yjno AND b.sczl_gxh = d.Gy0_gxh')
             ->field([
                 'a.设备编号' => '设备编号',
                 'rtrim(a.设备名称)' => '设备名称',
@@ -425,6 +435,7 @@ class Decision extends Api
             ->group('a.设备编号')
             ->order('a.设备编号')
             ->select();
+
         // 处理总工时的计算
         $total = [
             '设备运行工时' => 0,