Skip to content

Commit 3b3054c

Browse files
committed
fix(repo): 更新数据库字段
1 parent 01e3fe1 commit 3b3054c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

laravel/app/Http/Controllers/Api/ApiExcelController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers\Api;
44

55
use App\Events\ApiExcelEvent;
6+
use App\Http\Repository\ApiRepository;
67
use App\Http\Repository\ExcelRepository;
78
use App\Http\Requests\ApiExcel\Store;
89
use App\Http\Requests\ApiExcel\Update;
@@ -57,6 +58,8 @@ public function index()
5758
$where = ['uid' => $user_id];
5859
}
5960
$list = ApiExcel::with('apiParam')->where($where)->orderBy('id', 'desc')->paginate($this->perPage);
61+
// 获取完成进度情况
62+
$list = ApiRepository::getInstent()->workProgress($list);
6063

6164
$appUrl = env('APP_URL') ?? '';
6265
$collect = collect(['appUrl' => $appUrl]);
@@ -264,6 +267,11 @@ public function forceDelete($id)
264267
return $this->out(200);
265268
}
266269

270+
/**
271+
* 下载已完成数据
272+
*
273+
* @return \Illuminate\Http\Response
274+
*/
267275
public function downloadLog()
268276
{
269277
$api_excel_id = $this->request->input('id');
@@ -280,4 +288,5 @@ public function downloadLog()
280288
}
281289
return $this->out(200, ['failed_done_file' => $failed_done_file]);
282290
}
291+
283292
}

laravel/app/Http/Repository/MultithreadingRepository.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ public function loadExcel()
150150
}
151151

152152
$this->dataSet = $dataSet;
153-
return true;
153+
// return true;
154+
// 更新 api_excel 表 total_excel 条数
155+
return $this->saveTotalExcel($this->api_excel_id, count($dataSet['data']));
154156
} catch (\Exception $e) {
155157
return false;
156158
}
@@ -324,7 +326,9 @@ public function newLoadExcel()
324326
// 3. 循环数组每个单元格的数据
325327
$this->dataSet['data'] = $data;
326328

327-
return true;
329+
// return true;
330+
// 更新 api_excel 表 total_excel 条数
331+
return $this->saveTotalExcel($this->api_excel_id, count($data));
328332
} catch (Exception|\PhpOffice\PhpSpreadsheet\Exception $exception) {
329333
return false;
330334
}
@@ -647,6 +651,19 @@ public function completionRate($excel_id)
647651
return '100';
648652
}
649653

654+
/**
655+
* 保存 total_excel 字段
656+
*
657+
* @param $api_id
658+
* @param $total
659+
*
660+
* @return bool
661+
*/
662+
private function saveTotalExcel($api_id, $total)
663+
{
664+
return ApiExcel::where('id', $api_id)->update(['total_excel' => $total]);
665+
}
666+
650667
/**
651668
* BusRepository constructor.
652669
*/

0 commit comments

Comments
 (0)