瀏覽代碼

3.1.0-同步教研分析

xiaof 3 年之前
父節點
當前提交
a5603c2238

+ 102 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/GradeBatchStudentDto.java

@@ -0,0 +1,102 @@
+package com.qmth.distributed.print.business.bean.dto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.teachcloud.common.base.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 考务数据(包含任课老师)
+ * </p>
+ *
+ * @author wangliang
+ * @since 2022-05-20
+ */
+public class GradeBatchStudentDto {
+
+    private String courseCode;
+    private String courseName;
+    private String paperNumber;
+    private String paperType;
+    private String studentCode;
+    private String studentName;
+    private String ticketNumber;
+    private String teacherName;
+    private String teacherNumber;
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getPaperNumber() {
+        return paperNumber;
+    }
+
+    public void setPaperNumber(String paperNumber) {
+        this.paperNumber = paperNumber;
+    }
+
+    public String getPaperType() {
+        return paperType;
+    }
+
+    public void setPaperType(String paperType) {
+        this.paperType = paperType;
+    }
+
+    public String getStudentCode() {
+        return studentCode;
+    }
+
+    public void setStudentCode(String studentCode) {
+        this.studentCode = studentCode;
+    }
+
+    public String getStudentName() {
+        return studentName;
+    }
+
+    public void setStudentName(String studentName) {
+        this.studentName = studentName;
+    }
+
+    public String getTicketNumber() {
+        return ticketNumber;
+    }
+
+    public void setTicketNumber(String ticketNumber) {
+        this.ticketNumber = ticketNumber;
+    }
+
+    public String getTeacherName() {
+        return teacherName;
+    }
+
+    public void setTeacherName(String teacherName) {
+        this.teacherName = teacherName;
+    }
+
+    public String getTeacherNumber() {
+        return teacherNumber;
+    }
+
+    public void setTeacherNumber(String teacherNumber) {
+        this.teacherNumber = teacherNumber;
+    }
+}

+ 28 - 18
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradeBatchServiceImpl.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
+import com.qmth.distributed.print.business.bean.dto.GradeBatchStudentDto;
 import com.qmth.distributed.print.business.bean.params.analyze.GradeBatchParam;
 import com.qmth.distributed.print.business.bean.result.analyze.GradeBatchResult;
 import com.qmth.distributed.print.business.entity.GradeBatch;
@@ -37,10 +38,8 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
+import java.net.URLEncoder;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -175,29 +174,29 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
             XSSFCell cell0 = row.createCell(0);
             cell0.setCellValue(examStudentCourseDto.getCourseCode());
 
-            XSSFCell cell1 = row.createCell(0);
+            XSSFCell cell1 = row.createCell(1);
             cell1.setCellValue(examStudentCourseDto.getCourseName());
 
-            XSSFCell cell2 = row.createCell(0);
+            XSSFCell cell2 = row.createCell(2);
             cell2.setCellValue(examStudentCourseDto.getPaperNumber());
 
-            XSSFCell cell3 = row.createCell(0);
+            XSSFCell cell3 = row.createCell(3);
             cell3.setCellValue(examStudentCourseDto.getPaperType());
 
-            XSSFCell cell4 = row.createCell(0);
+            XSSFCell cell4 = row.createCell(4);
             cell4.setCellValue(examStudentCourseDto.getStudentCode());
 
-            XSSFCell cell5 = row.createCell(0);
+            XSSFCell cell5 = row.createCell(5);
             cell5.setCellValue(examStudentCourseDto.getStudentName());
 
-            XSSFCell cell6 = row.createCell(0);
+            XSSFCell cell6 = row.createCell(6);
             cell6.setCellValue(examStudentCourseDto.getTicketNumber());
         }
 
         OutputStream output = response.getOutputStream();
         response.reset();
-        response.setCharacterEncoding("UTF-8");
-        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
+        response.setCharacterEncoding("ISO-8859-1");
+        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
         response.setContentType("application/vnd.ms-excel;charset=utf-8");
         wb.write(output);
         output.flush();
@@ -206,19 +205,20 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
 
     @Override
     public void uploadFile(Long batchId, MultipartFile file) throws IOException, NoSuchFieldException {
-        List<ExamStudentCourseDto> list = new ArrayList<>();
-        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(ExamStudentCourseDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
+        List<GradeBatchStudentDto> list = new ArrayList<>();
+        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(GradeBatchStudentDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
             List<ExcelError> excelErrorTemp = new ArrayList<>();
             // 只允许导入一个sheet
             if (finalExcelList.size() > 1) {
                 throw ExceptionResultEnum.ERROR.exception("excel中只允许有一个sheet");
             }
 
+            Map<String, String> teacherMap = new HashMap<>();
             for (int i = 0; i < finalExcelList.size(); i++) {
                 LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
                 List<Object> gradeBatchStudentTempList = excelMap.get(i);
                 for (int y = 0; y < gradeBatchStudentTempList.size(); y++) {
-                    ExamStudentCourseDto examStudentCourseDto = (ExamStudentCourseDto) gradeBatchStudentTempList.get(y);
+                    GradeBatchStudentDto examStudentCourseDto = (GradeBatchStudentDto) gradeBatchStudentTempList.get(y);
                     if (StringUtils.isBlank(examStudentCourseDto.getCourseCode())) {
                         excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程代码]必填"));
                     }
@@ -240,27 +240,36 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
                     if (StringUtils.isBlank(examStudentCourseDto.getTicketNumber())) {
                         excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[准考证号]必填"));
                     }
-                    if (StringUtils.isBlank(examStudentCourseDto.getTeacherName())) {
+                    String teacherName = examStudentCourseDto.getTeacherName();
+                    if (StringUtils.isBlank(teacherName)) {
                         excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[任课老师]必填"));
                     }
-                    if (StringUtils.isBlank(examStudentCourseDto.getTeacherNumber())) {
+                    String teacherNumber = examStudentCourseDto.getTeacherNumber();
+                    if (StringUtils.isBlank(teacherNumber)) {
                         excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[任课老师工号]必填"));
                     }
+                    if(teacherMap.containsKey(teacherNumber) && !teacherName.equals(teacherMap.get(teacherNumber))){
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel中同一个任课老师工号有多个姓名"));
+                    }
+
+                    teacherMap.put(examStudentCourseDto.getTeacherNumber(), examStudentCourseDto.getTeacherName());
 
                     list.add(examStudentCourseDto);
                 }
             }
+
             if (excelErrorTemp.size() > 0) {
                 List<String> errors = excelErrorTemp.stream().map(m -> m.getExcelErrorType()).collect(Collectors.toList());
                 throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(errors));
             }
             return finalExcelList;
         });
+
         executeImportGradeBatchStudent(batchId, list);
     }
 
     @Transactional
-    public void executeImportGradeBatchStudent(Long batchId, List<ExamStudentCourseDto> list) {
+    public void executeImportGradeBatchStudent(Long batchId, List<GradeBatchStudentDto> list) {
         UpdateWrapper<GradeBatchStudent> updateWrapper = new UpdateWrapper<>();
         updateWrapper.lambda().eq(GradeBatchStudent::getBatchId, batchId);
         gradeBatchStudentService.remove(updateWrapper);
@@ -268,6 +277,7 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
         List<GradeBatchStudent> gradeBatchStudents = list.stream().map(m -> {
             GradeBatchStudent gradeBatchStudent = new GradeBatchStudent();
             gradeBatchStudent.setBatchId(SystemConstant.getDbUuid());
+            gradeBatchStudent.setBatchId(batchId);
             gradeBatchStudent.setCourseCode(m.getCourseCode());
             gradeBatchStudent.setCourseName(m.getCourseName());
             gradeBatchStudent.setPaperNumber(m.getPaperNumber());

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/GradeBatchController.java

@@ -114,7 +114,7 @@ public class GradeBatchController {
      * @param batchId 批次ID
      */
     @ApiOperation(value = "成绩分析批次课程-批次同步")
-    @RequestMapping(value = "/batch_sync", method = RequestMethod.POST)
+    @RequestMapping(value = "/push", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "同步成功", response = EditResult.class)})
     public Result batchSync(@RequestParam Long batchId) {
         GradeBatch gradeBatch = gradeBatchService.getById(batchId);