mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 12:02:51 +00:00
perf: 优化导出签到功能
This commit is contained in:
parent
1fd7f0314a
commit
a5b8609df1
@ -3,6 +3,8 @@
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\UserDevice;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use Request;
|
||||
use Session;
|
||||
use Response;
|
||||
@ -22,6 +24,7 @@ use App\Module\Apps;
|
||||
use App\Module\BillMultipleExport;
|
||||
use LdapRecord\LdapRecordException;
|
||||
use Guanguans\Notify\Messages\EmailMessage;
|
||||
use Swoole\Coroutine;
|
||||
|
||||
/**
|
||||
* @apiDefine system
|
||||
@ -1264,7 +1267,7 @@ class SystemController extends AbstractController
|
||||
*/
|
||||
public function checkin__export()
|
||||
{
|
||||
User::auth('admin');
|
||||
$user = User::auth('admin');
|
||||
//
|
||||
$setting = Base::setting('checkinSetting');
|
||||
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");
|
||||
$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[] = Doo::translate('签到人');
|
||||
$headings[] = Doo::translate('签到日期');
|
||||
@ -1304,6 +1316,12 @@ class SystemController extends AbstractController
|
||||
$headings[] = Doo::translate('最后签到结果');
|
||||
$headings[] = Doo::translate('参数数据');
|
||||
//
|
||||
$content = [];
|
||||
$content[] = [
|
||||
'content' => '导出签到数据已完成',
|
||||
'style' => 'font-weight: bold;padding-bottom: 4px;',
|
||||
];
|
||||
//
|
||||
$sheets = [];
|
||||
$startD = Carbon::parse($date[0])->startOfDay();
|
||||
$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);
|
||||
}
|
||||
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;
|
||||
@ -1389,7 +1416,16 @@ class SystemController 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";
|
||||
@ -1406,14 +1442,34 @@ class SystemController extends AbstractController
|
||||
$base64 = base64_encode(Base::array2string([
|
||||
'file' => $zipFile,
|
||||
]));
|
||||
$fileUrl = Base::fillUrl('api/system/checkin/down?key=' . urlencode($base64));
|
||||
Session::put('checkin::export:userid', $user->userid);
|
||||
return Base::retSuccess('success', [
|
||||
'size' => Base::twoFloat(filesize($zipPath) / 1024, true),
|
||||
'url' => Base::fillUrl('api/system/checkin/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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -92,6 +92,8 @@
|
||||
正在导出超期任务,请稍等...
|
||||
导出审批数据已完成
|
||||
正在导出审批数据,请稍等...
|
||||
导出签到数据已完成
|
||||
正在导出签到数据,请稍等...
|
||||
任务列表不存在或已被删除
|
||||
主任务已完成无法添加子任务
|
||||
子任务不支持此功能
|
||||
|
||||
@ -1644,6 +1644,8 @@ Token
|
||||
正在导出超期任务,请稍等...
|
||||
导出审批数据已完成
|
||||
正在导出审批数据,请稍等...
|
||||
导出签到数据已完成
|
||||
正在导出签到数据,请稍等...
|
||||
(*)查看了(*)的联系电话
|
||||
标记任务未完成
|
||||
标记任务已完成
|
||||
|
||||
@ -103,11 +103,9 @@ export default {
|
||||
this.$store.dispatch("call", {
|
||||
url: 'system/checkin/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(_ => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user