Browse Source

机台日报表缓存优化

曹鹤洋 1 year ago
parent
commit
4fcf84204c
1 changed files with 43 additions and 41 deletions
  1. 43 41
      application/api/controller/MachineProductionReport.php

+ 43 - 41
application/api/controller/MachineProductionReport.php

@@ -32,25 +32,26 @@ class MachineProductionReport extends Api
             $this->error('请求方式错误');
         }
 
-        $rows = db()->table('设备_产量计酬')->cache(true,300)
+        $rows = db('设备_产量计酬')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
             ->group('date')
             ->order('UniqId desc')
             ->limit(30)
             ->select();
-        $rows1 = db()->table('db_sczl')->cache(true,300)
+
+        $rows1 = db('db_sczl')->cache(true,300)
             ->group('date')
             ->order('UniqId desc')
             ->limit(40)
             ->column('LEFT(sys_rq, 10) as date, COUNT(*) as counts');
 
-        $arr2 = db()->table('设备_产量计酬')->cache(true,300)
+        $arr2 = db('设备_产量计酬')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
             ->where('sys_rq','>=',$rows[29]['date'])
             ->group('date, sys_id')
             ->select();
 
-        $arr1 = db()->table('db_sczl')->cache(true,300)
+        $arr1 = db('db_sczl')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
             ->where('sys_rq','>=',$rows[29]['date'])
             ->group('date, sys_id')
@@ -130,13 +131,13 @@ class MachineProductionReport extends Api
             WHERE t1.sczl_yjno = t2.yj_Yjno
             ORDER BY t1.`sczl_gdbh` DESC
             LIMIT 65';
-        $rows = db()->cache(true,300)->query($sql);
-
-        $arr1 = db()->table('设备_产量计酬')->cache(true,300)
+        $rows = db()->query($sql);
+        $arr1 = db('设备_产量计酬')->cache(true,300)
             ->field('sczl_gdbh,rtrim(sys_id) as sys_id')
             ->where('sczl_gdbh','>=',$rows[64]['sczl_gdbh'])
             ->select();
-        $arr2 = db()->table('db_sczl')->cache(true,300)
+
+        $arr2 = db('db_sczl')->cache(true,300)
             ->field('sczl_gdbh,rtrim(sys_id) as sys_id')
             ->where('sczl_gdbh','>=',$rows[64]['sczl_gdbh'])
             ->select();
@@ -195,8 +196,8 @@ class MachineProductionReport extends Api
             $where['a.sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
             $option['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
         }
-        $total1 = db()->table('设备_产量计酬')->where($option)->count();
-        $total2 = db()->table('db_sczl')->where($option)->count();
+        $total1 = db('设备_产量计酬')->where($option)->count();
+        $total2 = db('db_sczl')->where($option)->count();
 
         if (!cache('ReportGetList-'.$req['date'].'-'.$req['sys_id'].'-'.$req['page'].'-'.$req['limit'])){
             // a.sczl_来料少数,
@@ -242,8 +243,8 @@ class MachineProductionReport extends Api
             $rows = cache('ReportGetList-'.$req['date'].'-'.$req['sys_id'].'-'.$req['page'].'-'.$req['limit']);
         }
 
-        $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
-        $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
+        $gd = db('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
+        $rs = db('人事_基本资料')->column('员工编号, 员工姓名');
         foreach ($rows as $key=>$value){
             $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
             $rows[$key]['Gd_cpmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? trim($gd[$value['sczl_gdbh']]) : '';
@@ -313,7 +314,7 @@ class MachineProductionReport extends Api
             $option = [
                 'sczl_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']
             ];
-            if (!cache('ReportGetList-'.$req['gdbh'].'-'.$req['cpmc'].'-'.$req['page'].'-'.$req['limit'])){
+            if (!cache('ReportGetList-'.$req['gdbh'].'-'.$req['page'].'-'.$req['limit'])){
                 //a.拆片联拼系数, a.拆片条小盒系数,
                 $sql = 'SELECT a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
         a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp,
@@ -335,17 +336,17 @@ class MachineProductionReport extends Api
                 $sql .= 'ORDER BY sys_id ASC, sczl_num ASC LIMIT '.($page-1)*$limit.','.$limit;
                 $rows = db()->query($sql);
 
-                cache('ReportGetList-'.$req['gdbh'].'-'.$req['cpmc'].'-'.$req['page'].'-'.$req['limit'],$rows,3600);
+                cache('ReportGetList-'.$req['gdbh'].'-'.$req['page'].'-'.$req['limit'],$rows,3600);
             }else{
-                $rows = cache('ReportGetList-'.$req['gdbh'].'-'.$req['cpmc'].'-'.$req['page'].'-'.$req['limit']);
+                $rows = cache('ReportGetList-'.$req['gdbh'].'-'.$req['page'].'-'.$req['limit']);
             }
 
-            $total1 = db()->table('设备_产量计酬')->where($option)->count();
-            $total2 = db()->table('db_sczl')->where($option)->count();
+            $total1 = db('设备_产量计酬')->where($option)->count();
+            $total2 = db('db_sczl')->where($option)->count();
         }else{
             if (isset($req['cpmc']) && !empty($req['cpmc'])){
                 //查询工单表
-                $gd = db()->table('工单_基本资料')
+                $gd = db('工单_基本资料')
                     ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
                     ->column('Gd_gdbh');
                 $in = "'" . implode("','", $gd) . "'";
@@ -354,7 +355,7 @@ class MachineProductionReport extends Api
                     'sczl_gdbh'=>['in', $gd]
                 ];
 
-                if (!cache('ReportLocate')){
+                if (!cache('ReportGetList-'.$req['gdbh'].'-'.$req['cpmc'].'-'.$req['limit'])){
                     $sql = 'SELECT a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
         a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp,
         a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 
@@ -374,20 +375,21 @@ class MachineProductionReport extends Api
                     $sql .= 'WHERE `a`.`sczl_gdbh` IN ('.$in.') ';
                     $sql .= 'ORDER BY sys_id ASC, sczl_num ASC LIMIT '.($page-1)*$limit.','.$limit;
                     $rows = db()->query($sql);
+                    cache('ReportGetList-'.$req['cpmc'].'-'.$req['page'].'-'.$req['limit'],$rows,3600);
                 }else{
-
+                    $rows = cache('ReportGetList-'.$req['cpmc'].'-'.$req['page'].'-'.$req['limit']);
                 }
 
 
-                $total1 = db()->table('设备_产量计酬')->where($option)->count();
-                $total2 = db()->table('db_sczl')->where($option)->count();
+                $total1 = db('设备_产量计酬')->where($option)->count();
+                $total2 = db('db_sczl')->where($option)->count();
             }else{
                 $this->error('参数错误');
             }
         }
 
-        $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
-        $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
+        $gd = db('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
+        $rs = db('人事_基本资料')->column('员工编号, 员工姓名');
         foreach ($rows as $key=>$value){
             $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
             $rows[$key]['Gd_cpmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? trim($gd[$value['sczl_gdbh']]) : '';
@@ -450,7 +452,7 @@ class MachineProductionReport extends Api
             $this->error('参数错误');
         }
 
-        $rows = db()->table('db_sczl')->alias('a')
+        $rows = db('db_sczl')->alias('a')
             ->field('a.sczl_gdbh, rtrim(j.Gd_cpmc) as Gd_cpmc, 
             a.sczl_yjno, rtrim(y.yj_yjmc) as yj_yjmc, 
             rtrim(a.sczl_gxmc) as sczl_gxmc, a.sczl_gxh, rtrim(a.sczl_type) as sczl_type, 
@@ -470,7 +472,7 @@ class MachineProductionReport extends Api
             ->join(['工单_基本资料'=>'j'],'a.sczl_gdbh = j.Gd_gdbh')
             ->join(['工单_印件资料'=>'y'],'a.sczl_gdbh = y.Yj_Gdbh')
             ->find();
-        $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
+        $rs = db('人事_基本资料')->column('员工编号, 员工姓名');
         for($i=1;$i<=10;$i++){
             if(trim($rows['sczl_bh'.$i])!=''){
                 $rows['sczl_bh'.$i.'_name'] = array_key_exists($rows['sczl_bh'.$i],$rs) ? trim($rs[$rows['sczl_bh'.$i]]) : '';
@@ -501,7 +503,7 @@ class MachineProductionReport extends Api
             $this->error('参数错误');
         }
 
-        $row = db()->table('工单_基本资料')
+        $row = db('工单_基本资料')
             ->field('rtrim(Gd_cpmc) as Gd_cpmc')
             ->where('Gd_gdbh',$gdbh)
             ->find();
@@ -535,7 +537,7 @@ class MachineProductionReport extends Api
             $this->error('参数错误');
         }
 
-        $row = db()->table('工单_印件资料')
+        $row = db('工单_印件资料')
             ->field('rtrim(yj_yjmc) as yj_yjmc')
             ->where(['Yj_Gdbh'=>$gdbh,'yj_Yjno'=>$yjno])
             ->find();
@@ -575,7 +577,7 @@ class MachineProductionReport extends Api
             $keyword = '';
         }
 
-        $rows = db()->table('工单_工艺资料')
+        $rows = db('工单_工艺资料')
             ->field('Gy0_gxh as sczl_gxh, rtrim(Gy0_gxmc) as sczl_type, rtrim(Add_gxmc) as Add_gxmc,Gy0_ls as sczl_ls, Gy0_ms as sczl_ms')
             ->where(['Gy0_gdbh'=>$gdbh,'Gy0_yjno'=>$yjno])
             ->where('Gy0_gxh|Gy0_gxmc|Add_gxmc','like','%'.$keyword.'%')
@@ -603,24 +605,24 @@ class MachineProductionReport extends Api
             $this->error('请求方式错误');
         }
 
-        $row = db()->table('dic_lzde')
+        $row = db('dic_lzde')
             ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
             ->where('sys_mc','人工作业计件定额')
             ->find();
-        $rows = db()->table('dic_lzde')
+        $rows = db('dic_lzde')
             ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
             ->where('Parent',$row['Key_'])
             ->order('sys_bh asc')
             ->select();
         foreach ($rows as $key=>$value){
-            $bool = db()->table('dic_lzde')
+            $bool = db('dic_lzde')
                 ->field('Key_,sys_bh, rtrim(sys_mc) as sys_mc')
                 ->where('Parent',$value['Key_'])
                 ->order('sys_bh asc')
                 ->select();
             if ($bool){
                 foreach ($bool as $k=>$v){
-                    $bool1 = db()->table('dic_lzde')
+                    $bool1 = db('dic_lzde')
                         ->field('sys_bh, rtrim(sys_mc) as sys_mc')
                         ->where('Parent',$v['Key_'])
                         ->order('sys_bh asc')
@@ -672,13 +674,13 @@ class MachineProductionReport extends Api
         $data['sys_rq'] = date('Y-m-d H:i:s');
 
         //查询UniqId
-        $UniqId = db()->table('db_sczl')->max('UniqId');
+        $UniqId = db('db_sczl')->max('UniqId');
         $data['UniqId'] = $UniqId+1;
 
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_sczl')->fetchSql(true)->insert($data);
+            $sql = db('db_sczl')->fetchSql(true)->insert($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -729,7 +731,7 @@ class MachineProductionReport extends Api
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_sczl')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $sql = db('db_sczl')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -763,7 +765,7 @@ class MachineProductionReport extends Api
         //开启事务
         db()->startTrans();
         try{
-            $bool = db()->table('db_sczl')->where('UniqId',$req['UniqId'])->delete();
+            $bool = db('db_sczl')->where('UniqId',$req['UniqId'])->delete();
 
             // 提交事务
             db()->commit();
@@ -852,7 +854,7 @@ class MachineProductionReport extends Api
         }
 
         //拆片联拼系数 拆片条小盒系数
-        $rows1 = db()->table('设备_产量计酬')->alias('a')->cache(true)
+        $rows1 = db('设备_产量计酬')->alias('a')->cache(true)
             ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp, a.sczl_来料少数 as sczl_来料异常, 
             a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 
@@ -864,7 +866,7 @@ class MachineProductionReport extends Api
             ->order('a.sys_id asc, a.sczl_num asc')
             ->select();
 
-        $rows2 = db()->table('db_sczl')->alias('a')
+        $rows2 = db('db_sczl')->alias('a')
             ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_fp as sczl_zcfp, a.sczl_cp as sczl_zccp, 
             a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 
@@ -876,8 +878,8 @@ class MachineProductionReport extends Api
             ->order('a.sys_id asc, a.sczl_num asc')
             ->select();
 
-        $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
-        $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
+        $gd = db('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
+        $rs = db('人事_基本资料')->column('员工编号, 员工姓名');
         foreach ($rows2 as $key=>$value){
             $subArray = [];
             foreach ($arr as $k=>$v){