querySize

This commit is contained in:
邓皓元 2019-12-16 17:54:07 +08:00
parent 9536fb7fa5
commit 388c7b75d1
2 changed files with 23 additions and 2 deletions

View File

@ -9,12 +9,13 @@ use Dipper\Excel\Concerns\FromQuery;
use Dipper\Excel\Concerns\WithHeadings;
use Illuminate\Database\Eloquent\Collection;
use App\Domains\Virtual\Services\CardService;
use Dipper\Excel\Concerns\WithCustomQuerySize;
use Dipper\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use App\Domains\Virtual\Repositories\PropertyRepository;
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;
@ -25,6 +26,25 @@ class CardExport extends AbstractExport implements FromQuery, WithHeadings, With
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()
{
$this->conditions['type'] = 0;

View File

@ -56,7 +56,8 @@ class CardController extends Controller
}
$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) {
throw new NotAllowedException('一次性导出数据超过25万条请添加筛选条件后重试');