|
@@ -21,11 +21,12 @@ use Illuminate\Console\Command; |
|
@@ -21,11 +21,12 @@ use Illuminate\Console\Command; |
|
21
|
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
|
21
|
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
|
|
22
|
use Illuminate\Support\Facades\Cache;
|
22
|
use Illuminate\Support\Facades\Cache;
|
|
23
|
use Illuminate\Support\Facades\DB;
|
23
|
use Illuminate\Support\Facades\DB;
|
|
|
|
24
|
+use Illuminate\Support\Facades\Redis;
|
|
24
|
use function Symfony\Component\String\s;
|
25
|
use function Symfony\Component\String\s;
|
|
25
|
|
26
|
|
|
26
|
/***
|
27
|
/***
|
|
27
|
* @remark :根据项目更新blog列表
|
28
|
* @remark :根据项目更新blog列表
|
|
28
|
- * @name :AiBlogListTask
|
29
|
+ * @name :AiBlogListProjectTask
|
|
29
|
* @author :lyh
|
30
|
* @author :lyh
|
|
30
|
* @method :post
|
31
|
* @method :post
|
|
31
|
* @time :2025/3/6 9:45
|
32
|
* @time :2025/3/6 9:45
|
|
@@ -37,24 +38,45 @@ class AiBlogListTask extends Command |
|
@@ -37,24 +38,45 @@ class AiBlogListTask extends Command |
|
37
|
*
|
38
|
*
|
|
38
|
* @var string
|
39
|
* @var string
|
|
39
|
*/
|
40
|
*/
|
|
40
|
- protected $signature = 'save_ai_blog_list {project_id}';
|
41
|
+ protected $signature = 'save_ai_blog_list_task';
|
|
41
|
|
42
|
|
|
42
|
/**
|
43
|
/**
|
|
43
|
* The console command description.
|
44
|
* The console command description.
|
|
44
|
*
|
45
|
*
|
|
45
|
* @var string
|
46
|
* @var string
|
|
46
|
*/
|
47
|
*/
|
|
47
|
- protected $description = '生成blog列表';
|
48
|
+ protected $description = '生成blog列表页';
|
|
48
|
|
49
|
|
|
49
|
public function handle(){
|
50
|
public function handle(){
|
|
50
|
- $project_id = $this->argument('project_id');
|
|
|
|
51
|
- @file_put_contents(storage_path('logs/lyh_error.log'), var_export('执行的项目id->'.$project_id, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
52
|
- ProjectServer::useProject($project_id);
|
|
|
|
53
|
- $projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
54
|
- $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
55
|
- $this->updateBlogList($aiSettingInfo);
|
|
|
|
56
|
- $this->curlDelRoute($project_id);
|
|
|
|
57
|
- DB::disconnect('custom_mysql');
|
51
|
+ while (true){
|
|
|
|
52
|
+ $task_id = $this->getTaskId();
|
|
|
|
53
|
+ if(empty($task_id)){
|
|
|
|
54
|
+ sleep(200);
|
|
|
|
55
|
+ continue;
|
|
|
|
56
|
+ }
|
|
|
|
57
|
+ $aiBlogTaskModel = new AiBlogTaskModel();
|
|
|
|
58
|
+ $info = $aiBlogTaskModel->read(['id'=>$task_id]);
|
|
|
|
59
|
+ if($info === false){
|
|
|
|
60
|
+ echo date('Y-m-d H:i:s').',当前数据不存在或者已被删除。'.PHP_EOL;
|
|
|
|
61
|
+ }
|
|
|
|
62
|
+ $project_id = $info['project_id'];
|
|
|
|
63
|
+ echo '执行的项目ID:'.$info['project_id'].PHP_EOL;
|
|
|
|
64
|
+ ProjectServer::useProject($project_id);
|
|
|
|
65
|
+ $projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
66
|
+ $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
67
|
+ $res = $this->updateBlogList($aiSettingInfo);
|
|
|
|
68
|
+ if($res){
|
|
|
|
69
|
+ $aiBlogTaskModel->edit(['status'=>2],['id'=>$task_id]);
|
|
|
|
70
|
+ }else{
|
|
|
|
71
|
+ if($info['sort'] >= 5){
|
|
|
|
72
|
+ $aiBlogTaskModel->edit(['status'=>9],['id'=>$task_id]);
|
|
|
|
73
|
+ }else{
|
|
|
|
74
|
+ $aiBlogTaskModel->edit(['status'=>9,'sort'=>($info['sort'] + 1)],['id'=>$task_id]);
|
|
|
|
75
|
+ }
|
|
|
|
76
|
+ }
|
|
|
|
77
|
+ $this->curlDelRoute($project_id);
|
|
|
|
78
|
+ DB::disconnect('custom_mysql');
|
|
|
|
79
|
+ }
|
|
58
|
return true;
|
80
|
return true;
|
|
59
|
}
|
81
|
}
|
|
60
|
|
82
|
|
|
@@ -73,8 +95,8 @@ class AiBlogListTask extends Command |
|
@@ -73,8 +95,8 @@ class AiBlogListTask extends Command |
|
73
|
$saveData = [];
|
95
|
$saveData = [];
|
|
74
|
$result = $aiBlogService->getAiBlogList($page,15);
|
96
|
$result = $aiBlogService->getAiBlogList($page,15);
|
|
75
|
if(!isset($result['status']) || $result['status'] != 200){
|
97
|
if(!isset($result['status']) || $result['status'] != 200){
|
|
76
|
- echo '请示失败。'.json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
77
|
- return true;
|
98
|
+ echo '请求失败。'.json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
99
|
+ return false;
|
|
78
|
}
|
100
|
}
|
|
79
|
$total_page = $result['data']['total_page'];
|
101
|
$total_page = $result['data']['total_page'];
|
|
80
|
//组装数据保存
|
102
|
//组装数据保存
|
|
@@ -90,6 +112,9 @@ class AiBlogListTask extends Command |
|
@@ -90,6 +112,9 @@ class AiBlogListTask extends Command |
|
90
|
'route'=>$page,
|
112
|
'route'=>$page,
|
|
91
|
'text'=>$result['data']['section'],
|
113
|
'text'=>$result['data']['section'],
|
|
92
|
];
|
114
|
];
|
|
|
|
115
|
+ }else{
|
|
|
|
116
|
+ echo '请求失败。'.json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
117
|
+ return false;
|
|
93
|
}
|
118
|
}
|
|
94
|
}
|
119
|
}
|
|
95
|
$aiBlogListModel = new AiBlogList();
|
120
|
$aiBlogListModel = new AiBlogList();
|
|
@@ -97,6 +122,7 @@ class AiBlogListTask extends Command |
|
@@ -97,6 +122,7 @@ class AiBlogListTask extends Command |
|
97
|
//写一条路由信息
|
122
|
//写一条路由信息
|
|
98
|
$aiBlogListModel->truncate();
|
123
|
$aiBlogListModel->truncate();
|
|
99
|
$aiBlogListModel->insertAll($saveData);
|
124
|
$aiBlogListModel->insertAll($saveData);
|
|
|
|
125
|
+ return true;
|
|
100
|
}
|
126
|
}
|
|
101
|
return true;
|
127
|
return true;
|
|
102
|
}
|
128
|
}
|
|
@@ -126,4 +152,27 @@ class AiBlogListTask extends Command |
|
@@ -126,4 +152,27 @@ class AiBlogListTask extends Command |
|
126
|
}
|
152
|
}
|
|
127
|
return true;
|
153
|
return true;
|
|
128
|
}
|
154
|
}
|
|
|
|
155
|
+
|
|
|
|
156
|
+ /**
|
|
|
|
157
|
+ * 获取任务id
|
|
|
|
158
|
+ * @param int $finish_at
|
|
|
|
159
|
+ * @return mixed
|
|
|
|
160
|
+ */
|
|
|
|
161
|
+ public function getTaskId($finish_at = 2)
|
|
|
|
162
|
+ {
|
|
|
|
163
|
+ $keys = 'ai_blog_list_task';
|
|
|
|
164
|
+ $task_id = Redis::rpop($keys);
|
|
|
|
165
|
+ if (empty($task_id)) {
|
|
|
|
166
|
+ $aiBlogTaskModel = new AiBlogTaskModel();
|
|
|
|
167
|
+ $finish_at = date('Y-m-d H:i:s', strtotime('-' . $finish_at . ' hour'));
|
|
|
|
168
|
+ $ids = $aiBlogTaskModel->formatQuery(['status'=>$aiBlogTaskModel::STATUS_RUNNING, 'type'=>$aiBlogTaskModel::TYPE_LIST, 'updated_at'=>['<=',$finish_at]])->pluck('id');
|
|
|
|
169
|
+ if(!empty($ids)){
|
|
|
|
170
|
+ foreach ($ids as $id) {
|
|
|
|
171
|
+ Redis::lpush($keys, $id);
|
|
|
|
172
|
+ }
|
|
|
|
173
|
+ }
|
|
|
|
174
|
+ $task_id = Redis::rpop($keys);
|
|
|
|
175
|
+ }
|
|
|
|
176
|
+ return $task_id;
|
|
|
|
177
|
+ }
|
|
129
|
} |
178
|
} |