考试卷app

This commit is contained in:
2025-09-04 21:26:19 +08:00
parent 490820d080
commit fbffc18a9f
4 changed files with 21 additions and 1 deletions

View File

@ -4,6 +4,8 @@ package org.dromara.safety.bo.res;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.dromara.common.translation.annotation.Translation;
import org.dromara.common.translation.constant.TransConstant;
import java.io.Serializable;
@ -49,4 +51,7 @@ public class WgzAppSubmitATestPaperRes implements Serializable {
* 试卷
*/
private String pdfStr;
@Translation(type = TransConstant.OSS_ID_TO_URL, mapper = "pdfStr")
private String pdfUrl;
}

View File

@ -4,6 +4,8 @@ package org.dromara.safety.bo.res;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.dromara.common.translation.annotation.Translation;
import org.dromara.common.translation.constant.TransConstant;
import java.io.Serializable;
@ -39,4 +41,10 @@ public class WgzAppUserScoreQuery implements Serializable {
* 试卷
*/
private String pdfStr;
@Translation(type = TransConstant.OSS_ID_TO_URL, mapper = "pdfStr")
private String pdfUrl;
}

View File

@ -48,6 +48,6 @@ public interface WgzQuestionSaveMapper extends BaseMapperPlus<WgzQuestionSave, W
String pdfSumScore (@Param("userId") Long userId);
//
@Select("SELECT c.question_type,c.question_text,c.OPTIONS,a.answer,c.correct_answer,a.correct,a.score,a.sign,a.id,a.pass,b.username as userName FROM wgz_question_save AS a LEFT JOIN wgz_user AS b ON b.user_id=a.user_id LEFT JOIN wgz_question_bank AS c ON a.bank_id=c.id WHERE a.user_id=#{userId}")
@Select("SELECT c.question_type,c.question_text,c.OPTIONS,a.answer,c.correct_answer,a.correct,a.score,a.sign,a.id,a.pass,b.nick_name as userName FROM wgz_question_save AS a LEFT JOIN sys_user AS b ON b.user_id=a.user_id LEFT JOIN wgz_question_bank AS c ON a.bank_id=c.id WHERE a.user_id=#{userId}")
List<PdfEntity> pdfSc (@Param("userId") Long userId);
}

View File

@ -266,6 +266,7 @@ public class WgzQuestionSaveServiceImpl extends ServiceImpl<WgzQuestionSaveMappe
.setSumScore(corySumScore);
wgzQuestionSavePdfService.insert(wgzQuestionSavePdf);
} catch (Exception e1) {
System.out.println("--------!!! "+e1);
throw new RuntimeException("生成PDF试卷出现了意外请重新提交");
}
return res;
@ -326,8 +327,14 @@ public class WgzQuestionSaveServiceImpl extends ServiceImpl<WgzQuestionSaveMappe
// pdf生成
private String generateExamPaper(ExaminationPaper rs) throws IOException {
//pdf文件需要改动
String fileName = DateUtils.datePath() + File.separator + rs.getUserId() + IdUtil.fastUUID() + ".pdf";
File desc = new File("file" + File.separator + "exam" + File.separator + fileName);
// 3. 关键步骤:获取父文件夹并创建(核心!)
File parentDir = desc.getParentFile(); // 获取父文件夹路径file/exam/2025/09/04
if (!parentDir.exists()) { // 判断父文件夹是否存在
parentDir.mkdirs(); // 不存在则创建所有层级文件夹mkdirs() 支持多级创建)
}
// 创建PDF文档
PdfWriter writer = new PdfWriter(desc);
PdfDocument pdfDoc = new PdfDocument(writer);