|
|
@@ -1,172 +1,184 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace App\Console\Commands;
|
|
|
-
|
|
|
-use App\Facades\Servers\Logs\Log;
|
|
|
-use App\Models\CollectProduct;
|
|
|
-use App\Models\CollectEquipment;
|
|
|
-use App\Models\CollectTask;
|
|
|
-use App\Models\CollectTaskAllocate;
|
|
|
-use App\Models\CollectRegion;
|
|
|
-use Carbon\Carbon;
|
|
|
-use Illuminate\Console\Command;
|
|
|
-
|
|
|
-class CollectTaskCommand extends Command
|
|
|
-{
|
|
|
- protected $signature = 'collect-task';
|
|
|
-
|
|
|
- protected $description = '定时分配采集任务设备';
|
|
|
- public function __construct()
|
|
|
- {
|
|
|
- parent::__construct();
|
|
|
- }
|
|
|
- public function handle()
|
|
|
- {
|
|
|
- Log::info('collect-task','分配采集任务开始');
|
|
|
- $CollectTaskModel = new CollectTask();
|
|
|
- $endTime = strtotime(date('Y-m-d',time())) + 86400;
|
|
|
- $time = time();
|
|
|
- $week = date('w');
|
|
|
- $map = [
|
|
|
- ['status','=',0],
|
|
|
- ['sampling_start_time','<=',$time],
|
|
|
- ];
|
|
|
- $collectProductList = CollectProduct::query()
|
|
|
- ->where($map)
|
|
|
- ->where(function ($query) use ($time) {
|
|
|
- $query->where('sampling_end_time', '>=', $time)
|
|
|
- ->orWhere('sampling_end_time', 0);
|
|
|
- })
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
- if ($collectProductList){
|
|
|
- $region = [];
|
|
|
- $region = CollectRegion::query()->value('id');
|
|
|
- foreach ($collectProductList as $collectProduct){
|
|
|
- if ($collectProduct['sampling_cycle']){
|
|
|
- $weekArray = explode(',',$collectProduct['sampling_cycle']);
|
|
|
- if (!in_array($week,$weekArray)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- //查询任务最新执行时间
|
|
|
- $collectTask = $CollectTaskModel::query()->where([['collect_product_id','=',$collectProduct['id']]])->select('insert_time')->orderBy('insert_time','desc')->first();
|
|
|
- if($collectTask){
|
|
|
- if (date('Y-m-d',time()) == date('Y-m-d',$collectTask['insert_time'])){
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!$collectProduct['platform']){
|
|
|
- continue;
|
|
|
- }
|
|
|
- $data = [];
|
|
|
- $platforms = explode(',',$collectProduct['platform']);
|
|
|
- if ($collectProduct['round_number'] > 1 && $collectProduct['round_number_config']){
|
|
|
- $data = $this->collectTask($collectProduct,$platforms,$region,$collectProduct['round_number_config']);
|
|
|
- }else{
|
|
|
- $data = $this->collectTask($collectProduct,$platforms,$region);
|
|
|
- }
|
|
|
-
|
|
|
- //添加到任务
|
|
|
- $res = $CollectTaskModel::query()->insert($data);
|
|
|
- if (!$res){
|
|
|
- Log::info('collect-task','添加采集任务失败');
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- Log::info('collect-task','暂无采集任务');
|
|
|
- }
|
|
|
- Log::info('collect-task','分配采集任务结束');
|
|
|
- return 0;
|
|
|
- }
|
|
|
- public function collectTask($collectProduct,$platforms,$region,$roundNumberConfig = null){
|
|
|
- $data = [];
|
|
|
- if ($roundNumberConfig){
|
|
|
- $roundNumberConfig = json_decode($roundNumberConfig,true);
|
|
|
- foreach ($roundNumberConfig as $roundNumber){
|
|
|
- foreach ($platforms as $platform){
|
|
|
- if ($collectProduct['region'] > 0 && $region){
|
|
|
- foreach ($region as $regionId){
|
|
|
- $data[] = [
|
|
|
- 'collect_product_id' => $collectProduct['id'],
|
|
|
- 'platform' => $platform,
|
|
|
- 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
- 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
- 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
- 'company_id' => $collectProduct['company_id'],
|
|
|
- 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
- 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
- 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
- 'max_equipment_number' => 1,
|
|
|
- 'status' => 0,
|
|
|
- 'insert_time' => time(),
|
|
|
- 'region_id' => $regionId,
|
|
|
- 'round_start_time' => $roundNumber['round_start_time'],
|
|
|
- 'round_end_time' => $roundNumber['round_end_time'],
|
|
|
- ];
|
|
|
- }
|
|
|
- }else{
|
|
|
- $data[] = [
|
|
|
- 'collect_product_id' => $collectProduct['id'],
|
|
|
- 'platform' => $platform,
|
|
|
- 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
- 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
- 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
- 'company_id' => $collectProduct['company_id'],
|
|
|
- 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
- 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
- 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
- 'max_equipment_number' => 1,
|
|
|
- 'status' => 0,
|
|
|
- 'insert_time' => time(),
|
|
|
- 'region_id' => $collectProduct['region'],
|
|
|
- 'round_start_time' => $roundNumber['round_start_time'],
|
|
|
- 'round_end_time' => $roundNumber['round_end_time'],
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- foreach ($platforms as $platform){
|
|
|
- if ($collectProduct['region'] > 0 && $region){
|
|
|
- foreach ($region as $regionId){
|
|
|
- $data[] = [
|
|
|
- 'collect_product_id' => $collectProduct['id'],
|
|
|
- 'platform' => $platform,
|
|
|
- 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
- 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
- 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
- 'company_id' => $collectProduct['company_id'],
|
|
|
- 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
- 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
- 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
- 'max_equipment_number' => 1,
|
|
|
- 'status' => 0,
|
|
|
- 'insert_time' => time(),
|
|
|
- 'region_id' => $regionId,
|
|
|
- ];
|
|
|
- }
|
|
|
- }else{
|
|
|
- $data[] = [
|
|
|
- 'collect_product_id' => $collectProduct['id'],
|
|
|
- 'platform' => $platform,
|
|
|
- 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
- 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
- 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
- 'company_id' => $collectProduct['company_id'],
|
|
|
- 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
- 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
- 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
- 'max_equipment_number' => 1,
|
|
|
- 'status' => 0,
|
|
|
- 'insert_time' => time(),
|
|
|
- 'region_id' => $collectProduct['region'],
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- return $data;
|
|
|
- }
|
|
|
-}
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Console\Commands;
|
|
|
+
|
|
|
+use App\Facades\Servers\Logs\Log;
|
|
|
+use App\Models\CollectProduct;
|
|
|
+use App\Models\CollectEquipment;
|
|
|
+use App\Models\CollectTask;
|
|
|
+use App\Models\CollectTaskAllocate;
|
|
|
+use App\Models\CollectRegion;
|
|
|
+use Carbon\Carbon;
|
|
|
+use Illuminate\Console\Command;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+class CollectTaskCommand extends Command
|
|
|
+{
|
|
|
+ protected $signature = 'collect-task';
|
|
|
+
|
|
|
+ protected $description = '定时分配采集任务设备';
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ }
|
|
|
+ public function handle()
|
|
|
+ {
|
|
|
+ Log::info('collect-task','分配采集任务开始');
|
|
|
+ $CollectTaskModel = new CollectTask();
|
|
|
+ $endTime = strtotime(date('Y-m-d',time())) + 86400;
|
|
|
+ $time = time();
|
|
|
+ $week = date('w');
|
|
|
+ if ($week == 0){
|
|
|
+ $week = 7;
|
|
|
+ }
|
|
|
+ $map = [
|
|
|
+ ['status','=',0],
|
|
|
+ ['sampling_start_time','<=',$time],
|
|
|
+ ];
|
|
|
+ $collectProductList = CollectProduct::query()
|
|
|
+ ->leftJoin('collect_product_keyword','collect_product.id','=','collect_product_keyword.collect_product_id')
|
|
|
+ ->where($map)
|
|
|
+ ->where(function ($query) use ($time) {
|
|
|
+ $query->where('collect_product.sampling_end_time', '>=', $time)
|
|
|
+ ->orWhere('collect_product.sampling_end_time', 0);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'collect_product.*',
|
|
|
+ DB::raw('GROUP_CONCAT(retrieve_collect_product_keyword.keyword SEPARATOR ",") as product_keyword')
|
|
|
+ )
|
|
|
+ ->groupBy('collect_product.id')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ if ($collectProductList){
|
|
|
+ $region = [];
|
|
|
+ $region = CollectRegion::query()->value('id');
|
|
|
+ foreach ($collectProductList as $collectProduct){
|
|
|
+ if ($collectProduct['sampling_cycle']){
|
|
|
+ $weekArray = explode(',',$collectProduct['sampling_cycle']);
|
|
|
+ if (!in_array($week,$weekArray)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //查询任务最新执行时间
|
|
|
+ $collectTask = $CollectTaskModel::query()->where([['collect_product_id','=',$collectProduct['id']]])->select('insert_time')->orderBy('insert_time','desc')->first();
|
|
|
+ if($collectTask){
|
|
|
+ if (date('Y-m-d',time()) == date('Y-m-d',$collectTask['insert_time'])){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$collectProduct['platform']){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $data = [];
|
|
|
+ $platforms = explode(',',$collectProduct['platform']);
|
|
|
+ if ($collectProduct['round_number'] > 1 && $collectProduct['round_number_config']){
|
|
|
+ $data = $this->collectTask($collectProduct,$platforms,$region,$collectProduct['round_number_config']);
|
|
|
+ }else{
|
|
|
+ $data = $this->collectTask($collectProduct,$platforms,$region);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加到任务
|
|
|
+ $res = $CollectTaskModel::query()->insert($data);
|
|
|
+ if (!$res){
|
|
|
+ Log::info('collect-task','添加采集任务失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ Log::info('collect-task','暂无采集任务');
|
|
|
+ }
|
|
|
+ Log::info('collect-task','分配采集任务结束');
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ public function collectTask($collectProduct,$platforms,$region,$roundNumberConfig = null){
|
|
|
+ $data = [];
|
|
|
+ if ($roundNumberConfig){
|
|
|
+ $roundNumberConfig = json_decode($roundNumberConfig,true);
|
|
|
+ foreach ($roundNumberConfig as $roundNumber){
|
|
|
+ foreach ($platforms as $platform){
|
|
|
+ if ($collectProduct['region'] > 0 && $region){
|
|
|
+ foreach ($region as $regionId){
|
|
|
+ $data[] = [
|
|
|
+ 'collect_product_id' => $collectProduct['id'],
|
|
|
+ 'platform' => $platform,
|
|
|
+ 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
+ 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
+ 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
+ 'company_id' => $collectProduct['company_id'],
|
|
|
+ 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
+ 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
+ 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
+ 'max_equipment_number' => 1,
|
|
|
+ 'status' => 0,
|
|
|
+ 'insert_time' => time(),
|
|
|
+ 'region_id' => $regionId,
|
|
|
+ 'round_start_time' => $roundNumber['round_start_time'],
|
|
|
+ 'round_end_time' => $roundNumber['round_end_time'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $data[] = [
|
|
|
+ 'collect_product_id' => $collectProduct['id'],
|
|
|
+ 'platform' => $platform,
|
|
|
+ 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
+ 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
+ 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
+ 'company_id' => $collectProduct['company_id'],
|
|
|
+ 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
+ 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
+ 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
+ 'max_equipment_number' => 1,
|
|
|
+ 'status' => 0,
|
|
|
+ 'insert_time' => time(),
|
|
|
+ 'region_id' => $collectProduct['region'],
|
|
|
+ 'round_start_time' => $roundNumber['round_start_time'],
|
|
|
+ 'round_end_time' => $roundNumber['round_end_time'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ foreach ($platforms as $platform){
|
|
|
+ if ($collectProduct['region'] > 0 && $region){
|
|
|
+ foreach ($region as $regionId){
|
|
|
+ $data[] = [
|
|
|
+ 'collect_product_id' => $collectProduct['id'],
|
|
|
+ 'platform' => $platform,
|
|
|
+ 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
+ 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
+ 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
+ 'company_id' => $collectProduct['company_id'],
|
|
|
+ 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
+ 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
+ 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
+ 'product_keyword' => $collectProduct['product_keyword'],
|
|
|
+ 'max_equipment_number' => 1,
|
|
|
+ 'status' => 0,
|
|
|
+ 'insert_time' => time(),
|
|
|
+ 'region_id' => $regionId,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $data[] = [
|
|
|
+ 'collect_product_id' => $collectProduct['id'],
|
|
|
+ 'platform' => $platform,
|
|
|
+ 'product_name' => $collectProduct['product_name'] ?? '',
|
|
|
+ 'product_specs' => $collectProduct['product_specs'] ?? '',
|
|
|
+ 'product_brand' => $collectProduct['product_brand'] ?? '',
|
|
|
+ 'company_id' => $collectProduct['company_id'],
|
|
|
+ 'sampling_cycle' => $collectProduct['sampling_cycle'],
|
|
|
+ 'sampling_start_time' => $collectProduct['sampling_start_time'],
|
|
|
+ 'sampling_end_time' => $collectProduct['sampling_end_time'],
|
|
|
+ 'product_keyword' => $collectProduct['product_keyword'],
|
|
|
+ 'max_equipment_number' => 1,
|
|
|
+ 'status' => 0,
|
|
|
+ 'insert_time' => time(),
|
|
|
+ 'region_id' => $collectProduct['region'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+}
|