فهرست منبع

产品工艺复制和产品工艺排序优化

unknown 10 ماه پیش
والد
کامیت
25f5b54755
2فایلهای تغییر یافته به همراه255 افزوده شده و 11 حذف شده
  1. 244 4
      application/api/controller/MachineList.php
  2. 11 7
      application/api/controller/Product.php

+ 244 - 4
application/api/controller/MachineList.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 
 use think\Request;
 use app\common\controller\Api;
+use think\response\Json;
 
 /**
  * 设备维修保养记录
@@ -141,15 +142,254 @@ class MachineList extends Api
         return $data;
     }
 
-    //年度维修记录上方列表
-    public function MachineList()
+    /**
+     * 年度维修记录上方列表
+     * @return Json|void
+     */
+    public function YearMaintenanceList()
     {
-        if ($this->request->isGet() === false){
+        // 验证请求方法
+        if (!$this->request->isGet()) {
+            $this->error('请求错误');
+        }
+
+        // 获取并验证参数
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['sist']) || !isset($param['year'])) {
+            $this->error('参数错误');
+        }
+
+        $department = $param['sist'];
+        $year = $param['year'];
+
+        try {
+            // 获取该部门该年份的所有维修设备编号
+            $machineQuery = db('设备_维修记录')
+                ->where('使用部门', $department)
+                ->where('报障时间', 'like', $year . '%')
+                ->order('设备编号');
+
+            $machines = $machineQuery->column('distinct(设备编号) as 设备编号');
+            if (empty($machines)) {
+                $this->success('成功', []);
+            }
+
+            // 预加载设备名称
+            $machineNames = db('设备_基本资料')
+                ->whereIn('设备编号', $machines)
+                ->column('rtrim(设备名称) as 设备名称', '设备编号');
+
+            $result = [];
+
+            // 一次性获取所有维修记录
+            $allRecords = db('设备_维修记录')
+                ->where('使用部门', $department)
+                ->where('报障时间', 'like', $year . '%')
+                ->field([
+                    '设备编号',
+                    'DATE_FORMAT(报障时间, "%m") AS month', // 直接提取月份数字
+                    'COUNT(*) AS count'
+                ])
+                ->group('设备编号, DATE_FORMAT(报障时间, "%m")')
+                ->select();
+
+            // 按设备编号组织数据
+            $recordsByMachine = [];
+            foreach ($allRecords as $record) {
+                $monthKey = $record['month']; // 直接使用月份数字作为键
+                $recordsByMachine[$record['设备编号']][$monthKey] = $record['count'];
+            }
+
+            // 构建结果数组
+            foreach ($machines as $machineId) {
+                $monthData = [];
+                $total = 0;
+
+                if (isset($recordsByMachine[$machineId])) {
+                    foreach ($recordsByMachine[$machineId] as $month => $count) {
+                        $monthData[$month] = $count; // 保持月份键为字符串
+                        $total += $count;
+                    }
+                }
+
+                // 确保月份键是两位数格式
+                $formattedMonthData = [];
+                foreach ($monthData as $month => $count) {
+                    $formattedMonth = str_pad($month, 2, '0', STR_PAD_LEFT);
+                    $formattedMonthData[$formattedMonth] = $count;
+                }
+
+                $result[] = [
+                        '使用部门' => $department,
+                        '设备编号' => $machineId,
+                        '设备名称' => $machineNames[$machineId] ?? '未知设备',
+                        'total' => $total
+                    ] + $formattedMonthData;
+            }
+            return json([
+                'code' => 1,
+                'msg' => '成功',
+                'time' =>time(),
+                'data' => $result
+            ]);
+        } catch (\Exception $e) {
+            $this->error('查询失败: ' . $e->getMessage());
+        }
+    }
+
+
+    /**
+     * 设备维修记录配件详情
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function YearAccessoriesList()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['machine']) || !isset($param['year']) || !isset($param['sist'])) {
+            $this->error('参数错误');
+        }
+        $list = db('物料_收发记录')
+            ->alias('a')
+            ->join('物料_仓库信息 b', 'a.仓库编号 = b.编号','left')
+            ->join('设备_基本资料 c', 'a.st_jtbh = c.设备编号','left')
+            ->join('物料_存货编码 d', 'a.st_wlbh = d.物料代码')
+            ->where('a.st_jtbh',$param['machine'])
+            ->where('a.st_rq','like',$param['year'].'%')
+            ->where(function ($query) {
+                $query->where('a.仓库编号', '107')
+                    ->whereOr('a.仓库编号', 'Y107');
+            })
+            ->where('st_jylb','like','修理领用%')
+            ->field(['DATE_FORMAT(a.st_rq, "%y-%m-%d") AS 日期','rtrim(a.st_jylb) as 交易类别','a.st_jtbh AS 机台编号','rtrim(a.仓库编号) as 仓库编号',
+                'rtrim(b.名称) as 仓库名称','rtrim(c.使用部门) as 领用部门','a.st_wlbh as 物料编号','rtrim(d.物料名称) as 物料名称','a.st_sl as 领用数量',
+                'rtrim(a.st_dw) as 领用单位','a.领用单价','a.st_sl*a.领用单价 as 金额','a.st_desc as 备注'])
+            ->order('日期 DESC')
+            ->select();
+        if (empty($list)) {
+            $this->error('未找到数据');
+        }else{
+            $this->success('成功', $list);
+        }
+    }
+
+    /**
+     * 年度保养统计上方几台列表
+     * @return Json|void
+     */
+    public function YearMaintainList()
+    {
+        // 验证请求方法
+        if (!$this->request->isGet()) {
             $this->error('请求错误');
         }
+
+        // 获取并验证参数
         $param = $this->request->param();
-        if (empty($param)){
+        if (empty($param) || !isset($param['sist']) || !isset($param['year'])) {
             $this->error('参数错误');
         }
+
+        $department = $param['sist'];
+        $year = $param['year'];
+
+        try {
+            // 获取该部门该年份的所有维修设备编号
+            $machineQuery = db('设备_保养记录')
+                ->where('使用部门', $department)
+                ->where('保养开始时间', 'like', $year . '%')
+                ->order('设备编号');
+
+            $machines = $machineQuery->column('distinct(设备编号) as 设备编号');
+
+            if (empty($machines)) {
+                $this->success('成功', []);
+            }
+
+            // 预加载设备名称
+            $machineNames = db('设备_基本资料')
+                ->whereIn('设备编号', $machines)
+                ->column('rtrim(设备名称) as 设备名称', '设备编号');
+
+            $result = [];
+
+            // 一次性获取所有维修记录
+            $allRecords = db('设备_保养记录')
+                ->where('使用部门', $department)
+                ->where('保养开始时间', 'like', $year . '%')
+                ->field([
+                    '设备编号',
+                    'DATE_FORMAT(保养开始时间, "%m") AS month', // 直接提取月份数字
+                    'COUNT(*) AS count'
+                ])
+                ->group('设备编号, DATE_FORMAT(保养开始时间, "%m")')
+                ->select();
+
+            // 按设备编号组织数据
+            $recordsByMachine = [];
+            foreach ($allRecords as $record) {
+                $monthKey = $record['month']; // 直接使用月份数字作为键
+                $recordsByMachine[$record['设备编号']][$monthKey] = $record['count'];
+            }
+
+            // 构建结果数组
+            foreach ($machines as $machineId) {
+                $monthData = [];
+                $total = 0;
+
+                if (isset($recordsByMachine[$machineId])) {
+                    foreach ($recordsByMachine[$machineId] as $month => $count) {
+                        $monthData[$month] = $count; // 保持月份键为字符串
+                        $total += $count;
+                    }
+                }
+
+                // 确保月份键是两位数格式
+                $formattedMonthData = [];
+                foreach ($monthData as $month => $count) {
+                    $formattedMonth = str_pad($month, 2, '0', STR_PAD_LEFT);
+                    $formattedMonthData[$formattedMonth] = $count;
+                }
+
+                $result[] = [
+                        '使用部门' => $department,
+                        '设备编号' => $machineId,
+                        '设备名称' => $machineNames[$machineId] ?? '未知设备',
+                        'total' => $total
+                    ] + $formattedMonthData;
+            }
+            return json([
+                'code' => 1,
+                'msg' => '成功',
+                'time' =>time(),
+                'data' => $result
+            ]);
+        } catch (\Exception $e) {
+            $this->error('查询失败: ' . $e->getMessage());
+        }
     }
+
+
+    //月度设备维修记录上方机台列表
+//    public function MonthAccessoriesList()
+//    {
+//        if ($this->request->isGet() === false) {
+//            $this->error('请求错误');
+//        }
+//        $param = $this->request->param();
+//        if (empty($param) || !isset($param['sist']) || !isset($param['mouth'])) {
+//            $this->error('参数错误');
+//        }
+//        $list = db('设备_维修记录')
+//            ->alias('a')
+//            ->join('<UNK>_<UNK> b', 'a.<UNK> = b.<UNK>','left')
+//            ->where('使用部门', $param['sist'])
+//            ->where('保障时间', 'like', $param['mouth'] . '%')
+//            ->field('设备编号,设备名称,报障时间,维修受理时间,修复时间,实际维修工时 as 故障维修工时,验收情况,');
+//    }
 }

+ 11 - 7
application/api/controller/Product.php

@@ -353,7 +353,10 @@ class Product extends Api
         if (empty($params['from_code']) || empty($params['to_code'])) {
             $this->error('参数不能为空');
         }
-
+        $where = [];
+        if (isset($params['type']) && $params['type'] == 1) {
+            $where = ['Gy0_gxh' => ['>',20]];
+        }
         // 定义数据处理策略
         $strategies = [
             'gy' => [
@@ -412,7 +415,7 @@ class Product extends Api
             // 构建查询条件
             $query = db($strategy['table'])->where($strategy['source_field'], $params['from_code']);
             if ($key === 'gy') {
-                $query->where('Gy0_方案', $params['from_pro']);
+                $query->where($where)->where('Gy0_方案', $params['from_pro']);
             }
 
             $data = $query->select();
@@ -1286,17 +1289,18 @@ class Product extends Api
         if (empty($param) || !isset($param['cpdh'])) {
             $this->error('参数错误');
         }
-
+        if (!isset($param['yjno']) && empty($param['yjno'])) {
+            $this->error('请选择印件');
+        }
         // 构建查询条件
         $where = ['Gy0_cpdh' => $param['cpdh']];
-        if (isset($param['yjno']) && !empty($param['yjno'])) {
-            $where['Gy0_yjno'] = $param['yjno'];
-        }
+        $where['Gy0_yjno'] = $param['yjno'];
+
 
         // 获取待排序的数据
         $list = \db('产品_工艺资料')
             ->where($where)
-            ->order('Gy0_gxh,mod_rq desc')
+            ->order('Gy0_gxh,Sys_rq desc,Mod_rq desc')
             ->column('Gy0_gxh', 'UniqID');
         // 更新排序字段
         $i = 1;