querySize
This commit is contained in:
parent
9536fb7fa5
commit
388c7b75d1
@ -9,12 +9,13 @@ use Dipper\Excel\Concerns\FromQuery;
|
|||||||
use Dipper\Excel\Concerns\WithHeadings;
|
use Dipper\Excel\Concerns\WithHeadings;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use App\Domains\Virtual\Services\CardService;
|
use App\Domains\Virtual\Services\CardService;
|
||||||
|
use Dipper\Excel\Concerns\WithCustomQuerySize;
|
||||||
use Dipper\Excel\Concerns\WithColumnFormatting;
|
use Dipper\Excel\Concerns\WithColumnFormatting;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
use App\Domains\Virtual\Repositories\PropertyRepository;
|
use App\Domains\Virtual\Repositories\PropertyRepository;
|
||||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||||
|
|
||||||
class CardExport extends AbstractExport implements FromQuery, WithHeadings, WithRows, WithColumnFormatting
|
class CardExport extends AbstractExport implements FromQuery, WithHeadings, WithRows, WithColumnFormatting, WithCustomQuerySize
|
||||||
{
|
{
|
||||||
public $conditions;
|
public $conditions;
|
||||||
|
|
||||||
@ -25,6 +26,25 @@ class CardExport extends AbstractExport implements FromQuery, WithHeadings, With
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queued exportables are processed in chunks; each chunk being a job pushed to the queue by the QueuedWriter.
|
||||||
|
* In case of exportables that implement the FromQuery concern, the number of jobs is calculated by dividing the $query->count() by the chunk size.
|
||||||
|
* Depending on the implementation of the query() method (eg. When using a groupBy clause), this calculation might not be correct.
|
||||||
|
*
|
||||||
|
* When this is the case, you should use this method to provide a custom calculation of the query size.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function querySize(): int
|
||||||
|
{
|
||||||
|
$this->conditions['type'] = 0;
|
||||||
|
|
||||||
|
// 添加卡属性匹配查找
|
||||||
|
CardService::propConditions($this->conditions);
|
||||||
|
|
||||||
|
return app(OrderCardPartitionRepository::class)->skipCache()->selectRaw("COUNT(*) AS count")->withConditions($this->conditions)->first()->count;
|
||||||
|
}
|
||||||
|
|
||||||
public function query()
|
public function query()
|
||||||
{
|
{
|
||||||
$this->conditions['type'] = 0;
|
$this->conditions['type'] = 0;
|
||||||
|
@ -56,7 +56,8 @@ class CardController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$conditions['type'] = 0;
|
$conditions['type'] = 0;
|
||||||
$total = app(OrderCardPartitionRepository::class)->skipCache()->withConditions($conditions)->count();
|
|
||||||
|
$total = app(OrderCardPartitionRepository::class)->skipCache()->selectRaw("COUNT(*) AS count")->withConditions($conditions)->first()->count;
|
||||||
|
|
||||||
if ($total > 250000) {
|
if ($total > 250000) {
|
||||||
throw new NotAllowedException('一次性导出数据超过25万条,请添加筛选条件后重试');
|
throw new NotAllowedException('一次性导出数据超过25万条,请添加筛选条件后重试');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user