Browse Source

feat:试卷解析

yanghz 5 months ago
parent
commit
a4dc104561

+ 5 - 12
protected/commands/WordPushCommand.php

@@ -19,11 +19,8 @@ class WordPushCommand extends CConsoleCommand
     public function actionIndex($school_id = '', $YII_ENV = 'development')
     {
 		// 连接业务库
-//        $pdoParam = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";');
-//        $businessServer = Yii::app()->params["businessDb"];
+        $pdoParam = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";');
         $databaseFields = 'database_host,database_name,database_user,database_password,school_id';
-//        $busDsn = 'mysql:host=' . $businessServer['addr'] . ';dbname=' . Yii::app()->params["default_db"]['name'] . ';';
-//        $busDbh = new PDO($busDsn, $businessServer['username'], $businessServer['password'], $pdoParam);
         $busDbh = Yii::app()->businessDb;
         // 获取所有可用的学校
         if ($school_id) {
@@ -31,10 +28,8 @@ class WordPushCommand extends CConsoleCommand
         } else {
             $dataSql = "SELECT {$databaseFields} FROM `database` WHERE `school_id` IN (SELECT school_id FROM `school` WHERE `status`=0)";
         }
-
         // 找出学校的链接信息
-        $dataObj = $busDbh->query($dataSql);
-        $dataInfo = $dataObj->fetchAll(PDO::FETCH_ASSOC);
+        $dataInfo = $busDbh->createCommand($dataSql)->queryAll();
         if (empty($dataInfo)) {
             exit('未找到学校数据库链接信息!');
         }
@@ -47,15 +42,13 @@ class WordPushCommand extends CConsoleCommand
         }
 
 		$schoolIdString = implode(',', $schoolIds);
-        $schoolObj = $busDbh->query("SELECT s.school_id,r.region_name FROM `school` s LEFT JOIN `region` r ON r.region_id = s.province_id WHERE s.`school_id` IN ({$schoolIdString})");
-        $schoolInfo = $schoolObj->fetchAll(PDO::FETCH_ASSOC);
+        $schoolInfo = $busDbh->createCommand("SELECT s.school_id,r.region_name FROM `school` s LEFT JOIN `region` r ON r.region_id = s.province_id WHERE s.`school_id` IN ({$schoolIdString})")->queryAll();
         foreach ($schoolInfo as $key => $tempProvince) {
             $schoolProvince[$tempProvince['school_id']] = $tempProvince['region_name'];
         }
 
 		// 获取所有学科
-        $packSubject = array();
-        $subjectObj = $busDbh->query('SELECT subject_id,subject_name,section FROM `subject`')->fetchAll(PDO::FETCH_ASSOC);
+        $subjectObj = $busDbh->createCommand('SELECT subject_id,subject_name,section FROM `subject`')->queryAll();
         foreach($subjectObj as $tempSubject) {
             $packSubject[$tempSubject['subject_id']]['name'] = $tempSubject['subject_name'];
             $packSubject[$tempSubject['subject_id']]['section'] = $tempSubject['section'];
@@ -95,7 +88,7 @@ class WordPushCommand extends CConsoleCommand
 						if (empty($callbackUrl) || empty($analysisUrl)) continue;
 						echo $analysisUrl.'----'.$callbackUrl. "\n";
 
-						if (false !== strpos($info['word_path'], 'http://')) {
+						if (false !== strpos($info['word_path'], 'https://') || false !== strpos($info['word_path'], 'http://')) {
 							$time = time();
 							$arr = self::getFile($info['word_path'], '/tem', $info['uploader_id'] . $time . '.docx');
 							if ($arr && file_exists($arr['save_path'])) {

+ 1 - 2
protected/controllers/ParseapiController.php

@@ -29,8 +29,7 @@ class ParseapiController extends CController
 //        $busDsn = 'mysql:host=' . Yii::app()->params["businessDb"]['addr'] . ';dbname=' . Yii::app()->params["default_db"]['name'] . ';';
 //        $busDbh = new PDO($busDsn, Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
         $busDbh = Yii::app()->businessDb;
-        $getDataBase = $busDbh->query('SELECT * FROM `database` WHERE `school_id`=' . $schoolId);
-        $dataBaseInfo = $getDataBase->fetch(PDO::FETCH_ASSOC);
+        $dataBaseInfo = $busDbh->createCommand('SELECT * FROM `database` WHERE `school_id`=' . $schoolId)->queryOne();
         if (empty($dataBaseInfo)) {
             exit('未找到数据库链接信息!');
         }

+ 41 - 85
protected/controllers/WordapiController.php

@@ -21,7 +21,7 @@ class WordapiController extends CController
         set_time_limit(0);
         //$this->ucloud = new Ucloud();
         $this->ucloud = new Qcloud();
-        $this->webSiteUrl = Yii::app()->params['siteurl'];
+        $this->webSiteUrl = Yii::app()->params['teacherSiteurl'];
         $this->flag = isset($_GET['flag']) ? intval($_GET['flag']) : 1;
     }
 
@@ -38,8 +38,7 @@ class WordapiController extends CController
 //        $busDsn = 'mysql:host=' . Yii::app()->params["default_server"]['addr'] . ';dbname=' . Yii::app()->params["default_db"]['name'] . ';';
 //        $busdbh = new PDO($busDsn, Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
         $busdbh = Yii::app()->businessDb;
-        $getDataBase = $busdbh->query('SELECT * FROM `database` WHERE `school_id`=' . $school_id);
-        $dataBaseInfo = $getDataBase->fetch(PDO::FETCH_ASSOC);
+        $dataBaseInfo = $busdbh->createCommand('SELECT * FROM `database` WHERE `school_id`=' . $school_id)->queryOne();
         if (empty($dataBaseInfo)) {
             exit('未找到数据库链接信息!');
         }
@@ -905,50 +904,48 @@ class WordapiController extends CController
      */
 	public function actionAllSubjectCoach()
 	{
-                $apiTopics = array();
+        $apiTopics = array();
 		// 获取curl过来值
-                $word_id = isset($_GET['wid']) ? intval($_GET['wid']) : 0;
-                $school_id = isset($_GET['sid']) ? intval($_GET['sid']) : 0;
-                if (empty($word_id) || empty($school_id)) {
-                    exit('未找到word Id或者学校id');
-                }
+        $word_id = isset($_GET['wid']) ? intval($_GET['wid']) : 0;
+        $school_id = isset($_GET['sid']) ? intval($_GET['sid']) : 0;
+        if (empty($word_id) || empty($school_id)) {
+            exit('未找到word Id或者学校id');
+        }
 		// 连接业务库
-                $busDsn = 'mysql:host=' . Yii::app()->params["default_server"]['addr'] . ';dbname=' . Yii::app()->params["default_db"]['name'] . ';';
-                $busdbh = new PDO($busDsn, Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
-                $getDataBase = $busdbh->query('SELECT * FROM `database` WHERE `school_id`=' . $school_id);
-                $dataBaseInfo = $getDataBase->fetch(PDO::FETCH_ASSOC);
-                if (empty($dataBaseInfo)) {
-                    exit('未找到数据库链接信息!');
-                }
-                $busdbh = null;
-
-                // 连接学校库
-                $schDsn = 'mysql:host=' . $dataBaseInfo['database_host'] . ';dbname=' . $dataBaseInfo['database_name'] . ';';
-                $schdbh = new PDO($schDsn, $dataBaseInfo['database_user'], $dataBaseInfo['database_password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
-                $wordInfo = $schdbh->query('SELECT `word_id`,`word_name`,`subject_id`,`uploader_id`,`exam_group_id` FROM `topic_word` WHERE `word_id`=' . $word_id)->fetch(PDO::FETCH_ASSOC);
-                if (empty($wordInfo)) {
-                    exit('未找到上传word信息!');
-                }
+        $busDsn = Yii::app()->businessDb;
+        $dataBaseInfo = $busDsn->createCommand('SELECT * FROM `database` WHERE `school_id`=' . $school_id)->queryOne();
+        if (empty($dataBaseInfo)) {
+            exit('未找到数据库链接信息!');
+        }
+        $busdbh = null;
+
+        // 连接学校库
+        $schDsn = 'mysql:host=' . $dataBaseInfo['database_host'] . ';dbname=' . $dataBaseInfo['database_name'] . ';';
+        $schdbh = new PDO($schDsn, $dataBaseInfo['database_user'], $dataBaseInfo['database_password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
+        $wordInfo = $schdbh->query('SELECT `word_id`,`word_name`,`subject_id`,`uploader_id`,`exam_group_id` FROM `topic_word` WHERE `word_id`=' . $word_id)->fetch(PDO::FETCH_ASSOC);
+        if (empty($wordInfo)) {
+            exit('未找到上传word信息!');
+        }
 		
 		$getWordJson = file_get_contents('php://input');
-                $jsonArray = json_decode($getWordJson, true);
+        $jsonArray = json_decode($getWordJson, true);
 		if (empty($jsonArray) || $jsonArray['errcode'] == 1 || empty($jsonArray['items'])) {
-                    $errMsg = array();
-                    if (isset($jsonArray['errmsgs']) && $jsonArray['errmsgs']) {
-                        if (is_array($jsonArray['errmsgs'])) {
-                            foreach ($jsonArray['errmsgs'] as $msg) {
-                                $errMsg[] = key($msg) . ':' . implode(', ', $msg[key($msg)]);
-                            }
-                        } else {
-                            $errMsg[] = $jsonArray['errmsgs'];
-                        }
+            $errMsg = array();
+            if (isset($jsonArray['errmsgs']) && $jsonArray['errmsgs']) {
+                if (is_array($jsonArray['errmsgs'])) {
+                    foreach ($jsonArray['errmsgs'] as $msg) {
+                        $errMsg[] = key($msg) . ':' . implode(', ', $msg[key($msg)]);
                     }
-
-                    $errMsg = $errMsg ? implode('<br/>', $errMsg) : '解析异常';
-                    $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content,`file_path` = :path,parse_time=:time WHERE `word_id` =:wid');
-                    $stmt->execute(array(':wid' => $word_id, ':reason' => $errMsg, ':content' => $getWordJson, ':path' => '', ':time' => time()));
-                    exit('解析失败!');
                 } else {
+                    $errMsg[] = $jsonArray['errmsgs'];
+                }
+            }
+
+            $errMsg = $errMsg ? implode('<br/>', $errMsg) : '解析异常';
+            $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content,`file_path` = :path,parse_time=:time WHERE `word_id` =:wid');
+            $stmt->execute(array(':wid' => $word_id, ':reason' => $errMsg, ':content' => $getWordJson, ':path' => '', ':time' => time()));
+            exit('解析失败!');
+        } else {
 			// 获取科目题型
 			$tempTypeName = array(1=>'选择题','2'=>'多选题',11=>'多选题',5=>'填空题',7=>'解答题');
 			$apiParam = Yii::app()->params['api'][0];
@@ -1030,41 +1027,6 @@ class WordapiController extends CController
 				exit('题型不存在');
 			}
 
-			// 验证试卷题型是否和解析题型完全匹配
-			/*if ($relate_topic_type && $parse_topic_type) {
-				foreach ($relate_topic_type as $rttId) {
-					if (in_array($rttId, $parse_topic_type)) {
-						array_splice($parse_topic_type,array_search($rttId ,$parse_topic_type),1);
-					} else {
-						$topic_type_error[] = "上传Word未包含考试创建的题型({$rttId})";
-					}
-				}
-
-				if (count($parse_topic_type) > 0) {
-					$topic_type_error[] = '上传的题型与试卷题型不一致';
-				}
-
-				if ($topic_type_error) {
-					$stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content, parse_time=:time WHERE `word_id` =:wid');
-					$stmt->execute(array(':wid' => $word_id, ':reason' => implode('<br/>', $topic_type_error),':content' => $getWordJson, ':time' => time()));
-					exit('上传的题型与试卷题型不一致');
-				}
-			}
-
-			// 验证题型数量
-			$validate_topic_info = array();
-			foreach ($p_topic_type_num as $vtnKey => $vtnVal) {
-				if (!isset($topic_type_num[$vtnKey]) || count($vtnVal) != count($topic_type_num[$vtnKey])) {
-					$validate_topic_info[] = 'word'.$tempTypeName[$vtnKey].'题量与试卷的题量不同';
-				}
-			}
-			
-			if ($validate_topic_info) {
-				$stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content,parse_time=:time WHERE `word_id` =:wid');
-				$stmt->execute(array(':wid' => $word_id, ':reason' => implode('<br/>', $validate_topic_info),':content' => $getWordJson, ':time' => time()));
-				exit(implode("<br/>",$validate_topic_info));
-			}*/
-
 			// 获取默认文件夹id
 			$defaultFolder = $schdbh->query('SELECT `folder_id` FROM `topic_folder` WHERE `is_system`=1')->fetch(PDO::FETCH_ASSOC);
 			$folderId = empty($defaultFolder['folder_id']) ? 0 : $defaultFolder['folder_id'];
@@ -1156,18 +1118,12 @@ class WordapiController extends CController
 		$resPro = $schdbh->prepare("INSERT INTO `exam_process` (`exam_group_id`, `action_type`, `action_time`) VALUES (:exam_group_id, :tempType, :time)");
 		$resPro->execute(array(':exam_group_id' => $wordInfo['exam_group_id'], ':tempType' => 4, ':time' => time()));
 
-		// 监控日志
-		BMonitorLog::model()->addLog(array(
-			'school_id' => $school_id,
-			'teacher_id' => $wordInfo['uploader_id'],
-			'log_content' => array('助教','上传了',$wordInfo['word_name'],'试卷')
-		));
 
 		$schdbh = null;
-                if($apiTopics){
-                    //调用试题检索接口
-                    $this->searchTopics($apiTopics,$school_id);
-                }
+        if($apiTopics){
+            //调用试题检索接口
+            $this->searchTopics($apiTopics,$school_id);
+        }
 		exit('解析完成!');
 	}
 

+ 10 - 1
protected/yiic.php

@@ -1,7 +1,16 @@
 <?php
 
 // change the following paths if necessary
+foreach ($_SERVER['argv'] as $k => $v) {
+    if (strpos($v, '--YII_ENV=') !== FALSE) {
+        $env = substr($v, strlen('--YII_ENV='));
+    }
+}
 $yiic=dirname(__FILE__).'/../framework/yiic.php';
-$config=dirname(__FILE__).'/config/console.php';
+$configFile = dirname(__FILE__)."/config/cache/console.{$env}.php";
+if (! file_exists($configFile)) {
+    $configFile=dirname(__FILE__)."/config/console.{$env}.php";;
+}
+$config=$configFile;
 
 require_once($yiic);