unknown 6 месяцев назад
Родитель
Сommit
f0583cd72b
1 измененных файлов с 151 добавлено и 3 удалено
  1. 151 3
      application/api/controller/Decision.php

+ 151 - 3
application/api/controller/Decision.php

@@ -8,7 +8,7 @@ use think\Db;
 use think\Request;
 
 /**
- * 设备运行跟踪
+ * 决策支持
  */
 
 class Decision extends Api
@@ -610,7 +610,6 @@ class Decision extends Api
             $output = floatval($item['产量']);
             $waste = floatval($item['制程废品']) + floatval($item['质检废品']);
             $rate = $output > 0 ? (1 - $waste / $output) * 100 : 0;
-
             $result[$processKey][$monthKey] = sprintf('%.2f%%', $rate);
 
             if (!isset($annual[$processKey])) {
@@ -619,7 +618,6 @@ class Decision extends Api
             $annual[$processKey]['sum'] += $rate;
             $annual[$processKey]['count']++;
         }
-
         // 5. 补充“平均值”
         foreach ($annual as $processKey => $v) {
             if ($v['count'] > 0) {
@@ -845,4 +843,154 @@ class Decision extends Api
         }
         $this->success('成功', array_values($grouped));
     }
+
+
+    /**
+     * 年度质检废品率统计左侧菜单
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function QualityInspectionGetTab()
+    {
+        if (!$this->request->isGet()) {
+            $this->error('请求错误');
+        }
+        $monthStats = \db('db_qczl')
+            ->group('month')
+            ->order('month desc')
+            ->column("DATE_FORMAT(qczl_rq, '%Y%m') AS month");
+
+        // 按年月层次结构归类(返回树形结构)
+        $treeData = \db('db_qczl')
+            ->field([
+                "DATE_FORMAT(qczl_rq, '%Y') AS year",
+                "DATE_FORMAT(qczl_rq, '%m') AS month",
+                "COUNT(*) AS total"
+            ])
+            ->order('year desc,month desc')
+            ->group('year, month')
+            ->select();
+        // 构建树形结构
+        $result = [];
+        foreach ($treeData as $item) {
+            $year = $item['year'];
+            $month = $year . $item['month'];
+
+            if (!isset($result[$year])) {
+                $result[$year] = [
+                    'year' => $year,
+                    'children' => []
+                ];
+            }
+
+            $result[$year]['children'][] = [
+                'month' => $month,
+                'total' => $item['total']
+            ];
+        }
+
+        $this->success('成功', $result);
+    }
+
+
+    //年度质检废品统计右侧上方列表
+
+    /**
+     * @return array
+     */
+    public function QualityInspectionList()
+    {
+        if (!$this->request->isGet()) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        $mouth = date_create_from_format('Ym', $param['month'])->format('Y-m');
+        $where = ['qczl_rq' => ['like', $mouth . '%']];
+        $list = \db('db_qczl')
+            ->alias('a')
+            ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh and a.qczl_yjno = b.行号','LEFT')
+            ->field([
+                'a.qczl_gdbh',
+                'a.qczl_yjno',
+                'a.qczl_fp',
+                'a.fp_lb1',
+                'a.fp_lb2',
+                'a.fp_lb3',
+                'a.fp_lb4',
+                'a.fp_lb5',
+                'a.fp_lb6',
+                'a.fp_lb7',
+                'a.fp_lb8',
+                'a.fp_lb9',
+                'a.fp_lb10',
+                'a.fp_lb11',
+                'a.fp_lb12',
+                'a.fp_lb13',
+                'a.fp_sl1',
+                'a.fp_sl2',
+                'a.fp_sl3',
+                'a.fp_sl4',
+                'a.fp_sl5',
+                'a.fp_sl6',
+                'a.fp_sl7',
+                'a.fp_sl8',
+                'a.fp_sl9',
+                'a.fp_sl10',
+                'a.fp_sl11',
+                'a.fp_sl12',
+                'a.fp_sl13',
+            ])
+            ->where($where)
+            ->select();
+        $data = Db::name('db_qczl')
+            ->alias('a')
+            ->join('工单_基本资料 b', 'a.qczl_gdbh = b.Gd_gdbh AND a.qczl_yjno = b.行号', 'LEFT')
+            ->field([
+                'b.实际投料*10000 as 实际投料', 'CONCAT(a.qczl_gdbh,"-",a.qczl_yjno) as 工单'
+            ])
+            ->where($where)
+            ->group('a.qczl_gdbh, a.qczl_yjno')
+            ->select();
+        $workOrder = [];
+        foreach ($data as $item) {
+            $workOrder[$item['工单']] = $item['实际投料'];
+        }
+        // 用于存储废品类别和对应废品数量的数组
+        $categories = array();
+        // 循环遍历原始数组
+        foreach ($list as $item) {
+            $str = $item['qczl_gdbh'].'-'.$item['qczl_yjno'];
+            // 提取废品类别和对应废品数量
+            foreach ($item as $key => $value) {
+                if (strpos($key, "fp_lb") === 0) {
+                    $categoryKey = $key;
+                    $quantityKey = str_replace("fp_lb", "fp_sl", $key);
+                    $quantityValue = $item[$quantityKey];
+
+                    if (!isset($categories[$value]['number1'])) {
+                        $categories[$value]['number1'] = 0;
+                        $categories[$value]['number2'] = 0;
+                    }
+
+                    $categories[$value]['number1'] += (int)$quantityValue;
+                    $categories[$value]['number2'] += (int)$workOrder[$str];
+                }
+            }
+        }
+        ksort($categories);
+        $result = [];
+        foreach ($categories as $category => $value) {
+            if ($category !== '') {
+                $result[] = [
+                    '类别' => $category,
+                    '实际投料' => $value['number2'],
+                    '废品数量' => $value['number1'],
+                    '质检废品率' => (round($value['number1']/$value['number2'], 7)*100).'%'
+                ];
+            }
+        }
+        $this->success('成功', $result);
+    }
 }