refactor(exam): 重构摸底测试为考试词汇模块
- 删除原 Assessment 相关的实体、Mapper、Service 接口及实现和 Controller - 重命名常量类 AssessmentConstant 为 ExamWordsConstant 并调整相关常量值 - 新增 ExamWordsController 替代 AssessmentController,使用新模板生成试卷 - 新增 ExamWordsService 及其实现,实现按年级、等级和学生列表生成考试词汇 - 新增 ListWordIdTypeHandler 处理 List<Integer> 与数据库间的 JSON 转换 - 调整 PngUtil 中常量引用改为 ExamWordsConstant - 修改配置文件新增模板路径及临时目录设置 - 新增单元测试 ExamTest 验证考试词汇生成及文档导出功能 - 修改生成配置文件,支持 student_exam_words 表的数据操作 - 清理未使用的 Assessment 相关代码,精简项目结构
This commit is contained in:
@@ -1,28 +1,20 @@
|
||||
package com.yinlihupo.enlish.service.omr;
|
||||
|
||||
import com.yinlihupo.enlish.service.enums.AssessmentsType;
|
||||
import com.yinlihupo.enlish.service.model.bo.CoordinatesXY;
|
||||
import com.yinlihupo.enlish.service.model.bo.Word;
|
||||
import com.yinlihupo.enlish.service.service.AssessmentService;
|
||||
import com.yinlihupo.enlish.service.utils.PngUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import nu.pattern.OpenCV;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opencv.core.*;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class TestOmr {
|
||||
|
||||
@Resource
|
||||
private AssessmentService assessmentService;
|
||||
|
||||
@Test
|
||||
public void testOmr(){
|
||||
OpenCV.loadLocally();
|
||||
@@ -38,28 +30,7 @@ public class TestOmr {
|
||||
String path = "C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\templates\\p3.png";
|
||||
List<CoordinatesXY> coordinatesXIES = PngUtil.analysisXY(path);
|
||||
|
||||
for (CoordinatesXY coordinatesXY : coordinatesXIES) {
|
||||
log.info("坐标: {}", coordinatesXY);
|
||||
}
|
||||
|
||||
Integer studentId = 1;
|
||||
HashMap<Integer, Integer> unitIdAndWordCount = new HashMap<>();
|
||||
unitIdAndWordCount.put(142, 30);
|
||||
unitIdAndWordCount.put(132, 40);
|
||||
|
||||
Integer assessmentDocxId = assessmentService.getAssessmentDocxId(studentId, AssessmentsType.ASSESSMENT_FELT);
|
||||
List<Word> assessmentWords;
|
||||
if (assessmentDocxId == null || assessmentDocxId == 0) {
|
||||
assessmentWords = assessmentService.genAssessmentWords(studentId, unitIdAndWordCount);
|
||||
} else {
|
||||
assessmentWords = assessmentService.getAssessmentWordsById(assessmentDocxId);
|
||||
}
|
||||
|
||||
List<Integer> integers = PngUtil.analyzePngForUnmemorizedWordIds(path, assessmentWords, coordinatesXIES);
|
||||
|
||||
for (Integer integer : integers) {
|
||||
log.info("未背熟的单词ID: {}", integer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.yinlihupo.enlish.service.service;
|
||||
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import com.deepoove.poi.config.Configure;
|
||||
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
||||
import com.yinlihupo.enlish.service.enums.AssessmentsType;
|
||||
import com.yinlihupo.enlish.service.model.bo.Word;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootTest
|
||||
public class assessmentTest {
|
||||
|
||||
@Resource
|
||||
private AssessmentService assessmentService;
|
||||
|
||||
@Test
|
||||
public void generateAssessmentDocxStudent() {
|
||||
|
||||
Integer studentId = 1;
|
||||
HashMap<Integer, Integer> unitIdAndWordCount = new HashMap<>();
|
||||
unitIdAndWordCount.put(142, 30);
|
||||
unitIdAndWordCount.put(132, 40);
|
||||
|
||||
Integer assessmentDocxId = assessmentService.getAssessmentDocxId(studentId, AssessmentsType.ASSESSMENT_FELT);
|
||||
List<Word> assessmentWords;
|
||||
if (assessmentDocxId == null || assessmentDocxId == 0) {
|
||||
assessmentWords = assessmentService.genAssessmentWords(studentId, unitIdAndWordCount);
|
||||
assessmentDocxId = assessmentService.getAssessmentDocxId(studentId, AssessmentsType.ASSESSMENT_FELT);
|
||||
} else {
|
||||
assessmentWords = assessmentService.getAssessmentWordsById(assessmentDocxId);
|
||||
}
|
||||
|
||||
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
||||
Configure config = Configure.builder()
|
||||
.bind("words", policy)
|
||||
.build();
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("assessment_id", assessmentDocxId);
|
||||
data.put("words", assessmentWords);
|
||||
|
||||
// 4. 渲染并输出
|
||||
try (XWPFTemplate template = XWPFTemplate.compile("C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\templates\\assessment_v4.docx", config)) {
|
||||
template.render(data);
|
||||
template.write(new FileOutputStream("学生单词测试卷.docx"));
|
||||
System.out.println("文档生成成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.yinlihupo.enlish.service.service.exam;
|
||||
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import com.deepoove.poi.config.Configure;
|
||||
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
||||
import com.yinlihupo.enlish.service.domain.dataobject.ExamWordsDO;
|
||||
import com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO;
|
||||
import com.yinlihupo.enlish.service.model.bo.Word;
|
||||
import com.yinlihupo.enlish.service.service.ExamWordsService;
|
||||
import com.yinlihupo.enlish.service.service.VocabularyService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.*;
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class ExamTest {
|
||||
|
||||
@Resource
|
||||
private ExamWordsService examWordsService;
|
||||
@Resource
|
||||
private VocabularyService vocabularyService;
|
||||
@Test
|
||||
public void test() {
|
||||
ExamWordsDO examWordsDO = examWordsService.generateExamWords(5, 0, List.of(1));
|
||||
log.info("{}", examWordsDO);
|
||||
List<VocabularyBankDO> vocabularyBankDOS = vocabularyService.findVocabularyBankDOListById(examWordsDO.getWordIds());
|
||||
List<Word> assessmentWords = vocabularyBankDOS.stream().map(vocabularyBankDO -> Word.builder()
|
||||
.id(vocabularyBankDO.getId())
|
||||
.title(vocabularyBankDO.getWord())
|
||||
.definition(vocabularyBankDO.getDefinition())
|
||||
.build()).toList();
|
||||
|
||||
|
||||
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
||||
Configure config = Configure.builder()
|
||||
.bind("words", policy)
|
||||
.build();
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", examWordsDO.getId());
|
||||
data.put("words", assessmentWords);
|
||||
|
||||
// 4. 渲染并输出
|
||||
try (XWPFTemplate template = XWPFTemplate.compile("C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\templates\\assessment_v5.docx", config)) {
|
||||
template.render(data);
|
||||
template.write(new FileOutputStream("学生单词测试卷.docx"));
|
||||
System.out.println("文档生成成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user