From 5b0714d4938cc9dd8f4fa5fe606a51179d15ed38 Mon Sep 17 00:00:00 2001 From: chengxl Date: Fri, 4 Jul 2025 15:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=9F=E5=88=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Aireview.php | 43 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/application/api/controller/Aireview.php b/application/api/controller/Aireview.php index 02e592a..c5319f9 100644 --- a/application/api/controller/Aireview.php +++ b/application/api/controller/Aireview.php @@ -32,7 +32,7 @@ class Aireview extends Base //查询文章 $aWhere = ['article_id' => $aParam['article_id']]; - $aArticle = Db::name('article')->field('article_id,abstrart,keywords,journal_id')->where('article_id',$aParam['article_id'])->find(); + $aArticle = Db::name('article')->field('article_id,abstrart,keywords,journal_id,title,state')->where('article_id',$aParam['article_id'])->find(); if(empty($aArticle)){ return json_encode(array('status' => 3,'msg' => 'No articles requiring review were found' )); } @@ -50,24 +50,36 @@ class Aireview extends Base //实例化公共方法 $oOpenAi = new OpenAi; - //查询文章内容 - $aWhere['type'] = 0; - $aWhere['content'] = ['<>','']; - $aWhere['state'] = 0; - $aArticleMain = Db::table('t_article_main')->where($aWhere)->column('content'); - if(empty($aArticleMain)){//读取文件内容 + if($aArticle['state'] > 4 ){ + //查询文章内容 + $aWhere['type'] = 0; + $aWhere['content'] = ['<>','']; + $aWhere['state'] = 0; + $aArticleMain = Db::table('t_article_main')->where($aWhere)->column('content'); + //查询参考文献 + $aWhere = ['state' => ['in',[0,2]],'article_id' => $iArticleId]; + $aProductionArticle = Db::name('production_article')->field('p_article_id')->where($aWhere)->find(); + if(!empty($aProductionArticle)){ + $aWhere = ['state' => 0,'p_article_id' => $aProductionArticle['p_article_id']]; + $aRefer = Db::name('production_article_refer')->field('refer_content')->where($aWhere)->column('refer_content'); + $aArticleMain = empty($aRefer) ? $aArticleMain : array_merge($aRefer,$aArticleMain); + } + }else{ + $aFile = json_decode($oOpenAi->getFileContent(['article_id' => $iArticleId]),true); $aFile = empty($aFile['data']) ? [] : $aFile['data']; $aArticleMain = empty($aFile['mains']) ? [] : $aFile['mains']; } //获取提问AI的内容 $aSearch = []; + $title = empty($aArticle['title']) ? '' : $aArticle['title'];//简介 $abstrart = empty($aArticle['abstrart']) ? '' : $aArticle['abstrart'];//简介 $keywords = empty($aArticle['keywords']) ? '' : $aArticle['keywords'];//关键词 - $sContent = empty($aArticleMain) ? '' : strip_tags(implode('', array_unique($aArticleMain)),'');//文章内容 - if(empty(trim($sContent))){ - $sContent = '摘要:'.$abstrart.'关键词:'.$keywords; - } + //文章内容 + $sContent = '文章标题:'.$title.'文章摘要:'.$abstrart.'文章关键词:'.$keywords."文章内容"; + $sContent .= empty($aArticleMain) ? '' : implode('', array_unique($aArticleMain)); + $sContent = preg_replace('/[\r\n]+/', '', $sContent); + $sContent = preg_replace('/ +/', ' ', $sContent); // 合并连续空格 $aSearch['{content}'] = $sContent; $aSearch['{journal_name}'] = empty($aJournal['zname']) ? '' : $aJournal['zname'];//期刊名 if($aJournal['journal_id'] == 1){ @@ -75,11 +87,12 @@ class Aireview extends Base } //查询期刊内容 $aJournalPaperArt = json_decode($oOpenAi->getJournalPaperArt($aJournal),true); - $sJournalContent = empty($aJournalPaperArt['data']) ? '' : strip_tags(implode('', $aJournalPaperArt['data'])); + $sJournalContent = empty($aJournalPaperArt['data']) ? '' : implode('', $aJournalPaperArt['data']); + $sJournalContent = preg_replace('/[\r\n]+/', '', $sJournalContent); + $sJournalContent = preg_replace('/ +/', ' ', $sJournalContent); // 合并连续空格 + $sJournalContent = strip_tags($sJournalContent); $sJournalContent = empty($sJournalContent) ? $aJournal['scope'] : $sJournalContent; $aSearch['{scope}'] = $sJournalContent;//期刊范围 - //获取问答内容 - $oOpenAi = new OpenAi; $aMessage = $oOpenAi->buildReviewArticlePrompt($aSearch); if(empty($aMessage)){ return json_encode(['status' => 5,'msg' => 'AI Q&A content not obtained']); @@ -118,7 +131,7 @@ class Aireview extends Base //返回数组 $aResult = ['status' => 1,'msg' => 'AI review successful']; //必填参数验证 - $aFields = ['journal_scope','attribute','contradiction','unreasonable','ethics','academic','conclusion','fund_number','hotspot','submit_direction','overall_evaluation','article_id','references_past_three','references_past_five','references_ratio_JCR1','references_ratio_JCR2','registration_assessment','cite_rate']; + $aFields = ['journal_scope','attribute','contradiction','unreasonable','ethics','academic','conclusion','fund_number','hotspot','submit_direction','overall_evaluation','article_id','references_past_three','references_past_five','references_ratio_JCR1','references_ratio_JCR2','registration_assessment','cite_rate','references_num']; $aInsert = ['create_time' => date('Y-m-d H:i:s')]; foreach($aFields as $val){ $aValue = empty($aParam[$val]) ? [] : $aParam[$val];