test(service): 添加考试评测相关单元测试
- 新增AssessmentService相关测试,生成学生单词测试卷文档 - 实现Excel文件单词数据导入及写入数据库的测试 - 新增OMR测试,加载OpenCV库并分析PNG文件坐标数据 - 测试未记忆单词识别功能,输出对应单词ID日志 - 更新.gitignore,移除对测试目录的忽略规则
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package com.yinlihupo.enlish.service.mapper;
|
||||
|
||||
import com.yinlihupo.enlish.service.domain.dataobject.UnitDO;
|
||||
import com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO;
|
||||
import com.yinlihupo.enlish.service.domain.mapper.UnitDOMapper;
|
||||
import com.yinlihupo.enlish.service.domain.mapper.VocabularyBankDOMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class TestInsert {
|
||||
|
||||
@Resource
|
||||
private VocabularyBankDOMapper vocabularyBankMapper;
|
||||
@Resource
|
||||
private UnitDOMapper unitDOMapper;
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
String file = "C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\test\\java\\com\\yinlihupo\\enlish\\service\\mapper\\min.xlsx";
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
try (FileInputStream fis = new FileInputStream(file); Workbook workbook = new XSSFWorkbook(fis)) {
|
||||
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
||||
Row row = sheet.getRow(i);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String gradeUnit = row.getCell(0).getStringCellValue();
|
||||
String word = row.getCell(1).getStringCellValue();
|
||||
String phonetic = row.getCell(2) != null ? row.getCell(2).getStringCellValue() : "";
|
||||
String meaning = row.getCell(3) != null ? row.getCell(3).getStringCellValue() : "";
|
||||
|
||||
int gradeUnitId = 0;
|
||||
if (map.containsKey(gradeUnit)) {
|
||||
gradeUnitId = map.get(gradeUnit);
|
||||
} else {
|
||||
UnitDO unitDO = unitDOMapper.selectByTitle(gradeUnit);
|
||||
if (unitDO == null) {
|
||||
unitDO = UnitDO.builder()
|
||||
.title(gradeUnit)
|
||||
.version("人教版")
|
||||
.createAt(LocalDateTime.now())
|
||||
.build();
|
||||
unitDOMapper.insert(unitDO);
|
||||
gradeUnitId = unitDO.getId();
|
||||
} else {
|
||||
gradeUnitId = unitDO.getId();
|
||||
}
|
||||
|
||||
map.put(gradeUnit, gradeUnitId);
|
||||
}
|
||||
VocabularyBankDO vocabularyBankDO = VocabularyBankDO.builder()
|
||||
.word(word)
|
||||
.definition(meaning)
|
||||
.pronunciation(phonetic)
|
||||
.unitId(gradeUnitId)
|
||||
.build();
|
||||
vocabularyBankMapper.insertSelective(vocabularyBankDO);
|
||||
log.info("插入数据 {} ", vocabularyBankDO);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user