|
@@ -41,52 +41,76 @@ class AiBlogTask extends Command |
|
@@ -41,52 +41,76 @@ class AiBlogTask extends Command |
|
41
|
public function handle(){
|
41
|
public function handle(){
|
|
42
|
$aiBlogTaskModel = new AiBlogTaskModel();
|
42
|
$aiBlogTaskModel = new AiBlogTaskModel();
|
|
43
|
while (true){
|
43
|
while (true){
|
|
44
|
- $info = $aiBlogTaskModel->where('status',1)->where('type',2)->inRandomOrder()->first();
|
|
|
|
45
|
- if(empty($info)){
|
44
|
+ $list = $aiBlogTaskModel->list(['status'=>1,'type'=>2],'id',['*'],'asc',1000);
|
|
|
|
45
|
+ if(empty($list)){
|
|
46
|
sleep(300);
|
46
|
sleep(300);
|
|
47
|
continue;
|
47
|
continue;
|
|
48
|
}
|
48
|
}
|
|
49
|
- $info = $info->toArray();
|
|
|
|
50
|
- echo '开始->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
51
|
- //获取配置
|
|
|
|
52
|
- $aiSettingInfo = $this->getSetting($info['project_id']);
|
|
|
|
53
|
- $aiBlogService = new AiBlogService();
|
|
|
|
54
|
- $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
55
|
- $aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
56
|
- $aiBlogService->task_id = $info['task_id'];
|
|
|
|
57
|
- $result = $aiBlogService->getDetail();
|
|
|
|
58
|
- if(!isset($result['status'])){
|
|
|
|
59
|
- continue;
|
|
|
|
60
|
- }
|
|
|
|
61
|
- if($result['status'] != 200){
|
|
|
|
62
|
- sleep(10);
|
|
|
|
63
|
- continue;
|
|
|
|
64
|
- }
|
|
|
|
65
|
- //保存当前项目ai_blog数据
|
|
|
|
66
|
- ProjectServer::useProject($info['project_id']);
|
|
|
|
67
|
- $aiBlogModel = new AiBlog();
|
|
|
|
68
|
- $aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']);
|
|
|
|
69
|
- if($aiBlogInfo === false){
|
|
|
|
70
|
- $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
|
|
|
|
71
|
- continue;
|
49
|
+ $updateProject = [];
|
|
|
|
50
|
+ foreach ($list as $item){
|
|
|
|
51
|
+ echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
52
|
+ //获取配置
|
|
|
|
53
|
+ $aiSettingInfo = $this->getSetting($item['project_id']);
|
|
|
|
54
|
+ $aiBlogService = new AiBlogService();
|
|
|
|
55
|
+ $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
56
|
+ $aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
57
|
+ $aiBlogService->task_id = $item['task_id'];
|
|
|
|
58
|
+ $result = $aiBlogService->getDetail();
|
|
|
|
59
|
+ if($result['status'] != 200){
|
|
|
|
60
|
+ sleep(10);
|
|
|
|
61
|
+ continue;
|
|
|
|
62
|
+ }
|
|
|
|
63
|
+ //保存当前项目ai_blog数据
|
|
|
|
64
|
+ ProjectServer::useProject($item['project_id']);
|
|
|
|
65
|
+ $aiBlogModel = new AiBlog();
|
|
|
|
66
|
+ $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);
|
|
|
|
67
|
+ if($aiBlogInfo === false){
|
|
|
|
68
|
+ $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
|
|
|
|
69
|
+ continue;
|
|
|
|
70
|
+ }
|
|
|
|
71
|
+ if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {
|
|
|
|
72
|
+ $updateProject[$item['project_id']][] = $result['data']['author_id'];
|
|
|
|
73
|
+ }
|
|
|
|
74
|
+ //拿到返回的路由查看是否重复
|
|
|
|
75
|
+ $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
|
|
|
|
76
|
+ if($route != $result['data']['url']){
|
|
|
|
77
|
+ $aiBlogService->updateDetail(['route'=>$this->param['route']]);
|
|
|
|
78
|
+ }
|
|
|
|
79
|
+ $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);
|
|
|
|
80
|
+ DB::disconnect('custom_mysql');
|
|
|
|
81
|
+ $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
|
|
72
|
}
|
82
|
}
|
|
73
|
- //拿到返回的路由查看是否重复
|
|
|
|
74
|
- $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $info['project_id']);
|
|
|
|
75
|
- if($route != $result['data']['url']){
|
|
|
|
76
|
- $aiBlogService->updateDetail(['route'=>$this->param['route']]);
|
|
|
|
77
|
- }
|
|
|
|
78
|
- $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$info['task_id']]);
|
|
|
|
79
|
- $this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']);
|
83
|
+ //TODO::更新列表页及作者
|
|
|
|
84
|
+ $this->updateProject($updateProject);
|
|
|
|
85
|
+ echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
86
|
+ }
|
|
|
|
87
|
+ return true;
|
|
|
|
88
|
+ }
|
|
|
|
89
|
+
|
|
|
|
90
|
+ /**
|
|
|
|
91
|
+ * @remark :更新项目作者页面及列表页
|
|
|
|
92
|
+ * @name :updateProject
|
|
|
|
93
|
+ * @author :lyh
|
|
|
|
94
|
+ * @method :post
|
|
|
|
95
|
+ * @time :2025/3/4 10:25
|
|
|
|
96
|
+ */
|
|
|
|
97
|
+ public function updateProject($updateProject){
|
|
|
|
98
|
+ if(empty($updateProject)){
|
|
|
|
99
|
+ return true;
|
|
|
|
100
|
+ }
|
|
|
|
101
|
+ foreach ($updateProject as $project_id => $author){
|
|
|
|
102
|
+ ProjectServer::useProject($project_id);
|
|
|
|
103
|
+ $aiSettingInfo = $this->getSetting($project_id);
|
|
80
|
$this->updateBlogList($aiSettingInfo);
|
104
|
$this->updateBlogList($aiSettingInfo);
|
|
|
|
105
|
+ //更新作者
|
|
|
|
106
|
+ foreach ($author as $val){
|
|
|
|
107
|
+ $this->updateAiBlogAuthor($aiSettingInfo,$val);
|
|
|
|
108
|
+ }
|
|
81
|
DB::disconnect('custom_mysql');
|
109
|
DB::disconnect('custom_mysql');
|
|
82
|
- //修改任务状态
|
|
|
|
83
|
- $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
|
|
|
|
84
|
- echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
85
|
}
|
110
|
}
|
|
86
|
return true;
|
111
|
return true;
|
|
87
|
}
|
112
|
}
|
|
88
|
|
113
|
|
|
89
|
-
|
|
|
|
90
|
/**
|
114
|
/**
|
|
91
|
* @remark :获取项目配置
|
115
|
* @remark :获取项目配置
|
|
92
|
* @name :getSetting
|
116
|
* @name :getSetting
|