caozixuan 4 years ago
parent
commit
e05daf1fcf

+ 14 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/FieldsDto.java

@@ -1,5 +1,7 @@
 package com.qmth.distributed.print.business.bean.dto;
 
+import io.swagger.annotations.ApiModelProperty;
+
 /**
  * @Description: 考务字段Dto
  * @Author: CaoZixuan
@@ -32,6 +34,9 @@ public class FieldsDto {
      */
     private int index;
 
+    @ApiModelProperty(value = "字段级别(必选字段 - 'primary'、扩展字段 - 'secondary')")
+    private String level;
+
     public String getCode() {
         return code;
     }
@@ -72,6 +77,14 @@ public class FieldsDto {
         this.index = index;
     }
 
+    public String getLevel() {
+        return level;
+    }
+
+    public void setLevel(String level) {
+        this.level = level;
+    }
+
     @Override
     public String toString() {
         return "FieldsDto{" +
@@ -80,6 +93,7 @@ public class FieldsDto {
                 ", enable=" + enable +
                 ", value='" + value + '\'' +
                 ", index=" + index +
+                ", level='" + level + '\'' +
                 '}';
     }
 }

+ 4 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamDetailService.java

@@ -10,6 +10,9 @@ import com.qmth.distributed.print.business.bean.result.SummarizedDataResult;
 import com.qmth.distributed.print.business.entity.ExamDetail;
 import com.qmth.distributed.print.business.entity.ExamPrintPlan;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.List;
 import java.util.Map;
 
@@ -54,7 +57,7 @@ public interface ExamDetailService extends IService<ExamDetail> {
      * @param schoolId 学校id
      * @return 是否成功
      */
-    boolean downLoadExaminationTemplate(Long schoolId);
+    void downLoadExaminationTemplate(Long schoolId, HttpServletResponse response) throws IOException;
 
 
     /**

+ 56 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java

@@ -18,15 +18,25 @@ import com.qmth.distributed.print.business.entity.ExamPrintPlan;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.mapper.ExamDetailMapper;
 import com.qmth.distributed.print.business.service.BasicExamRuleService;
+import com.qmth.distributed.print.business.service.CacheService;
 import com.qmth.distributed.print.business.service.ExamDetailCourseService;
 import com.qmth.distributed.print.business.service.ExamDetailService;
 import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -48,7 +58,10 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
     private BasicExamRuleService basicExamRuleService;
     @Resource
     private ExamDetailMapper examDetailMapper;
+    @Resource
+    private CacheService cacheService;
 
+    private final static Logger log = LoggerFactory.getLogger(ExamDetailServiceImpl.class);
 
     @Transactional(rollbackFor = Exception.class)
     @Override
@@ -90,7 +103,9 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
     @Transactional(rollbackFor = Exception.class)
     @Override
     public List<FieldsDto> findExaminationFields(Long schoolId) {
-        BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
+        // TODO: 2021/4/9 回复schoolId的获取方式
+//        BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
+        BasicExamRule basicExamRule = basicExamRuleService.list(new QueryWrapper<BasicExamRule>().lambda().eq(BasicExamRule::getSchoolId,schoolId)).get(0);
         if (basicExamRule == null){
             throw ExceptionResultEnum.ERROR.exception("找不到该学校考务字段信息 + schoolId" + schoolId);
         }
@@ -101,6 +116,10 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
         if (requiredFieldsList.stream().anyMatch(e -> !e.getEnable())){
             throw ExceptionResultEnum.ERROR.exception("该学校考务字段设置存在必选字段禁用的情况 schoolId = " + schoolId);
         }
+        for (FieldsDto fieldsDto : requiredFieldsList) {
+            fieldsDto.setLevel("primary");
+        }
+
         // 扩展字段
         List<FieldsDto> extendFieldsList = JSONObject.parseArray(extendFields,FieldsDto.class);
         List<String> extendCodeList = extendFieldsList.stream().map(FieldsDto::getCode).collect(Collectors.toList());
@@ -109,6 +128,9 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
         }
         // 有效的扩展字段
         List<FieldsDto> validExtendList = extendFieldsList.stream().filter(FieldsDto::getEnable).collect(Collectors.toList());
+        for (FieldsDto fieldsDto : validExtendList) {
+            fieldsDto.setLevel("secondary");
+        }
 
         // 有效的考务字段
         List<FieldsDto> validExaminationFieldList = new ArrayList<>();
@@ -125,13 +147,41 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public boolean downLoadExaminationTemplate(Long schoolId) {
-        BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
-        if (basicExamRule == null){
-            throw ExceptionResultEnum.ERROR.exception("找不到该学校考务字段信息 + schoolId" + schoolId);
+    public void downLoadExaminationTemplate(Long schoolId, HttpServletResponse response) throws IOException {
+        final String DEFALUT_EXT = ".xlsx";
+        final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
+        List<String> fieldsNameList = this.findExaminationFields(schoolId).stream().map(FieldsDto::getName).distinct().collect(Collectors.toList());
+
+        log.debug("导出Excel开始...");
+        HSSFWorkbook wb = new HSSFWorkbook();
+        String fileName = "考务数据模板";
+        response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(fileName, SystemConstant.CHARSET_NAME) + DEFALUT_EXT);
+        response.setContentType(DEFALUT_CONTENT_TYPE);
+        HSSFSheet sheet = wb.createSheet(cacheService.schoolCache(schoolId).getName() + "考务数据模板");
+        sheet.setDefaultRowHeight((short) (2 * 256));
+        sheet.setColumnWidth(0, 50 * 160);
+
+        HSSFFont font = wb.createFont();
+        font.setFontHeightInPoints((short) 16);
+
+        HSSFRow row = sheet.createRow((int) 0);
+        HSSFCellStyle style = wb.createCellStyle();
+        style.setAlignment(HorizontalAlignment.CENTER);
+
+        for(int i = 0; i<fieldsNameList.size(); i++){
+            HSSFCell cell = row.createCell(i);
+            cell.setCellValue(fieldsNameList.get(i));
+            cell.setCellStyle(style);
+        }
+        try {
+            ServletOutputStream outputStream = response.getOutputStream();
+            wb.write(outputStream);
+            outputStream.close();
+            log.debug("导出Excel结束...");
         }
+        catch (IOException e){
 
-        return false;
+        }
     }
 
     @Transactional(rollbackFor = Exception.class)

+ 331 - 51
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncExaminationImportTemplateService.java

@@ -1,33 +1,39 @@
 package com.qmth.distributed.print.business.templete.execute;
 
-import com.alibaba.excel.ExcelReader;
-import com.alibaba.excel.support.ExcelTypeEnum;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.FieldsDto;
-import com.qmth.distributed.print.business.entity.ExamPrintPlan;
-import com.qmth.distributed.print.business.entity.TBTask;
+import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.enums.TaskResultEnum;
 import com.qmth.distributed.print.business.enums.TaskStatusEnum;
+import com.qmth.distributed.print.business.service.ExamDetailCourseService;
 import com.qmth.distributed.print.business.service.ExamDetailService;
 import com.qmth.distributed.print.business.service.ExamPrintPlanService;
-import com.qmth.distributed.print.business.templete.excelListener.ExaminationListener;
+import com.qmth.distributed.print.business.service.ExamStudentService;
 import com.qmth.distributed.print.business.templete.importData.AsyncImportTaskTemplete;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.Result;
-import org.omg.CORBA.OBJ_ADAPTER;
+import com.qmth.distributed.print.common.util.ResultUtil;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.io.IOException;
 import java.io.InputStream;
 import java.text.MessageFormat;
-import java.util.List;
-import java.util.Map;
-import java.util.StringJoiner;
+import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * @Description: 考务数据导入模板
@@ -40,63 +46,337 @@ public class AsyncExaminationImportTemplateService extends AsyncImportTaskTemple
     private ExamDetailService examDetailService;
     @Resource
     private ExamPrintPlanService examPrintPlanService;
+    @Resource
+    private ExamDetailCourseService examDetailCourseService;
+    @Resource
+    private ExamStudentService examStudentService;
+
+    private final static Logger log = LoggerFactory.getLogger(AsyncExaminationImportTemplateService.class);
 
     public static final String OBJ_TITLE = "考务数据";
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public Result importTask(Map<String, Object> map) throws IOException {
+    public Result importTask(Map<String, Object> map) throws Exception {
         TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
-        System.out.println("printPlanId = " + tbTask.getPrintPlanId());
+        Long printPlanId = tbTask.getPrintPlanId();
+        Long userId = tbTask.getCreateId();
+        ExamPrintPlan examPrintPlan = examPrintPlanService.getById(printPlanId);
+
+        if (examPrintPlan == null){
+            throw ExceptionResultEnum.ERROR.exception("印刷计划不存在printPlanId : " + printPlanId);
+        }
+        String printPlanName = examPrintPlan.getName();
+        Long schoolId = tbTask.getSchoolId();
+
         System.out.println("------开始----------");
         InputStream inputStream = super.getUploadFileInputStream(tbTask);
         System.out.println("------结束----------");
         StringJoiner stringJoinerSummary = new StringJoiner("\n")
                 .add(MessageFormat.format("{0}{1}{2}", FORMAT_TIME, BEGIN_TITLE, OBJ_TITLE));
         tbTask.setStatus(TaskStatusEnum.RUNNING);
-        // try
 
+
+        // 该学校有效考务数据
+        List<FieldsDto> fieldsDtoList = examDetailService.findExaminationFields(schoolId);
+        if (fieldsDtoList.size() == 0) {
+            throw ExceptionResultEnum.ERROR.exception("该学校没有设置考务数据");
+        }
+
+        try {
             String importFilePath = tbTask.getImportFilePath();
             Map importFilePathMap = JSONObject.parseObject(importFilePath);
             String path = String.valueOf(importFilePathMap.get("path"));
             System.out.println("path = " + path);
-//            // 该学校有效考务数据
-//            List<FieldsDto> fieldsDtoList = examDetailService.findExaminationFields(tbTask.getSchoolId());
-//            if (fieldsDtoList.size() == 0){
-//                throw ExceptionResultEnum.ERROR.exception("该学校没有设置考务数据");
-//            }
-//            for (FieldsDto fieldsDto : fieldsDtoList) {
-//                if (!headerList.contains(fieldsDto.getName())){
-//                    System.out.println("exception " + fieldsDto.getName());
-//                    throw ExceptionResultEnum.ERROR.exception("学校考务必填字段 :'" + fieldsDto.getName() + "' 不存在");
-//                }
-//            }
-//            for (FieldsDto fieldsDto : fieldsDtoList) {
-//                String name = fieldsDto.getName();
-//                String code = fieldsDto.getCode();
-//                for (int i = 0;i < headerList.size();i++){
-//                    String headName = headerList.get(i);
-//                    if (name.equals(headName)){
-//                        fieldsDto.setIndex(i);
-//                    }
-//                }
-//            }
-//
-//            // 组装exam_detail数据
-//            Long schoolId = tbTask.getSchoolId();
-//            Long printPlanId = tbTask.getPrintPlanId();
-//            List<ExamPrintPlan> examPrintPlanList = examPrintPlanService.list(new QueryWrapper<ExamPrintPlan>().lambda().eq(ExamPrintPlan::getSchoolId,schoolId).eq(ExamPrintPlan::getId,printPlanId));
-//            if (examPrintPlanList.size() != 1){
-//                throw ExceptionResultEnum.ERROR.exception("没有找到对应的考试计划");
-//            }
-//            String printPlanName = examPrintPlanList.get(0).getName();
-//            int examPlaceIndex = fieldsDtoList.stream().filter(e -> "examPlace".equals(e.getCode())).map(FieldsDto::getIndex).collect(Collectors.toList()).get(0);
-//
-//            // 组装exam_detail_course数据
-//
-//            // 组装exam_student数据
-
-
-        return null;
+            Workbook workbook = null;
+            if (path.endsWith(SystemConstant.XLSX)) {
+                workbook = new XSSFWorkbook(inputStream);
+            } else if (path.endsWith("xls")) {
+                workbook = new HSSFWorkbook(inputStream);
+            } else {
+                throw ExceptionResultEnum.ERROR.exception("文件格式异常");
+            }
+            // 读取第一个工作表
+            Sheet sheet = workbook.getSheetAt(0);
+            // 获取sheet行数
+            int totalRows = sheet.getPhysicalNumberOfRows();
+            // 获取sheet列数
+            int totalCells = 0;
+            if (totalRows > 1 && sheet.getRow(0) != null) {
+                totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
+            }
+            System.out.println("行 : " + totalRows + "\n列 : " + totalCells);
+            Row head = sheet.getRow(0);
+            List<String> headList = new ArrayList<>();
+            // 将必填字段匹配excel解析的表头索引
+            for (int i = 0; i < totalCells; i++) {
+                String cellValue = head.getCell(i).getStringCellValue();
+                for (FieldsDto fieldsDto : fieldsDtoList) {
+                    if (cellValue.equals(fieldsDto.getName())) {
+                        fieldsDto.setIndex(i);
+                    }
+                }
+                headList.add(cellValue);
+            }
+
+            // 搜索所有有效字段 excel中的表头是否包含
+            for (FieldsDto fieldsDto : fieldsDtoList) {
+                if (!headList.contains(fieldsDto.getName())) {
+                    System.out.println("exception " + fieldsDto.getName());
+                    throw ExceptionResultEnum.ERROR.exception("学校考务必填字段 :'" + fieldsDto.getName() + "' 不存在");
+                }
+            }
+
+            System.out.println("headList : " + headList);
+            System.out.println("fieldsDtoList : " + JSONObject.toJSONString(fieldsDtoList));
+
+            List<Map<String, Object>> dataList = new ArrayList<>();
+
+            for (int r = 1; r < totalRows; r++) {
+                Row row = sheet.getRow(r);
+
+                String studentCode = null;
+                String studentName = null;
+                String courseCode = null;
+                String courseName = null;
+                String examPlace = null;
+                String examRoom = null;
+                String examDate = null;
+                String examTime = null;
+                String paperNumber = null;
+                List<FieldsDto> secondaryFieldList = new ArrayList<>();
+                for (FieldsDto fieldsDto : fieldsDtoList) {
+                    String name = fieldsDto.getName();
+                    String code = fieldsDto.getCode();
+                    int index = fieldsDto.getIndex();
+                    String level = fieldsDto.getLevel();
+                    if ("学号".equals(name)) {
+                        studentCode = row.getCell(index).getStringCellValue();
+                    } else if ("姓名".equals(name)) {
+                        studentName = row.getCell(index).getStringCellValue();
+                    } else if ("课程代码".equals(name)) {
+                        courseCode = row.getCell(index).getStringCellValue();
+                    } else if ("课程名称".equals(name)) {
+                        courseName = row.getCell(index).getStringCellValue();
+                    } else if ("考点".equals(name)) {
+                        examPlace = row.getCell(index).getStringCellValue();
+                    } else if ("考场".equals(name)) {
+                        examRoom = row.getCell(index).getStringCellValue();
+                    } else if ("考试日期".equals(name)) {
+                        row.getCell(index).setCellType(CellType.STRING);
+                        examDate = row.getCell(index).getStringCellValue();
+                    } else if ("考试时间".equals(name)) {
+                        row.getCell(index).setCellType(CellType.STRING);
+                        examTime = row.getCell(index).getStringCellValue();
+                    } else if ("试卷编号".equals(name)) {
+                        paperNumber = row.getCell(index).getStringCellValue();
+                    } else {
+                        if ("primary".equals(level)) {
+                            throw ExceptionResultEnum.ERROR.exception("有数据库不需要的必选字段 : " + name);
+                        }
+                        if ("secondary".equals(level)) {
+                            // 备选字段处理
+                            FieldsDto secondaryField = new FieldsDto();
+                            secondaryField.setLevel(level);
+                            secondaryField.setCode(code);
+                            secondaryField.setName(name);
+                            secondaryField.setEnable(true);
+                            secondaryField.setValue(row.getCell(index).getStringCellValue());
+                            secondaryFieldList.add(secondaryField);
+                        }
+                    }
+                }
+                Map<String, Object> dataMap = new HashMap<>();
+                dataMap.put("studentCode", studentCode);
+                dataMap.put("studentName", studentName);
+                // TODO: 2021/4/9 校验课程
+                dataMap.put("courseCode", courseCode);
+                dataMap.put("courseName", courseName);
+                dataMap.put("examPlace", examPlace);
+                dataMap.put("examRoom", examRoom);
+                // TODO: 2021/4/9 解析时间
+                dataMap.put("examDate", examDate);
+                dataMap.put("examTime", examTime);
+                dataMap.put("paperNumber", paperNumber);
+                dataMap.put("secondaryFieldList", secondaryFieldList);
+                dataMap.put("schoolId", schoolId);
+                dataMap.put("printPlanId", printPlanId);
+                dataMap.put("printPlanName", printPlanName);
+                dataList.add(dataMap);
+            }
+            System.out.println("dataList = " + JSON.toJSONString(dataList));
+
+
+            // 组装exam_detail数据
+            this.disposeExamDetailByExaminationExcel(dataList,userId);
+            // 组装exam_detail_course数据
+            this.disposeExamDetailCourseByExaminationExcel(dataList,userId);
+            // 组装exam_student数据
+            this.disposeExamStudentByExaminationExcel(dataList,userId);
+            stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", FORMAT_TIME, FINISH_TITLE, 111, FINISH_SIZE));
+            tbTask.setResult(TaskResultEnum.SUCCESS);
+        }catch (Exception e){
+            log.error("请求出错", e);
+            stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", FORMAT_TIME, EXCEPTION_TITLE, EXCEPTION_DATA, e.getMessage()));
+            tbTask.setResult(TaskResultEnum.ERROR);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {//生成txt文件
+            tbTask.setSummary(stringJoinerSummary.toString());
+            super.createTxt(tbTask);
+        }
+        return ResultUtil.ok(map);
+    }
+
+    private void disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList,Long userId){
+        List<Map<String, Object>> examDetailKeyList = dataList.stream().flatMap(e -> {
+            Map<String, Object> map = new HashMap<>();
+            map.put("schoolId",e.get("schoolId"));
+            map.put("printPlanId",e.get("printPlanId"));
+            map.put("printPlanName",e.get("printPlanName"));
+            map.put("examPlace",e.get("examPlace"));
+            map.put("examRoom",e.get("examRoom"));
+            map.put("examDate",e.get("examDate"));
+            map.put("examTime",e.get("examTime"));
+            return Stream.of(map);
+        }).distinct().collect(Collectors.toList());
+
+        System.out.println("examDetailKeyList = " + JSON.toJSONString(examDetailKeyList));
+
+        List<ExamDetail> examDetailList = new ArrayList<>();
+        for (Map<String, Object> map : examDetailKeyList) {
+            String examPlace = String.valueOf(map.get("examPlace"));
+            String examRoom = String.valueOf(map.get("examRoom"));
+            String examDate = String.valueOf(map.get("examDate"));
+            String examTime = String.valueOf(map.get("examTime"));
+            System.out.println("dataList : " + JSON.toJSONString(dataList));
+            System.out.println(examPlace + examRoom + examDate + examTime);
+            long totalSubjects = dataList.stream()
+                    .filter(e -> String.valueOf(e.get("examPlace")).equals(examPlace) &&
+                            String.valueOf(e.get("examRoom")).equals(examRoom) &&
+                            String.valueOf(e.get("examDate")).equals(examDate) &&
+                            String.valueOf(e.get("examTime")).equals(examTime)).count();
+
+            System.out.println("totalSubjects" + totalSubjects);
+            ExamDetail examDetail = new ExamDetail();
+            examDetail.setId(SystemConstant.getDbUuid());
+            examDetail.setExamName("");
+            examDetail.setSchoolId(Long.valueOf(String.valueOf(map.get("schoolId"))));
+            examDetail.setPrintPlanId(Long.valueOf(String.valueOf(map.get("printPlanId"))));
+            examDetail.setPrintPlanName(String.valueOf(map.get("printPlanName")));
+            examDetail.setExamPlace(examPlace);
+            examDetail.setExamRoom(examRoom);
+            examDetail.setTotalSubjects(Math.toIntExact(totalSubjects));
+            // TODO: 2021/4/9 解析日期和时间
+            examDetail.setExamStartTime(1L);
+            examDetail.setExamEndTime(2L);
+            examDetail.setCreateId(userId);
+            examDetail.setUpdateId(userId);
+            examDetailList.add(examDetail);
+        }
+        examDetailService.saveBatch(examDetailList);
+    }
+
+    private void disposeExamDetailCourseByExaminationExcel(List<Map<String, Object>> dataList,Long userId){
+
+        List<Map<String, Object>> examDetailKeyList = dataList.stream().flatMap(e -> {
+            Map<String, Object> map = new HashMap<>();
+            map.put("schoolId",e.get("schoolId"));
+            map.put("printPlanId",e.get("printPlanId"));
+            map.put("examPlace",e.get("examPlace"));
+            map.put("examRoom",e.get("examRoom"));
+            map.put("examDate",e.get("examDate"));
+            map.put("examTime",e.get("examTime"));
+            map.put("courseCode",e.get("courseCode"));
+            map.put("courseName",e.get("courseName"));
+            map.put("paperNumber",e.get("paperNumber"));
+            return Stream.of(map);
+        }).distinct().collect(Collectors.toList());
+
+        List<ExamDetailCourse> examDetailCourseList = new ArrayList<>();
+        for (Map<String, Object> map : examDetailKeyList) {
+            Long schoolId = Long.valueOf(String.valueOf(map.get("schoolId")));
+            Long printPlanId = Long.valueOf(String.valueOf(map.get("printPlanId")));
+            String examPlace = String.valueOf(map.get("examPlace"));
+            String examRoom = String.valueOf(map.get("examRoom"));
+            Long examStartTime = 1L;
+            Long examEndTime = 2L;
+            String courseCode = String.valueOf(map.get("courseCode"));
+            String courseName = String.valueOf(map.get("courseName"));
+            String paperNumber = String.valueOf(map.get("paperNumber"));
+            List<ExamDetail> examDetailList = examDetailService.list(new QueryWrapper<ExamDetail>().lambda()
+                    .eq(ExamDetail::getPrintPlanId,printPlanId)
+                    .eq(ExamDetail::getExamPlace,examPlace)
+                    .eq(ExamDetail::getExamRoom,examRoom)
+                    .eq(ExamDetail::getExamStartTime,examStartTime)
+                    .eq(ExamDetail::getExamEndTime,examEndTime));
+            if (examDetailList.size() != 1){
+                throw ExceptionResultEnum.ERROR.exception("无法找到新增的考务场次数据");
+            }
+            Long examDetailId = examDetailList.get(0).getId();
+            ExamDetailCourse examDetailCourse = new ExamDetailCourse();
+            examDetailCourse.setId(SystemConstant.getDbUuid());
+            examDetailCourse.setSchoolId(schoolId);
+            examDetailCourse.setExamDetailId(examDetailId);
+            examDetailCourse.setCourseCode(courseCode);
+            examDetailCourse.setCourseName(courseName);
+            examDetailCourse.setPaperNumber(paperNumber);
+            examDetailCourse.setCreateId(userId);
+            examDetailCourse.setUpdateId(userId);
+            examDetailCourseList.add(examDetailCourse);
+        }
+        examDetailCourseService.saveBatch(examDetailCourseList);
+    }
+
+    private void disposeExamStudentByExaminationExcel(List<Map<String, Object>> dataList,Long userId){
+        List<ExamStudent> examStudentList = new ArrayList<>();
+        for (Map<String, Object> map : dataList) {
+            Long schoolId = Long.valueOf(String.valueOf(map.get("schoolId")));
+            Long printPlanId = Long.valueOf(String.valueOf(map.get("printPlanId")));
+            String examPlace = String.valueOf(map.get("examPlace"));
+            String examRoom = String.valueOf(map.get("examRoom"));
+            Long examStartTime = 1L;
+            Long examEndTime = 2L;
+            String courseCode = String.valueOf(map.get("courseCode"));
+            String courseName = String.valueOf(map.get("courseName"));
+            String paperNumber = String.valueOf(map.get("paperNumber"));
+            String studentName = String.valueOf(map.get("studentName"));
+            String studentCode = String.valueOf(map.get("studentCode"));
+            List<ExamDetail> examDetailList = examDetailService.list(new QueryWrapper<ExamDetail>().lambda()
+                    .eq(ExamDetail::getPrintPlanId,printPlanId)
+                    .eq(ExamDetail::getExamPlace,examPlace)
+                    .eq(ExamDetail::getExamRoom,examRoom)
+                    .eq(ExamDetail::getExamStartTime,examStartTime)
+                    .eq(ExamDetail::getExamEndTime,examEndTime));
+            if (examDetailList.size() != 1){
+                throw ExceptionResultEnum.ERROR.exception("无法找到新增的考务场次数据");
+            }
+            Long examDetailId = examDetailList.get(0).getId();
+            List<ExamDetailCourse> examDetailCourseList = examDetailCourseService.list(new QueryWrapper<ExamDetailCourse>().lambda()
+                    .eq(ExamDetailCourse::getExamDetailId,examDetailId)
+                    .eq(ExamDetailCourse::getCourseCode,courseCode)
+                    .eq(ExamDetailCourse::getCourseName,courseName)
+                    .eq(ExamDetailCourse::getPaperNumber,paperNumber));
+            if (examDetailCourseList.size() != 1){
+                throw ExceptionResultEnum.ERROR.exception("无法找到新增的考务科目数据");
+            }
+            Long examDetailCourseId = examDetailCourseList.get(0).getId();
+
+            ExamStudent examStudent = new ExamStudent();
+            examStudent.setId(SystemConstant.getDbUuid());
+            examStudent.setSchoolId(schoolId);
+            examStudent.setExamDetailCourseId(examDetailCourseId);
+            examStudent.setStudentName(studentName);
+            examStudent.setStudentCode(studentCode);
+            examStudent.setTicketNumber("");
+            examStudent.setSiteNumber("");
+            examStudent.setCreateId(userId);
+            examStudent.setUpdateId(userId);
+            examStudentList.add(examStudent);
+        }
+        examStudentService.saveBatch(examStudentList);
     }
 }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -53,7 +53,7 @@ public abstract class AsyncImportTaskTemplete {
      * @throws IOException
      */
     @Async
-    public abstract Result importTask(Map<String, Object> map) throws IOException;
+    public abstract Result importTask(Map<String, Object> map) throws IOException, Exception;
 
     /**
      * 获取上传的文件

+ 6 - 0
distributed-print-common/src/main/java/com/qmth/distributed/print/common/contant/SystemConstant.java

@@ -101,6 +101,12 @@ public class SystemConstant {
     public static String TEMP_FILES_DIR;
     public static String PDF_TEMP_FILES_DIR;
 
+    /**
+     * excel相关
+     */
+    public static String XLSX = "xlsx";
+    public static String XLS = "xls";
+
     /**
      * 初始化附件文件路径
      */

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

@@ -11,6 +11,7 @@ import com.qmth.distributed.print.business.enums.TaskTypeEnum;
 import com.qmth.distributed.print.business.service.ExamDetailService;
 import com.qmth.distributed.print.business.service.TBTaskService;
 import com.qmth.distributed.print.business.templete.execute.AsyncExaminationImportTemplateService;
+import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.util.Result;
 import com.qmth.distributed.print.common.util.ResultUtil;
@@ -51,7 +52,7 @@ public class ExamDetailController {
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
     public Result examinationImportAysnc(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
                                          @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
-                                         @ApiParam(value = "印刷计划id", required = true) @RequestParam String printPlanId) throws IOException {
+                                         @ApiParam(value = "印刷计划id", required = true) @RequestParam String printPlanId) throws Exception {
         Map<String, Object> map = tbTaskService.saveTask(SystemConstant.convertIdToLong(printPlanId), file, TaskTypeEnum.EXAMINATION_IMPORT);
         asyncExaminationImportTemplateService.importTask(map);
         TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
@@ -119,5 +120,13 @@ public class ExamDetailController {
     public Result findExamRoomDatasource(@ApiParam(value = "印刷计划主键", required = true) @RequestParam String printPlanId) {
         return ResultUtil.ok(examDetailService.findExamRoomDatasource(SystemConstant.convertIdToLong(printPlanId)));
     }
+
+    @ApiOperation(value = "考务数据导入-模板下载")
+    @RequestMapping(value = "/template_download", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Result.class)})
+    public Result downLoadExaminationTemplate(@ApiParam(value = "学校id", required = true) @RequestParam String schoolId) throws IOException {
+        examDetailService.downLoadExaminationTemplate(SystemConstant.convertIdToLong(schoolId), ServletUtil.getResponse());
+        return ResultUtil.ok();
+    }
 }