createdFile(''); //$this->putRow($head); // $needExchangeTopics = [ // [ // 'fileName' => '1第一节 感冒', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\1第一节 感冒\\1第一节 感冒.txt" // ], // [ // 'fileName' => '2第二节 咳嗽', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\2第二节 咳嗽\\2第二节 咳嗽.txt" // ], // [ // 'fileName' => '3第三节 喘证', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\3第三节 喘证\\3第三节 喘证.txt" // ], // [ // 'fileName' => '4第四节 肺胀', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\4第四节 肺胀\\4第四节 肺胀.txt" // ], // [ // 'fileName' => '5第五节 心悸', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\5第五节 心悸\\5第五节 心悸.txt" // ], // [ // 'fileName' => '6第六节 胸痹', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\6第六节 胸痹\\6第六节 胸痹.txt" // ], // [ // 'fileName' => '7第七节 不寐', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\7第七节 不寐\\7第七节 不寐.txt" // ], // [ // 'fileName' => '8第八节 胃痛', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\8第八节 胃痛\\8第八节 胃痛.txt" // ], // [ // 'fileName' => '9第九节 泄泻', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\9第九节 泄泻\\9第九节 泄泻.txt" // ], // [ // 'fileName' => '10第十节 便秘', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\10第十节 便秘\\10第十节 便秘.txt" // ], // [ // 'fileName' => '11第十一节 头痛', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\11第十一节 头痛\\11第十一节 头痛.txt" // ], // [ // 'fileName' => '12第十二节 眩晕', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\12第十二节 眩晕\\12第十二节 眩晕.txt" // ], // [ // 'fileName' => '13第十三节 胁痛', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\13第十三节 胁痛\\13第十三节 胁痛.txt" // ], // [ // 'fileName' => '14第十四节 中风', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\14第十四节 中风\\14第十四节 中风.txt" // ], // [ // 'fileName' => '15第十五节 汗证', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\15第十五节 汗证\\15第十五节 汗证.txt" // ], // [ // 'fileName' => '4第四节 肝功能检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\4第四节 肝功能检查\\4第四节 肝功能检查.txt" // ], // [ // 'fileName' => '1第一节 血常规检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\1第一节 血常规检查\\1第一节 血常规检查.txt" // ], // [ // 'fileName' => '2第二节 尿常规检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\2第二节 尿常规检查\\2第二节 尿常规检查.txt" // ], // [ // 'fileName' => '3第三节 粪常规检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\3第三节 粪常规检查\\3第三节 粪常规检查.txt" // ], // [ // 'fileName' => '4第四节 肝功能检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\4第四节 肝功能检查\\4第四节 肝功能检查.txt" // ], // [ // 'fileName' => '1第一节 血常规检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\1第一节 血常规检查\\1第一节 血常规检查.txt" // ], // [ // 'fileName' => '2第二节 尿常规检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\2第二节 尿常规检查\\2第二节 尿常规检查.txt" // ], // [ // 'fileName' => '3第三节 粪常规检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\3第三节 粪常规检查\\3第三节 粪常规检查.txt" // ], // [ // 'fileName' => '4第四节 肝功能检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\4第四节 肝功能检查\\4第四节 肝功能检查.txt" // ], // [ // 'fileName' => '3第三节 粪常规检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\3第三节 粪常规检查\\3第三节 粪常规检查.txt" // ], // [ // 'fileName' => '4第四节 肝功能检查', // 'data' => "E:\\鸭题库数据\中药综\\5第五章 中医内科常见病的辨证论治\\4第四节 肝功能检查\\4第四节 肝功能检查.txt" // ], // // ]; $directory = "E:\\鸭题库数据\\药综\\6第六章 常见病症的健康管理"; $needExchangeTopics = $this->getFilesRecursively($directory); //dd($needExchangeTopics); $dataCount = count($needExchangeTopics); $this->info('开始转换'); $this->info("总共有:{$dataCount} 节"); $bar = $this->output->createProgressBar($dataCount); //$answerArray = ['A', 'B', 'C', 'D', 'E']; foreach ($needExchangeTopics as $needExchangeTopic) { $this->createdFile($needExchangeTopic['directory'], $needExchangeTopic['fileName']); $this->putRow($head); $data = file_get_contents($needExchangeTopic['data']); $data = json_decode($data, true); foreach ($data['data'] as $value) { //题目类型 $style = $value['style']; $styleName = $this->getStyleName($style); //dd($styleName); //题目 $title = ''; if (!empty($value['exerciseQuestionsTopicPo'])) { $title = $value['exerciseQuestionsTopicPo']['content'] . "\r\n"; } $title = $title . $value['title']; //解析 $explain = $value['explain']; //准确率 $accuracy = $value['accuracy']; // $correctAnswerStr = ''; //正确选项Str $correctAnswers = []; //正确答案数据 $selectAContent = ''; $selectBContent = ''; $selectCContent = ''; $selectDContent = ''; $selectEContent = ''; //考点 $examPointStr = ''; $examPointNames = []; $examPoints = $value['points']; foreach ($examPoints as $examPoint) { $examPointNames [] = $examPoint['name']; } $examPointStr = implode(',', $examPointNames);//考点 //dd($examPointStr); //$answerFlag = false; // $answer = $data['answer']; // // if (in_array($answer, $answerArray)) { // $answerFlag = true; //获取answer成功 // } $questionCount = $value['questionCount'] ; //选项数量 //获取选项: $questionsOptionsPos = $value['questionsOptionsPos']; foreach ($questionsOptionsPos as $key => $item) { if ($key == 0 && $key <= $questionCount-1) { $selectAContent = $item['option']; if ($item['isTrue'] == true) { $correctAnswers [] = 'A'; } } elseif ($key == 1 && $key <= $questionCount-1) { $selectBContent = $item['option']; if ($item['isTrue'] == true) { $correctAnswers [] = 'B'; } } elseif ($key == 2 && $key <= $questionCount-1) { $selectCContent = $item['option']; if ($item['isTrue'] == true) { $correctAnswers [] = 'C'; } } elseif ($key == 3 && $key <= $questionCount-1) { $selectDContent = $item['option']; if ($item['isTrue'] == true) { $correctAnswers [] = 'D'; } } elseif ($key == 4 && $key <= $questionCount-1) { $selectEContent = $item['option']; if ($item['isTrue'] == true) { $correctAnswers [] = 'E'; } } } $correctAnswerStr = implode(',', $correctAnswers); //正确答案 //dd($correctAnswerStr); $exportData = []; $exportData['style'] = $styleName; $exportData['title'] = $title; $exportData['selectA'] = $selectAContent; $exportData['selectB'] = $selectBContent; $exportData['selectC'] = $selectCContent; $exportData['selectD'] = $selectDContent; $exportData['selectE'] = $selectEContent; $exportData['answer'] = $correctAnswerStr; $exportData['explain'] = $explain; $exportData['accuracy'] = $accuracy; $exportData['point'] = $examPointStr; $this->putRow($exportData); } $this->closeFile(); $bar->advance(); } $bar->finish(); $this->info(''); $this->info('导出完成'); } public function getStyleName($style) { if ($style == 6) { $styleName = '配伍题'; } elseif ($style == 2) { $styleName = '单选题'; } elseif ($style == 3) { $styleName = '多选题'; } else { $styleName = $style; } return $styleName; } public function getFilesRecursively($directory) { // 检查目录是否存在 if (!is_dir($directory)) { return "目录不存在"; } // 获取目录下的所有文件和子目录 $files = scandir($directory); // 过滤掉 "." 和 ".."(当前目录和上一级目录) $files = array_diff($files, array('.', '..')); $result = []; foreach ($files as $file) { // 拼接完整的文件路径 $filePath = $directory . DIRECTORY_SEPARATOR . $file; // 判断是否为文件 if (is_file($filePath)) { // 过滤掉文件名中包含“数据源”的文件 if (strpos($file, '数据源') === false) { // 获取文件名的主名称(去除.txt后缀) $fileNameWithoutExtension = pathinfo($file, PATHINFO_FILENAME); // 获取文件所在的目录路径 $fileDir = dirname($filePath); // 获取文件的大小 $fileSize = filesize($filePath); $result[] = [ 'fileName' => $fileNameWithoutExtension, // 文件名(去除.txt后缀) 'data' => $filePath, // 完整路径 'directory' => $fileDir, // 文件所在目录 'size' => $fileSize // 文件大小 ]; } } elseif (is_dir($filePath)) { // 如果是目录,则递归调用 $result = array_merge($result, $this->getFilesRecursively($filePath)); } } return $result; } }