|
@@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Schema;
|
|
|
* 题目质检服务
|
|
* 题目质检服务
|
|
|
*
|
|
*
|
|
|
* 校验规则:题干、答案、解析、选项、公式、PDF 呈现
|
|
* 校验规则:题干、答案、解析、选项、公式、PDF 呈现
|
|
|
- * 自动质检 + 人工质检结果分别记录到 question_qc_results
|
|
|
|
|
|
|
+ * 结果由命令输出,不落库(避免本地库覆盖)
|
|
|
*/
|
|
*/
|
|
|
class QuestionQualityCheckService
|
|
class QuestionQualityCheckService
|
|
|
{
|
|
{
|
|
@@ -27,7 +27,7 @@ class QuestionQualityCheckService
|
|
|
* 对单道题目执行自动质检
|
|
* 对单道题目执行自动质检
|
|
|
*
|
|
*
|
|
|
* @param array $question 题目数据,需包含 stem, answer, solution, question_type, options
|
|
* @param array $question 题目数据,需包含 stem, answer, solution, question_type, options
|
|
|
- * @param int|null $questionTemId question_tem 表 ID
|
|
|
|
|
|
|
+ * @param int|null $questionTemId questions_tem 表 ID
|
|
|
* @param int|null $questionId questions 表 ID
|
|
* @param int|null $questionId questions 表 ID
|
|
|
* @return array ['passed' => bool, 'results' => array, 'errors' => array]
|
|
* @return array ['passed' => bool, 'results' => array, 'errors' => array]
|
|
|
*/
|
|
*/
|
|
@@ -108,10 +108,6 @@ class QuestionQualityCheckService
|
|
|
|
|
|
|
|
$passed = empty($errors);
|
|
$passed = empty($errors);
|
|
|
|
|
|
|
|
- foreach ($results as $r) {
|
|
|
|
|
- $this->saveQcResult($r, $questionTemId, $questionId, 'auto');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
return [
|
|
return [
|
|
|
'passed' => $passed,
|
|
'passed' => $passed,
|
|
|
'results' => $results,
|
|
'results' => $results,
|
|
@@ -153,54 +149,8 @@ class QuestionQualityCheckService
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private function saveQcResult(array $r, ?int $questionTemId, ?int $questionId, string $source): void
|
|
|
|
|
- {
|
|
|
|
|
- if (!Schema::hasTable('question_qc_results')) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- DB::table('question_qc_results')->insert([
|
|
|
|
|
- 'question_tem_id' => $questionTemId,
|
|
|
|
|
- 'question_id' => $questionId,
|
|
|
|
|
- 'rule_code' => $r['rule_code'],
|
|
|
|
|
- 'rule_name' => $r['rule_name'] ?? null,
|
|
|
|
|
- 'passed' => $r['passed'],
|
|
|
|
|
- 'auto_result' => $r['auto_result'] ?? ($r['passed'] ? 'pass' : 'fail'),
|
|
|
|
|
- 'manual_result' => null,
|
|
|
|
|
- 'pdf_render_ok' => null,
|
|
|
|
|
- 'detail' => $r['detail'] ?? null,
|
|
|
|
|
- 'source' => $source,
|
|
|
|
|
- 'created_at' => now(),
|
|
|
|
|
- 'updated_at' => now(),
|
|
|
|
|
- ]);
|
|
|
|
|
- } catch (\Throwable $e) {
|
|
|
|
|
- Log::warning('QuestionQualityCheckService: 保存质检结果失败', [
|
|
|
|
|
- 'rule_code' => $r['rule_code'],
|
|
|
|
|
- 'error' => $e->getMessage(),
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 记录人工质检结果(更新已有自动质检记录)
|
|
|
|
|
- */
|
|
|
|
|
- public function recordManualResult(int $questionTemId, string $ruleCode, string $manualResult, ?bool $pdfRenderOk = null): void
|
|
|
|
|
- {
|
|
|
|
|
- if (!Schema::hasTable('question_qc_results')) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- DB::table('question_qc_results')
|
|
|
|
|
- ->where('question_tem_id', $questionTemId)
|
|
|
|
|
- ->where('rule_code', $ruleCode)
|
|
|
|
|
- ->update([
|
|
|
|
|
- 'manual_result' => $manualResult,
|
|
|
|
|
- 'pdf_render_ok' => $pdfRenderOk,
|
|
|
|
|
- 'updated_at' => now(),
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 获取下学期章节关联的、题少的 KP 列表(用于筛选 question_tem)
|
|
|
|
|
|
|
+ * 获取下学期章节关联的、题少的 KP 列表(用于筛选 questions_tem)
|
|
|
*
|
|
*
|
|
|
* @param int|null $textbookId 教材 ID,null 则取默认教材
|
|
* @param int|null $textbookId 教材 ID,null 则取默认教材
|
|
|
* @param int $semesterCode 学期 1=上 2=下
|
|
* @param int $semesterCode 学期 1=上 2=下
|
|
@@ -209,7 +159,10 @@ class QuestionQualityCheckService
|
|
|
*/
|
|
*/
|
|
|
public function getKpsWithFewQuestions(?int $textbookId = null, int $semesterCode = 2, int $limit = 50): array
|
|
public function getKpsWithFewQuestions(?int $textbookId = null, int $semesterCode = 2, int $limit = 50): array
|
|
|
{
|
|
{
|
|
|
- $textbooksQuery = DB::table('textbooks')->where('is_deleted', 0);
|
|
|
|
|
|
|
+ $textbooksQuery = DB::table('textbooks');
|
|
|
|
|
+ if (Schema::hasColumn('textbooks', 'is_deleted')) {
|
|
|
|
|
+ $textbooksQuery->where('is_deleted', 0);
|
|
|
|
|
+ }
|
|
|
if ($textbookId) {
|
|
if ($textbookId) {
|
|
|
$textbooksQuery->where('id', $textbookId);
|
|
$textbooksQuery->where('id', $textbookId);
|
|
|
}
|
|
}
|