From 8426110096a479d85606c0cf5830a1e1bf887f03 Mon Sep 17 00:00:00 2001
From: lisgroup <407505297@qq.com>
Date: Sat, 4 May 2019 22:01:54 +0800
Subject: [PATCH 21/60] =?UTF-8?q?fix(repo):=20=E4=BD=BF=E7=94=A8=20$total?=
=?UTF-8?q?=5Fexcel=20=E8=AE=A1=E7=AE=97=E5=80=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
laravel/app/Http/Repository/MultithreadingRepository.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/laravel/app/Http/Repository/MultithreadingRepository.php b/laravel/app/Http/Repository/MultithreadingRepository.php
index 6656206..68cb47d 100644
--- a/laravel/app/Http/Repository/MultithreadingRepository.php
+++ b/laravel/app/Http/Repository/MultithreadingRepository.php
@@ -643,7 +643,7 @@ public function completionRate($excel_id)
// 2. 查询 api_excel_logs 表更新的数据量
$total = ApiExcelLogs::where('api_excel_id', $excel_id)->count();
// 3. 返回完成率
- return floor($total / $api_excel['total_excel'] * 100);
+ return floor($total / $total_excel * 100);
}
}
}
From 6cedda96e557958d72d0d8008831ccf3fc365f2c Mon Sep 17 00:00:00 2001
From: lisgroup <407505297@qq.com>
Date: Sat, 4 May 2019 22:20:00 +0800
Subject: [PATCH 22/60] =?UTF-8?q?fix(repo):=20=E8=BF=9B=E5=BA=A6=E6=9D=A1?=
=?UTF-8?q?=E5=AE=8C=E6=88=90=E5=90=8E=E5=8F=B0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
laravel/app/Http/Repository/ApiRepository.php | 44 +++++++++++++++++--
1 file changed, 41 insertions(+), 3 deletions(-)
diff --git a/laravel/app/Http/Repository/ApiRepository.php b/laravel/app/Http/Repository/ApiRepository.php
index 636f973..35cd926 100644
--- a/laravel/app/Http/Repository/ApiRepository.php
+++ b/laravel/app/Http/Repository/ApiRepository.php
@@ -10,6 +10,7 @@
use App\Models\ApiExcel;
+use App\Models\ApiExcelLogs;
class ApiRepository
{
@@ -75,7 +76,6 @@ public function autoFailed()
// 开启任务后 10 分钟未查询出结果=》失败
if ($excel['auto_delete'] > 0 && strtotime($excel['updated_at']) + 600 < time()) {
ApiExcel::where('id', $excel['id'])->update(['state' => 5]);
-
}
}
@@ -111,9 +111,47 @@ public function randomTime()
/**
* 获取下载进度条
+ *
+ * @param $lists
+ *
+ * @return mixed
*/
- public function workProgress($list)
+ public function workProgress($lists)
{
- return $list;
+ foreach ($lists as $key => $list) {
+ $rate = 100;
+ switch ($list['state']) {
+ case '1': // 正在处理的任务
+ case '5': // 失败任务
+ $rate = $this->progressRate($list['id'], $list['total_excel']);
+ break;
+ }
+
+ $lists[$key]['rate'] = $rate;
+ }
+ return $lists;
}
+
+
+ /**
+ * 计算任务完成百分比
+ *
+ * @param int $excel_id api_excel 主键 id
+ * @param int $total_excel 总数
+ *
+ * @return int|bool
+ */
+ private function progressRate($excel_id, $total_excel)
+ {
+ if ($total_excel > 0) {
+ // 2. 查询 api_excel_logs 表更新的数据量
+ $total = ApiExcelLogs::where('api_excel_id', $excel_id)->count();
+ // 3. 返回完成率
+ $rate = floor($total / $total_excel * 100);
+ return $rate > 100 ? 100 : $rate;
+ }
+
+ return 100;
+ }
+
}
From e96c961cd2864d42e5047813723dbc9214d1b296 Mon Sep 17 00:00:00 2001
From: lisgroup <407505297@qq.com>
Date: Sat, 4 May 2019 22:39:03 +0800
Subject: [PATCH 23/60] =?UTF-8?q?fix(socket):=20=E8=8E=B7=E5=8F=96?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
laravel/app/Services/WebSocketService.php | 29 +++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/laravel/app/Services/WebSocketService.php b/laravel/app/Services/WebSocketService.php
index 018d49f..89e6468 100644
--- a/laravel/app/Services/WebSocketService.php
+++ b/laravel/app/Services/WebSocketService.php
@@ -8,9 +8,9 @@
namespace App\Services;
+use App\Http\Repository\ApiRepository;
use App\Http\Repository\MultithreadingRepository;
use App\Models\ApiExcel;
-use App\Models\ApiExcelLogs;
use Hhxsv5\LaravelS\Swoole\WebSocketHandlerInterface;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
@@ -21,6 +21,8 @@
*/
class WebSocketService implements WebSocketHandlerInterface
{
+ public $perPage = 10;
+
// 声明没有参数的构造函数
public function __construct()
{
@@ -37,10 +39,13 @@ public function onOpen($server, $request)
// \Log::info('New WebSocket connection', [$request->fd, request()->all(), session()->getId(), session('xxx'), session(['yyy' => time()])]);
// 1. 根据 api_excel 的 id 查询总数,
$req = $request->get;
+ $this->perPage = isset($req['perPage']) ? intval($req['perPage']) : 10;
+
$action = $req['action'] ?? '';
switch ($action) {
case 'api_excel':
-
+ return $this->apiExcel();
+ break;
}
if (isset($req['id']) && $req['id'] == floor($req['id'])) {
@@ -91,4 +96,24 @@ public function outJson($code = 200, $data = [], $reason = 'success')
return json_encode(['code' => $code, 'reason' => $reason, 'data' => $data], JSON_UNESCAPED_UNICODE);
}
+
+ private function apiExcel()
+ {
+ $user_id = auth('api')->user()['id'];
+
+ // 查询对应用户的上传数据
+ $where = [];
+ if ($user_id != 1) {
+ $where = ['uid' => $user_id];
+ }
+ $list = ApiExcel::with('apiParam')->where($where)->orderBy('id', 'desc')->paginate($this->perPage);
+ // 获取完成进度情况
+ $list = ApiRepository::getInstent()->workProgress($list);
+
+ $appUrl = env('APP_URL') ?? '';
+ $collect = collect(['appUrl' => $appUrl]);
+ $items = $collect->merge($list);
+
+ return $this->outJson(200, $items);
+ }
}
From 8537a7813001a4cfd7edf146a5c78c625a2b1c8a Mon Sep 17 00:00:00 2001
From: lisgroup <407505297@qq.com>
Date: Sun, 5 May 2019 13:21:42 +0800
Subject: [PATCH 24/60] =?UTF-8?q?fix(view):=20websocket=20=E8=8E=B7?=
=?UTF-8?q?=E5=8F=96=E6=95=B0=E6=8D=AE=E5=88=97=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/views/api_excel/index.vue | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/admin/src/views/api_excel/index.vue b/admin/src/views/api_excel/index.vue
index 9276dab..526aa1b 100644
--- a/admin/src/views/api_excel/index.vue
+++ b/admin/src/views/api_excel/index.vue
@@ -127,6 +127,7 @@