Browse Source

Merge remote-tracking branch 'origin/dev' into dev

fanxp 3 months ago
parent
commit
38b2f83733

+ 47 - 29
src/main/java/com/xjrsoft/module/base/controller/BaseClassCourseController.java

@@ -26,6 +26,7 @@ import com.xjrsoft.module.base.service.IBaseClassCourseService;
 import com.xjrsoft.module.base.service.IBaseClassService;
 import com.xjrsoft.module.base.service.IBaseCourseSubjectService;
 import com.xjrsoft.module.base.service.IBaseSemesterService;
+import com.xjrsoft.module.base.vo.BaseClassCourseExcelVo;
 import com.xjrsoft.module.base.vo.BaseClassCourseExportListVo;
 import com.xjrsoft.module.base.vo.BaseClassCourseListVo;
 import com.xjrsoft.module.base.vo.BaseClassCoursePageVo;
@@ -56,7 +57,6 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * @title: 班级课程
@@ -207,7 +207,7 @@ public class BaseClassCourseController {
     @PostMapping("/import")
     @ApiOperation(value = "导入")
     public RT<Boolean> importData(@RequestParam MultipartFile file) throws IOException {
-        List<BaseClassCoursePageVo> savedDataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(BaseClassCoursePageVo.class).sheet().doReadSync();
+        List<BaseClassCourseExcelVo> savedDataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(BaseClassCourseExcelVo.class).sheet().doReadSync();
 
         List<BaseClassCourse> baseClassCourses = new ArrayList<>();
         List<String> duplicateLogs = new ArrayList<>();
@@ -234,36 +234,54 @@ public class BaseClassCourseController {
             semesterMap.put(baseSemester.getName(), baseSemester.getId());
         }
 
-        for (BaseClassCoursePageVo vo : savedDataList) {
-            String[] textbookNames = vo.getTextbookName().split(" ");
-            for (String textbookName : textbookNames) {
-                try {
-                    Long classId = classMap.get(vo.getClassName());
-                    Long courseId = courseSubjectMap.get(vo.getCourseName());
-                    Long textbookId = textbookMap.get(textbookName);
-                    Long baseSemesterId = semesterMap.get(vo.getSemester());
-
-                    if (baseClassCourseService.checkExits(classId, courseId, textbookId)) {
-                        duplicateLogs.add(String.format("[输入的信息重复添加] 班级: %s, 课程: %s, 教材: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
-                        continue;
-                    }
-
-                    if (classId != null && courseId != null && textbookId != null && baseSemesterId != null) {
-                        BaseClassCourse baseClassCourse = new BaseClassCourse();
-                        baseClassCourse.setClassId(classId);
-                        baseClassCourse.setCourseId(courseId);
-                        baseClassCourse.setTextbookId(textbookId);
-                        baseClassCourse.setCreateDate(new Date());
-                        baseClassCourse.setDeleteMark(0);
-                        baseClassCourse.setBaseSemesterId(baseSemesterId);
-                        baseClassCourses.add(baseClassCourse);
+        for (BaseClassCourseExcelVo vo : savedDataList) {
+            if(vo.getClassName() == null){
+                continue;
+            }
+            if(vo.getTextbookName() != null){
+                String[] textbookNames = vo.getTextbookName().split(" ");
+                for (String textbookName : textbookNames) {
+                    try {
+                        Long classId = classMap.get(vo.getClassName());
+                        Long courseId = courseSubjectMap.get(vo.getCourseName());
+                        Long textbookId = textbookMap.get(textbookName);
+                        Long baseSemesterId = semesterMap.get(vo.getSemester());
+
+                        if (baseClassCourseService.checkExits(classId, courseId, textbookId)) {
+                            duplicateLogs.add(String.format("[输入的信息重复添加] 班级: %s, 课程: %s, 教材: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
+                            continue;
+                        }
+
+                        if (classId != null && courseId != null && textbookId != null && baseSemesterId != null) {
+                            BaseClassCourse baseClassCourse = new BaseClassCourse();
+                            baseClassCourse.setClassId(classId);
+                            baseClassCourse.setCourseId(courseId);
+                            baseClassCourse.setTextbookId(textbookId);
+                            baseClassCourse.setCreateDate(new Date());
+                            baseClassCourse.setDeleteMark(0);
+                            baseClassCourse.setBaseSemesterId(baseSemesterId);
+                            baseClassCourses.add(baseClassCourse);
+                        }
+                    } catch (NumberFormatException e) {
+                        errorLogs.add(String.format("[无法解析输入的信息] 班级: %s, 班级: %s, 教材: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
+                    } catch (Exception e) {
+                        errorLogs.add(String.format("[意外错误(检查输入的名称是否正确且存在,输入错误可能返回 null)] 班级: %s, 课程: %s, 教材: %s - 错误信息:%s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName(), e.getMessage()));
                     }
-                } catch (NumberFormatException e) {
-                    errorLogs.add(String.format("[无法解析输入的信息] 班级: %s, 班级: %s, 教材: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
-                } catch (Exception e) {
-                    errorLogs.add(String.format("[意外错误(检查输入的名称是否正确且存在,输入错误可能返回 null)] 班级: %s, 课程: %s, 教材: %s - 错误信息:%s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName(), e.getMessage()));
                 }
+            }else{
+                Long classId = classMap.get(vo.getClassName());
+                Long courseId = courseSubjectMap.get(vo.getCourseName());
+                Long baseSemesterId = semesterMap.get(vo.getSemester());
+
+                BaseClassCourse baseClassCourse = new BaseClassCourse();
+                baseClassCourse.setClassId(classId);
+                baseClassCourse.setCourseId(courseId);
+                baseClassCourse.setCreateDate(new Date());
+                baseClassCourse.setDeleteMark(0);
+                baseClassCourse.setBaseSemesterId(baseSemesterId);
+                baseClassCourses.add(baseClassCourse);
             }
+
         }
 
         Boolean result = baseClassCourseService.saveBatch(baseClassCourses);

+ 32 - 0
src/main/java/com/xjrsoft/module/base/vo/BaseClassCourseExcelVo.java

@@ -0,0 +1,32 @@
+package com.xjrsoft.module.base.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+* @title: 班级课程分页列表出参
+* @Author brealinxx
+* @Date: 2024-06-04
+* @Version 1.0
+*/
+@Data
+public class BaseClassCourseExcelVo {
+
+
+    @ApiModelProperty("班级名称")
+    @ExcelProperty("班级名称")
+    private String className;
+
+    @ApiModelProperty("教学课程")
+    @ExcelProperty("教学课程")
+    private String courseName;
+
+    @ApiModelProperty("对应教材")
+    @ExcelProperty("对应教材")
+    private String textbookName;
+
+    @ApiModelProperty("学期")
+    @ExcelProperty("学期")
+    private String semester;
+}

+ 1 - 0
src/main/java/com/xjrsoft/module/base/vo/BaseClassCoursePageVo.java

@@ -104,6 +104,7 @@ public class BaseClassCoursePageVo {
     @ExcelProperty("对应教材")
     private String textbookName;
 
+    @ApiModelProperty("学期")
     @ExcelProperty("学期")
     private String semester;
 }