Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -3298,9 +3298,14 @@ class Production extends Base
|
||||
echo $res;
|
||||
}
|
||||
|
||||
public function tableCovertLatex($amt_id, $references)
|
||||
public function tableCovertLatex($amt_id, $references,$aTableInfo = [])
|
||||
{
|
||||
$table_info = $this->article_main_table_obj->where('amt_id', $amt_id)->find();
|
||||
if(empty($aTableInfo)){
|
||||
$table_info = $this->article_main_table_obj->where('amt_id', $amt_id)->find();
|
||||
}else{
|
||||
$table_info = $aTableInfo;
|
||||
}
|
||||
|
||||
$tableData = json_decode($table_info['table_data'], true);
|
||||
|
||||
// 检查JSON解码是否成功
|
||||
@@ -3615,7 +3620,7 @@ class Production extends Base
|
||||
}
|
||||
|
||||
//查询文章
|
||||
$aWhere = ['p_article_id' => $iPArticleId,'state' => 0];
|
||||
$aWhere = ['p_article_id' => $iPArticleId,'state' => ['in',[0,2]]];
|
||||
$aProductionArticle = Db::name('production_article')->where($aWhere)->find();
|
||||
if(empty($aProductionArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'No articles found' ));
|
||||
@@ -3638,20 +3643,87 @@ class Production extends Base
|
||||
return json_encode(array('status' => 5,'msg' => 'Article content retrieval failed'));
|
||||
}
|
||||
|
||||
//获取参考文献
|
||||
$aResult = $this->creatReferences($aProductionArticle);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? 'Content generation failed-Reference' : $aResult['msg'];
|
||||
$aResult = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
$sReferences = empty($aResult['references']) ? '' : $aResult['references'];//参考文献内容
|
||||
$aReferencesLists = empty($aResult['references_list']) ? [] : $aResult['references_list'];//参考文献数组
|
||||
if($iStatus != 1){
|
||||
return json_encode(array('status' => 8,'msg' => $sMsg));
|
||||
}
|
||||
if(empty($sReferences)){
|
||||
return json_encode(array('status' => 9,'msg' => 'Article content retrieval failed'));
|
||||
}
|
||||
|
||||
//生成主内容
|
||||
$aResult = $oLatexContent->buildMain($aProductionArticle);
|
||||
$aResult = $oLatexContent->buildMain(['production_article' => $aProductionArticle,'references' => $aReferencesLists]);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? 'Content generation failed-Main' : $aResult['msg'];
|
||||
$sMainTemplateInfo = empty($aResult['data']) ? '' : $aResult['data'];
|
||||
if($iStatus != 1){
|
||||
return json_encode(array('status' => 4,'msg' => $sMsg));
|
||||
return json_encode(array('status' => 6,'msg' => $sMsg));
|
||||
}
|
||||
if(empty($sMainTemplateInfo)){
|
||||
return json_encode(array('status' => 5,'msg' => 'Article content retrieval failed'));
|
||||
return json_encode(array('status' => 7,'msg' => 'Article content retrieval failed'));
|
||||
}
|
||||
|
||||
//生成文件
|
||||
//创建基础目录
|
||||
$sDir = ROOT_PATH . 'public' . DS . 'latex' . DS . 'tex_' . $iPArticleId;
|
||||
if (!is_dir($sDir)) {
|
||||
mkdir($sDir, 0755, true);
|
||||
}
|
||||
|
||||
//生成Reference文件
|
||||
$sFileUrl = $sDir. DS . 'references_' . $iPArticleId . '.bib';
|
||||
file_put_contents($sFileUrl, $sReferences);
|
||||
if(!file_exists($sFileUrl)){
|
||||
return json_encode(array('status' => 10,'msg' => 'Reference file generation failed'));
|
||||
}
|
||||
|
||||
//生成运行文件.tex
|
||||
$sTexName = 'article_' . $iPArticleId;
|
||||
$sTexFileUrl = $sDir. DS . $sTexName .'.tex';
|
||||
$sTemplateInfo = $sFirstTemplateInfo."\n".$sMainTemplateInfo;
|
||||
file_put_contents($sTexFileUrl, $sTemplateInfo);
|
||||
return json_encode(array('status' => 1,'msg' => 'PDF generated successfully'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成初稿-参考文献
|
||||
* @param p_article_id 生产环境文章信息
|
||||
*/
|
||||
private function creatReferences($aParam = []){
|
||||
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||
//必填值验证
|
||||
$iPArticleId = empty($aParam['p_article_id']) ? '' : $aParam['p_article_id'];
|
||||
if(empty($iPArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//查询参考文献
|
||||
$aWhere = ['p_article_id' => $iPArticleId,'state' => 0];
|
||||
$aReferences = Db::name('production_article_refer')->where($aWhere)->order('index asc')->select();
|
||||
if(empty($aReferences)){
|
||||
return json_encode(array('status' => 3,'msg' => 'No reference information found' ));
|
||||
}
|
||||
//参考文献处理
|
||||
$sContent = "% BibTeX file generated for article ID: {$iPArticleId}\n";
|
||||
$sContent .= "% Generated on " . date('Y-m-d H:i:s') . "\n\n";
|
||||
$sReferences = '';
|
||||
$aReferencesLists = [];
|
||||
foreach ($aReferences as $value) {
|
||||
$aReferencesLists[$value['index'] + 1] = $value;
|
||||
$sReferencesInfo = $this->generateBibEntry($value);
|
||||
if(empty($sReferencesInfo)){
|
||||
continue;
|
||||
}
|
||||
$sReferences .= $sReferencesInfo . "\n\n";
|
||||
}
|
||||
if(empty($sReferences)){
|
||||
return json_encode(array('status' => 4,'msg' => 'No reference information found' ));
|
||||
}
|
||||
$sContent .= $sReferences;
|
||||
return ['status' => 1,'msg' => 'success','data' => ['references' => $sContent,'references_list' => $aReferencesLists]];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user