Selaa lähdekoodia

超节损队列优化

unknown 2 viikkoa sitten
vanhempi
sitoutus
079e6edbdb

+ 15 - 13
application/api/controller/OrderSuperLoss.php

@@ -6,6 +6,7 @@ use app\common\controller\Api;
 use think\Cache;
 use think\Exception;
 use think\Log;
+use think\Queue;
 use \think\Request;
 use \think\Db;
 /**
@@ -1381,6 +1382,7 @@ class OrderSuperLoss extends Api
         $waste_total = $data['zcfp'] + $wasteTotal;
         //工单无形损 = 实际投料-入仓数量-废品合计
         $data['intangible_loss'] = (int)($data['实际投料'] * 10000 - $total_number[0] - $waste_total);
+     
         //查询核检单废品上报数据
         $out_sql = "SELECT qczl_num,fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
                         fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13,
@@ -1508,6 +1510,7 @@ class OrderSuperLoss extends Api
                 $sumBz[$vv['sczl_bh1'].'-'.$vv['Gy0_gxh']] = $vv['total_cl'];
             }
         }
+   
         foreach ($gy_data as $kk => $vv) {
             $banju = $vv['版距']/1000;
             if ($vv['印刷方式'] === '卷对卷'){
@@ -1579,7 +1582,7 @@ class OrderSuperLoss extends Api
             foreach ($total_cl_data as $k => $v) {
                 $banju1 = $v['版距']/1000;
                 if ($v['印刷方式'] === '卷对卷'){
-                    $v['total_cl'] = $v['total_cl']*$banju1;
+                    $v['total_cl'] = $v['total_cl']/$banju1;
                 }
                 if ($v['Gy0_yjno'] === $vv['Gy0_yjno'] && $v['Gy0_gxh'] === $vv['Gy0_gxh']) {
                     if (strpos($v['gxmc'], '拆片') !== false) {
@@ -1596,6 +1599,7 @@ class OrderSuperLoss extends Api
             unset($gy_data[$kk]['sczl_bh']);
             unset($gy_data[$kk]['bzdh']);
         }
+        // halt($gy_data);
         //计算超节损金额
         foreach ($gy_data as $n => $item) {
             //节损数量
@@ -1630,6 +1634,7 @@ class OrderSuperLoss extends Api
             $total['waste_intangible'] += $item['无形损分摊'];
             $total['reward'] += floatval(str_replace(',', '', $gy_data[$n]['节损奖']));
         }
+        // halt($gy_data);
         //整合数据
         $result = [];
         foreach ($gy_data as $key => $value) {
@@ -2230,23 +2235,20 @@ class OrderSuperLoss extends Api
             $this->error('未搜索到工单入仓数据');
         }
         foreach ($list as $item){
-            $result = $this->OneOrderSuperLoss($item['jjcp_gdbh'],$item['jjcp_yjno']);
-            \db('工单_质量考核汇总')
-                ->where('Gy0_gdbh', $item['jjcp_gdbh'])
-                ->where('印件及工序', $item['jjcp_yjno'])
-                ->delete();
-            $sql = \db('工单_质量考核汇总')
-                ->fetchSql(true)
-                ->insertAll($result);
-            $res = \db()->query($sql);
-            if ($res === false){
+            $jobData = [
+                'gdbh' => $item['jjcp_gdbh'],
+                'yjno' => $item['jjcp_yjno'],
+                'created_at' => date('Y-m-d H:i:s'),
+            ];
+            $res = Queue::push('app\\job\\OrderSuperLossJob', $jobData, 'order_loss_calculation');
+            if (!$res) {
                 $i++;
             }
         }
         if ($i === 0){
-            $this->success('成功');
+            $this->success('任务已提交,共' . count($list) . '条');
         }else{
-            $this->error('失败');
+            $this->error('提交完成,失败' . $i . '条');
         }
     }
 

+ 7 - 0
application/extra/queue.php

@@ -39,6 +39,13 @@ return [
             'delay'  => 0,           // 立即执行
             'retry'  => 3,           // 重试次数
         ],
+        // 工单超节损队列
+        'order_loss_calculation' => [
+            'select'     => 13,
+            'expire' => 1800,
+            'delay'  => 0,
+            'retry'  => 3,
+        ],
         // 低优先级队列
         'low_priority' => [
             'expire' => 3600,        // 1小时超时

+ 1 - 1
application/job/OrderLossQueueWorker.php

@@ -24,7 +24,7 @@ class OrderLossQueueWorker
             'host'       => '127.0.0.1',
             'port'       => 6379,
             'password'   => '',
-            'select'     => 14,
+            'select'     => 13,
             'timeout'    => 0,
             'expire'     => 0,
             'persistent' => false,