|
@@ -159,25 +159,43 @@ public class BaseClassCourseController {
|
|
|
List<BaseClassCoursePageVo> savedDataList = EasyExcel.read(file.getInputStream()).head(BaseClassCoursePageVo.class).sheet().doReadSync();
|
|
|
|
|
|
List<BaseClassCourse> baseClassCourses = new ArrayList<>();
|
|
|
+ List<String> duplicateLogs = new ArrayList<>();
|
|
|
+ List<String> errorLogs = new ArrayList<>();
|
|
|
+
|
|
|
for (BaseClassCoursePageVo vo : savedDataList) {
|
|
|
- Long classId = Long.parseLong(baseClassCourseService.GetClassIdByName(vo.getClassName()).toString());
|
|
|
- Long courseId = Long.parseLong(baseClassCourseService.GetCourseIdByName(vo.getCourseName()).toString());
|
|
|
- Long textbookId = Long.parseLong(baseClassCourseService.GetTextbookIdByName(vo.getTextbookName()).toString());
|
|
|
-
|
|
|
- if (baseClassCourseService.checkExits(classId, courseId, textbookId)) continue;
|
|
|
-
|
|
|
- if (classId != null && courseId != null && textbookId != null) {
|
|
|
- BaseClassCourse baseClassCourse = new BaseClassCourse();
|
|
|
- baseClassCourse.setClassId(classId);
|
|
|
- baseClassCourse.setCourseId(courseId);
|
|
|
- baseClassCourse.setTextbookId(textbookId);
|
|
|
- baseClassCourse.setCreateDate(new Date());
|
|
|
- baseClassCourse.setDeleteMark(0);
|
|
|
- baseClassCourses.add(baseClassCourse);
|
|
|
+ try {
|
|
|
+ Long classId = Long.parseLong(baseClassCourseService.GetClassIdByName(vo.getClassName()).toString());
|
|
|
+ Long courseId = Long.parseLong(baseClassCourseService.GetCourseIdByName(vo.getCourseName()).toString());
|
|
|
+ Long textbookId = Long.parseLong(baseClassCourseService.GetTextbookIdByName(vo.getTextbookName()).toString());
|
|
|
+
|
|
|
+ if (baseClassCourseService.checkExits(classId, courseId, textbookId)) {
|
|
|
+ duplicateLogs.add(String.format("输入的信息重复添加: %s, Course: %s, Textbook: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (classId != null && courseId != null && textbookId != null) {
|
|
|
+ BaseClassCourse baseClassCourse = new BaseClassCourse();
|
|
|
+ baseClassCourse.setClassId(classId);
|
|
|
+ baseClassCourse.setCourseId(courseId);
|
|
|
+ baseClassCourse.setTextbookId(textbookId);
|
|
|
+ baseClassCourse.setCreateDate(new Date());
|
|
|
+ baseClassCourse.setDeleteMark(0);
|
|
|
+ baseClassCourses.add(baseClassCourse);
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ errorLogs.add(String.format("无法解析输入的信息: %s, Course: %s, Textbook: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ errorLogs.add(String.format("Unexpected error for Class: %s, Course: %s, Textbook: %s - %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName(), e.getMessage()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Boolean result = baseClassCourseService.saveBatch(baseClassCourses);
|
|
|
+
|
|
|
+ if (!duplicateLogs.isEmpty() || !errorLogs.isEmpty()) {
|
|
|
+ String detailedMessage = String.format("导入完成但存在问题. Duplicates: %s. Errors: %s", String.join("; ", duplicateLogs), String.join("; ", errorLogs));
|
|
|
+ return RT.error(400, detailedMessage);
|
|
|
+ }
|
|
|
+
|
|
|
return RT.ok(result);
|
|
|
}
|
|
|
|