作者 李美松

Revert "优化程序"

This reverts commit 2e4661c6
... ... @@ -12,8 +12,6 @@ use Illuminate\Http\File;
class ProjectFilePDF extends Command
{
use CmdSignal;
/**
* The name and signature of the console command.
*
... ... @@ -34,11 +32,6 @@ class ProjectFilePDF extends Command
protected $time;
// 最大支持5个进程
public $maxRunNumber = 50;
public $fileController;
/**
* Create a new command instance.
*
... ... @@ -46,100 +39,73 @@ class ProjectFilePDF extends Command
*/
public function __construct()
{
$this->AiccWechat = new ProjectAssociation();
$this->DataFile = new DataFile();
$this->time = date("Y-m");
$this->fileController = new FileController();
$this->AiccWechat = new ProjectAssociation();
$this->DataFile = new DataFile();
$this->time = date("Y-m");
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$data = $this->get_data();
# 详细数据
$items = $data['items'];
# 总分页
$totalPage = $data['totalPage'];
$this->dataPush($items);
if ($totalPage > 1) {
for ($page = 2; $page <= $totalPage; $page++) {
$da = $this->get_data();
$this->dataPush($da['items']);
}
}
$this->info('生成pdf完成');
return 0;
}
// public function handle()
// {
// $status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题1
// $lists = $this->DataFile::query()->where('status', $status)
// ->where('project_id', '!=', 0)
// ->where('friend_id', '!=', 0)
// ->where('user_id', '!=', 0)
// ->where('created_at', 'like', $this->time . '%')->first();
// if (is_null($lists)) {
// $this->error('没有任务,等待中');
// sleep(60);
// return 0;
// }
// $key = $this->signature . '-' . $lists->id;
// $count = redis_get($key);
// $project_id = $lists->project_id;
// $user_id = $lists->user_id;
// $friend_id = $lists->friend_id;
// // todo 根据项目查询数据
// $project_data = [];
// $html = $this->html($project_data);
// $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
// $file_path = $this->savePDF($html, $filename);
// if (empty($file_path)) {
// $this->error('pdf生成失败!');
// return 0;
// }
// $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
// if (!$isRes) {
// if ($count == 2) {
// $lists->is_pdf = 2;
// $lists->save();
// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
// } else {
// redis_add($key, $count + 1);
// $this->error('项目文件数据保存失败! - ' . $key);
// }
// }
// $lists->is_pdf = 1;
// $lists->save();
// $this->error('项目文件数据保存成功!');
// return 0;
// }
public function start(): int
/**
* 数据生成并保存
* @param array $items
* @return void
*/
public function dataPush(array $items)
{
$status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题
$lists = $this->DataFile::query()->where('status', $status)
->where('project_id', '!=', 0)
->where('friend_id', '!=', 0)
->where('user_id', '!=', 0)
->where('created_at', 'like', $this->time . '%')->first();
if (is_null($lists)) {
$this->debug_echo('没有任务,等待中');
sleep(60);
return 0;
foreach ($items as $item) {
$project_id = $item->project_id;
$user_id = $item->user_id;
$friend_id = $item->friend_id;
// todo 根据项目查询数据
$project_data = [];
$html = $this->html($project_data);
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
$file_path = $this->savePDF($html, $filename);
var_dump($file_path);
$this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
}
$key = $this->signature . '-' . $lists->id;
$count = redis_get($key);
$project_id = $lists->project_id;
$user_id = $lists->user_id;
$friend_id = $lists->friend_id;
// todo 根据项目查询数据
$project_data = [];
$html = $this->html($project_data);
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
$file_path = $this->savePDF($html, $filename);
if (empty($file_path)) {
$this->debug_echo('pdf生成失败!');
}
public function get_data($page = 1, $perPage = 20)
{
$data = $this->AiccWechat->allData($page, $perPage);
# 总条数
$total = $data['total'];
if (empty($total)) {
$this->error('暂无绑定AICC微信数据');
return 0;
}
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
if (!$isRes) {
if ($count == 2) {
$lists->is_pdf = 2;
$lists->save();
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
} else {
redis_add($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
}
$lists->is_pdf = 1;
$lists->save();
$this->debug_echo('项目文件数据保存成功!');
return 0;
# 详细数据
$items = $data['items'];
# 总分页
$totalPage = $data['totalPage'];
# 当前页
$currentPage = $data['currentPage'];
return compact('total', 'items', 'totalPage', 'currentPage');
}
public function savePDF($html, $filename)
... ... @@ -172,15 +138,16 @@ class ProjectFilePDF extends Command
// 获取PDF内容
$pdfContent = $dompdf->output();
$fileController = new FileController();
// 将PDF内容保存到文件
@file_put_contents($savePath, $pdfContent);
// 创建一个文件实例
$file = new File($savePath);
// var_dump($file->getExtension());
// exit();
echo $this->fileController->single($file);
var_dump($file->getFilename());
exit();
return $fileController->single($file);
}
/**
... ...
... ... @@ -24,12 +24,10 @@ class WebsiteData extends Command
protected $description = '向AICC推送数据';
// 最大支持5个进程
public int $maxRunNumber = 50;
public $maxRunNumber = 50;
protected $time;
protected $url;
/**
* Create a new command instance.
*
... ... @@ -37,17 +35,13 @@ class WebsiteData extends Command
*/
public function __construct()
{
$this->time = date('Y-m');
$this->url = env('AICC_URL');
$this->time = date('y-d');
parent::__construct();
}
public function start(): int
{
# 0 - 未推送
# 1 - 已推送
# 2 - 其他问题
$status = 0;
$lists = DataFile::query()->where('status', $status)
->where('created_at', 'like', $this->time . '%')->first();
... ... @@ -56,23 +50,44 @@ class WebsiteData extends Command
sleep(60);
return 0;
}
$key = $this->signature . '-' . $lists->id;
$count = redis_get($key);
$isRes = http_post($this->url, json_encode(['data' => $lists->getOriginal()]));
if (!$isRes) {
if ($count == 2) {
$lists->is_pdf = 2;
$lists->save();
$this->debug_echo('项目文件数据推送失败! - 其他原因 - ' . $key);
} else {
redis_add($key, $count + 1);
$this->debug_echo('项目文件数据推送失败! - ' . $key);
}
}
$lists->status = 1;
$lists->save();
$this->debug_echo('项目文件数据保存成功!');
return 0;
var_dump($lists);
exit();
$data = $lists['items'];
$url = env('AICC_URL');
$msg = http_post($url, json_encode(compact('data')));
}
/**
* Execute the console command.
*
* @return int
*/
// public function handle()
// {
// $DataFile = new DataFile();
// $data = $DataFile->allData();
// # 详细数据
// $items = $data['items'];
// # 总分页
// $totalPage = $data['totalPage'];
// $this->post_data($items);
// if ($totalPage > 1) {
// for ($page = 2; $page <= $totalPage; $page++) {
// $da = $DataFile->allData($page);
// $this->post_data($da['items']);
// }
// }
// $this->info('项目文件数据推送完成!');
// return 0;
// }
public function post_data($data)
{
$url = env('AICC_URL');
$msg = http_post($url, json_encode(compact('data')));
print_r($msg);
}
}
... ...
... ... @@ -9,7 +9,6 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Carbon;
use App\Models\File\File;
use Illuminate\Support\Facades\Redis;
define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
/**
... ... @@ -617,29 +616,3 @@ function getRouteMap($source,$source_id){
}
return $route;
}
function redis_get($key){
return Redis::connection()->client()->get($key);
}
function redis_del(...$key){
return Redis::connection()->client()->del(...$key);
}
function redis_set($key,$val,$ttl=3600){
return Redis::connection()->client()->set($key,$val,$ttl);
}
/**
* 添加缓存,存在则失败
* @param $key
* @param $val
* @param int $ttl
* @return mixed
* @author:dc
* @time 2023/10/25 9:48
*/
function redis_add($key,$val,$ttl=3600){
return Redis::connection()->client()->eval(
"return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])", [$key, $val, $ttl], 1
);
}
... ...
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
... ...