|
@@ -28,6 +28,7 @@ class ExportViolationProductJobs implements ShouldQueue
|
|
|
{
|
|
{
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
protected $message_data;
|
|
protected $message_data;
|
|
|
|
|
+ protected $company_id;
|
|
|
/**
|
|
/**
|
|
|
* Create a new job instance.
|
|
* Create a new job instance.
|
|
|
*
|
|
*
|
|
@@ -49,6 +50,8 @@ class ExportViolationProductJobs implements ShouldQueue
|
|
|
$this->export_excel($this->message_data);
|
|
$this->export_excel($this->message_data);
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
Log::info('job_error', '违规数据-导出禁止挂网数据处理队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
Log::info('job_error', '违规数据-导出禁止挂网数据处理队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
|
|
|
+ //失败后清除缓存
|
|
|
|
|
+ Cache::forget('export_violation_product_job_'. $this->company_id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -71,7 +74,7 @@ class ExportViolationProductJobs implements ShouldQueue
|
|
|
// 查询条件
|
|
// 查询条件
|
|
|
$map = [];
|
|
$map = [];
|
|
|
$job_page = isset($message_data['job_page']) ? $message_data['job_page'] : 1;
|
|
$job_page = isset($message_data['job_page']) ? $message_data['job_page'] : 1;
|
|
|
- $limit = 5000; //每次处理1000条
|
|
|
|
|
|
|
+ $limit = 1000; //每次处理1000条
|
|
|
$status = $message_data['status'] ?? '';
|
|
$status = $message_data['status'] ?? '';
|
|
|
$start_time = $message_data['start_time'] ?? '';
|
|
$start_time = $message_data['start_time'] ?? '';
|
|
|
$end_time = $message_data['end_time'] ?? '';
|
|
$end_time = $message_data['end_time'] ?? '';
|
|
@@ -192,45 +195,38 @@ class ExportViolationProductJobs implements ShouldQueue
|
|
|
$shipment_city_ids = explode(',', $shipment_city_ids);
|
|
$shipment_city_ids = explode(',', $shipment_city_ids);
|
|
|
$ViolationProductModel = $ViolationProductModel->whereIn('shipment_city_id', $shipment_city_ids);
|
|
$ViolationProductModel = $ViolationProductModel->whereIn('shipment_city_id', $shipment_city_ids);
|
|
|
}
|
|
}
|
|
|
- if ($is_admin != 1 && $company_id != 0) {
|
|
|
|
|
- $result = $ViolationProductModel->where(function ($q) use ($user_id) {
|
|
|
|
|
- $q->where('first_responsible_person', 'like', "%,$user_id,%")
|
|
|
|
|
- ->orWhere('responsible_person', 'like', "%,$user_id,%")
|
|
|
|
|
- ->orWhere('source_responsible_person', 'like', "%,$user_id,%");
|
|
|
|
|
- })
|
|
|
|
|
- ->where($map)
|
|
|
|
|
- ->orderByDesc('id')
|
|
|
|
|
- ->paginate($limit, ['*'], 'page', $job_page)
|
|
|
|
|
- ->toarray();
|
|
|
|
|
- } else {
|
|
|
|
|
- $result = $ViolationProductModel
|
|
|
|
|
- ->where($map)
|
|
|
|
|
- ->orderByDesc('id')
|
|
|
|
|
- ->paginate($limit, ['*'], 'page', $job_page)
|
|
|
|
|
- ->toarray();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $this->company_id = $violation_product_where['company_id'];
|
|
|
$key_name = 'ExportViolationProductJobs_' . $violation_product_where['company_id'];
|
|
$key_name = 'ExportViolationProductJobs_' . $violation_product_where['company_id'];
|
|
|
- if ($job_page == 1) {
|
|
|
|
|
- //创建缓存
|
|
|
|
|
- Cache::put($key_name, [], 60 * 60 * 24);
|
|
|
|
|
- }
|
|
|
|
|
- // 分配数据
|
|
|
|
|
- $result_data = $result['data'];
|
|
|
|
|
- if (count($result_data) < 1) {
|
|
|
|
|
- $export_data_info = Cache::get($key_name);
|
|
|
|
|
- $this->export_download($export_data_info, $violation_product_where['company_id'], $file_id);
|
|
|
|
|
- } else {
|
|
|
|
|
- // 处理责任人展示信息
|
|
|
|
|
- $list_data = $this->processing_responsible_person($result_data);
|
|
|
|
|
- $list_data_info = Cache::get($key_name);
|
|
|
|
|
- $list_new_data = !empty($list_data_info) ? array_merge($list_data_info, $list_data) : $list_data;
|
|
|
|
|
- // 更新缓存
|
|
|
|
|
- Cache::put($key_name, $list_new_data, 60 * 60 * 24);
|
|
|
|
|
- // //继续执行下一页
|
|
|
|
|
- $message_data['job_page'] = $job_page + 1;
|
|
|
|
|
- ExportViolationProductJobs::dispatch($message_data);
|
|
|
|
|
- // ExportViolationProductJobs::dispatchSync($message_data);
|
|
|
|
|
|
|
+ //创建缓存
|
|
|
|
|
+ Cache::put($key_name, [], 60 * 60 * 24);
|
|
|
|
|
+
|
|
|
|
|
+ $query = $ViolationProductModel->where($map);
|
|
|
|
|
+ if ($is_admin != 1 && $company_id != 0) {
|
|
|
|
|
+ $query = $query->where(function ($q) use ($user_id) {
|
|
|
|
|
+ $q->where('first_responsible_person', 'like', "%,{$user_id},%")
|
|
|
|
|
+ ->orWhere('responsible_person', 'like', "%,{$user_id},%")
|
|
|
|
|
+ ->orWhere('source_responsible_person', 'like', "%,{$user_id},%");
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ $query->orderByDesc('id')
|
|
|
|
|
+ ->chunkById($limit, function ($rows) use ($key_name) {
|
|
|
|
|
+ $result_data = $rows->toArray();
|
|
|
|
|
+ if (empty($result_data)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $list_data = $this->processing_responsible_person($result_data);
|
|
|
|
|
+ $list_data_info = Cache::get($key_name) ?: [];
|
|
|
|
|
+ $list_new_data = !empty($list_data_info) ? array_merge($list_data_info, $list_data) : $list_data;
|
|
|
|
|
+ Cache::put($key_name, $list_new_data, 60 * 60 * 24);
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $export_data_info = Cache::get($key_name) ?: [];
|
|
|
|
|
+ $this->export_download($export_data_info, $violation_product_where['company_id'], $file_id);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -422,5 +418,9 @@ class ExportViolationProductJobs implements ShouldQueue
|
|
|
public function failed(\Throwable $exception)
|
|
public function failed(\Throwable $exception)
|
|
|
{
|
|
{
|
|
|
Log::info('job_error', '违规数据-导出违规商品数据队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
Log::info('job_error', '违规数据-导出违规商品数据队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
|
|
|
+ if($this->company_id) {
|
|
|
|
|
+ //失败后清除缓存
|
|
|
|
|
+ Cache::forget('export_violation_product_job_'. $this->company_id);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|