Explorar o código

Merge remote-tracking branch 'origin/dev_v3.1.0' into dev_v3.1.0

wangliang %!s(int64=3) %!d(string=hai) anos
pai
achega
6035187fb6

+ 22 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExamStudentCourseDto.java

@@ -28,6 +28,12 @@ public class ExamStudentCourseDto extends ExamStudent {
     @ApiModelProperty("试卷编号")
     private String paperNumber;
 
+    @ApiModelProperty("任课老师")
+    private String teacherName;
+
+    @ApiModelProperty("任课老师工号")
+    private String teacherNumber;
+
     public String getPaperNumber() {
         return paperNumber;
     }
@@ -59,4 +65,20 @@ public class ExamStudentCourseDto extends ExamStudent {
     public void setPaperPageA3(Integer paperPageA3) {
         this.paperPageA3 = paperPageA3;
     }
+
+    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;
+    }
 }

+ 134 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/GradeBatchStudent.java

@@ -0,0 +1,134 @@
+package com.qmth.distributed.print.business.entity;
+
+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
+ */
+@ApiModel(value = "GradeBatchStudent对象", description = "考务数据(包含任课老师)")
+public class GradeBatchStudent extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "分析-批次表ID")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long batchId;
+
+    @ApiModelProperty(value = "课程编码")
+    private String courseCode;
+
+    @ApiModelProperty(value = "课程名称")
+    private String courseName;
+
+    @ApiModelProperty(value = "试卷编号")
+    private String paperNumber;
+
+    @ApiModelProperty(value = "试卷类型")
+    private String paperType;
+
+    @ApiModelProperty(value = "学号")
+    private String studentCode;
+
+    @ApiModelProperty(value = "学生姓名")
+    private String studentName;
+
+    @ApiModelProperty(value = "准考证号")
+    private String ticketNumber;
+
+    @ApiModelProperty(value = "任课老师")
+    private String teacherName;
+
+    @ApiModelProperty(value = "任课老师工号")
+    private String teacherNumber;
+
+    public Long getBatchId() {
+        return batchId;
+    }
+
+    public void setBatchId(Long batchId) {
+        this.batchId = batchId;
+    }
+
+    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;
+    }
+}

+ 2 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamStudentMapper.java

@@ -49,4 +49,6 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudent> {
     ExamStudentPdfInfoDto getByStudentId(Long id);
 
     List<Map> listStudentScoreSync(@Param("schoolId") Long schoolId, @Param("studentCode") String studentCode, @Param("examNumber") String examNumber, @Param("subjectCode") String subjectCode, @Param("printPlanId") Long printPlanId);
+
+    List<ExamStudentCourseDto> listExamStudentByPaperNumberAndPaperType(@Param("paperNumber") String paperNumber, @Param("paperType") String paperType);
 }

+ 13 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/GradeBatchStudentMapper.java

@@ -0,0 +1,13 @@
+package com.qmth.distributed.print.business.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.distributed.print.business.entity.GradeBatchStudent;
+
+/**
+ * <p>
+ * 考试字典表 Mapper 接口
+ * </p>
+ */
+public interface GradeBatchStudentMapper extends BaseMapper<GradeBatchStudent> {
+
+}

+ 7 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/GradeBatchService.java

@@ -3,11 +3,13 @@ package com.qmth.distributed.print.business.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.distributed.print.business.bean.params.analyze.GradeBatchParam;
-import com.qmth.distributed.print.business.bean.result.TeachCourseResult;
 import com.qmth.distributed.print.business.bean.result.analyze.GradeBatchResult;
 import com.qmth.distributed.print.business.entity.GradeBatch;
 import com.qmth.teachcloud.common.entity.SysUser;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -47,4 +49,8 @@ public interface GradeBatchService extends IService<GradeBatch> {
      * @param requestUser 请求的用户
      */
     void deleteGradeBatch(List<Long> idList, SysUser requestUser);
+
+    void downloadFile(Long batchId, HttpServletResponse response) throws IOException;
+
+    void uploadFile(Long batchId, MultipartFile file) throws IOException, NoSuchFieldException;
 }

+ 15 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/GradeBatchStudentService.java

@@ -0,0 +1,15 @@
+package com.qmth.distributed.print.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.distributed.print.business.entity.GradeBatchStudent;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author wangliang
+ * @since 2022-05-20
+ */
+public interface GradeBatchStudentService extends IService<GradeBatchStudent> {
+
+}

+ 179 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradeBatchServiceImpl.java

@@ -1,25 +1,43 @@
 package com.qmth.distributed.print.business.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 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.params.analyze.GradeBatchParam;
 import com.qmth.distributed.print.business.bean.result.analyze.GradeBatchResult;
 import com.qmth.distributed.print.business.entity.GradeBatch;
 import com.qmth.distributed.print.business.entity.GradeBatchPaper;
+import com.qmth.distributed.print.business.entity.GradeBatchStudent;
 import com.qmth.distributed.print.business.enums.GradeAnalyzePaperStatusEnum;
+import com.qmth.distributed.print.business.mapper.ExamStudentMapper;
 import com.qmth.distributed.print.business.mapper.GradeBatchMapper;
 import com.qmth.distributed.print.business.service.GradeBatchPaperService;
 import com.qmth.distributed.print.business.service.GradeBatchService;
+import com.qmth.distributed.print.business.service.GradeBatchStudentService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.util.ExcelUtil;
+import com.qmth.teachcloud.common.util.excel.ExcelError;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.xssf.usermodel.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.web.multipart.MultipartFile;
 
 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;
@@ -38,6 +56,12 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
     @Resource
     GradeBatchPaperService gradeBatchPaperService;
 
+    @Resource
+    ExamStudentMapper examStudentMapper;
+
+    @Resource
+    GradeBatchStudentService gradeBatchStudentService;
+
     @Override
     public IPage<GradeBatchResult> gradeBatchPage(String batchName, int pageNumber, int pageSize, SysUser requestUser) {
         batchName = SystemConstant.translateSpecificSign(batchName);
@@ -98,4 +122,159 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
         }
         this.removeByIds(idList);
     }
+
+    @Override
+    public void downloadFile(Long batchId, HttpServletResponse response) throws IOException {
+        GradeBatch gradeBatch = this.getById(batchId);
+        QueryWrapper<GradeBatchPaper> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(GradeBatchPaper::getBatchId, batchId);
+        List<GradeBatchPaper> gradeBatchPaperList = gradeBatchPaperService.list(queryWrapper);
+        if (gradeBatchPaperList.isEmpty()) {
+            throw ExceptionResultEnum.ERROR.exception("请先添加分析课程");
+        }
+
+        List<ExamStudentCourseDto> finalList = new ArrayList<>();
+        for (GradeBatchPaper gradeBatchPaper : gradeBatchPaperList) {
+            List<ExamStudentCourseDto> examStudentList = examStudentMapper.listExamStudentByPaperNumberAndPaperType(gradeBatchPaper.getPaperNumber(), gradeBatchPaper.getPaperType());
+            if (!examStudentList.isEmpty()) {
+                finalList.addAll(examStudentList);
+            }
+        }
+
+        if (finalList.isEmpty()) {
+            throw ExceptionResultEnum.ERROR.exception("分析课程下没有考务数据");
+        }
+
+        String fileName = gradeBatch.getBatchName() + "考务数据.xlsx";
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet("考务数据");
+        XSSFFont font = wb.createFont();
+        font.setFontHeightInPoints((short) 11);
+        font.setFontName("宋体"); //什么字体
+
+        XSSFRow headRow = sheet.createRow(0);
+        XSSFCellStyle style = wb.createCellStyle();
+        style.setAlignment(HorizontalAlignment.CENTER);
+        style.setFont(font);
+
+        // 表头
+        String[] fieldsNameList = {"课程代码", "课程名称", "试卷编号", "试卷类型", "学号", "学生姓名", "准考证号", "任课老师", "任课老师工号"};
+        for (int i = 0; i < fieldsNameList.length; i++) {
+            XSSFCell cell = headRow.createCell(i);
+            cell.setCellValue(fieldsNameList[i]);
+            cell.setCellStyle(style);
+        }
+        for (int i = 1; i <= finalList.size(); i++) {
+            ExamStudentCourseDto examStudentCourseDto = finalList.get(i - 1);
+            XSSFRow row = sheet.createRow(i);
+            XSSFCell cell0 = row.createCell(0);
+            cell0.setCellValue(examStudentCourseDto.getCourseCode());
+
+            XSSFCell cell1 = row.createCell(0);
+            cell1.setCellValue(examStudentCourseDto.getCourseName());
+
+            XSSFCell cell2 = row.createCell(0);
+            cell2.setCellValue(examStudentCourseDto.getPaperNumber());
+
+            XSSFCell cell3 = row.createCell(0);
+            cell3.setCellValue(examStudentCourseDto.getPaperType());
+
+            XSSFCell cell4 = row.createCell(0);
+            cell4.setCellValue(examStudentCourseDto.getStudentCode());
+
+            XSSFCell cell5 = row.createCell(0);
+            cell5.setCellValue(examStudentCourseDto.getStudentName());
+
+            XSSFCell cell6 = row.createCell(0);
+            cell6.setCellValue(examStudentCourseDto.getTicketNumber());
+        }
+
+        OutputStream output = response.getOutputStream();
+        response.reset();
+        response.setCharacterEncoding("UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
+        response.setContentType("application/vnd.ms-excel;charset=utf-8");
+        wb.write(output);
+        output.flush();
+        output.close();
+    }
+
+    @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<ExcelError> excelErrorTemp = new ArrayList<>();
+            // 只允许导入一个sheet
+            if (finalExcelList.size() > 1) {
+                throw ExceptionResultEnum.ERROR.exception("excel中只允许有一个sheet");
+            }
+
+            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);
+                    if (StringUtils.isBlank(examStudentCourseDto.getCourseCode())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程代码]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getCourseName())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程名称]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getPaperNumber())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[试卷编号]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getPaperType())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[试卷类型]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getStudentCode())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[学号]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getStudentName())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[学生姓名]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getTicketNumber())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[准考证号]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getTeacherName())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[任课老师]必填"));
+                    }
+                    if (StringUtils.isBlank(examStudentCourseDto.getTeacherNumber())) {
+                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[任课老师工号]必填"));
+                    }
+
+                    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) {
+        UpdateWrapper<GradeBatchStudent> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.lambda().eq(GradeBatchStudent::getBatchId, batchId);
+        gradeBatchStudentService.remove(updateWrapper);
+
+        List<GradeBatchStudent> gradeBatchStudents = list.stream().map(m -> {
+            GradeBatchStudent gradeBatchStudent = new GradeBatchStudent();
+            gradeBatchStudent.setBatchId(SystemConstant.getDbUuid());
+            gradeBatchStudent.setCourseCode(m.getCourseCode());
+            gradeBatchStudent.setCourseName(m.getCourseName());
+            gradeBatchStudent.setPaperNumber(m.getPaperNumber());
+            gradeBatchStudent.setPaperType(m.getPaperType());
+            gradeBatchStudent.setStudentCode(m.getStudentCode());
+            gradeBatchStudent.setStudentName(m.getStudentName());
+            gradeBatchStudent.setTeacherName(m.getTeacherName());
+            gradeBatchStudent.setTeacherNumber(m.getTeacherNumber());
+            return gradeBatchStudent;
+        }).collect(Collectors.toList());
+
+        gradeBatchStudentService.saveBatch(gradeBatchStudents);
+    }
+
 }

+ 19 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradeBatchStudentServiceImpl.java

@@ -0,0 +1,19 @@
+package com.qmth.distributed.print.business.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.distributed.print.business.entity.GradeBatchStudent;
+import com.qmth.distributed.print.business.mapper.GradeBatchStudentMapper;
+import com.qmth.distributed.print.business.service.GradeBatchStudentService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 分析-批次表 服务实现类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2022-05-20
+ */
+@Service
+public class GradeBatchStudentServiceImpl extends ServiceImpl<GradeBatchStudentMapper, GradeBatchStudent> implements GradeBatchStudentService {
+}

+ 199 - 192
distributed-print-business/src/main/resources/mapper/ExamStudentMapper.xml

@@ -4,233 +4,240 @@
 
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.qmth.distributed.print.business.entity.ExamStudent">
-    <result column="id" property="id" />
-        <result column="school_id" property="schoolId" />
-        <result column="exam_detail_course_id" property="examDetailCourseId" />
-        <result column="student_name" property="studentName" />
-        <result column="student_code" property="studentCode" />
-        <result column="ticket_number" property="ticketNumber" />
-        <result column="site_number" property="siteNumber" />
-        <result column="print_paper" property="printPaper" />
-        <result column="print_card" property="printCard" />
-        <result column="extend_fields" property="extendFields" />
-        <result column="paper_type" property="paperType" />
+        <result column="id" property="id"/>
+        <result column="school_id" property="schoolId"/>
+        <result column="exam_detail_course_id" property="examDetailCourseId"/>
+        <result column="student_name" property="studentName"/>
+        <result column="student_code" property="studentCode"/>
+        <result column="ticket_number" property="ticketNumber"/>
+        <result column="site_number" property="siteNumber"/>
+        <result column="print_paper" property="printPaper"/>
+        <result column="print_card" property="printCard"/>
+        <result column="extend_fields" property="extendFields"/>
+        <result column="paper_type" property="paperType"/>
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id,
+        id
+        ,
         school_id, exam_detail_course_id, student_name, student_code, ticket_number, site_number, print_paper, print_card, extend_fields, paper_type
     </sql>
     <insert id="insertBatch">
-        insert into exam_student (id, school_id, org_id, exam_detail_course_id, student_name, student_code, ticket_number, site_number, extend_fields, clazz_id, clazz_name, campus_name, create_id) values
+        insert into exam_student (id, school_id, org_id, exam_detail_course_id, student_name, student_code,
+        ticket_number, site_number, extend_fields, clazz_id, clazz_name, campus_name, create_id) values
         <foreach collection="examStudents" separator="," item="item">
-            (#{item.id}, #{item.schoolId}, #{item.orgId}, #{item.examDetailCourseId}, #{item.studentName}, #{item.studentCode}, #{item.ticketNumber}, #{item.siteNumber}, #{item.extendFields}, #{item.clazzId}, #{item.clazzName}, #{item.campusName}, #{item.createId})
+            (#{item.id}, #{item.schoolId}, #{item.orgId}, #{item.examDetailCourseId}, #{item.studentName},
+            #{item.studentCode}, #{item.ticketNumber}, #{item.siteNumber}, #{item.extendFields}, #{item.clazzId},
+            #{item.clazzName}, #{item.campusName}, #{item.createId})
         </foreach>
     </insert>
     <select id="getStudentDetail" resultType="java.util.Map">
-        SELECT
-            a.student_name studentName,
-            a.student_code studentCode,
-            a.ticket_number ticketNumber,
-            a.site_number siteNumber,
-            a.extend_fields extendFields,
-            b.course_code courseCode,
-            b.course_name courseName,
-            b.paper_number paperNumber,
-            c.exam_start_time examStartTime,
-            c.exam_end_time examEndTime,
-            c.exam_place examPlace,
-            c.exam_room examRoom
-        FROM
-            exam_student a
-                LEFT JOIN
-            exam_detail_course b ON a.exam_detail_course_id = b.id
-                LEFT JOIN
-            exam_detail c ON b.exam_detail_id = c.id
-        WHERE
-            a.id = #{id}
+        SELECT a.student_name    studentName,
+               a.student_code    studentCode,
+               a.ticket_number   ticketNumber,
+               a.site_number     siteNumber,
+               a.extend_fields   extendFields,
+               b.course_code     courseCode,
+               b.course_name     courseName,
+               b.paper_number    paperNumber,
+               c.exam_start_time examStartTime,
+               c.exam_end_time   examEndTime,
+               c.exam_place      examPlace,
+               c.exam_room       examRoom
+        FROM exam_student a
+                 LEFT JOIN
+             exam_detail_course b ON a.exam_detail_course_id = b.id
+                 LEFT JOIN
+             exam_detail c ON b.exam_detail_id = c.id
+        WHERE a.id = #{id}
     </select>
 
-    <select id="queryBySchoolIdAndExamDetailCourseIds" resultType="com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto">
+    <select id="queryBySchoolIdAndExamDetailCourseIds"
+            resultType="com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto">
         select
-            es.id,
-            es.school_id as schoolId,
-            es.exam_detail_course_id as examDetailCourseId,
-            es.student_name as studentName,
-            es.student_code as studentCode,
-            es.ticket_number as ticketNumber,
-            es.site_number as siteNumber,
-            es.print_paper as printPaper,
-            es.print_card as printCard,
-            es.extend_fields as extendFields,
-            es.paper_type as paperType,
-            es.create_id as createId,
-            es.create_time as createTime,
-            es.update_id as updateId,
-            es.update_time as updateTime,
-            es.attachment_id as attachmentId,
-            edc.course_code as courseCode,
-            edc.course_name as courseName,
-            edc.paper_pages_a3 as paperPageA3,
-            edc.paper_number as paperNumber,
-            es.clazz_id clazzId,
-            es.clazz_name clazzName
+        es.id,
+        es.school_id as schoolId,
+        es.exam_detail_course_id as examDetailCourseId,
+        es.student_name as studentName,
+        es.student_code as studentCode,
+        es.ticket_number as ticketNumber,
+        es.site_number as siteNumber,
+        es.print_paper as printPaper,
+        es.print_card as printCard,
+        es.extend_fields as extendFields,
+        es.paper_type as paperType,
+        es.create_id as createId,
+        es.create_time as createTime,
+        es.update_id as updateId,
+        es.update_time as updateTime,
+        es.attachment_id as attachmentId,
+        edc.course_code as courseCode,
+        edc.course_name as courseName,
+        edc.paper_pages_a3 as paperPageA3,
+        edc.paper_number as paperNumber,
+        es.clazz_id clazzId,
+        es.clazz_name clazzName
         from
-            exam_student es
+        exam_student es
         left join exam_detail_course edc on
-            edc.id = es.exam_detail_course_id
-            <where>
-                <if test="schoolId != null and schoolId != ''">
-                    and es.school_id = #{schoolId}
-                </if>
-                <if test="examDetailCourseIds != null">
-                    AND edc.id IN
-                    <foreach collection="examDetailCourseIds" item="examDetailCourseId" index="index" open="(" separator="," close=")">
-                        #{examDetailCourseId}
-                    </foreach>
-                </if>
-            </where>
-            order by edc.course_code, 0+ cast(es.site_number as char)
+        edc.id = es.exam_detail_course_id
+        <where>
+            <if test="schoolId != null and schoolId != ''">
+                and es.school_id = #{schoolId}
+            </if>
+            <if test="examDetailCourseIds != null">
+                AND edc.id IN
+                <foreach collection="examDetailCourseIds" item="examDetailCourseId" index="index" open="(" separator=","
+                         close=")">
+                    #{examDetailCourseId}
+                </foreach>
+            </if>
+        </where>
+        order by edc.course_code, 0+ cast(es.site_number as char)
     </select>
     <select id="listStudentByPrintPlanIdAndSyncStatus"
             resultType="com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto">
-        SELECT
-            a.id,
-            b.course_code courseCode,
-            b.course_name courseName,
-            b.paper_number paperNumber,
-            a.student_name studentName,
-            a.student_code studentCode,
-            a.ticket_number ticketNumber,
-            a.clazz_name clazzName,
-            a.extend_fields extendFields,
-            a.paper_type paperType,
-            et.sequence
-        FROM
-            exam_student a
-                LEFT JOIN
-            exam_detail_course b ON a.exam_detail_course_id = b.id
-                LEFT JOIN
-            exam_detail c ON b.exam_detail_id = c.id
-                LEFT JOIN
-            exam_task et ON b.school_id = et.school_id
-                and b.course_code = et.course_code
-                and b.paper_number = et.paper_number
-        WHERE
-            c.print_plan_id = #{printPlanId}
+        SELECT a.id,
+               b.course_code   courseCode,
+               b.course_name   courseName,
+               b.paper_number  paperNumber,
+               a.student_name  studentName,
+               a.student_code  studentCode,
+               a.ticket_number ticketNumber,
+               a.clazz_name    clazzName,
+               a.extend_fields extendFields,
+               a.paper_type    paperType,
+               et.sequence
+        FROM exam_student a
+                 LEFT JOIN
+             exam_detail_course b ON a.exam_detail_course_id = b.id
+                 LEFT JOIN
+             exam_detail c ON b.exam_detail_id = c.id
+                 LEFT JOIN
+             exam_task et ON b.school_id = et.school_id
+                 and b.course_code = et.course_code
+                 and b.paper_number = et.paper_number
+        WHERE c.print_plan_id = #{printPlanId}
     </select>
     <select id="listExamStudentBySchoolIdAndClazzId"
             resultType="com.qmth.distributed.print.business.entity.ExamStudent">
         SELECT
-            *
+        *
         FROM
-            (SELECT
-                 bs.school_id AS schoolId,
-                 bs.student_code AS studentCode,
-                 bs.student_name AS studentName,
-                 bs.clazz_id AS clazzId,
-                 bc.clazz_name AS clazzName,
-                 bca.campus_name campusName
-             FROM
-                 basic_student bs
-                     INNER JOIN basic_clazz bc ON bs.clazz_id = bc.id
-                    LEFT JOIN basic_campus bca ON bs.campus_id = bca.id
-            <where>
-                <if test="schoolId != null and schoolId != ''">
-                    AND bs.school_id = #{schoolId}
-                </if>
-                <if test="classId != null and classId != ''">
-                    AND bc.id = #{classId}
-                </if>
-            </where>
+        (SELECT
+        bs.school_id AS schoolId,
+        bs.student_code AS studentCode,
+        bs.student_name AS studentName,
+        bs.clazz_id AS clazzId,
+        bc.clazz_name AS clazzName,
+        bca.campus_name campusName
+        FROM
+        basic_student bs
+        INNER JOIN basic_clazz bc ON bs.clazz_id = bc.id
+        LEFT JOIN basic_campus bca ON bs.campus_id = bca.id
+        <where>
+            <if test="schoolId != null and schoolId != ''">
+                AND bs.school_id = #{schoolId}
+            </if>
+            <if test="classId != null and classId != ''">
+                AND bc.id = #{classId}
+            </if>
+        </where>
         UNION
-            SELECT
-                ts.school_id AS schoolId,
-                bs.student_code AS studentCode,
-                bs.student_name AS studentName,
-                ts.teach_clazz_id AS clazzId,
-                tc.teach_clazz_name AS clazzName,
-                bca.campus_name campusName
-             FROM
-                 teach_student ts
-                    join basic_student bs on ts.student_id = bs.id
-                    INNER JOIN teach_clazz tc ON ts.teach_clazz_id = tc.id
-                    LEFT JOIN basic_campus bca ON bs.campus_id = bca.id
-            <where>
-                <if test="schoolId != null and schoolId != ''">
-                    AND ts.school_id = #{schoolId}
-                </if>
-                <if test="classId != null and classId != ''">
-                    AND tc.id = #{classId}
-                </if>
-            </where>
-                ) t0;
-    </select>
-    <select id="getSysOrgByBelongOrgId" resultType="com.qmth.teachcloud.common.entity.SysOrg">
         SELECT
-            so.id, so.name
+        ts.school_id AS schoolId,
+        bs.student_code AS studentCode,
+        bs.student_name AS studentName,
+        ts.teach_clazz_id AS clazzId,
+        tc.teach_clazz_name AS clazzName,
+        bca.campus_name campusName
         FROM
-            basic_student bs
-                LEFT JOIN
-            sys_org so ON bs.belong_org_id = so.id
-        WHERE
-            bs.student_code = #{studentCode}
-            and bs.school_id = #{schoolId}
+        teach_student ts
+        join basic_student bs on ts.student_id = bs.id
+        INNER JOIN teach_clazz tc ON ts.teach_clazz_id = tc.id
+        LEFT JOIN basic_campus bca ON bs.campus_id = bca.id
+        <where>
+            <if test="schoolId != null and schoolId != ''">
+                AND ts.school_id = #{schoolId}
+            </if>
+            <if test="classId != null and classId != ''">
+                AND tc.id = #{classId}
+            </if>
+        </where>
+        ) t0;
+    </select>
+    <select id="getSysOrgByBelongOrgId" resultType="com.qmth.teachcloud.common.entity.SysOrg">
+        SELECT so.id,
+               so.name
+        FROM basic_student bs
+                 LEFT JOIN
+             sys_org so ON bs.belong_org_id = so.id
+        WHERE bs.student_code = #{studentCode}
+          and bs.school_id = #{schoolId}
     </select>
     <select id="getByStudentId"
             resultType="com.qmth.distributed.print.business.bean.dto.ExamStudentPdfInfoDto">
-        SELECT
-            a.student_code studentCode,
-            a.student_name studentName,
-            a.ticket_number ticketNumber,
-            a.site_number siteNumber,
-            a.extend_fields extendFields,
-            a.paper_type paperType,
-            a.clazz_id clazzId,
-            a.clazz_name clazzName,
-            a.campus_name campusName,
-            a.attachment_id attachmentId,
-            b.course_code courseCode,
-            b.course_name courseName,
-            b.paper_number paperNumber,
-            c.exam_place examPlace,
-            c.exam_room examRoom
-        FROM
-            exam_student a
-                JOIN
-            exam_detail_course b ON a.exam_detail_course_id = b.id
-                JOIN
-            exam_detail c ON b.exam_detail_id = c.id
-        WHERE
-            a.id = #{id}
+        SELECT a.student_code  studentCode,
+               a.student_name  studentName,
+               a.ticket_number ticketNumber,
+               a.site_number   siteNumber,
+               a.extend_fields extendFields,
+               a.paper_type    paperType,
+               a.clazz_id      clazzId,
+               a.clazz_name    clazzName,
+               a.campus_name   campusName,
+               a.attachment_id attachmentId,
+               b.course_code   courseCode,
+               b.course_name   courseName,
+               b.paper_number  paperNumber,
+               c.exam_place    examPlace,
+               c.exam_room     examRoom
+        FROM exam_student a
+                 JOIN
+             exam_detail_course b ON a.exam_detail_course_id = b.id
+                 JOIN
+             exam_detail c ON b.exam_detail_id = c.id
+        WHERE a.id = #{id}
     </select>
     <select id="listStudentScoreSync" resultType="java.util.Map">
+        SELECT a.clazz_id     clazzId,
+               b.course_code  courseCode,
+               b.paper_number paperNumber,
+               a.paper_type   paperType,
+               d.sequence
+        FROM (SELECT *
+              FROM exam_student
+              WHERE school_id = #{schoolId}
+                AND student_code = #{studentCode}
+                AND ticket_number = #{examNumber}) a
+                 JOIN
+             exam_detail_course b ON a.exam_detail_course_id = b.id
+                 JOIN
+             exam_detail c ON b.exam_detail_id = c.id
+                 JOIN
+             exam_task d ON b.school_id = d.school_id
+                 AND b.course_code = d.course_code
+                 AND b.paper_number = d.paper_number
+        WHERE c.print_plan_id = #{printPlanId}
+          AND CONCAT(b.course_code, a.paper_type, d.sequence) = #{subjectCode}
+    </select>
+    <select id="listExamStudentByPaperNumberAndPaperType"
+            resultType="com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto">
         SELECT
-            a.clazz_id clazzId,
-            b.course_code courseCode,
-            b.paper_number paperNumber,
-            a.paper_type paperType,
-            d.sequence
+            edc.course_code courseCode,
+            edc.course_name courseName,
+            edc.paper_number paperNumber,
+            es.paper_type paperType,
+            es.student_name studentName,
+            es.student_code studentCode,
+            es.ticket_number ticketNumber
         FROM
-            (SELECT
-                 *
-             FROM
-                 exam_student
-             WHERE
-                 school_id = #{schoolId} AND student_code = #{studentCode}
-               AND ticket_number = #{examNumber}) a
-                JOIN
-            exam_detail_course b ON a.exam_detail_course_id = b.id
-                JOIN
-            exam_detail c ON b.exam_detail_id = c.id
+            exam_student es
                 JOIN
-            exam_task d ON b.school_id = d.school_id
-                AND b.course_code = d.course_code
-                AND b.paper_number = d.paper_number
+            exam_detail_course edc ON es.exam_detail_course_id = edc.id
         WHERE
-            c.print_plan_id = #{printPlanId}
-          AND CONCAT(b.course_code, a.paper_type, d.sequence) = #{subjectCode}
+            edc.paper_number = #{paperNumber}
+          AND es.paper_type = #{paperType}
     </select>
-
 </mapper>

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

@@ -15,11 +15,13 @@ import io.swagger.annotations.*;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.validation.Valid;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
+import java.io.IOException;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -71,5 +73,33 @@ public class GradeBatchController {
         return ResultUtil.ok();
     }
 
+    /**
+     * 按批次下载考务数据
+     *
+     * @param batchId 批次ID
+     */
+    @ApiOperation(value = "成绩分析批次课程-考务数据下载")
+    @RequestMapping(value = "/download", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = EditResult.class)})
+    public void downloadFile(@RequestParam Long batchId) throws IOException {
+        gradeBatchService.downloadFile(batchId, ServletUtil.getResponse());
+    }
+
+    /**
+     * 导入考务数据-包含任课老师信息
+     *
+     * @param batchId 批次ID
+     * @param file    上传文件
+     * @return
+     */
+    @ApiOperation(value = "成绩分析批次课程-考务数据导入")
+    @RequestMapping(value = "/upload", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "上传成功", response = EditResult.class)})
+    public Result upload(@RequestParam Long batchId,
+                         @RequestParam MultipartFile file) throws IOException, NoSuchFieldException {
+        gradeBatchService.uploadFile(batchId, file);
+        return ResultUtil.success(true);
+    }
+
     // TODO: 2022/6/2 成绩分析批次推送 
 }