定时任务提交

This commit is contained in:
Ghost
2025-03-24 16:42:36 +08:00
parent af2006f13e
commit 2df22cdecd
32 changed files with 1091 additions and 94 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use think\Queue;
use app\job\AccountListJob;
class AccountListCommand extends Command
{
protected function configure()
{
$this->setName('account:list')
->setDescription('获取公司账号列表,并根据分页自动处理下一页');
}
protected function execute(Input $input, Output $output)
{
$output->writeln('开始处理公司账号列表任务...');
try {
// 初始页码
$pageIndex = 0;
$pageSize = 100; // 每页获取100条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
$output->writeln('公司账号列表任务已添加到队列');
} catch (\Exception $e) {
Log::error('公司账号列表任务添加失败:' . $e->getMessage());
$output->writeln('公司账号列表任务添加失败:' . $e->getMessage());
return false;
}
return true;
}
/**
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
*/
protected function addToQueue($pageIndex, $pageSize)
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
// 添加到队列,设置任务名为 account_list
Queue::push(AccountListJob::class, $data, 'account_list');
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use think\Queue;
use app\job\DeviceListJob;
class DeviceListCommand extends Command
{
protected function configure()
{
$this->setName('device:list')
->setDescription('获取设备列表,并根据分页自动处理下一页');
}
protected function execute(Input $input, Output $output)
{
$output->writeln('开始处理设备列表任务...');
try {
// 初始页码
$pageIndex = 0;
$pageSize = 100; // 每页获取100条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
$output->writeln('设备列表任务已添加到队列');
} catch (\Exception $e) {
Log::error('设备列表任务添加失败:' . $e->getMessage());
$output->writeln('设备列表任务添加失败:' . $e->getMessage());
return false;
}
return true;
}
/**
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
*/
protected function addToQueue($pageIndex, $pageSize)
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
// 添加到队列,设置任务名为 device_list
Queue::push(DeviceListJob::class, $data, 'device_list');
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use think\Queue;
use app\job\FriendTaskJob;
class FriendTaskCommand extends Command
{
protected function configure()
{
$this->setName('friend:task')
->setDescription('获取添加好友认为列表,并根据分页自动处理下一页');
}
protected function execute(Input $input, Output $output)
{
$output->writeln('开始处理添加好友任务...');
try {
// 初始页码
$pageIndex = 0;
$pageSize = 100; // 每页获取100条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
$output->writeln('添加好友任务已添加到队列');
} catch (\Exception $e) {
Log::error('添加好友任务添加失败:' . $e->getMessage());
$output->writeln('添加好友任务添加失败:' . $e->getMessage());
return false;
}
return true;
}
/**
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
*/
protected function addToQueue($pageIndex, $pageSize)
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
// 添加到队列,设置任务名为 friend_task
Queue::push(FriendTaskJob::class, $data, 'friend_task');
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use think\Queue;
use app\job\WechatChatroomJob;
class WechatChatroomCommand extends Command
{
protected function configure()
{
$this->setName('wechatChatroom:list')
->setDescription('获取微信聊天室列表,并根据分页自动处理下一页');
}
protected function execute(Input $input, Output $output)
{
$output->writeln('开始处理微信聊天室列表任务...');
try {
// 初始页码
$pageIndex = 0;
$pageSize = 100; // 每页获取100条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
$output->writeln('微信聊天室列表任务已添加到队列');
} catch (\Exception $e) {
Log::error('微信聊天室列表任务添加失败:' . $e->getMessage());
$output->writeln('微信聊天室列表任务添加失败:' . $e->getMessage());
return false;
}
return true;
}
/**
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
*/
protected function addToQueue($pageIndex, $pageSize)
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
// 添加到队列,设置任务名为 device_list
Queue::push(WechatChatroomJob::class, $data, 'wechat_chatroom');
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use think\Queue;
use app\job\WechatFriendJob;
class WechatFriendCommand extends Command
{
protected function configure()
{
$this->setName('wechatFriends:list')
->setDescription('获微信列表,并根据分页自动处理下一页');
}
protected function execute(Input $input, Output $output)
{
$output->writeln('开始处理微信列表任务...');
try {
// 初始页码
$pageIndex = 0;
$pageSize = 100; // 每页获取100条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
$output->writeln('微信列表任务已添加到队列');
} catch (\Exception $e) {
Log::error('微信列表任务添加失败:' . $e->getMessage());
$output->writeln('微信列表任务添加失败:' . $e->getMessage());
return false;
}
return true;
}
/**
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
*/
protected function addToQueue($pageIndex, $pageSize)
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
// 添加到队列,设置任务名为 wechat_friends
Queue::push(WechatFriendJob::class, $data, 'wechat_friends');
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use think\Queue;
use app\job\WechatListJob;
class WechatListCommand extends Command
{
protected function configure()
{
$this->setName('wechat:list')
->setDescription('获取微信客服列表,并根据分页自动处理下一页');
}
protected function execute(Input $input, Output $output)
{
$output->writeln('开始处理微信客服列表任务...');
try {
// 初始页码
$pageIndex = 0;
$pageSize = 100; // 每页获取100条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
$output->writeln('微信客服列表任务已添加到队列');
} catch (\Exception $e) {
Log::error('微信客服列表任务添加失败:' . $e->getMessage());
$output->writeln('微信客服列表任务添加失败:' . $e->getMessage());
return false;
}
return true;
}
/**
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
*/
protected function addToQueue($pageIndex, $pageSize)
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
// 添加到队列,设置任务名为 wechat_list
Queue::push(WechatListJob::class, $data, 'wechat_list');
}
}