perf: 优化导出审批功能

This commit is contained in:
kuaifan 2025-06-04 15:08:31 +08:00
parent 25e82d690e
commit 1fd7f0314a
4 changed files with 187 additions and 123 deletions

View File

@ -23,6 +23,7 @@ use App\Models\WebSocketDialogMsg;
use App\Module\Apps;
use App\Module\BillMultipleExport;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Swoole\Coroutine;
/**
* @apiDefine approve
@ -768,11 +769,34 @@ class ApproveController extends AbstractController
if (Carbon::parse($date[1])->timestamp - Carbon::parse($date[0])->timestamp > 35 * 86400) {
return Base::retError('日期范围限制最大35天');
}
$botUser = User::botGetOrCreate('system-msg');
if (empty($botUser)) {
return Base::retError('系统机器人不存在');
}
$dialog = WebSocketDialog::checkUserDialog($botUser, $user->userid);
//
go(function () use ($data, $user, $botUser, $dialog) {
Coroutine::sleep(1);
//
$content = [];
$content[] = [
'content' => '导出审批数据已完成',
'style' => 'font-weight: bold;padding-bottom: 4px;',
];
//
$ret = Ihttp::ihttp_post($this->flow_url . '/api/v1/workflow/process/findAllProcIns', json_encode($data));
$process = json_decode($ret['ret'] == 1 ? $ret['data'] : '{}', true);
if (!$process || $process['status'] != 200) {
return Base::retError($process['message'] ?? '查询失败');
$content[] = [
'content' => $process['message'] ?? '查询失败',
'style' => 'color: #ff0000;',
];
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
'type' => 'content',
'title' => $content[0]['content'],
'content' => $content,
], $botUser->userid, true, false, true);
return;
}
//
$res = Base::arrayKeyToUnderline($process['data']);
@ -855,7 +879,16 @@ class ApproveController extends AbstractController
];
}
if (empty($datas)) {
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;
}
//
$title = Doo::translate("审批记录");
@ -868,7 +901,16 @@ class ApproveController extends AbstractController
$export = new BillMultipleExport($sheets);
$res = $export->store($filePath . "/" . $fileName);
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);
$zipFile = "app/" . $filePath . "/" . Base::rightDelete($fileName, '.xlsx') . ".zip";
@ -885,14 +927,34 @@ class ApproveController extends AbstractController
$base64 = base64_encode(Base::array2string([
'file' => $zipFile,
]));
$fileUrl = Base::fillUrl('api/approve/down?key=' . urlencode($base64));
Session::put('approve::export:userid', $user->userid);
return Base::retSuccess('success', [
'size' => Base::twoFloat(filesize($zipPath) / 1024, true),
'url' => Base::fillUrl('api/approve/down?key=' . urlencode($base64)),
]);
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
'type' => 'file_download',
'title' => '导出审批数据已完成',
'name' => $fileName,
'size' => filesize($zipPath),
'url' => $fileUrl,
], $botUser->userid, true, false, true);
} 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');
}
function getStateDescription($state)

View File

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

View File

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

View File

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