1
This commit is contained in:
@@ -90,15 +90,20 @@ class Datebase extends Controller
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
public function push_db(){
|
||||
$data = $this->request->post();
|
||||
return $this->bf_db_push($data['stage']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份数据推送至sftp
|
||||
*/
|
||||
public function bf_db_push($stage)
|
||||
{
|
||||
Vendor('PHPExcel.PHPExcel');
|
||||
Vendor('PHPExcel.PHPExcel');
|
||||
Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
|
||||
Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
|
||||
$baseDir = ROOT_PATH . 'public' . DS . 'davExcel' . DS .$stage.DS;
|
||||
$baseDir = ROOT_PATH . 'public' . DS . 'davExcel' . DS . $stage . DS;
|
||||
if (!is_dir($baseDir)) {
|
||||
@mkdir($baseDir);
|
||||
}
|
||||
@@ -119,6 +124,7 @@ class Datebase extends Controller
|
||||
|
||||
//查找数据
|
||||
$stage_info = $this->journal_stage_obj->where('journal_stage_id', $stage)->find();
|
||||
$journal_info = $this->journal_obj->where('journal_id',$stage_info['journal_id'])->find();
|
||||
$articles = $this->article_obj
|
||||
->field('j_article.*,j_journal.title journalTitle,j_journal.issn')
|
||||
->join("j_journal", "j_article.journal_id = j_journal.journal_id", 'left')
|
||||
@@ -128,11 +134,12 @@ class Datebase extends Controller
|
||||
//填充表格信息
|
||||
foreach ($articles as $k => $v) {
|
||||
$k += 2;
|
||||
$objActSheet->setCellValue('A' . $k, $v['journalTitle']);
|
||||
|
||||
$objActSheet->setCellValue('A' . $k, choiseti1($v['article_id'],$v['journalTitle']));
|
||||
$objActSheet->setCellValue('B' . $k, $v['issn']);
|
||||
$objActSheet->setCellValue('C' . $k, '');
|
||||
$objActSheet->setCellValue('D' . $k, $v['doi']);
|
||||
$fpdf = explode("/",$v['file_pdf']);
|
||||
$fpdf = explode("/", $v['file_pdf']);
|
||||
$objActSheet->setCellValue('E' . $k, $fpdf[1]);
|
||||
//下载pdf
|
||||
copy('http://journalapi.tmrjournals.com/public/articlePDF/' . $v['file_pdf'], $baseDir . $fpdf[1]);
|
||||
@@ -143,26 +150,35 @@ class Datebase extends Controller
|
||||
$objActSheet->setCellValue('G' . $k, implode(",", $cache_author));
|
||||
$objActSheet->setCellValue('H' . $k, $v['pub_date']);
|
||||
$objActSheet->setCellValue('I' . $k, $stage_info['stage_vol']);
|
||||
$objActSheet->setCellValue('J' . $k, $stage_info['issue_date']);
|
||||
if($v['file_sub']!=''){
|
||||
$spdf = explode("/",$v['file_sub']);
|
||||
//连续出版的issue为空
|
||||
if(($journal_info['journal_id']==2&&$stage_info['stage_year']>=2022)||($journal_info['journal_id']==3&&$stage_info['stage_year']>=2022)||($journal_info['journal_id']==17&&$stage_info['stage_year']>=2019)){
|
||||
$objActSheet->setCellValue('J' . $k, '');
|
||||
}else{
|
||||
$objActSheet->setCellValue('J' . $k, $stage_info['issue_date']);
|
||||
}
|
||||
|
||||
if ($v['file_sub'] != '') {
|
||||
$spdf = explode("/", $v['file_sub']);
|
||||
//下载附加信息
|
||||
copy('http://journalapi.tmrjournals.com/public/articleSUB/' . $v['file_sub'], $baseDir . $spdf[1]);
|
||||
$objActSheet->setCellValue('K' . $k, $spdf[1]);
|
||||
}else{
|
||||
} else {
|
||||
$objActSheet->setCellValue('K' . $k, '');
|
||||
}
|
||||
|
||||
//整理分期
|
||||
if (strpos(trim($v['npp']), '-') == false) {
|
||||
$npp = trim($v['npp']);
|
||||
$npp = str_replace('–','-',$npp);
|
||||
$npp = str_replace("—",'-',$npp);
|
||||
if (strpos($npp, '-') == false) {
|
||||
$objActSheet->setCellValue('L' . $k, '');
|
||||
$objActSheet->setCellValue('M' . $k, '');
|
||||
}else{
|
||||
$cc = explode('-',trim($v['npp']));
|
||||
} else {
|
||||
$cc = explode('-', trim($npp));
|
||||
$objActSheet->setCellValue('L' . $k, $cc[0]);
|
||||
$objActSheet->setCellValue('M' . $k, $cc[1]);
|
||||
}
|
||||
$objActSheet->setCellValue('N' . $k, "© ".$stage_info['stage_year']." By Author(s). Published by TMR Publishing Group Limited. This is an open access article under the CC-BY license. (http://creativecommons.org/licenses/BY/4.0/)");
|
||||
$objActSheet->setCellValue('N' . $k, "© " . $stage_info['stage_year'] . " By Author(s). Published by TMR Publishing Group Limited. This is an open access article under the CC-BY license. (http://creativecommons.org/licenses/BY/4.0/)");
|
||||
// 表格高度
|
||||
$objActSheet->getRowDimension($k)->setRowHeight(25);
|
||||
}
|
||||
@@ -182,27 +198,59 @@ class Datebase extends Controller
|
||||
$objActSheet->getColumnDimension('L')->setWidth($width[1]);
|
||||
$objActSheet->getColumnDimension('M')->setWidth($width[1]);
|
||||
$objActSheet->getColumnDimension('N')->setWidth($width[4]);
|
||||
|
||||
// $baseDir = ROOT_PATH . 'public' . DS . 'davExcel' . DS ;
|
||||
// if (!is_dir($baseDir)) {
|
||||
// @mkdir($baseDir);
|
||||
// }
|
||||
$outfileTitle = $stage_info['journal_stage_id']."dav";
|
||||
|
||||
$outfileTitle = $stage_info['journal_stage_id'] . "dav";
|
||||
$res = $objWriter->save($baseDir . $outfileTitle . ".xlsx");
|
||||
|
||||
// 生成zip
|
||||
// $path = $baseDir . $outfileTitle . ".xlsx";
|
||||
// $fileName = $outfileTitle . ".zip";
|
||||
// $zip = new \ZipArchive;
|
||||
// $zip->open($baseDir . $fileName, \ZipArchive::CREATE);
|
||||
// $zip->addFile($path, basename($path));
|
||||
// $zip->close();
|
||||
// unlink($baseDir . $outfileTitle . ".xlsx");
|
||||
$this->push_sftp($stage);
|
||||
|
||||
// if (!file_exists($baseDir . $fileName)) {
|
||||
// return json_encode(['code' => 1, 'msg' => '无法找到文件']);
|
||||
// }
|
||||
return json_encode(['code' => 0, 'msg' => '成功', 'data' => $baseDir . $outfileTitle . ".xlsx"]);
|
||||
return json_encode(['code' => 0, 'msg' => '成功']);
|
||||
}
|
||||
|
||||
// public function ls_push(){
|
||||
// $stages = $this->journal_stage_obj->where('state',0)->where('is_publish',1)
|
||||
// ->where('journal_stage_id',">",360)
|
||||
// ->where('journal_stage_id',"<=",360)
|
||||
// ->select();
|
||||
// foreach($stages as $v){
|
||||
// $this->push_sftp($v['journal_stage_id']);
|
||||
// file_put_contents('/home/wwwroot/journalapi.tmrjournals.com/public/system/1.txt','****'.$v['journal_stage_id'],FILE_APPEND);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private function push_sftp($stage)
|
||||
{
|
||||
$stage_info = $this->journal_stage_obj->where('journal_stage_id',$stage)->find();
|
||||
$journal_info = $this->journal_obj->where('journal_id',$stage_info['journal_id'])->find();
|
||||
//链接sftp服务器
|
||||
$config['host'] = 'ftp.portico.org';
|
||||
$config['port'] = 22;
|
||||
$config['username'] = "TMR";
|
||||
$config['password'] = "h6EHD8";
|
||||
$sftp_obj = new Sftp($config);
|
||||
|
||||
//判断目录是否存在,不存在创建
|
||||
$j_base = $sftp_obj->ssh2_dir_exits("/SPREADSHEET/".$journal_info['issn']);
|
||||
if(!$j_base){
|
||||
$sftp_obj->ssh2_sftp_mchkdir("/SPREADSHEET/".$journal_info['issn']);
|
||||
}
|
||||
$m_base = $sftp_obj->ssh2_dir_exits("/SPREADSHEET/".$journal_info['issn'].'/'.$stage_info['stage_year'].'-'.$stage_info['stage_vol'].'-'.$stage_info['stage_no']);
|
||||
if(!$m_base){
|
||||
$sftp_obj->ssh2_sftp_mchkdir("/SPREADSHEET/".$journal_info['issn'].'/'.$stage_info['stage_year'].'-'.$stage_info['stage_vol'].'-'.$stage_info['stage_no']);
|
||||
}
|
||||
|
||||
//读取文件夹内的内容
|
||||
$files = scandir(ROOT_PATH . 'public' . DS . 'davExcel' . DS . $stage);
|
||||
foreach($files as $v){
|
||||
if($v=='.'||$v=='..'){
|
||||
continue;
|
||||
}
|
||||
$cdata['local'] = ROOT_PATH . 'public' . DS . 'davExcel' . DS . $stage.DS.$v;
|
||||
$cdata['remote'] = "/SPREADSHEET/".$journal_info['issn'].'/'.$stage_info['stage_year'].'-'.$stage_info['stage_vol'].'-'.$stage_info['stage_no']."/".$v;
|
||||
Queue::push('app\api\job\mysftp@push', $cdata, "mysftp");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,6 +403,9 @@ class Datebase extends Controller
|
||||
// 发送ftp
|
||||
$this->createFtpFileInfo($data["journal_stage_id"]);
|
||||
|
||||
//发送sftp
|
||||
$this->bf_db_push($data["journal_stage_id"]);
|
||||
|
||||
$journal_info = $this->journal_obj->where("journal_id", $stage_info["journal_id"])->find();
|
||||
$zipfile = ROOT_PATH . "public/dataFile/" . $data["journal_stage_id"] . '/' . $data["journal_stage_id"] . '.zip';
|
||||
$tt = "Dear Database,<br><br>";
|
||||
@@ -564,19 +615,10 @@ class Datebase extends Controller
|
||||
return json_encode(['code' => 0, 'msg' => '成功', 'data' => $baseDir . $fileName]);
|
||||
}
|
||||
|
||||
public function phpinfo(){
|
||||
|
||||
phpinfo();
|
||||
}
|
||||
public function phpinfo()
|
||||
{
|
||||
|
||||
public function testsftp(){
|
||||
$config = [];
|
||||
$config['host'] = 'sftp://ftp.portico.org';
|
||||
$config['port'] = 22;
|
||||
$config['username'] = "TMR";
|
||||
$config['password'] = "h6EHD8";
|
||||
$sftp_obj = new Sftp($config);
|
||||
var_dump($sftp_obj);
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
// 连接ftp
|
||||
|
||||
Reference in New Issue
Block a user