diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/config/SaTokenConfigure.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/config/SaTokenConfigure.java index b0228b1..3753107 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/config/SaTokenConfigure.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/config/SaTokenConfigure.java @@ -25,11 +25,13 @@ public class SaTokenConfigure implements WebMvcConfigurer { SaRouter.match("/**") .notMatch("/login/**") - .notMatch("plan/word/voice") + .notMatch("/plan/word/voice") + .notMatch("/plan/word/voice/tts") .check(r -> StpUtil.checkLogin()); SaRouter.match("/admin/**") - .notMatch("plan/word/voice") + .notMatch("/plan/word/voice") + .notMatch("/plan/word/voice/tts") .check(r -> StpUtil.checkRole("root")); })) diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/ExamWordsController.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/ExamWordsController.java index 4170ae9..17a6950 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/ExamWordsController.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/ExamWordsController.java @@ -72,6 +72,12 @@ public class ExamWordsController { data.put("examStr", examWordsDO.getTitle()); data.put("words", assessmentWords); data.put("answer", assessmentWords); + + List words1 = assessmentWords.subList(0, assessmentWords.size() / 2); + List words2 = assessmentWords.subList(assessmentWords.size() / 2, assessmentWords.size()); + data.put("words1", words1); + data.put("words2", words2); + return data; }).toList(); diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/UserController.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/UserController.java index 97fd078..54b04d3 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/UserController.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/controller/UserController.java @@ -35,7 +35,7 @@ public class UserController { } @PostMapping("update-user-info") - @ApiOperationLog(description = "修改密码") + @ApiOperationLog(description = "修改用户信息") public Response updatePassword(@RequestBody UpdateUserInfoReqVO updateUserInfoReqVO) { try { String code = updateUserInfoReqVO.getCode(); diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/domain/mapper/VocabularyBankDOMapper.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/domain/mapper/VocabularyBankDOMapper.java index fd5e93f..6175f30 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/domain/mapper/VocabularyBankDOMapper.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/domain/mapper/VocabularyBankDOMapper.java @@ -26,4 +26,6 @@ public interface VocabularyBankDOMapper { Integer selectWordTotal(); List selectByUnitIds(@Param("unitIds") List unitIds); + + List selectByGradeIdAndNotMatchIds(@Param("gradeId") Integer gradeId, @Param("ids") List ids, @Param("wordCount") Integer wordCount); } \ No newline at end of file diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/exam/ExamWordsServiceImpl.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/exam/ExamWordsServiceImpl.java index fb1f81e..09b1b47 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/exam/ExamWordsServiceImpl.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/exam/ExamWordsServiceImpl.java @@ -47,7 +47,6 @@ public class ExamWordsServiceImpl implements ExamWordsService { @Transactional(rollbackFor = RuntimeException.class) public ExamWordsDO generateExamWords(Integer studentId, Integer type) { - ExamWordsDO examWordsDO; if (type == ExamWordsConstant.EXAM_TYPE_BASELINE) { @@ -61,6 +60,16 @@ public class ExamWordsServiceImpl implements ExamWordsService { examWordsDO = generateFinalExamWords(studentId); } + List wordIds = new ArrayList<>(examWordsDO.getWordIds()); + if (wordIds.size() < wordCount) { + log.info("单词数量不足,补充单词"); + StudentDO studentDO = studentDOMapper.selectStudentById(studentId); + List vocabularyBankDOS = vocabularyBankDOMapper.selectByGradeIdAndNotMatchIds(studentDO.getGradeId(), wordIds, wordCount - wordIds.size()); + List list = new ArrayList<>(vocabularyBankDOS.stream().map(VocabularyBankDO::getId).toList()); + wordIds.addAll(list); + examWordsDO.setWordIds(wordIds); + } + return examWordsDO; } diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/plan/LessonPlansServiceImpl.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/plan/LessonPlansServiceImpl.java index ad603fa..8b7ec52 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/plan/LessonPlansServiceImpl.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/service/plan/LessonPlansServiceImpl.java @@ -50,7 +50,8 @@ public class LessonPlansServiceImpl implements LessonPlansService { private PlanExamDOMapper planExamDOMapper; @Resource private RedisTemplate redisTemplate; - + @Resource + private ClassDOMapper classDOMapper; @Override public void generateLessonPlans(Integer studentId, Integer unitId, Integer wordSize) { @@ -227,11 +228,16 @@ public class LessonPlansServiceImpl implements LessonPlansService { examWordsDOMapper.insert(examWordsDO); studentExamWordsDOMapper.insertStudentsExam(studentId, examWordsDO.getId()); + ClassDO classDO = classDOMapper.selectClassDOById(studentDOMapper.selectStudentById(studentId).getClassId()); data.put("examId", examWordsDO.getId()); data.put("studentId", studentId); - data.put("studentStr", studentDO.getName()); + data.put("studentStr", gradeDO.getTitle() + " " + classDO.getTitle() + " " + studentDO.getName()); data.put("examStr", ExamTitle); - data.put("checkList", words); + + List words1 = words.subList(0, words.size() / 2); + List words2 = words.subList(words.size() / 2, words.size()); + data.put("words1", words1); + data.put("words2", words2); // LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); // Configure config = Configure.builder() // .bind("checkList", policy) @@ -250,6 +256,7 @@ public class LessonPlansServiceImpl implements LessonPlansService { List checkList, int day, GradeDO gradeDO, UnitDO unitDO, Integer studentId) throws Exception { + String title = gradeDO.getTitle() + " " + unitDO.getTitle() + " " + "第" + day + "天"; Map data = new HashMap<>(); data.put("title", title); @@ -258,7 +265,6 @@ public class LessonPlansServiceImpl implements LessonPlansService { data.put("reviewVocabList", reviewVocabList); data.put("checkList", checkList); data.put("checkListAns", checkList); - // 中译英 List list = syncVocabList.stream().map(vocabularyBankDO -> Word.builder().title(vocabularyBankDO.getWord()).definition(vocabularyBankDO.getDefinition()).build()).toList(); list.forEach(word -> word.setTitle(" ")); @@ -344,7 +350,12 @@ public class LessonPlansServiceImpl implements LessonPlansService { data.put("studentId", studentId); data.put("studentStr", studentDO.getName()); data.put("examStr", ExamTitle); - data.put("words", words); + + List words1 = words.subList(0, wordIds.size() / 2); + List words2 = words.subList(wordIds.size() / 2, wordIds.size()); + data.put("words1", words1); + data.put("words2", words2); + log.info("生成教案小测成功"); // LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/PngUtil.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/PngUtil.java index 27142b6..3c94a22 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/PngUtil.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/PngUtil.java @@ -48,14 +48,14 @@ public class PngUtil { // 反转后,黑色块变成白色(255),背景变成黑色(0),方便 findContours 查找。 Mat binary = new Mat(); // 阈值设为 50 左右即可,因为块是纯黑的 - Imgproc.threshold(gray, binary, 50, 255, Imgproc.THRESH_BINARY_INV); + Imgproc.threshold(gray, binary, 80, 255, Imgproc.THRESH_BINARY_INV); // 4. 查找轮廓 List contours = new ArrayList<>(); Mat hierarchy = new Mat(); // RETR_EXTERNAL 只检测最外层轮廓,忽略块内部可能存在的噪点 Imgproc.findContours(binary, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); - + //Imgcodecs.imwrite("output_red___v1.png", binary); System.out.println("检测到的轮廓总数: " + contours.size()); System.out.println("------------------------------------------------"); @@ -89,32 +89,18 @@ public class PngUtil { System.out.println("------------------------------------------------"); list.add(CoordinatesXY.builder().x(rect.x).y(rect.y).width(rect.width).height(rect.height).build()); // 可选:在原图上画出框,用于调试验证 -// Imgproc.rectangle(src, rect, new Scalar(0, 0, 255), 2); // 红色框 -// Imgproc.putText(src, "#" + blockCount, new Point(rect.x, rect.y - 5), Imgproc.FONT_HERSHEY_SIMPLEX, 0.5, new Scalar(0, 0, 255), 1); -// Imgcodecs.imwrite("output_red.png", src); + Imgproc.rectangle(src, rect, new Scalar(0, 0, 255), 2); // 红色框 + Imgproc.putText(src, "#" + blockCount, new Point(rect.x, rect.y - 5), Imgproc.FONT_HERSHEY_SIMPLEX, 0.5, new Scalar(0, 0, 255), 1); + //Imgcodecs.imwrite("output_red.png", src); } } System.out.println("找到 " + blockCount + " 个黑色块。"); - // 获取每一列的宽度 - list.sort(Comparator.comparingInt(CoordinatesXY::getHeight)); - int height = list.get(list.size() - 1).getHeight() / ExamWordsConstant.PGN_COL; - - // 删除两列答题卡区块 - list.sort(Comparator.comparingInt(CoordinatesXY::getWidth)); - list.remove(list.size() - 1); - list.remove(list.size() - 1); - list.sort(Comparator.comparingInt(CoordinatesXY::getX)); // 计算起始坐标 - List ans = getCoordinatesXIES(list, height); + list.sort(Comparator.comparingInt(CoordinatesXY::getX)); - src.release(); - binary.release(); - hierarchy.release(); - binary.release(); - - return ans; + return list; } // 获取(未背熟)单词的 id @@ -134,22 +120,18 @@ public class PngUtil { // 建议:如果光照不均匀,考虑使用 THRESH_OTSU 自动阈值,或者自适应阈值 Imgproc.threshold(gray, binary, 150, 255, Imgproc.THRESH_BINARY_INV); // 调试时打印 - // Imgcodecs.imwrite("output_binary.png", binary); + //Imgcodecs.imwrite("output_binary.png", binary); List answer = new ArrayList<>(); int words_index = 0; - for (int i = 0; i < coordinatesXYList.size(); i++) { - CoordinatesXY coordinatesXY = coordinatesXYList.get(i); - + for (CoordinatesXY coordinatesXY : coordinatesXYList) { int width = coordinatesXY.getWidth(); int height = coordinatesXY.getHeight(); int currentX = coordinatesXY.getX(); - int currentY = coordinatesXY.getY(); - - int count = i == 0 ? ExamWordsConstant.PGN_COL - 1 : ExamWordsConstant.PGN_COL; + int currentY = coordinatesXY.getY() + height; // 内层循环:遍历这一列的每一行 - for (int j = 0; j < count; j++) { + for (int j = 0; j < 50; j++) { // 安全检查:防止单词列表比格子少导致越界 if (words_index >= wordIds.size()) { log.warn("单词列表耗尽,停止检测。格子数多于单词数。"); @@ -169,11 +151,14 @@ public class PngUtil { Mat region = binary.submat(rect); int countNonZero = Core.countNonZero(region); - if (countNonZero > 500) { + if (countNonZero > 370) { Integer id = wordIds.get(words_index); answer.add(id); log.info("检测到标记(未背熟):ID={}, 当前坐标 x = {} y = {} ", id, currentX + 1, currentY + 1); } + if (countNonZero == 0) { + break; + } region.release(); words_index++; @@ -217,7 +202,7 @@ public class PngUtil { Imgproc.threshold(gray, binary, 0, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU); // 可选:保存预处理后的图片查看效果 -// Imgcodecs.imwrite("debug_roi.jpg", binary); + //Imgcodecs.imwrite("debug_roi.jpg", binary); // 4. 将 OpenCV Mat 转换为 BufferedImage (供 Tess4J 使用) BufferedImage processedImage = matToBufferedImage(binary); @@ -276,21 +261,4 @@ public class PngUtil { return image; } - private static @NonNull List getCoordinatesXIES(List list, int height) { - List ans = new ArrayList<>(); - CoordinatesXY left = new CoordinatesXY(); - left.setX(list.get(1).getX()); - left.setWidth(list.get(1).getWidth()); - left.setHeight(height); - left.setY(list.get(0).getY() + left.getHeight()); - ans.add(left); - - CoordinatesXY right = new CoordinatesXY(); - right.setX(list.get(2).getX()); - right.setY(list.get(0).getY()); - right.setWidth(list.get(1).getWidth()); - right.setHeight(height); - ans.add(right); - return ans; - } } diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/WordExportUtil.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/WordExportUtil.java index 89c86dd..4eb147c 100644 --- a/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/WordExportUtil.java +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/utils/WordExportUtil.java @@ -36,6 +36,8 @@ public class WordExportUtil { LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); config = Configure.builder() .bind("words", policy) + .bind("words1", policy) + .bind("words2", policy) .bind("answer", policy) .build(); @@ -52,12 +54,14 @@ public class WordExportUtil { .bind("checkListAns", policyLessonPlanWeekday) .bind("sentences", policyLessonPlanWeekday) .bind("sentencesAns", policyLessonPlanWeekday) - .bind("words", policyLessonPlanWeekday) + .bind("words1", policy) + .bind("words2", policy) .build(); LoopRowTableRenderPolicy policyLessonPlan = new LoopRowTableRenderPolicy(); configLessonPlanWeekend = Configure.builder() - .bind("checkList", policyLessonPlan) + .bind("words1", policy) + .bind("words2", policy) .build(); } diff --git a/enlish-service/src/main/resources/config/application-dev.yml b/enlish-service/src/main/resources/config/application-dev.yml index 79c1f5b..9d1a221 100644 --- a/enlish-service/src/main/resources/config/application-dev.yml +++ b/enlish-service/src/main/resources/config/application-dev.yml @@ -2,7 +2,7 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver # 指定数据库驱动类 # 数据库连接信息 - url: jdbc:mysql://124.220.58.5:3306/enlish?allowMultiQueries=true + url: jdbc:mysql://124.220.58.5:3306/dev_english?allowMultiQueries=true username: root # 数据库用户名 password: YLHP@admin123 # 数据库密码 data: @@ -31,12 +31,12 @@ spring: templates: - word: C:\project\java\enlish_edu\enlish\enlish-service\src\main\resources\templates\assessment_v5.docx + word: C:\project\java\enlish_edu\enlish\enlish-service\src\main\resources\templates\assessment_v9.docx count: 100 data: C:\project\tess plan: - weekday: C:\project\java\enlish_edu\enlish\enlish-service\src\main\resources\templates\tem_study_plan_v6.docx - weekend: C:\project\java\enlish_edu\enlish\enlish-service\src\main\resources\templates\study_plan_review_v2.docx + weekday: C:\project\java\enlish_edu\enlish\enlish-service\src\main\resources\templates\tem_study_plan_v7.docx + weekend: C:\project\java\enlish_edu\enlish\enlish-service\src\main\resources\templates\study_plan_review_v3.docx plan_day: 7 tmp: png: C:\project\java\enlish_edu\enlish\enlish-service\src\main\resources\tmp\png\ diff --git a/enlish-service/src/main/resources/config/application-pro.yml b/enlish-service/src/main/resources/config/application-pro.yml index 67722a2..8933e83 100644 --- a/enlish-service/src/main/resources/config/application-pro.yml +++ b/enlish-service/src/main/resources/config/application-pro.yml @@ -31,11 +31,11 @@ spring: templates: - word: assessment_v5.docx + word: assessment_v7.docx count: 100 data: eng.traineddata plan: - weekday: tem_study_plan_v5.docx + weekday: tem_study_plan_v6.docx weekend: study_plan_review_v2.docx plan_day: 7 tmp: diff --git a/enlish-service/src/main/resources/mapper/StudentExamWordsDOMapper.xml b/enlish-service/src/main/resources/mapper/StudentExamWordsDOMapper.xml index 9e52f3d..b962291 100644 --- a/enlish-service/src/main/resources/mapper/StudentExamWordsDOMapper.xml +++ b/enlish-service/src/main/resources/mapper/StudentExamWordsDOMapper.xml @@ -21,7 +21,6 @@ from student_exam_words where student_id = #{studentId} and exam_words_id = #{examWordsId} - and is_completed = 0 diff --git a/enlish-service/src/main/resources/mapper/VocabularyBankDOMapper.xml b/enlish-service/src/main/resources/mapper/VocabularyBankDOMapper.xml index 4d5ec67..a0dc1de 100644 --- a/enlish-service/src/main/resources/mapper/VocabularyBankDOMapper.xml +++ b/enlish-service/src/main/resources/mapper/VocabularyBankDOMapper.xml @@ -145,5 +145,21 @@ order by rand() limit 100 + \ No newline at end of file diff --git a/enlish-service/src/main/resources/templates/assessment_v7.docx b/enlish-service/src/main/resources/templates/assessment_v7.docx index 370ae0b..b68c8b2 100644 Binary files a/enlish-service/src/main/resources/templates/assessment_v7.docx and b/enlish-service/src/main/resources/templates/assessment_v7.docx differ diff --git a/enlish-service/src/main/resources/templates/assessment_v8.docx b/enlish-service/src/main/resources/templates/assessment_v8.docx new file mode 100644 index 0000000..cfc2f7d Binary files /dev/null and b/enlish-service/src/main/resources/templates/assessment_v8.docx differ diff --git a/enlish-service/src/main/resources/templates/assessment_v9.docx b/enlish-service/src/main/resources/templates/assessment_v9.docx new file mode 100644 index 0000000..cc82fb3 Binary files /dev/null and b/enlish-service/src/main/resources/templates/assessment_v9.docx differ diff --git a/enlish-service/src/main/resources/templates/study_plan_review_v3.docx b/enlish-service/src/main/resources/templates/study_plan_review_v3.docx new file mode 100644 index 0000000..d9f5de6 Binary files /dev/null and b/enlish-service/src/main/resources/templates/study_plan_review_v3.docx differ diff --git a/enlish-service/src/main/resources/templates/tem_study_plan_v7.docx b/enlish-service/src/main/resources/templates/tem_study_plan_v7.docx new file mode 100644 index 0000000..b7c5b22 Binary files /dev/null and b/enlish-service/src/main/resources/templates/tem_study_plan_v7.docx differ