perf: 优化导出签到功能

This commit is contained in:
kuaifan 2025-06-04 15:14:31 +08:00
parent 1fd7f0314a
commit a5b8609df1
4 changed files with 175 additions and 117 deletions

View File

@ -3,6 +3,8 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Models\UserDevice; use App\Models\UserDevice;
use App\Models\WebSocketDialog;
use App\Models\WebSocketDialogMsg;
use Request; use Request;
use Session; use Session;
use Response; use Response;
@ -22,6 +24,7 @@ use App\Module\Apps;
use App\Module\BillMultipleExport; use App\Module\BillMultipleExport;
use LdapRecord\LdapRecordException; use LdapRecord\LdapRecordException;
use Guanguans\Notify\Messages\EmailMessage; use Guanguans\Notify\Messages\EmailMessage;
use Swoole\Coroutine;
/** /**
* @apiDefine system * @apiDefine system
@ -1264,7 +1267,7 @@ class SystemController extends AbstractController
*/ */
public function checkin__export() public function checkin__export()
{ {
User::auth('admin'); $user = User::auth('admin');
// //
$setting = Base::setting('checkinSetting'); $setting = Base::setting('checkinSetting');
if ($setting['open'] !== 'open') { if ($setting['open'] !== 'open') {
@ -1294,6 +1297,15 @@ class SystemController extends AbstractController
$secondStart = strtotime("2000-01-01 {$time[0]}") - strtotime("2000-01-01 00:00:00"); $secondStart = strtotime("2000-01-01 {$time[0]}") - strtotime("2000-01-01 00:00:00");
$secondEnd = strtotime("2000-01-01 {$time[1]}") - strtotime("2000-01-01 00:00:00"); $secondEnd = strtotime("2000-01-01 {$time[1]}") - strtotime("2000-01-01 00:00:00");
// //
$botUser = User::botGetOrCreate('system-msg');
if (empty($botUser)) {
return Base::retError('系统机器人不存在');
}
$dialog = WebSocketDialog::checkUserDialog($botUser, $user->userid);
//
go(function () use ($secondStart, $secondEnd, $time, $userid, $date, $user, $botUser, $dialog) {
Coroutine::sleep(1);
//
$headings = []; $headings = [];
$headings[] = Doo::translate('签到人'); $headings[] = Doo::translate('签到人');
$headings[] = Doo::translate('签到日期'); $headings[] = Doo::translate('签到日期');
@ -1304,6 +1316,12 @@ class SystemController extends AbstractController
$headings[] = Doo::translate('最后签到结果'); $headings[] = Doo::translate('最后签到结果');
$headings[] = Doo::translate('参数数据'); $headings[] = Doo::translate('参数数据');
// //
$content = [];
$content[] = [
'content' => '导出签到数据已完成',
'style' => 'font-weight: bold;padding-bottom: 4px;',
];
//
$sheets = []; $sheets = [];
$startD = Carbon::parse($date[0])->startOfDay(); $startD = Carbon::parse($date[0])->startOfDay();
$endD = Carbon::parse($date[1])->endOfDay(); $endD = Carbon::parse($date[1])->endOfDay();
@ -1375,7 +1393,16 @@ class SystemController extends AbstractController
$sheets[] = BillExport::create()->setTitle($title)->setHeadings($headings)->setData($datas)->setStyles($styles); $sheets[] = BillExport::create()->setTitle($title)->setHeadings($headings)->setData($datas)->setStyles($styles);
} }
if (empty($sheets)) { if (empty($sheets)) {
return Base::retError('没有任何数据'); $content[] = [
'content' => '没有任何数据',
'style' => 'color: #ff0000;',
];
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
'type' => 'content',
'title' => $content[0]['content'],
'content' => $content,
], $botUser->userid, true, false, true);
return;
} }
// //
$fileName = $users[0]->nickname; $fileName = $users[0]->nickname;
@ -1389,7 +1416,16 @@ class SystemController extends AbstractController
$export = new BillMultipleExport($sheets); $export = new BillMultipleExport($sheets);
$res = $export->store($filePath . "/" . $fileName); $res = $export->store($filePath . "/" . $fileName);
if ($res != 1) { if ($res != 1) {
return Base::retError('导出失败,' . $fileName . ''); $content[] = [
'content' => "导出失败,{$fileName}",
'style' => 'color: #ff0000;',
];
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
'type' => 'content',
'title' => $content[0]['content'],
'content' => $content,
], $botUser->userid, true, false, true);
return;
} }
$xlsPath = storage_path("app/" . $filePath . "/" . $fileName); $xlsPath = storage_path("app/" . $filePath . "/" . $fileName);
$zipFile = "app/" . $filePath . "/" . Base::rightDelete($fileName, '.xlsx') . ".zip"; $zipFile = "app/" . $filePath . "/" . Base::rightDelete($fileName, '.xlsx') . ".zip";
@ -1406,14 +1442,34 @@ class SystemController extends AbstractController
$base64 = base64_encode(Base::array2string([ $base64 = base64_encode(Base::array2string([
'file' => $zipFile, 'file' => $zipFile,
])); ]));
$fileUrl = Base::fillUrl('api/system/checkin/down?key=' . urlencode($base64));
Session::put('checkin::export:userid', $user->userid); Session::put('checkin::export:userid', $user->userid);
return Base::retSuccess('success', [ WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
'size' => Base::twoFloat(filesize($zipPath) / 1024, true), 'type' => 'file_download',
'url' => Base::fillUrl('api/system/checkin/down?key=' . urlencode($base64)), 'title' => '导出签到数据已完成',
]); 'name' => $fileName,
'size' => filesize($zipPath),
'url' => $fileUrl,
], $botUser->userid, true, false, true);
} else { } else {
return Base::retError('打包失败,请稍后再试...'); $content[] = [
'content' => "打包失败,请稍后再试...",
'style' => 'color: #ff0000;',
];
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
'type' => 'content',
'title' => $content[0]['content'],
'content' => $content,
], $botUser->userid, true, false, true);
} }
});
//
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
'type' => 'content',
'content' => '正在导出签到数据,请稍等...',
], $botUser->userid, true, false, true);
//
return Base::retSuccess('success');
} }
/** /**

View File

@ -92,6 +92,8 @@
正在导出超期任务,请稍等... 正在导出超期任务,请稍等...
导出审批数据已完成 导出审批数据已完成
正在导出审批数据,请稍等... 正在导出审批数据,请稍等...
导出签到数据已完成
正在导出签到数据,请稍等...
任务列表不存在或已被删除 任务列表不存在或已被删除
主任务已完成无法添加子任务 主任务已完成无法添加子任务
子任务不支持此功能 子任务不支持此功能

View File

@ -1644,6 +1644,8 @@ Token
正在导出超期任务,请稍等... 正在导出超期任务,请稍等...
导出审批数据已完成 导出审批数据已完成
正在导出审批数据,请稍等... 正在导出审批数据,请稍等...
导出签到数据已完成
正在导出签到数据,请稍等...
(*)查看了(*)的联系电话 (*)查看了(*)的联系电话
标记任务未完成 标记任务未完成
标记任务已完成 标记任务已完成

View File

@ -103,11 +103,9 @@ export default {
this.$store.dispatch("call", { this.$store.dispatch("call", {
url: 'system/checkin/export', url: 'system/checkin/export',
data: this.formData, data: this.formData,
}).then(({data}) => { }).then(() => {
this.show = false; this.show = false;
this.$store.dispatch('downUrl', { $A.modalSuccess('正在打包,请留意系统消息。');
url: data.url
});
}).catch(({msg}) => { }).catch(({msg}) => {
$A.modalError(msg); $A.modalError(msg);
}).finally(_ => { }).finally(_ => {