perf: 优化导出统计国际化

This commit is contained in:
kuaifan 2024-10-28 12:45:38 +08:00
parent f1df4e07d2
commit 8e9ff1116a
3 changed files with 103 additions and 98 deletions

View File

@ -773,32 +773,31 @@ class ApproveController extends AbstractController
$res = Base::arrayKeyToUnderline($process['data']); $res = Base::arrayKeyToUnderline($process['data']);
// //
$headings = []; $headings = [];
$headings[] = '申请编号'; $headings[] = Doo::translate('申请编号');
$headings[] = '标题'; $headings[] = Doo::translate('标题');
$headings[] = '申请状态'; $headings[] = Doo::translate('申请状态');
$headings[] = '发起时间'; $headings[] = Doo::translate('发起时间');
$headings[] = '完成时间'; $headings[] = Doo::translate('完成时间');
$headings[] = '发起人工号'; $headings[] = Doo::translate('发起人工号');
$headings[] = '发起人User ID'; $headings[] = Doo::translate('发起人User ID');
$headings[] = '发起人姓名'; $headings[] = Doo::translate('发起人姓名');
$headings[] = '发起人部门'; $headings[] = Doo::translate('发起人部门');
$headings[] = '发起人部门ID'; $headings[] = Doo::translate('发起人部门ID');
$headings[] = '部门负责人'; $headings[] = Doo::translate('部门负责人');
$headings[] = '历史审批人'; $headings[] = Doo::translate('历史审批人');
$headings[] = '历史办理人'; $headings[] = Doo::translate('历史办理人');
$headings[] = '审批记录'; $headings[] = Doo::translate('审批记录');
$headings[] = '当前处理人'; $headings[] = Doo::translate('当前处理人');
$headings[] = '审批节点'; $headings[] = Doo::translate('审批节点');
$headings[] = '审批人数'; $headings[] = Doo::translate('审批人数');
$headings[] = '审批耗时'; $headings[] = Doo::translate('审批耗时');
$headings[] = '假期类型'; $headings[] = Doo::translate('假期类型');
$headings[] = '开始时间'; $headings[] = Doo::translate('开始时间');
$headings[] = '结束时间'; $headings[] = Doo::translate('结束时间');
$headings[] = '时长'; $headings[] = Doo::translate('时长');
$headings[] = '请假事由'; $headings[] = Doo::translate('请假事由');
$headings[] = '请假单位'; $headings[] = Doo::translate('请假单位');
// //
$sheets = [];
$datas = []; $datas = [];
foreach ($res as $val) { foreach ($res as $val) {
// //
@ -822,7 +821,7 @@ class ApproveController extends AbstractController
$varStartTime = Carbon::parse($val['var']['start_time']); $varStartTime = Carbon::parse($val['var']['start_time']);
$varEndTime = Carbon::parse($val['var']['end_time']); $varEndTime = Carbon::parse($val['var']['end_time']);
$duration = $varEndTime->floatDiffInHours($varStartTime); $duration = $varEndTime->floatDiffInHours($varStartTime);
$duration_unit = '小时'; // 时长单位 $duration_unit = Doo::translate('小时'); // 时长单位
$datas[] = [ $datas[] = [
$val['id'], // 申请编号 $val['id'], // 申请编号
$val['proc_def_name'], // 标题 $val['proc_def_name'], // 标题
@ -854,12 +853,12 @@ class ApproveController extends AbstractController
return Base::retError('没有任何数据'); return Base::retError('没有任何数据');
} }
// //
$title = "Sheet1"; $title = Doo::translate("审批记录");
$sheets = [ $sheets = [
BillExport::create()->setTitle($title)->setHeadings($headings)->setData($datas)->setStyles(["A1:Y1" => ["font" => ["bold" => true]]]) BillExport::create()->setTitle($title)->setHeadings($headings)->setData($datas)->setStyles(["A1:Y1" => ["font" => ["bold" => true]]])
]; ];
// //
$fileName = '审批记录_' . Base::time() . '.xlsx'; $fileName = $title . '_' . Base::time() . '.xlsx';
$filePath = "temp/approve/export/" . date("Ym", Base::time()); $filePath = "temp/approve/export/" . date("Ym", Base::time());
$export = new BillMultipleExport($sheets); $export = new BillMultipleExport($sheets);
$res = $export->store($filePath . "/" . $fileName); $res = $export->store($filePath . "/" . $fileName);

View File

@ -1211,22 +1211,22 @@ class ProjectController extends AbstractController
go(function () use ($user, $userid, $time, $type, $botUser, $dialog) { go(function () use ($user, $userid, $time, $type, $botUser, $dialog) {
Coroutine::sleep(0.1); Coroutine::sleep(0.1);
$headings = []; $headings = [];
$headings[] = '任务ID'; $headings[] = Doo::translate('任务ID');
$headings[] = '父级任务ID'; $headings[] = Doo::translate('父级任务ID');
$headings[] = '所属项目'; $headings[] = Doo::translate('所属项目');
$headings[] = '任务标题'; $headings[] = Doo::translate('任务标题');
$headings[] = '任务开始时间'; $headings[] = Doo::translate('任务开始时间');
$headings[] = '任务结束时间'; $headings[] = Doo::translate('任务结束时间');
$headings[] = '完成时间'; $headings[] = Doo::translate('完成时间');
$headings[] = '归档时间'; $headings[] = Doo::translate('归档时间');
$headings[] = '任务计划用时'; $headings[] = Doo::translate('任务计划用时');
$headings[] = '实际完成用时'; $headings[] = Doo::translate('实际完成用时');
$headings[] = '超时时间'; $headings[] = Doo::translate('超时时间');
$headings[] = '开发用时'; $headings[] = Doo::translate('开发用时');
$headings[] = '验收/测试用时'; $headings[] = Doo::translate('验收/测试用时');
$headings[] = '负责人'; $headings[] = Doo::translate('负责人');
$headings[] = '创建人'; $headings[] = Doo::translate('创建人');
$headings[] = '状态'; $headings[] = Doo::translate('状态');
$datas = []; $datas = [];
// //
$content = []; $content = [];
@ -1244,15 +1244,17 @@ class ProjectController extends AbstractController
/** @var ProjectTask $task */ /** @var ProjectTask $task */
foreach ($tasks as $task) { foreach ($tasks as $task) {
$flowChanges = ProjectTaskFlowChange::whereTaskId($task->id)->get(); $flowChanges = ProjectTaskFlowChange::whereTaskId($task->id)->get();
$testTime = 0;//验收/测试时间 $testTime = 0; // 测试时间
$taskStartTime = $task->start_at ? Carbon::parse($task->start_at)->timestamp : Carbon::parse($task->created_at)->timestamp; $taskStartTime = $task->start_at ? Carbon::parse($task->start_at)->timestamp : Carbon::parse($task->created_at)->timestamp;
$taskCompleteTime = $task->complete_at ? Carbon::parse($task->complete_at)->timestamp : time(); $taskCompleteTime = $task->complete_at ? Carbon::parse($task->complete_at)->timestamp : time();
$totalTime = $taskCompleteTime - $taskStartTime; //开发测试总用时 $totalTime = $taskCompleteTime - $taskStartTime; // 任务总用时
foreach ($flowChanges as $change) { foreach ($flowChanges as $change) {
if (!str_contains($change->before_flow_item_name, 'end')) { if (str_starts_with($change->before_flow_item_name, 'end')) {
continue;
}
$upOne = ProjectTaskFlowChange::where('id', '<', $change->id)->whereTaskId($task->id)->orderByDesc('id')->first(); $upOne = ProjectTaskFlowChange::where('id', '<', $change->id)->whereTaskId($task->id)->orderByDesc('id')->first();
if ($upOne) { if ($upOne) {
if (str_contains($change->before_flow_item_name, 'test') || str_contains($change->before_flow_item_name, '测试') || strpos($change->before_flow_item_name, '验收') !== false) { if (str_starts_with($change->before_flow_item_name, 'test')) {
$testCtime = Carbon::parse($change->created_at)->timestamp; $testCtime = Carbon::parse($change->created_at)->timestamp;
$tTime = Carbon::parse($upOne->created_at)->timestamp; $tTime = Carbon::parse($upOne->created_at)->timestamp;
$tMinusNum = $testCtime - $tTime; $tMinusNum = $testCtime - $tTime;
@ -1260,32 +1262,31 @@ class ProjectController extends AbstractController
} }
} }
} }
}
if (!$task->complete_at) { if (!$task->complete_at) {
$lastChange = ProjectTaskFlowChange::whereTaskId($task->id)->orderByDesc('id')->first(); $lastChange = ProjectTaskFlowChange::whereTaskId($task->id)->orderByDesc('id')->first();
$nowTime = time(); $nowTime = time();
$unFinishTime = $nowTime - Carbon::parse($lastChange->created_at)->timestamp; $unFinishTime = $nowTime - Carbon::parse($lastChange->created_at)->timestamp;
if (str_contains($lastChange->after_flow_item_name, 'test') || str_contains($lastChange->after_flow_item_name, '测试') || strpos($lastChange->after_flow_item_name, '验收') !== false) { if (str_starts_with($lastChange->after_flow_item_name, 'test')) {
$testTime += $unFinishTime; $testTime += $unFinishTime;
} }
} }
$developTime = $totalTime - $testTime;//开发时间 $developTime = $totalTime - $testTime; // 开发时间
$planTime = '-';//任务计划用时 $planTime = '-'; // 任务计划用时
$overTime = '-';//超时时间 $overTime = '-'; // 超时时间
if ($task->end_at) { if ($task->end_at) {
$startTime = Carbon::parse($task->start_at)->timestamp; $startTime = Carbon::parse($task->start_at)->timestamp;
$endTime = Carbon::parse($task->end_at)->timestamp; $endTime = Carbon::parse($task->end_at)->timestamp;
$planTotalTime = $endTime - $startTime; $planTotalTime = $endTime - $startTime;
$residueTime = $planTotalTime - $totalTime; $residueTime = $planTotalTime - $totalTime;
if ($residueTime < 0) { if ($residueTime < 0) {
$overTime = Base::timeFormat(abs($residueTime)); $overTime = Doo::translate(Base::timeFormat(abs($residueTime)));
} }
$planTime = Base::timeDiff($startTime, $endTime); $planTime = Base::timeDiff($startTime, $endTime);
} }
$actualTime = $task->complete_at ? $totalTime : 0;//实际完成用时 $actualTime = $task->complete_at ? $totalTime : 0; // 实际完成用时
$statusText = '未完成'; $statusText = '未完成';
if ($task->flow_item_name) { if (str_starts_with($task->flow_item_name, 'end')) {
if (str_contains($task->flow_item_name, '已取消')) { if (preg_match('/已取消|Cancelled|취소됨|キャンセル済み|Abgebrochen|Annulé|Dibatalkan|Отменено/', $task->flow_item_name)) {
$statusText = '已取消'; $statusText = '已取消';
$actualTime = 0; $actualTime = 0;
$testTime = 0; $testTime = 0;
@ -1321,13 +1322,13 @@ class ProjectController extends AbstractController
$task->complete_at ?: '-', $task->complete_at ?: '-',
$task->archived_at ?: '-', $task->archived_at ?: '-',
$planTime ?: '-', $planTime ?: '-',
$actualTime ? Base::timeFormat($actualTime) : '-', $actualTime ? Doo::translate(Base::timeFormat($actualTime)) : '-',
$overTime, $overTime,
$developTime > 0 ? Base::timeFormat($developTime) : '-', $developTime > 0 ? Doo::translate(Base::timeFormat($developTime)) : '-',
$testTime > 0 ? Base::timeFormat($testTime) : '-', $testTime > 0 ? Doo::translate(Base::timeFormat($testTime)) : '-',
Base::filterEmoji(User::userid2nickname($task->ownerid)) . " (ID: {$task->ownerid})", Base::filterEmoji(User::userid2nickname($task->ownerid)) . " (ID: {$task->ownerid})",
Base::filterEmoji(User::userid2nickname($task->userid)) . " (ID: {$task->userid})", Base::filterEmoji(User::userid2nickname($task->userid)) . " (ID: {$task->userid})",
$statusText Doo::translate($statusText),
]; ];
} }
}); });
@ -1357,9 +1358,11 @@ class ProjectController extends AbstractController
// //
$fileName = User::userid2nickname($userid[0]) ?: $userid[0]; $fileName = User::userid2nickname($userid[0]) ?: $userid[0];
if (count($userid) > 1) { if (count($userid) > 1) {
$fileName .= '等' . count($userid) . '位成员任务统计'; $fileName .= '等' . count($userid) . '位成员的任务统计';
} else {
$fileName .= '的任务统计';
} }
$fileName .= '_' . Base::time() . '.xls'; $fileName = Doo::translate($fileName) . '_' . Base::time() . '.xls';
$filePath = "temp/task/export/" . date("Ym", Base::time()); $filePath = "temp/task/export/" . date("Ym", Base::time());
$export = new BillMultipleExport($sheets); $export = new BillMultipleExport($sheets);
$res = $export->store($filePath . "/" . $fileName); $res = $export->store($filePath . "/" . $fileName);
@ -1432,16 +1435,16 @@ class ProjectController extends AbstractController
$user = User::auth('admin'); $user = User::auth('admin');
// //
$headings = []; $headings = [];
$headings[] = '任务ID'; $headings[] = Doo::translate('任务ID');
$headings[] = '父级任务ID'; $headings[] = Doo::translate('父级任务ID');
$headings[] = '所属项目'; $headings[] = Doo::translate('所属项目');
$headings[] = '任务标题'; $headings[] = Doo::translate('任务标题');
$headings[] = '任务开始时间'; $headings[] = Doo::translate('任务开始时间');
$headings[] = '任务结束时间'; $headings[] = Doo::translate('任务结束时间');
$headings[] = '任务计划用时'; $headings[] = Doo::translate('任务计划用时');
$headings[] = '超时时间'; $headings[] = Doo::translate('超时时间');
$headings[] = '负责人'; $headings[] = Doo::translate('负责人');
$headings[] = '创建人'; $headings[] = Doo::translate('创建人');
$data = []; $data = [];
// //
ProjectTask::whereNull('complete_at') ProjectTask::whereNull('complete_at')
@ -1461,7 +1464,7 @@ class ProjectController extends AbstractController
$planTotalTime = $endTime - $startTime; $planTotalTime = $endTime - $startTime;
$residueTime = $planTotalTime - $totalTime; $residueTime = $planTotalTime - $totalTime;
if ($residueTime < 0) { if ($residueTime < 0) {
$overTime = Base::timeFormat(abs($residueTime)); $overTime = Doo::translate(Base::timeFormat(abs($residueTime)));
} }
$planTime = Base::timeDiff($startTime, $endTime); $planTime = Base::timeDiff($startTime, $endTime);
} }
@ -1488,11 +1491,12 @@ class ProjectController extends AbstractController
return Base::retError('没有任何数据'); return Base::retError('没有任何数据');
} }
// //
$title = Doo::translate('超期任务');
$sheets = [ $sheets = [
BillExport::create()->setTitle("超期任务")->setHeadings($headings)->setData($data)->setStyles(["A1:J1" => ["font" => ["bold" => true]]]) BillExport::create()->setTitle($title)->setHeadings($headings)->setData($data)->setStyles(["A1:J1" => ["font" => ["bold" => true]]])
]; ];
// //
$fileName = '超期任务_' . Base::time() . '.xls'; $fileName = $title . '_' . Base::time() . '.xls';
$filePath = "temp/task/export/" . date("Ym", Base::time()); $filePath = "temp/task/export/" . date("Ym", Base::time());
$export = new BillMultipleExport($sheets); $export = new BillMultipleExport($sheets);
$res = $export->store($filePath . "/" . $fileName); $res = $export->store($filePath . "/" . $fileName);

View File

@ -1193,14 +1193,14 @@ class SystemController extends AbstractController
$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");
// //
$headings = []; $headings = [];
$headings[] = '签到人'; $headings[] = Doo::translate('签到人');
$headings[] = '签到日期'; $headings[] = Doo::translate('签到日期');
$headings[] = '班次时间'; $headings[] = Doo::translate('班次时间');
$headings[] = '首次签到时间'; $headings[] = Doo::translate('首次签到时间');
$headings[] = '首次签到结果'; $headings[] = Doo::translate('首次签到结果');
$headings[] = '最后签到时间'; $headings[] = Doo::translate('最后签到时间');
$headings[] = '最后签到结果'; $headings[] = Doo::translate('最后签到结果');
$headings[] = '参数数据'; $headings[] = Doo::translate('参数数据');
// //
$sheets = []; $sheets = [];
$startD = Carbon::parse($date[0])->startOfDay(); $startD = Carbon::parse($date[0])->startOfDay();
@ -1230,12 +1230,12 @@ class SystemController extends AbstractController
if (Base::time() < $startT + $secondStart) { if (Base::time() < $startT + $secondStart) {
$firstResult = "-"; $firstResult = "-";
} else { } else {
$firstResult = "正常"; $firstResult = Doo::translate("正常");
if (empty($firstTimestamp)) { if (empty($firstTimestamp)) {
$firstResult = "缺卡"; $firstResult = Doo::translate("缺卡");
$styles["E{$index}"] = ["font" => ["color" => ["rgb" => "ff0000"]]]; $styles["E{$index}"] = ["font" => ["color" => ["rgb" => "ff0000"]]];
} elseif ($firstTimestamp > $startT + $secondStart) { } elseif ($firstTimestamp > $startT + $secondStart) {
$firstResult = "迟到"; $firstResult = Doo::translate("迟到");
$styles["E{$index}"] = ["font" => ["color" => ["rgb" => "436FF6"]]]; $styles["E{$index}"] = ["font" => ["color" => ["rgb" => "436FF6"]]];
} }
} }
@ -1243,12 +1243,12 @@ class SystemController extends AbstractController
$lastResult = "-"; $lastResult = "-";
$lastTimestamp = 0; $lastTimestamp = 0;
} else { } else {
$lastResult = "正常"; $lastResult = Doo::translate("正常");
if (empty($lastTimestamp) || $lastTimestamp === $firstTimestamp) { if (empty($lastTimestamp) || $lastTimestamp === $firstTimestamp) {
$lastResult = "缺卡"; $lastResult = Doo::translate("缺卡");
$styles["G{$index}"] = ["font" => ["color" => ["rgb" => "ff0000"]]]; $styles["G{$index}"] = ["font" => ["color" => ["rgb" => "ff0000"]]];
} elseif ($lastTimestamp < $startT + $secondEnd) { } elseif ($lastTimestamp < $startT + $secondEnd) {
$lastResult = "早退"; $lastResult = Doo::translate("早退");
$styles["G{$index}"] = ["font" => ["color" => ["rgb" => "436FF6"]]]; $styles["G{$index}"] = ["font" => ["color" => ["rgb" => "436FF6"]]];
} }
} }
@ -1278,9 +1278,11 @@ class SystemController extends AbstractController
// //
$fileName = $users[0]->nickname; $fileName = $users[0]->nickname;
if (count($users) > 1) { if (count($users) > 1) {
$fileName .= "" . count($userid) . "位成员"; $fileName .= "" . count($userid) . "位成员的签到记录";
} else {
$fileName .= '的签到记录';
} }
$fileName .= '签到记录_' . Base::time() . '.xlsx'; $fileName = Doo::translate($fileName) . '_' . Base::time() . '.xlsx';
$filePath = "temp/checkin/export/" . date("Ym", Base::time()); $filePath = "temp/checkin/export/" . date("Ym", Base::time());
$export = new BillMultipleExport($sheets); $export = new BillMultipleExport($sheets);
$res = $export->store($filePath . "/" . $fileName); $res = $export->store($filePath . "/" . $fileName);