소스 검색

导入报错

brealinxx 1 년 전
부모
커밋
70db358b38

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

@@ -2,6 +2,7 @@ package com.xjrsoft.module.base.controller;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xjrsoft.common.handler.FormContentStyleStrategy;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
 import com.xjrsoft.common.model.result.RT;
@@ -11,6 +12,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import com.alibaba.excel.EasyExcel;
 import com.xjrsoft.module.base.entity.ClassCourseTextbook;
 import com.xjrsoft.module.base.entity.CourseBookInfo;
+import com.xjrsoft.module.base.entity.ExportBaseClassCourseVo;
 import com.xjrsoft.module.base.service.impl.BaseCourseSubjectServiceImpl;
 import com.xjrsoft.module.textbook.service.impl.TextbookServiceImpl;
 import org.apache.ibatis.annotations.Param;
@@ -21,7 +23,7 @@ import java.io.IOException;
 import com.alibaba.excel.support.ExcelTypeEnum;
 import org.springframework.http.ResponseEntity;
 import java.io.ByteArrayOutputStream;
-import java.util.ArrayList;
+import java.util.*;
 
 import com.xjrsoft.module.base.dto.BaseClassCoursePageDto;
 import com.xjrsoft.module.base.entity.BaseClassCourse;
@@ -35,9 +37,7 @@ import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
 * @title: 班级课程
@@ -156,7 +156,7 @@ public class BaseClassCourseController {
     @PostMapping("/import")
     @ApiOperation(value = "导入")
     public RT<Boolean> importData(@RequestParam MultipartFile file) throws IOException {
-        List<BaseClassCoursePageVo> savedDataList = EasyExcel.read(file.getInputStream()).head(BaseClassCoursePageVo.class).sheet().doReadSync();
+        List<BaseClassCoursePageVo> savedDataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(BaseClassCoursePageVo.class).sheet().doReadSync();
 
         List<BaseClassCourse> baseClassCourses = new ArrayList<>();
         List<String> duplicateLogs = new ArrayList<>();
@@ -169,7 +169,7 @@ public class BaseClassCourseController {
                 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()));
+                    duplicateLogs.add(String.format("[输入的信息重复添加] 班级: %s, 课程: %s, 教材: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
                     continue;
                 }
 
@@ -183,16 +183,16 @@ public class BaseClassCourseController {
                     baseClassCourses.add(baseClassCourse);
                 }
             } catch (NumberFormatException e) {
-                errorLogs.add(String.format("无法解析输入的信息: %s, Course: %s, Textbook: %s", vo.getClassName(), vo.getCourseName(), vo.getTextbookName()));
+                errorLogs.add(String.format("[无法解析输入的信息] 班级: %s, 班级: %s, 教材: %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()));
+                errorLogs.add(String.format("[意外错误(检查输入的名称是否正确且存在,输入错误可能返回 null)] 班级: %s, 课程: %s, 教材: %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));
+            String detailedMessage = String.format("[导入完成但存在问题] 问题: %s. 其他错误: %s", String.join("; ", duplicateLogs), String.join("; ", errorLogs));
             return RT.error(400, detailedMessage);
         }
 

+ 25 - 0
src/main/java/com/xjrsoft/module/base/entity/ExportBaseClassCourseVo.java

@@ -0,0 +1,25 @@
+package com.xjrsoft.module.base.entity;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class ExportBaseClassCourseVo {
+
+    @ExcelProperty("年级")
+    @ApiModelProperty("年级")
+    private String semester;
+
+    @ExcelProperty("班级名称")
+    @ApiModelProperty("班级名称")
+    private String className;
+
+    @ExcelProperty("教学课程")
+    @ApiModelProperty("教学课程")
+    private String courseName;
+
+    @ExcelProperty("对应教材")
+    @ApiModelProperty("对应教材")
+    private String textbookName;
+}

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

@@ -27,77 +27,66 @@ public class BaseClassCoursePageVo {
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private String id;
     /**
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private Long createUserId;
     /**
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private Date createDate;
     /**
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private Long modifyUserId;
     /**
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private Date modifyDate;
     /**
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private Integer deleteMark;
     /**
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private Integer enabledMark;
     /**
     * 
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("")
     @ApiModelProperty("")
     private Integer sortCode;
     /**
     * 班级id(base_class)
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("班级id(base_class)")
     @ApiModelProperty("班级id(base_class)")
     private Long classId;
     /**
     * 课程id(base_course_subject)
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("课程id(base_course_subject)")
     @ApiModelProperty("课程id(base_course_subject)")
     private Long courseId;
     /**
     * 教材id(textbook)
     */
     @ContentStyle(dataFormat = 49)
-    @ExcelProperty("教材id(textbook)")
     @ApiModelProperty("教材id(textbook)")
     private Long textbookId;
 

+ 14 - 13
src/main/resources/mapper/base/BaseClassCourse.xml

@@ -4,24 +4,24 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.xjrsoft.module.base.mapper.BaseClassCourseMapper">
     <select id="getPage" parameterType="com.xjrsoft.module.base.dto.BaseClassCoursePageDto" resultType="com.xjrsoft.module.base.vo.BaseClassCoursePageVo">
-        select t5.id, t.name as class_name, t1.name as teacher_name, t3.name as major_name, t4.name as dept_name,
-               GROUP_CONCAT(t6.name SEPARATOR '、') as course_name, GROUP_CONCAT(t7.book_name SEPARATOR '、') as textbook_name
-        from base_class t
-        left join xjr_user t1 on t1.id = t.teacher_id
-        left join base_class_major_set t2 on t2.class_id = t.id
-        left join base_major_set t3 on t3.id = t2.major_set_id
-        left join xjr_department t4 on t4.id = t.org_id
-        left join base_class_course t5 on t5.class_id = t.id
-        left join base_course_subject t6 on t6.id = t5.course_id
-        left join textbook t7 on t7.id = t5.textbook_id
-        where t5.delete_mark = 0
+        SELECT t.id AS class_id, t.name AS class_name, t1.name AS teacher_name, t3.name AS major_name, t4.name AS dept_name,
+        GROUP_CONCAT(DISTINCT t6.name SEPARATOR '、') AS course_name,
+        GROUP_CONCAT(DISTINCT t7.book_name SEPARATOR '、') AS textbook_name
+        FROM base_class t
+        LEFT JOIN xjr_user t1 ON t1.id = t.teacher_id
+        LEFT JOIN base_class_major_set t2 ON t2.class_id = t.id
+        LEFT JOIN base_major_set t3 ON t3.id = t2.major_set_id
+        LEFT JOIN xjr_department t4 ON t4.id = t.org_id
+        LEFT JOIN base_class_course t5 ON t5.class_id = t.id
+        LEFT JOIN base_course_subject t6 ON t6.id = t5.course_id
+        LEFT JOIN textbook t7 ON t7.id = t5.textbook_id
+        WHERE t5.delete_mark = 0
         <if test="dto.className != null">
             and t.name = #{dto.className}
         </if>
         <if test="dto.deptId != null">
             and t4.id = #{dto.deptId}
         </if>
-
         <if test="dto.semester != null">
             and (
             SELECT base_semester_id
@@ -31,7 +31,7 @@
             HAVING COUNT(DISTINCT base_semester_id) = 1
             ) = #{dto.semester}
         </if>
-        GROUP BY t5.id, t.name, t1.name, t3.name, t4.name
+        GROUP BY t.id, t.name, t1.name, t3.name, t4.name
         <if test="dto.courseSet == 1">
             HAVING LENGTH(course_name) > 0
         </if>
@@ -40,6 +40,7 @@
         </if>
     </select>
 
+
     <select id="getAllCourseBook" resultType="com.xjrsoft.module.base.entity.CourseBookInfo">
         select t1.id as courseId, t1.name as courseName,t.book_name as bookName
         from textbook t