Browse Source

优化数据导出超时问题

master
崔茂正 10 months ago
parent
commit
955389dd2d
  1. 37
      app/Admin/Extensions/Exporter/StudentExporter.php

37
app/Admin/Extensions/Exporter/StudentExporter.php

@ -4,8 +4,10 @@ @@ -4,8 +4,10 @@
namespace App\Admin\Extensions\Exporter;
use App\Models\SecondaryCollege;
use App\Models\Speciality;
use Dcat\Admin\Grid\Exporters\AbstractExporter;
use Illuminate\Support\Facades\Cache;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
@ -75,16 +77,35 @@ class StudentExporter extends AbstractExporter implements WithMapping, WithHeadi @@ -75,16 +77,35 @@ class StudentExporter extends AbstractExporter implements WithMapping, WithHeadi
public function getSpecialityAndCollegeNameById($id)
{
$nameInfo = Speciality::query()->where("speciality.id", $id)->leftJoin("secondary_college as b", "speciality.secondary_college_id", "=", "b.id")->first();
if(empty($nameInfo)){
return [
"name" => "",
"speciality_name" => ""
];
}
$value = Cache::store('file')->remember('specialityInfo', 600, function () {
//所有专业
$specialityList = Speciality::query()->get(["id", "speciality_name", "secondary_college_id"])->toArray();
if(!empty($specialityList)){
//所有学院
$secondaryCollegeList = SecondaryCollege::query()->get(["id", "name"])->toArray();
if(!empty($secondaryCollegeList)){
$secondaryCollegeList = array_column($secondaryCollegeList, null, "id");
foreach($specialityList as $key => $item){
if(array_key_exists($item["secondary_college_id"], $secondaryCollegeList)){
$specialityList[$key]["name"] = $secondaryCollegeList[$item['secondary_college_id']]['name'];
}else{
$specialityList[$key]["name"] = "";
}
}
}
return array_column($specialityList, null, "id");
}
});
return [
"name" => $value[$id]["name"],
"speciality_name" => $value[$id]["speciality_name"]
];
return $nameInfo->toArray();
}
}

Loading…
Cancel
Save