|
@@ -2,10 +2,12 @@ package com.qmth.paper.library.business.templete.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.paper.library.business.bean.result.DocManageDetailResult;
|
|
import com.qmth.paper.library.business.bean.result.DocManageDetailResult;
|
|
|
|
+import com.qmth.paper.library.business.bean.result.PictureManageDetailResult;
|
|
import com.qmth.paper.library.business.entity.PaperLibrary;
|
|
import com.qmth.paper.library.business.entity.PaperLibrary;
|
|
import com.qmth.paper.library.business.entity.PaperScanTask;
|
|
import com.qmth.paper.library.business.entity.PaperScanTask;
|
|
import com.qmth.paper.library.business.service.*;
|
|
import com.qmth.paper.library.business.service.*;
|
|
@@ -14,6 +16,7 @@ import com.qmth.paper.library.common.bean.dto.excel.DescribeImportDto;
|
|
import com.qmth.paper.library.common.bean.dto.excel.SysOrgImportDto;
|
|
import com.qmth.paper.library.common.bean.dto.excel.SysOrgImportDto;
|
|
import com.qmth.paper.library.common.bean.dto.excel.SysUserImportDto;
|
|
import com.qmth.paper.library.common.bean.dto.excel.SysUserImportDto;
|
|
import com.qmth.paper.library.common.bean.params.DownLoadPaperParams;
|
|
import com.qmth.paper.library.common.bean.params.DownLoadPaperParams;
|
|
|
|
+import com.qmth.paper.library.common.bean.params.DownloadPictureParams;
|
|
import com.qmth.paper.library.common.config.DictionaryConfig;
|
|
import com.qmth.paper.library.common.config.DictionaryConfig;
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
import com.qmth.paper.library.common.entity.*;
|
|
import com.qmth.paper.library.common.entity.*;
|
|
@@ -77,6 +80,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
private BasicSemesterService basicSemesterService;
|
|
private BasicSemesterService basicSemesterService;
|
|
@Resource
|
|
@Resource
|
|
private BasicExamService basicExamService;
|
|
private BasicExamService basicExamService;
|
|
|
|
+ @Resource
|
|
|
|
+ private PictureManageService pictureManageService;
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
@@ -279,6 +284,260 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> executeDownloadPictureLogic(Map<String, Object> map) {
|
|
|
|
+ List<File> sourceFileList = new ArrayList<>();
|
|
|
|
+ File zipFile = null;
|
|
|
|
+ String rootPath = null;
|
|
|
|
+ String zipLocalRootPath;
|
|
|
|
+ List<PaperLibrary> paperLibraryList;
|
|
|
|
+ try {
|
|
|
|
+ BasicSchool school = basicSchoolService.getById(Long.valueOf(map.get("schoolId").toString()));
|
|
|
|
+ TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
|
+ DownloadPictureParams downLoadPaperParams = JSON.parseObject(tbTask.getRemark(), DownloadPictureParams.class);
|
|
|
|
+ List<PictureManageDetailResult> studentList = pictureManageService.listPictureResult(downLoadPaperParams);
|
|
|
|
+
|
|
|
|
+ rootPath = fileStoreUtil.buildPath(UploadFileEnum.DOWNLOAD, true, String.valueOf(System.currentTimeMillis()));
|
|
|
|
+ String dirName = SystemConstant.getUuid() + SystemConstant.ZIP_SUFFIX;
|
|
|
|
+ zipFile = new File(rootPath + dirName);
|
|
|
|
+ if (!zipFile.getParentFile().exists()) {
|
|
|
|
+ boolean dirSuccess = zipFile.getParentFile().mkdirs();
|
|
|
|
+ if(!dirSuccess){
|
|
|
|
+ log.error(String.format("[图片管理],目录创建失败,dirPath:%s",rootPath));
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("目录创建失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //zip文件存放本地根目录
|
|
|
|
+ zipLocalRootPath = rootPath + File.separator + school.getName();
|
|
|
|
+ Map<Long, Integer> successMap = new HashMap<>();
|
|
|
|
+ Map<Long, Integer> errorMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ for(PictureManageDetailResult student : studentList) {
|
|
|
|
+ Long studentId = student.getStudentId();
|
|
|
|
+ successMap.putIfAbsent(studentId, 0);
|
|
|
|
+ errorMap.putIfAbsent(studentId, 0);
|
|
|
|
+
|
|
|
|
+ //考生的所有试卷
|
|
|
|
+ LambdaQueryWrapper<PaperLibrary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(PaperLibrary::getStudentId, studentId);
|
|
|
|
+ paperLibraryList = paperLibraryService.list(queryWrapper);
|
|
|
|
+
|
|
|
|
+ ExamStudent examStudent = examStudentService.getById(studentId);
|
|
|
|
+ String courseNameCode = String.format("%s(%s)", examStudent.getCourseName(), examStudent.getCourseCode());
|
|
|
|
+ String imagePath = zipLocalRootPath + File.separator + courseNameCode + File.separator + examStudent.getTeachClass();
|
|
|
|
+
|
|
|
|
+ for (PaperLibrary paperLibrary : paperLibraryList) {
|
|
|
|
+ List<JSONObject> objectList = JSON.parseArray(paperLibrary.getPath(), JSONObject.class);
|
|
|
|
+ //下载考生试卷
|
|
|
|
+ for (JSONObject jsonObject : objectList) {
|
|
|
|
+ try {
|
|
|
|
+ File file = paperLibraryCommonService.downloadFile(imagePath, jsonObject.getString(SystemConstant.PATH),
|
|
|
|
+ jsonObject.getString(SystemConstant.UPLOAD_TYPE), jsonObject.getString(SystemConstant.TYPE));
|
|
|
|
+ sourceFileList.add(file);
|
|
|
|
+ successMap.put(studentId, successMap.get(studentId) + 1);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ errorMap.put(studentId, errorMap.get(studentId) + 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!CollectionUtils.isEmpty(sourceFileList)) {
|
|
|
|
+ // 生成清单
|
|
|
|
+ createPictureDownloadExcel(rootPath, studentList, successMap, errorMap);
|
|
|
|
+
|
|
|
|
+ Zip4jUtil.zipEncryptFile(zipFile.getPath(), rootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
|
+ String ossDirName = dirName.replaceAll("\\\\", "/");
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ if (fileStoreUtil.isOssStore()) {
|
|
|
|
+ fileStoreUtil.fileUpload(ossDirName, zipFile);
|
|
|
|
+ jsonObject.put(SystemConstant.PATH, ossDirName);
|
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
|
+ } else {
|
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
|
+ jsonObject.put(SystemConstant.PATH, rootPath + ossDirName);
|
|
|
|
+ }
|
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
|
+ tbTask.setExportFilePath(jsonObject.toJSONString());
|
|
|
|
+ }
|
|
|
|
+ map.put(SystemConstant.SIZE, studentList.size());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ if (e instanceof ApiException) {
|
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
|
+ } else {
|
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ if (Objects.nonNull(rootPath)) {
|
|
|
|
+ ConvertUtil.delFolder(rootPath);
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(dictionaryConfig.sysDomain()) && fileStoreUtil.isOssStore() && Objects.nonNull(zipFile)) {
|
|
|
|
+ boolean success = zipFile.delete();
|
|
|
|
+ if(!success) {
|
|
|
|
+ log.warn(String.format("[图片管理],临时zip目录删除失败,zipPath:%s",zipFile.getPath()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void createPictureDownloadExcel(String zipLocalRootPath, List<PictureManageDetailResult> list, Map<Long, Integer> successMap,
|
|
|
|
+ Map<Long, Integer> errorMap) throws IOException {
|
|
|
|
+ String fileName = "下载记录清单.xlsx";
|
|
|
|
+ XSSFWorkbook wb = new XSSFWorkbook();
|
|
|
|
+ XSSFSheet sheet = wb.createSheet("数据");
|
|
|
|
+
|
|
|
|
+ // 表头
|
|
|
|
+ CellStyle headerStyle = wb.createCellStyle();
|
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
|
+ headerStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
|
+ headerStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ headerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
|
+ headerStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
|
+ headerStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ // 背景颜色
|
|
|
|
+ headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerStyle.setFillForegroundColor(IndexedColors.GREY_80_PERCENT.getIndex());
|
|
|
|
+ Font font = wb.createFont();
|
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
|
+ font.setFontName("宋体");
|
|
|
|
+ font.setColor(IndexedColors.WHITE.getIndex());
|
|
|
|
+ headerStyle.setFont(font);
|
|
|
|
+
|
|
|
|
+ // 数据
|
|
|
|
+ XSSFCellStyle dataStyle = wb.createCellStyle();
|
|
|
|
+ dataStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ dataStyle.setBorderRight(BorderStyle.THIN);
|
|
|
|
+ dataStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ dataStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
|
+ dataStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ dataStyle.setBorderTop(BorderStyle.THIN);
|
|
|
|
+ dataStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ dataStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
|
+ dataStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
|
+ dataStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ // 背景颜色
|
|
|
|
+ dataStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
|
+ font = wb.createFont();
|
|
|
|
+ font.setFontHeightInPoints((short) 10);
|
|
|
|
+ font.setFontName("宋体");
|
|
|
|
+ dataStyle.setFont(font);
|
|
|
|
+
|
|
|
|
+ // 锁定样式
|
|
|
|
+ XSSFCellStyle lockStyle = wb.createCellStyle();
|
|
|
|
+ lockStyle.setLocked(true);//设置锁定
|
|
|
|
+
|
|
|
|
+ // 未锁定样式
|
|
|
|
+ XSSFCellStyle unlockStyle = wb.createCellStyle();
|
|
|
|
+ unlockStyle.setLocked(false);//设置未锁定
|
|
|
|
+
|
|
|
|
+ XSSFRow headRow = sheet.createRow(0);
|
|
|
|
+ // 表头
|
|
|
|
+ String[] fieldsNameList = {"学号", "姓名", "学期", "考试", "扫描批次号", "课程名称(代码)","任课老师", "教学班", "学院", "专业", "班级", "绑定图片数量(张)", "下载成功数量(页)", "下载失败(页)"};
|
|
|
|
+ for (int i = 0; i < fieldsNameList.length; i++) {
|
|
|
|
+ XSSFCell cell = headRow.createCell(i);
|
|
|
|
+ cell.setCellValue(fieldsNameList[i]);
|
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 1; i <= list.size(); i++) {
|
|
|
|
+ PictureManageDetailResult result = list.get(i - 1);
|
|
|
|
+ XSSFRow row = sheet.createRow(i);
|
|
|
|
+
|
|
|
|
+ XSSFCell cell0 = row.createCell(0);
|
|
|
|
+ cell0.setCellStyle(lockStyle);
|
|
|
|
+ cell0.setCellStyle(dataStyle);
|
|
|
|
+ cell0.setCellValue(result.getStudentCode());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell1 = row.createCell(1);
|
|
|
|
+ cell1.setCellStyle(lockStyle);
|
|
|
|
+ cell1.setCellStyle(dataStyle);
|
|
|
|
+ cell1.setCellValue(result.getStudentName());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell2 = row.createCell(2);
|
|
|
|
+ cell2.setCellStyle(lockStyle);
|
|
|
|
+ cell2.setCellStyle(dataStyle);
|
|
|
|
+ cell2.setCellValue(result.getSemesterName());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell3 = row.createCell(3);
|
|
|
|
+ cell3.setCellStyle(lockStyle);
|
|
|
|
+ cell3.setCellStyle(dataStyle);
|
|
|
|
+ cell3.setCellValue(result.getExamName());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell4 = row.createCell(4);
|
|
|
|
+ cell4.setCellStyle(lockStyle);
|
|
|
|
+ cell4.setCellStyle(dataStyle);
|
|
|
|
+ cell4.setCellValue(Objects.isNull(result.getBatchNo()) || "null".equals(result.getBatchNo()) ? "" : result.getBatchNo());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell5 = row.createCell(5);
|
|
|
|
+ cell5.setCellStyle(lockStyle);
|
|
|
|
+ cell5.setCellStyle(dataStyle);
|
|
|
|
+ cell5.setCellValue(result.getCourseName()+"("+result.getCourseCode()+")");
|
|
|
|
+
|
|
|
|
+ XSSFCell cell6 = row.createCell(6);
|
|
|
|
+ cell6.setCellStyle(lockStyle);
|
|
|
|
+ cell6.setCellStyle(dataStyle);
|
|
|
|
+ cell6.setCellValue(result.getTeacher());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell7 = row.createCell(7);
|
|
|
|
+ cell7.setCellStyle(lockStyle);
|
|
|
|
+ cell7.setCellStyle(dataStyle);
|
|
|
|
+ cell7.setCellValue(result.getTeachClass());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell8 = row.createCell(8);
|
|
|
|
+ cell8.setCellStyle(lockStyle);
|
|
|
|
+ cell8.setCellStyle(dataStyle);
|
|
|
|
+ cell8.setCellValue(result.getCollegeName());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell9 = row.createCell(9);
|
|
|
|
+ cell9.setCellStyle(lockStyle);
|
|
|
|
+ cell9.setCellStyle(dataStyle);
|
|
|
|
+ cell9.setCellValue(result.getMajorName());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell10 = row.createCell(10);
|
|
|
|
+ cell10.setCellStyle(lockStyle);
|
|
|
|
+ cell10.setCellStyle(dataStyle);
|
|
|
|
+ cell10.setCellValue(result.getClassName());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell11 = row.createCell(11);
|
|
|
|
+ cell11.setCellStyle(lockStyle);
|
|
|
|
+ cell11.setCellStyle(dataStyle);
|
|
|
|
+ cell11.setCellValue(result.getBindCount());
|
|
|
|
+
|
|
|
|
+ XSSFCell cell12 = row.createCell(12);
|
|
|
|
+ cell12.setCellStyle(lockStyle);
|
|
|
|
+ cell12.setCellStyle(dataStyle);
|
|
|
|
+ cell12.setCellValue(successMap.get(result.getStudentId()));
|
|
|
|
+
|
|
|
|
+ XSSFCell cell13 = row.createCell(13);
|
|
|
|
+ cell13.setCellStyle(lockStyle);
|
|
|
|
+ cell13.setCellStyle(dataStyle);
|
|
|
|
+ cell13.setCellValue(errorMap.get(result.getStudentId()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < fieldsNameList.length; i++) {
|
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
|
+ sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 13);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // sheet添加保护,这个一定要否则光锁定还是可以编辑的
|
|
|
|
+ sheet.protectSheet(SystemConstant.EXCEL_PROTECT_KEY);
|
|
|
|
+
|
|
|
|
+ File file = new File(zipLocalRootPath, fileName);
|
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(file);
|
|
|
|
+ wb.write(outputStream);
|
|
|
|
+ outputStream.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 生成清单
|
|
* 生成清单
|
|
*
|
|
*
|