From 809170fed6e67bf962fe91071519d9cc3d0ee67f Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Wed, 13 Jul 2022 12:03:08 +0800 Subject: [PATCH] 1 --- application/api/controller/Journal.php | 9 +- application/api/job/mysftp.php | 20 +++ application/common.php | 28 +++++ application/master/controller/Article.php | 21 +++- application/master/controller/Datebase.php | 126 ++++++++++++------- application/master/controller/Journal.php | 30 ++++- application/master/controller/Medicament.php | 99 +++++++++++++++ 7 files changed, 286 insertions(+), 47 deletions(-) create mode 100644 application/api/job/mysftp.php create mode 100644 application/master/controller/Medicament.php diff --git a/application/api/controller/Journal.php b/application/api/controller/Journal.php index f988610..4c04737 100644 --- a/application/api/controller/Journal.php +++ b/application/api/controller/Journal.php @@ -393,6 +393,7 @@ class Journal extends Controller { */ public function getAllTopics() { $parents = $this->base_topic_obj->where('parent_id', 0)->where('state', 0)->order('sort desc')->select(); + $topicIds = $this->journal_topic_obj->where('title', 'Topics')->where('state', 0)->column('journal_topic_id'); $ca = $this->journal_topic_obj->where('parent_id', 'in', $topicIds)->where('state', 0)->select(); foreach ($parents as $k => $v) { @@ -862,6 +863,7 @@ class Journal extends Controller { ->where('j_article.journal_id', $data['journal_id']) ->where('j_article.state', 0) ->where('j_journal_stage.is_publish', 1) + ->where("j_journal_stage.stage_year",">",intval(date("Y"))-3) ->orderRaw('j_article.cited+j_article.abs_num+j_article.pdf_num desc') ->limit($limit_start, $data['pageSize']) ->select(); @@ -871,6 +873,7 @@ class Journal extends Controller { ->where('j_article.journal_id', $data['journal_id']) ->where('j_article.state', 0) ->where('j_journal_stage.is_publish', 1) + ->where("j_journal_stage.stage_year",">",intval(date("Y"))-3) ->count(); if($count>50){//只显示前50片 @@ -1018,15 +1021,15 @@ class Journal extends Controller { * * @param name:journal_topic_id type:int require:1 desc:期刊话题id * - * @return oldJournal:父期刊信息 + * @return oldJournal:父话题信息 * @return journalList:话题列表array# */ public function getTopicList() { $data = $this->request->post(); - $journal_info = $this->journal_topic_obj->where('journal_topic_id', $data['journal_topic_id'])->find(); + $parent_info = $this->journal_topic_obj->where('journal_topic_id', $data['journal_topic_id'])->find(); $list = $this->journal_topic_obj->where('parent_id', $data['journal_topic_id'])->where('state', 0)->order('sort asc')->select(); - $re['oldJournal'] = $journal_info; + $re['oldJournal'] = $parent_info; $re['journalList'] = $list; return jsonSuccess($re); } diff --git a/application/api/job/mysftp.php b/application/api/job/mysftp.php new file mode 100644 index 0000000..4903f1d --- /dev/null +++ b/application/api/job/mysftp.php @@ -0,0 +1,20 @@ +delete(); + //链接sftp服务器 + $config['host'] = 'ftp.portico.org'; + $config['port'] = 22; + $config['username'] = "TMR"; + $config['password'] = "h6EHD8"; + $sftp_obj = new Sftp($config); + $sftp_obj->upftp($data['local'],$data['remote']); + } + +} diff --git a/application/common.php b/application/common.php index a883df0..b420b98 100644 --- a/application/common.php +++ b/application/common.php @@ -90,9 +90,37 @@ function choiseti($v){ if($v['article_id']<1869&&$v['journal_title']=="Nursing Communications"){ return "TMR Integrative Nursing"; } + if($v['article_id']<1981&&$v['journal_title']=="Toxicology Communications"){ + return "Asian Toxicology Research"; + } return $v['journal_title']; } +function choiseti1($article_id,$journal_title){ + if($article_id<1799&&$journal_title=="Cancer Advances"){ + return "TMR Cancer"; + } + if($article_id<910&&$journal_title=="Microenvironment & Microecology Research"){ + return "Tumor Microenvironment Research"; + } + if($article_id<1799&&$journal_title=="Medical Theory and Hypothesis"){ + return "TMR Theory and Hypothesis"; + } + if($article_id<1821&&$journal_title=="Clinical Research Communications"){ + return "TMR Clinical Research"; + } + if($article_id<1665&&$journal_title=="Aging Communications"&&$article_id!=1612){ + return "TMR Aging"; + } + if($article_id<1869&&$journal_title=="Nursing Communications"){ + return "TMR Integrative Nursing"; + } + if($article_id<1981&&$journal_title=="Toxicology Communications"){ + return "TMR Integrative Nursing"; + } + return $journal_title; +} + /** * @function sendEmail * @intro 发送邮件(带附件) diff --git a/application/master/controller/Article.php b/application/master/controller/Article.php index f66e417..a2df05d 100644 --- a/application/master/controller/Article.php +++ b/application/master/controller/Article.php @@ -31,6 +31,8 @@ class Article extends Controller { protected $subscribe_topic_obj = ''; protected $base_topic_obj = ''; protected $subscribe_base_topic_obj = ''; + protected $medicament_obj = ''; + protected $article_to_medicament_obj = ''; public function __construct(\think\Request $request = null) { parent::__construct($request); @@ -51,6 +53,8 @@ class Article extends Controller { $this->subscribe_topic_obj = Db::name('subscribe_topic'); $this->base_topic_obj = Db::name('base_topic'); $this->subscribe_base_topic_obj = Db::name('subscribe_base_topic'); + $this->medicament_obj = Db::name('medicament'); + $this->article_to_medicament_obj = Db::name('ArticleToMedicament'); } /** @@ -572,7 +576,12 @@ class Article extends Controller { if (intval($data['journal_id']) !== 0) { $where['j_article.journal_id'] = $data['journal_id']; } else { - $journals = $this->journal_obj->where('editor_id', $data['editor_id'])->column('journal_id'); + $journals = []; + if(isset($data['editor_id'])&&$data['editor_id']!=''){ + $journals = $this->journal_obj->where('editor_id', $data['editor_id'])->column('journal_id'); + }else{ + $journals = $this->journal_obj->where('state',0)->column('journal_id'); + } $where['j_article.journal_id'] = ['in', $journals]; } if (intval($data['journal_stage_id']) !== 0) { @@ -590,6 +599,16 @@ class Article extends Controller { $cache_title = str_replace($val, '' . $val . '', $cache_title); } $article_list[$k]['title'] = $cache_title; + //获取药剂信息 + $atm = $this->article_to_medicament_obj->where('article_id',$v['article_id'])->where('atm_state',0)->find(); + if($atm){ + $med_info = $this->medicament_obj->where('med_id',$atm['med_id'])->where('med_state',0)->find(); + $article_list[$k]['med_title'] = $med_info['med_title']; + $article_list[$k]['med_ename'] = $med_info['med_ename']; + }else{ + $article_list[$k]['med_title'] = ''; + $article_list[$k]['med_ename'] = ''; + } } $count = $this->article_obj->where($where)->count(); return json(['code' => 0, 'msg' => 'success', 'data' => ['count' => $count, 'articleList' => $article_list]]); diff --git a/application/master/controller/Datebase.php b/application/master/controller/Datebase.php index 6469c90..02ac369 100644 --- a/application/master/controller/Datebase.php +++ b/application/master/controller/Datebase.php @@ -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,

"; @@ -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 diff --git a/application/master/controller/Journal.php b/application/master/controller/Journal.php index f6d8038..2f6318a 100644 --- a/application/master/controller/Journal.php +++ b/application/master/controller/Journal.php @@ -34,7 +34,7 @@ class Journal extends Controller { protected $board_group_obj = ''; protected $base_topic_obj = ''; protected $subscribe_base_topic_obj = ''; - protected $journal_for_author; + protected $journal_for_author=''; public function __construct(\think\Request $request = null) { parent::__construct($request); @@ -87,6 +87,34 @@ class Journal extends Controller { ->select(); return json(['code'=>0,'msg'=>'success','data'=>['journalList'=>$res]]); } + + /** + * 获取全部期刊 + */ + public function getJournals(){ + $jouranls = $this->journal_obj->where('state',0)->select(); + $re['journals'] = $jouranls; + return jsonSuccess($re); + } + + /** + * 获取分期通过期刊 + */ + public function getStagesByJournal(){ + $data = $this->request->post(); + $rule = new Validate([ + 'journal_id'=>'require|number' + ]); + if(!$rule->check($data)){ + return jsonError($rule->getError()); + } + $list = $this->journal_stage_obj->where('journal_id',$data['journal_id'])->where('state',0)->select(); + foreach ($list as $k => $vv) { + $list[$k]['title'] = $vv['stage_year'] . ' Vol.' . $vv['stage_vol'] . ' issue.' . $vv['stage_no'] . $vv['stage_pagename'] . $vv['stage_page']; + } + $re['stages']=$list; + return jsonSuccess($re); + } /** * @title 获取所有期刊 diff --git a/application/master/controller/Medicament.php b/application/master/controller/Medicament.php new file mode 100644 index 0000000..0638968 --- /dev/null +++ b/application/master/controller/Medicament.php @@ -0,0 +1,99 @@ +article_obj = Db::name('article'); + $this->medicament_obj = Db::name('medicament'); + $this->article_to_medicament_obj = Db::name('ArticleToMedicament'); + } + + + /** + * 增加文章药剂项 + */ + public function addMedicament() + { + $data = $this->request->post(); + // 验证规则 + $rule = new Validate([ + 'article_id' => 'require|number', + 'med_title' => 'require', + 'med_ename' => 'require' + ]); + if (!$rule->check($data)) { + return jsonError($rule->getError()); + } + + $article_info = $this->article_obj->where('article_id', $data['article_id'])->find(); + + //检测当前药剂是否存在 + $med_check = $this->medicament_obj->where('med_title', trim($data['med_title']))->whereOr('med_ename',trim($data['med_ename']))->where('med_state',0)->find(); + if($med_check){ + return json(['code'=>2,'data'=>$med_check]); + } + + //添加药剂信息 + $insert_med['med_title'] = trim($data['med_title']); + $insert_med['med_ename'] = trim($data['med_ename']); + $insert_med['med_ctime'] = time(); + $med_id = $this->medicament_obj->insertGetId($insert_med); + + //添加文章对应关系 + $insert_atm['article_id'] = $data['article_id']; + $insert_atm['med_id'] = $med_id; + $this->article_to_medicament_obj->insert($insert_atm); + + return jsonSuccess([]); + } + + /** + * 添加已存在药剂的归属对应关系 + */ + public function addMedicamentHas(){ + $data = $this->request->post(); + // 验证规则 + $rule = new Validate([ + 'article_id' => 'require|number', + 'med_id' => 'require' + ]); + if (!$rule->check($data)) { + return jsonError($rule->getError()); + } + + $insert_atm['article_id'] = $data['article_id']; + $insert_atm['med_id'] = $data['med_id']; + $this->article_to_medicament_obj->insert($insert_atm); + return jsonSuccess([]); + } + + /** + * 删除药剂话题与文章对应关系 + */ + public function delMedicament(){ + $data = $this->request->post(); + $rule = new Validate([ + 'article_id'=>'require', + 'med_id'=>'require' + ]); + if(!$rule->check($data)){ + return jsonError($rule->getError()); + } + $this->article_to_medicament_obj->where('article_id',$data['article_id'])->where('med_id',$data['med_id'])->update(['med_state'=>1]); + return jsonSuccess([]); + } + + +}