作者 李美松

优化程序

... ... @@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Http\Controllers\File\FileController;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\File\DataFile;
use App\Services\CosService;
use Dompdf\Dompdf;
use Dompdf\Options;
use Illuminate\Console\Command;
... ... @@ -36,6 +37,8 @@ class ProjectFilePDF extends Command
protected $fileController;
protected $CosService;
// 最大支持5个进程
public $maxRunNumber = 50;
... ... @@ -50,6 +53,7 @@ class ProjectFilePDF extends Command
$this->DataFile = new DataFile();
$this->time = date("Y-m");
$this->fileController = new FileController();
$this->CosService = new CosService();
parent::__construct();
}
... ... @@ -86,8 +90,7 @@ class ProjectFilePDF extends Command
$this->debug_echo('pdf生成失败!');
return 0;
}
$file_path = json_encode($file_path['data']);
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
$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;
... ... @@ -100,14 +103,15 @@ class ProjectFilePDF extends Command
}
$lists->is_pdf = 1;
$lists->save();
$this->debug_echo('项目文件数据保存成功!');
$this->info('项目文件数据保存成功!');
return 0;
}
/**
* @param $html
* @param $filename
* @return array
* @return string
*/
public function savePDF($html, $filename)
{
... ... @@ -137,14 +141,14 @@ class ProjectFilePDF extends Command
$dompdf->render();
// 获取PDF内容
$pdfContent = $dompdf->output();
$this->fileController->path = '/V6/PDF';
$pdfContent = $dompdf->output();
$path = '/V6/PDF/' . $this->time;
// 将PDF内容保存到文件
@file_put_contents($savePath, $pdfContent);
// 创建一个文件实例
$file = new File($savePath);
return $this->fileController->api_upload_single($file);
return $this->CosService->uploadFile($file, $path, $filename . '.pdf');
}
/**
... ...