|
@@ -3,11 +3,14 @@ package com.qmth.distributed.print.business.templete.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.oss.common.utils.BinaryUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.dto.ExaminationExportDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.FieldsDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.PdfDto;
|
|
|
+import com.qmth.distributed.print.business.bean.params.ArraysParams;
|
|
|
+import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
|
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
|
import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
|
import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
@@ -20,12 +23,20 @@ import com.qmth.distributed.print.business.util.ExcelUtil;
|
|
|
import com.qmth.distributed.print.business.util.OssUtil;
|
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.distributed.print.common.util.FileUtil;
|
|
|
+import com.qmth.distributed.print.common.util.HexUtils;
|
|
|
import com.qmth.distributed.print.common.util.ResultUtil;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
-import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+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.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.data.redis.support.atomic.RedisAtomicLong;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -92,6 +103,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
@Resource
|
|
|
CreatePdfUtil createPdfUtil;
|
|
|
|
|
|
+ @Resource
|
|
|
+ RedisTemplate<String, Object> redisTemplate;
|
|
|
+
|
|
|
/**
|
|
|
* 创建pdf逻辑
|
|
|
*
|
|
@@ -317,7 +331,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public Map<String, Object> executeImportExaminationLogic(Map<String, Object> map) throws Exception {
|
|
|
TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
@@ -474,29 +488,115 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
|
|
|
// 删除印刷计划下的考务数据
|
|
|
examDetailService.deleteExaminationData(printPlanId);
|
|
|
- // 组装exam_detail数据
|
|
|
- examDetailService.disposeExamDetailByExaminationExcel(dataList, userId);
|
|
|
- // 组装exam_detail_course数据
|
|
|
- examDetailService.disposeExamDetailCourseByExaminationExcel(dataList, userId);
|
|
|
- // 组装exam_student数据
|
|
|
- examDetailService.disposeExamStudentByExaminationExcel(dataList, userId);
|
|
|
-
|
|
|
- List<Map<String, Object>> checkList = dataList.stream().flatMap(e -> {
|
|
|
- Map<String, Object> tmp = new HashMap<>();
|
|
|
- tmp.put("schoolId", e.get("schoolId"));
|
|
|
- tmp.put("courseCode", e.get("courseCode"));
|
|
|
- tmp.put("paperNumber", e.get("paperNumber"));
|
|
|
- return Stream.of(tmp);
|
|
|
- }).distinct().collect(Collectors.toList());
|
|
|
- for (Map<String, Object> stringObjectMap : checkList) {
|
|
|
- Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
|
|
|
- String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
|
|
|
- String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
|
|
|
- SysUser user = (SysUser) map.get(SystemConstant.USER);
|
|
|
- user.setSchoolId(schoolId);
|
|
|
- commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber, user);
|
|
|
+
|
|
|
+
|
|
|
+ SerialNumberParams serialNumberParams = new SerialNumberParams("packageCode-", "p", 6);
|
|
|
+ String key = serialNumberParams.getModel() + serialNumberParams.getPrefix();
|
|
|
+ RedisAtomicLong counter = new RedisAtomicLong(key, Objects.requireNonNull(redisTemplate.getConnectionFactory()));
|
|
|
+ Long value = counter.get();
|
|
|
+ try {
|
|
|
+ // 组装exam_detail数据
|
|
|
+ examDetailService.disposeExamDetailByExaminationExcel(dataList, userId, serialNumberParams);
|
|
|
+ // 组装exam_detail_course数据
|
|
|
+ examDetailService.disposeExamDetailCourseByExaminationExcel(dataList, userId);
|
|
|
+ // 组装exam_student数据
|
|
|
+ examDetailService.disposeExamStudentByExaminationExcel(dataList, userId);
|
|
|
+
|
|
|
+ List<Map<String, Object>> checkList = dataList.stream().flatMap(e -> {
|
|
|
+ Map<String, Object> tmp = new HashMap<>();
|
|
|
+ tmp.put("schoolId", e.get("schoolId"));
|
|
|
+ tmp.put("courseCode", e.get("courseCode"));
|
|
|
+ tmp.put("paperNumber", e.get("paperNumber"));
|
|
|
+ return Stream.of(tmp);
|
|
|
+ }).distinct().collect(Collectors.toList());
|
|
|
+ for (Map<String, Object> stringObjectMap : checkList) {
|
|
|
+ Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
|
|
|
+ String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
|
|
|
+ String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
|
|
|
+ SysUser user = (SysUser) map.get(SystemConstant.USER);
|
|
|
+ user.setSchoolId(schoolId);
|
|
|
+ commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber, user);
|
|
|
+ }
|
|
|
+ map.put("dataCount", dataList.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ redisTemplate.opsForValue().set(key, value);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载pdf
|
|
|
+ *
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> executeDownloadPdfLogic(Map<String, Object> map) throws Exception {
|
|
|
+ try {
|
|
|
+ TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(tbTask.getRemark());
|
|
|
+ ArraysParams arraysParams = new ArraysParams(jsonArray.toArray(new Long[jsonArray.size()]));
|
|
|
+ if (Objects.isNull(arraysParams) || arraysParams.getIds().length == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("数组id为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询examDetail
|
|
|
+ QueryWrapper<ExamDetail> examDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ examDetailQueryWrapper.lambda().in(ExamDetail::getPrintPlanId, arraysParams.getIds());
|
|
|
+ List<ExamDetail> examDetailList = examDetailService.list(examDetailQueryWrapper);
|
|
|
+ if (Objects.nonNull(examDetailList)) {
|
|
|
+ Set<Long> attachmentIds = examDetailList.stream().map(ExamDetail::getAttachmentId).collect(Collectors.toSet());
|
|
|
+ List<BasicAttachment> basicAttachmentList = basicAttachmentService.listByIds(attachmentIds);
|
|
|
+
|
|
|
+ if (Objects.nonNull(basicAttachmentList)) {
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("")
|
|
|
+ .add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
|
+ StringJoiner dirName = new StringJoiner("")
|
|
|
+ .add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
+ .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.ZIP_PREFIX);
|
|
|
+ File zipFile = new File(stringJoiner.toString() + dirName.toString());
|
|
|
+ if (!zipFile.getParentFile().exists()) {
|
|
|
+ zipFile.getParentFile().mkdirs();
|
|
|
+ zipFile.createNewFile();
|
|
|
+ }
|
|
|
+ List<File> sourceFiles = new ArrayList<>();
|
|
|
+ for (BasicAttachment basicAttachment : basicAttachmentList) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
|
|
|
+ StringJoiner stringJoinerPdf = new StringJoiner("")
|
|
|
+ .add(SystemConstant.TEMP_FILES_DIR).add(File.separator)
|
|
|
+ .add((String) jsonObject.get("path"));
|
|
|
+ sourceFiles.add(ossUtil.ossDownload((String) jsonObject.get("path"), stringJoinerPdf.toString()));
|
|
|
+ }
|
|
|
+ FileUtil.doZip(zipFile, sourceFiles);
|
|
|
+ ossUtil.ossUpload(dirName.toString(), zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put(SystemConstant.PATH, dirName.toString());
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
+ tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
|
+ for (File file : sourceFiles) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
+ map.computeIfAbsent(SystemConstant.SIZE, v -> attachmentIds.size());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("请求出错", e);
|
|
|
+ if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
- map.put("dataCount", dataList.size());
|
|
|
return map;
|
|
|
}
|
|
|
}
|