Browse Source

Merge branch 'dev' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev

xiaof 4 years ago
parent
commit
f3dac2abfe
21 changed files with 565 additions and 1176 deletions
  1. 0 5
      distributed-print-business/pom.xml
  2. 16 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PdfDto.java
  3. 0 100
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/excel/UserExportDto.java
  4. 0 105
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/excel/UserImportDto.java
  5. 0 10
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/SysUserMapper.java
  6. 3 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java
  7. 2 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicExamRuleService.java
  8. 0 11
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/SysUserService.java
  9. 11 27
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java
  10. 12 5
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicExamRuleServiceImpl.java
  11. 1 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CommonServiceImpl.java
  12. 9 17
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/SysUserServiceImpl.java
  13. 0 40
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/excelListener/ExaminationListener.java
  14. 0 121
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncUserImportTempleteService.java
  15. 0 97
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/UserImportTempleteService.java
  16. 0 9
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/TaskLogicService.java
  17. 41 474
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java
  18. 440 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java
  19. 2 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java
  20. 1 45
      distributed-print-business/src/main/resources/mapper/SysUserMapper.xml
  21. 27 106
      distributed-print/src/main/java/com/qmth/distributed/print/api/SysUserController.java

+ 0 - 5
distributed-print-business/pom.xml

@@ -80,11 +80,6 @@
             <groupId>com.itextpdf</groupId>
             <artifactId>itextpdf</artifactId>
         </dependency>
-		<dependency>
-			<groupId>com.alibaba</groupId>
-			<artifactId>easyexcel</artifactId>
-			<version>2.2.8</version>
-		</dependency>
         <dependency>
             <groupId>com.google.zxing</groupId>
             <artifactId>core</artifactId>

+ 16 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PdfDto.java

@@ -16,11 +16,26 @@ public class PdfDto {
     String path;
 
     @ApiModelProperty(name = "页数")
-    Integer pageCount;
+    Integer pageCount = 0;
 
     @ApiModelProperty(name = "页面大小")
     PageSizeEnum pageSize;
 
+    public PdfDto() {
+
+    }
+
+    public PdfDto(String path, PageSizeEnum pageSize) {
+        this.path = path;
+        this.pageSize = pageSize;
+    }
+
+    public PdfDto(String path, PageSizeEnum pageSize, Integer pageCount) {
+        this.path = path;
+        this.pageSize = pageSize;
+        this.pageCount = pageCount;
+    }
+
     public String getPath() {
         return path;
     }

+ 0 - 100
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/excel/UserExportDto.java

@@ -1,100 +0,0 @@
-package com.qmth.distributed.print.business.bean.dto.excel;
-
-import com.qmth.distributed.print.business.annotation.ExcelProperty;
-import io.swagger.annotations.ApiModelProperty;
-
-import java.io.Serializable;
-
-/** 
-* @Description: 用户导出dto
-* @Param:  
-* @return:  
-* @Author: wangliang
-* @Date: 2021/3/30 
-*/ 
-public class UserExportDto implements Serializable {
-
-    @ApiModelProperty(name = "姓名")
-    @ExcelProperty(name = "姓名", width = 30, index = 1)
-    String realName;
-
-    @ApiModelProperty(name = "登录名")
-    @ExcelProperty(name = "登录名", width = 30, index = 2)
-    String loginName;
-
-    @ApiModelProperty(name = "角色")
-    @ExcelProperty(name = "角色", width = 30, index = 3)
-    String roleName;
-
-    @ApiModelProperty(name = "学校名称代码")
-    @ExcelProperty(name = "学校名称代码", width = 40, index = 4)
-    String schoolNameCode;
-
-    @ApiModelProperty(name = "状态")
-    @ExcelProperty(name = "状态", width = 30, index = 6)
-    String enable;
-
-    @ApiModelProperty(name = "更新时间")
-    @ExcelProperty(name = "更新时间", width = 30, index = 7)
-    String updateTime;
-
-    @ApiModelProperty(name = "执行人")
-    @ExcelProperty(name = "执行人", width = 30, index = 8)
-    String updateName;
-
-    public String getRealName() {
-        return realName;
-    }
-
-    public void setRealName(String realName) {
-        this.realName = realName;
-    }
-
-    public String getLoginName() {
-        return loginName;
-    }
-
-    public void setLoginName(String loginName) {
-        this.loginName = loginName;
-    }
-
-    public String getRoleName() {
-        return roleName;
-    }
-
-    public void setRoleName(String roleName) {
-        this.roleName = roleName;
-    }
-
-    public String getSchoolNameCode() {
-        return schoolNameCode;
-    }
-
-    public void setSchoolNameCode(String schoolNameCode) {
-        this.schoolNameCode = schoolNameCode;
-    }
-
-    public String getEnable() {
-        return enable;
-    }
-
-    public void setEnable(String enable) {
-        this.enable = enable;
-    }
-
-    public String getUpdateTime() {
-        return updateTime;
-    }
-
-    public void setUpdateTime(String updateTime) {
-        this.updateTime = updateTime;
-    }
-
-    public String getUpdateName() {
-        return updateName;
-    }
-
-    public void setUpdateName(String updateName) {
-        this.updateName = updateName;
-    }
-}

+ 0 - 105
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/excel/UserImportDto.java

@@ -1,105 +0,0 @@
-package com.qmth.distributed.print.business.bean.dto.excel;
-
-import com.qmth.distributed.print.business.annotation.ExcelNote;
-import com.qmth.distributed.print.business.entity.SysRole;
-import io.swagger.annotations.ApiModelProperty;
-
-import javax.validation.constraints.NotNull;
-import java.io.Serializable;
-
-/**
- * @Description: 用户导入dto
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2021/3/29
- */
-public class UserImportDto implements Serializable {
-
-    @NotNull
-    @ExcelNote(value = "姓名")
-    @ApiModelProperty(value = "姓名")
-    String realName;
-
-    @NotNull
-    @ExcelNote(value = "登录名")
-    @ApiModelProperty(value = "登录名")
-    String loginName;
-
-    @NotNull
-    @ExcelNote(value = "密码")
-    @ApiModelProperty(value = "密码")
-    String password;
-
-    @NotNull
-    @ExcelNote(value = "角色")
-    @ApiModelProperty(value = "角色")
-    String role;
-
-    @ExcelNote(value = "学校代码")
-    @ApiModelProperty(value = "学校代码")
-    String schoolCode;
-
-    @ExcelNote(value = "学校名称")
-    @ApiModelProperty(value = "学校名称")
-    String schoolName;
-
-    @ApiModelProperty(value = "角色")
-    SysRole sysRole;
-
-    public SysRole getSysRole() {
-        return sysRole;
-    }
-
-    public void setSysRole(SysRole sysRole) {
-        this.sysRole = sysRole;
-    }
-
-    public String getRealName() {
-        return realName;
-    }
-
-    public void setRealName(String realName) {
-        this.realName = realName;
-    }
-
-    public String getLoginName() {
-        return loginName;
-    }
-
-    public void setLoginName(String loginName) {
-        this.loginName = loginName;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    public void setPassword(String password) {
-        this.password = password;
-    }
-
-    public String getRole() {
-        return role;
-    }
-
-    public void setRole(String role) {
-        this.role = role;
-    }
-
-    public String getSchoolCode() {
-        return schoolCode;
-    }
-
-    public void setSchoolCode(String schoolCode) {
-        this.schoolCode = schoolCode;
-    }
-
-    public String getSchoolName() {
-        return schoolName;
-    }
-
-    public void setSchoolName(String schoolName) {
-        this.schoolName = schoolName;
-    }
-}

+ 0 - 10
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/SysUserMapper.java

@@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.distributed.print.business.bean.dto.BlurryUserDto;
 import com.qmth.distributed.print.business.bean.dto.UserDto;
-import com.qmth.distributed.print.business.bean.dto.excel.UserExportDto;
-import com.qmth.distributed.print.business.bean.params.ArraysParams;
 import com.qmth.distributed.print.business.entity.SysUser;
 import org.apache.ibatis.annotations.Param;
 
@@ -24,13 +22,5 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
 
     IPage<UserDto> listPage(Page<UserDto> page, @Param("schoolId") Long schoolId, @Param("realName") String realName, @Param("roleId") String roleId, @Param("enable") Boolean enable);
 
-    /**
-     * 用户导出
-     *
-     * @param arraysParams
-     * @return
-     */
-    public List<UserExportDto> queryByExport(@Param("arraysParams") ArraysParams arraysParams);
-
     List<BlurryUserDto> listUser(@Param("schoolId") Long schoolId, @Param("type") String type, @Param("courseCode") String courseCode, @Param("param") String param);
 }

+ 3 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.itextpdf.text.DocumentException;
+import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.entity.BasicAttachment;
 import com.qmth.distributed.print.business.enums.UploadFileEnum;
 import org.springframework.web.multipart.MultipartFile;
@@ -50,7 +51,7 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<String> localFileList) throws IOException;
+    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList) throws IOException;
 
     /**
      * 保存附件
@@ -71,7 +72,7 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<String> pdfList, Integer printCount) throws IOException, DocumentException;
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount) throws IOException, DocumentException;
 
     /**
      * 删除附件

+ 2 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicExamRuleService.java

@@ -15,5 +15,7 @@ public interface BasicExamRuleService extends IService<BasicExamRule> {
 
     BasicExamRule getBySchoolId();
 
+    BasicExamRule getBySchoolId(Long schoolId);
+
     boolean saveExamRule(BasicExamRule examRule);
 }

+ 0 - 11
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/SysUserService.java

@@ -5,9 +5,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.distributed.print.business.bean.dto.BlurryUserDto;
 import com.qmth.distributed.print.business.bean.dto.LoginDto;
 import com.qmth.distributed.print.business.bean.dto.UserDto;
-import com.qmth.distributed.print.business.bean.dto.excel.UserExportDto;
-import com.qmth.distributed.print.business.bean.params.ArraysParams;
-import com.qmth.distributed.print.business.bean.params.UserParam;
 import com.qmth.distributed.print.business.entity.SysUser;
 
 import java.util.List;
@@ -36,14 +33,6 @@ public interface SysUserService extends IService<SysUser> {
 
     LoginDto getUserRoles(SysUser sysUser);
 
-    /**
-     * 用户导出
-     *
-     * @param arraysParams
-     * @return
-     */
-    public List<UserExportDto> queryByExport(ArraysParams arraysParams);
-
     List<BlurryUserDto> listUser(String courseCode, String param);
 
     List<SysUser> listByOrgId(Long id);

+ 11 - 27
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -5,8 +5,8 @@ import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.itextpdf.text.DocumentException;
 import com.itextpdf.text.pdf.PdfReader;
-import com.itextpdf.text.pdf.PdfStamper;
 import com.qmth.boot.api.exception.ApiException;
+import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.config.DictionaryConfig;
 import com.qmth.distributed.print.business.entity.BasicAttachment;
 import com.qmth.distributed.print.business.entity.SysUser;
@@ -24,7 +24,6 @@ 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.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,7 +33,9 @@ import org.springframework.util.FileCopyUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.List;
@@ -100,7 +101,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<String> localFileList) throws IOException {
+    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList) throws IOException {
         BasicAttachment basicAttachment = null;
         try {
             byte[] bytes = htmlContent.getBytes();
@@ -134,7 +135,8 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                     pdfFile.getParentFile().mkdirs();
                     pdfFile.createNewFile();
                 }
-                localFileList.add(pdfFile.getPath());
+                int pageCount = PdfUtil.addPdfPage(pdfFile);
+                localFileList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A3, pageCount));
                 fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
                 ossUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
                 localHtmlFile.delete();
@@ -218,7 +220,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<String> pdfList, Integer printCount) throws IOException, DocumentException {
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount) throws IOException, DocumentException {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
@@ -244,9 +246,9 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                 pdfFile.createNewFile();
             }
             String fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
+            int pageCount = 0;
             if (oss) {//上传至oss
-                int pageCount = PdfUtil.addPdfPage(pdfFile);
-
+                pageCount = PdfUtil.addPdfPage(pdfFile);
                 ossUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
                 jsonObject.put(SystemConstant.PDF_PATH, pdfDirName);
                 if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.FTL_PREFIX)) {
@@ -265,7 +267,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             }
             basicAttachment.setPath(jsonObject.toJSONString());
             for (int i = 0; i < printCount; i++) {
-                pdfList.add(pdfFile.getPath());
+                pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pageCount));
             }
             this.updateById(basicAttachment);
         } catch (Exception e) {
@@ -279,24 +281,6 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
         return basicAttachment;
     }
 
-    public static void main(String[] args) throws IOException, DocumentException {
-        File file = new File("/Users/king/Downloads/669ad9917f814bcabdd35201073885be.pdf");
-        PdfReader reader = new PdfReader(file.getPath());
-        int pageCount = reader.getNumberOfPages();
-        System.out.println("pageCount:" + pageCount);
-//
-        if (Math.abs(pageCount % 2) == 1) {//取偶
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            PdfStamper stamper = new PdfStamper(reader, baos);
-            stamper.insertPage(pageCount + 1, reader.getPageSizeWithRotation(1));
-            stamper.close();
-            FileOutputStream fileOutputStream = new FileOutputStream(file);
-            IOUtils.write(baos.toByteArray(), fileOutputStream);
-        }
-        pageCount = reader.getNumberOfPages();
-        System.out.println("pageCount:" + pageCount);
-    }
-
     /**
      * 删除附件
      *

+ 12 - 5
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicExamRuleServiceImpl.java

@@ -42,6 +42,13 @@ public class BasicExamRuleServiceImpl extends ServiceImpl<BasicExamRuleMapper, B
         return this.getOne(queryWrapper);
     }
 
+    @Override
+    public BasicExamRule getBySchoolId(Long schoolId) {
+        QueryWrapper<BasicExamRule> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(BasicExamRule::getSchoolId, schoolId);
+        return this.getOne(queryWrapper);
+    }
+
     @Override
     public boolean saveExamRule(BasicExamRule examRule) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
@@ -50,7 +57,7 @@ public class BasicExamRuleServiceImpl extends ServiceImpl<BasicExamRuleMapper, B
 
         // 已开始新建印刷计划,不能新增、删除扩展字段
         // 新增
-        if (examRule.getId() == null){
+        if (examRule.getId() == null) {
             examRule.setId(SystemConstant.getDbUuid());
             examRule.setCreateId(sysUser.getId());
             examRule.setCreateTime(System.currentTimeMillis());
@@ -62,14 +69,14 @@ public class BasicExamRuleServiceImpl extends ServiceImpl<BasicExamRuleMapper, B
             QueryWrapper<ExamPrintPlan> queryWrapper = new QueryWrapper<>();
             queryWrapper.lambda().ne(ExamPrintPlan::getStatus, PrintPlanStatusEnum.END);
             List<ExamPrintPlan> examPrintPlanList = examPrintPlanService.list(queryWrapper);
-            if(examPrintPlanList != null && examPrintPlanList.size() > 0) {
+            if (examPrintPlanList != null && examPrintPlanList.size() > 0) {
                 BasicExamRule basicExamRule = this.getById(examRule.getId());
                 // 匹配扩展字段是否有变动
                 String oldExtends = basicExamRule.getExtendFields();
                 String newExtends = examRule.getExtendFields();
                 List<Map> oldMapList = JSONObject.parseArray(oldExtends, Map.class);
                 List<Map> newMapList = JSONObject.parseArray(newExtends, Map.class);
-                if (oldMapList.size() != newMapList.size()){
+                if (oldMapList.size() != newMapList.size()) {
                     throw ExceptionResultEnum.ERROR.exception("有未结束的印刷计划,不能修改扩展字段");
                 }
                 for (Map map : oldMapList) {
@@ -82,10 +89,10 @@ public class BasicExamRuleServiceImpl extends ServiceImpl<BasicExamRuleMapper, B
                         String code1 = String.valueOf(map1.get("code"));
                         String name1 = String.valueOf(map1.get("name"));
                         String enable1 = String.valueOf(map1.get("enable"));
-                        if (code.equals(code1) && name.equals(name1) && enable.equals(enable1)){
+                        if (code.equals(code1) && name.equals(name1) && enable.equals(enable1)) {
                             flag = false;
                         }
-                        if(flag) {
+                        if (flag) {
                             throw ExceptionResultEnum.ERROR.exception("有未结束的印刷计划,不能修改扩展字段");
                         }
                     }

+ 1 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CommonServiceImpl.java

@@ -518,6 +518,7 @@ public class CommonServiceImpl implements CommonService {
                         if (Objects.nonNull(examDetail.getId())) {
                             map.computeIfAbsent("examDetailId", v -> examDetail.getId());
                         }
+                        map.computeIfAbsent("schoolId", v -> schoolId);
                         asyncCreatePdfTempleteService.createPdf(map);
                     }
                 }

+ 9 - 17
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/SysUserServiceImpl.java

@@ -1,7 +1,6 @@
 package com.qmth.distributed.print.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.Update;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -9,16 +8,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.distributed.print.business.bean.dto.BlurryUserDto;
 import com.qmth.distributed.print.business.bean.dto.LoginDto;
 import com.qmth.distributed.print.business.bean.dto.UserDto;
-import com.qmth.distributed.print.business.bean.dto.excel.UserExportDto;
-import com.qmth.distributed.print.business.bean.params.ArraysParams;
 import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.enums.RoleTypeEnum;
 import com.qmth.distributed.print.business.mapper.SysUserMapper;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.business.util.security.Md5Utils;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
-import com.qmth.distributed.print.business.enums.RoleTypeEnum;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -147,9 +144,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
         // 角色里是否有考务老师角色
         List<SysRole> sysRoles = sysRoleService.list(user.getRoleIds(), RoleTypeEnum.QUESTION_TEACHER.name());
-        if(sysRoles != null && sysRoles.size() > 0){
+        if (sysRoles != null && sysRoles.size() > 0) {
             Long[] courseIds = user.getCourseIds();
-            if(courseIds.length == 0){
+            if (courseIds.length == 0) {
                 throw ExceptionResultEnum.ERROR.exception("请选择课程");
             }
 
@@ -184,12 +181,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     @Override
     public boolean updatePassword(Long id, String oldPassword, String password) {
         SysUser sysUser = this.getById(id);
-        if(sysUser == null){
+        if (sysUser == null) {
             throw ExceptionResultEnum.ERROR.exception("用户不存在");
         }
 
         oldPassword = Md5Utils.toMd5Hex(oldPassword);
-        if(!StringUtils.equals(sysUser.getPassword(), oldPassword)){
+        if (!StringUtils.equals(sysUser.getPassword(), oldPassword)) {
             throw ExceptionResultEnum.ERROR.exception("原密码不正确");
         }
         String md5Password = Md5Utils.toMd5Hex(password);
@@ -201,7 +198,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     @Override
     public boolean bindRoles(SysUser sysUser) {
         Long[] roleIds = sysUser.getRoleIds();
-        if(roleIds.length == 0){
+        if (roleIds.length == 0) {
             throw ExceptionResultEnum.ERROR.exception("请选择角色");
         }
 
@@ -222,9 +219,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
         // 角色里是否有考务老师角色
         List<SysRole> sysRoles = sysRoleService.list(roleIds, RoleTypeEnum.QUESTION_TEACHER.name());
-        if(sysRoles != null && sysRoles.size() > 0){
+        if (sysRoles != null && sysRoles.size() > 0) {
             Long[] courseIds = sysUser.getCourseIds();
-            if(courseIds.length == 0){
+            if (courseIds.length == 0) {
                 throw ExceptionResultEnum.ERROR.exception("请选择课程");
             }
 
@@ -246,7 +243,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         loginDto.setEnable(sysUser.getEnable());
         loginDto.setPwdUpdateTime(sysUser.getPwdUpdateTime());
 
-        if("admin".equals(sysUser.getLoginName())){
+        if ("admin".equals(sysUser.getLoginName())) {
             loginDto.setRoles(Arrays.asList("ADMIN"));
         } else {
             List<SysRole> list = sysUserRoleService.listRoleByUserId(sysUser.getId());
@@ -256,11 +253,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         return loginDto;
     }
 
-    @Override
-    public List<UserExportDto> queryByExport(ArraysParams arraysParams) {
-        return sysUserMapper.queryByExport(arraysParams);
-    }
-
     @Override
     public List<BlurryUserDto> listUser(String courseCode, String param) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());

+ 0 - 40
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/excelListener/ExaminationListener.java

@@ -1,40 +0,0 @@
-package com.qmth.distributed.print.business.templete.excelListener;
-
-import com.alibaba.excel.context.AnalysisContext;
-import com.alibaba.excel.event.AnalysisEventListener;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @Description: 考务数据监听
- * @Author: CaoZixuan
- * @Date: 2021-04-07
- */
-public class ExaminationListener extends AnalysisEventListener{
-    private List<Map<Integer, String>>  dataList= new ArrayList<>();
-
-    @Override
-    public void invoke(Object o, AnalysisContext analysisContext) {
-        System.out.println("当前行:"+analysisContext.getCurrentRowNum());
-        System.out.println(o);
-        Map<Integer, String> map = new HashMap<>();
-        map.put(analysisContext.readRowHolder().getRowIndex(), String.valueOf(o));
-        dataList.add(map);//数据存储到list,供批量处理,或后续自己业务逻辑处理。
-    }
-
-    @Override
-    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
-
-    }
-
-    public List<Map<Integer, String>> getDataList() {
-        return dataList;
-    }
-
-    public void setDataList(List<Map<Integer, String>> dataList) {
-        this.dataList = dataList;
-    }
-}

+ 0 - 121
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncUserImportTempleteService.java

@@ -1,121 +0,0 @@
-package com.qmth.distributed.print.business.templete.execute;
-
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.google.common.collect.Lists;
-import com.qmth.boot.api.exception.ApiException;
-import com.qmth.distributed.print.business.bean.dto.excel.UserImportDto;
-import com.qmth.distributed.print.business.entity.SysRole;
-import com.qmth.distributed.print.business.entity.TBTask;
-import com.qmth.distributed.print.business.enums.RoleTypeEnum;
-import com.qmth.distributed.print.business.enums.TaskResultEnum;
-import com.qmth.distributed.print.business.enums.TaskStatusEnum;
-import com.qmth.distributed.print.business.service.SysRoleService;
-import com.qmth.distributed.print.business.templete.importData.AsyncImportTaskTemplete;
-import com.qmth.distributed.print.business.templete.service.TaskLogicService;
-import com.qmth.distributed.print.business.util.ExcelUtil;
-import com.qmth.distributed.print.business.util.excel.ExcelError;
-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 com.qmth.distributed.print.common.util.ResultUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-import org.springframework.util.LinkedMultiValueMap;
-
-import javax.annotation.Resource;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.MessageFormat;
-import java.util.*;
-
-/**
- * @Description: 用户导入模版
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2021/3/29
- */
-@Service
-public class AsyncUserImportTempleteService extends AsyncImportTaskTemplete {
-    private final static Logger log = LoggerFactory.getLogger(AsyncUserImportTempleteService.class);
-
-    static final String OBJ_TITLE = "用户数据";
-
-    @Resource
-    TaskLogicService taskLogicService;
-
-    @Resource
-    SysRoleService sysRoleService;
-
-    /**
-     * 异步处理导入
-     *
-     * @param map
-     * @return
-     */
-    @Override
-    public Result importTask(Map<String, Object> map) throws IOException {
-        TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
-        InputStream inputStream = super.getUploadFileInputStream(tbTask);
-        StringJoiner stringJoinerSummary = new StringJoiner("\n")
-                .add(MessageFormat.format("{0}{1}{2}", FORMAT_TIME, BEGIN_TITLE, OBJ_TITLE));
-        tbTask.setStatus(TaskStatusEnum.RUNNING);
-        try {
-            List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(UserImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
-                List<ExcelError> excelErrorTemp = new ArrayList<>();
-                for (int i = 0; i < finalExcelList.size(); i++) {
-                    LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
-                    List<Object> userImportDtoList = excelMap.get(i);
-                    for (int y = 0; y < userImportDtoList.size(); y++) {
-                        UserImportDto userImportDto = (UserImportDto) userImportDtoList.get(y);
-                        excelErrorTemp.addAll(ExcelUtil.checkExcelField(userImportDto, y, i));
-                        //查角色名是否存在
-                        QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
-                        sysRoleQueryWrapper.lambda().eq(SysRole::getName, userImportDto.getRole());
-                        SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
-                        if (Objects.isNull(sysRole)) {
-                            throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[角色名]不存在")));
-                        }
-                        if (sysRole.getType() == RoleTypeEnum.SCHOOL_ADMIN && Objects.isNull(userImportDto.getSchoolCode())) {
-                            excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[学校代码]必填"));
-                        }
-                        if (userImportDto.getPassword().length() < 6) {
-                            excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[密码]不能小于6位"));
-                        } else if (userImportDto.getPassword().length() > 30) {
-                            excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[密码]不能大于30位"));
-                        }
-                        if (userImportDto.getRealName().length() > 25) {
-                            excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[姓名]不能超过25个字符"));
-                        }
-                        if (userImportDto.getLoginName().length() > 25) {
-                            excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[登录名]不能超过25个字符"));
-                        }
-                        userImportDto.setSysRole(sysRole);
-                    }
-                }
-                if (excelErrorTemp.size() > 0) {
-                    throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(excelErrorTemp));
-                }
-                return finalExcelList;
-            });
-//            Map<String, Object> mapLogic = taskLogicService.executeUserImportLogic(finalList, map);
-            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);
-    }
-}

+ 0 - 97
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/UserImportTempleteService.java

@@ -1,97 +0,0 @@
-package com.qmth.distributed.print.business.templete.execute;
-
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.google.common.collect.Lists;
-import com.qmth.distributed.print.business.bean.dto.excel.UserImportDto;
-import com.qmth.distributed.print.business.entity.SysRole;
-import com.qmth.distributed.print.business.enums.RoleTypeEnum;
-import com.qmth.distributed.print.business.service.SysRoleService;
-import com.qmth.distributed.print.business.templete.importData.SyncImportTaskTemplete;
-import com.qmth.distributed.print.business.templete.service.TaskLogicService;
-import com.qmth.distributed.print.business.util.ExcelUtil;
-import com.qmth.distributed.print.business.util.excel.ExcelError;
-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 com.qmth.distributed.print.common.util.ResultUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.annotation.Resource;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * @Description: 用户导入模版
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2021/3/29
- */
-@Service
-public class UserImportTempleteService implements SyncImportTaskTemplete, Serializable {
-    private final static Logger log = LoggerFactory.getLogger(UserImportTempleteService.class);
-
-    @Resource
-    TaskLogicService taskLogicService;
-
-    @Resource
-    SysRoleService sysRoleService;
-
-    /**
-     * 处理导入
-     *
-     * @param map
-     * @return
-     */
-    @Override
-    public Result importTask(Map<String, Object> map) throws IOException, NoSuchFieldException {
-        MultipartFile file = (MultipartFile) map.get(SystemConstant.FILE);
-        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(UserImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
-            List<ExcelError> excelErrorTemp = new ArrayList<>();
-            for (int i = 0; i < finalExcelList.size(); i++) {
-                LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
-                List<Object> userImportDtoList = excelMap.get(i);
-                for (int y = 0; y < userImportDtoList.size(); y++) {
-                    UserImportDto userImportDto = (UserImportDto) userImportDtoList.get(y);
-                    excelErrorTemp.addAll(ExcelUtil.checkExcelField(userImportDto, y, i));
-                    //查角色名是否存在
-                    QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
-                    sysRoleQueryWrapper.lambda().eq(SysRole::getName, userImportDto.getRole());
-                    SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
-                    if (Objects.isNull(sysRole)) {
-                        throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[角色名]不存在")));
-                    }
-                    if (sysRole.getType() == RoleTypeEnum.SCHOOL_ADMIN && Objects.isNull(userImportDto.getSchoolCode())) {
-                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[学校代码]必填"));
-                    }
-                    if (userImportDto.getPassword().length() < 6) {
-                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[密码]不能小于6位"));
-                    } else if (userImportDto.getPassword().length() > 30) {
-                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[密码]不能大于30位"));
-                    }
-                    if (userImportDto.getRealName().length() > 25) {
-                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[姓名]不能超过25个字符"));
-                    }
-                    if (userImportDto.getLoginName().length() > 25) {
-                        excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[登录名]不能超过25个字符"));
-                    }
-                    userImportDto.setSysRole(sysRole);
-                }
-            }
-            if (excelErrorTemp.size() > 0) {
-                throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(excelErrorTemp));
-            }
-            return finalExcelList;
-        });
-        return ResultUtil.ok(taskLogicService.executeUserImportLogic(finalList, map));
-    }
-}

+ 0 - 9
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/TaskLogicService.java

@@ -16,15 +16,6 @@ import java.util.Map;
  */
 public interface TaskLogicService {
 
-    /**
-     * 执行导入用户逻辑
-     *
-     * @param finalList
-     * @param map
-     * @return
-     */
-    public Map<String, Object> executeUserImportLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map);
-
     /**
      * 创建pdf逻辑
      *

+ 41 - 474
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -4,24 +4,23 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.google.gson.Gson;
-import com.itextpdf.text.DocumentException;
 import com.qmth.boot.api.exception.ApiException;
-import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
 import com.qmth.distributed.print.business.bean.dto.FieldsDto;
-import com.qmth.distributed.print.business.bean.dto.excel.UserImportDto;
+import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.bean.result.ExaminationResult;
 import com.qmth.distributed.print.business.entity.*;
-import com.qmth.distributed.print.business.enums.*;
+import com.qmth.distributed.print.business.enums.ExamStatusEnum;
+import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
+import com.qmth.distributed.print.business.enums.UploadFileEnum;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.service.TaskLogicService;
-import com.qmth.distributed.print.business.util.*;
-import com.qmth.distributed.print.business.util.excel.ExcelError;
+import com.qmth.distributed.print.business.util.ConvertUtil;
+import com.qmth.distributed.print.business.util.CreatePdfUtil;
+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.Base64Util;
 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.CellType;
 import org.apache.poi.ss.usermodel.Row;
@@ -32,7 +31,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.LinkedMultiValueMap;
 
 import javax.annotation.Resource;
 import java.io.*;
@@ -52,12 +50,6 @@ import java.util.stream.Stream;
 public class TaskLogicServiceImpl implements TaskLogicService {
     private final static Logger log = LoggerFactory.getLogger(TaskLogicServiceImpl.class);
 
-    @Resource
-    SysUserService sysUserService;
-
-    @Resource
-    BasicSchoolService basicSchoolService;
-
     @Resource
     CommonService commonService;
 
@@ -97,62 +89,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     CacheService cacheService;
 
-    @Resource
-    FreemarkerUtil freemarkerUtil;
-
     @Resource
     BasicCourseService basicCourseService;
 
-    /**
-     * 执行导入用户逻辑
-     *
-     * @param finalList
-     * @param map
-     * @return
-     */
-    @Override
-    @Transactional
-    public Map<String, Object> executeUserImportLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) {
-        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
-        Gson gson = new Gson();
-        LinkedMultiValueMap<Long, SysUser> tbUserLinkedMultiValueMap = new LinkedMultiValueMap<>();
-        for (int i = 0; i < finalList.size(); i++) {
-            LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
-            List<Object> userImportDtoList = excelMap.get(i);
-            for (int y = 0; y < userImportDtoList.size(); y++) {
-                UserImportDto userImportDto = (UserImportDto) userImportDtoList.get(y);
-                SysUser sysUser = gson.fromJson(gson.toJson(userImportDto), SysUser.class);
-
-                //查用户登录名是否重复
-                QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
-                sysUserQueryWrapper.lambda().eq(SysUser::getLoginName, userImportDto.getLoginName());
-                long count = sysUserService.count(sysUserQueryWrapper);
-                if (count > 0) {
-                    throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[登录名]重复")));
-                }
-                //查学校是否存在
-                if (Objects.nonNull(userImportDto.getSchoolCode())) {
-                    QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
-                    basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, userImportDto.getSchoolCode());
-                    BasicSchool basicSchool = basicSchoolService.getOne(basicSchoolQueryWrapper);
-                    if (Objects.isNull(basicSchool)) {
-                        throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[学校代码]不存在")));
-                    }
-                    sysUser.setSchoolId(basicSchool.getId());
-                }
-                sysUser.setInsertInfo(requestUser.getId());
-                sysUser.setPassword(Base64Util.encode(userImportDto.getPassword().getBytes()));
-                tbUserLinkedMultiValueMap.add(userImportDto.getSysRole().getId(), sysUser);
-            }
-        }
-        tbUserLinkedMultiValueMap.forEach((k, v) -> {
-            sysUserService.saveBatch(v);
-            v.forEach(s -> {
-                commonService.addUserRolePrivilege(s, k);
-            });
-        });
-        return map;
-    }
+    @Resource
+    CreatePdfUtil createPdfUtil;
 
     /**
      * 创建pdf逻辑
@@ -168,6 +109,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
             SysUser sysUser = (SysUser) map.get(SystemConstant.USER);
             Long examDetailId = Objects.nonNull(map.get("examDetailId")) ? (Long) map.get("examDetailId") : null;
+            Long schoolId = (Long) map.get("schoolId");
 
             //这里为保存附件html的逻辑
             //查询题卡详情是否有附件id,有的话则把以前的附件删除
@@ -201,12 +143,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
                 List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
 
-                List<String> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
-                List<String> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
-                List<String> paperPdfList = new ArrayList<>();//所有试卷
-                List<String> examStudentPdfList = new ArrayList<>();//所有题卡
-                List<String> backupPaperPdfList = new ArrayList<>();//备份试卷
-                List<String> cardPdfList = new ArrayList<>();//备份题卡
+                List<PdfDto> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
+                List<PdfDto> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
+                List<PdfDto> paperPdfList = new ArrayList<>();//所有试卷
+                List<PdfDto> examStudentPdfList = new ArrayList<>();//所有题卡
+                List<PdfDto> backupPaperPdfList = new ArrayList<>();//备份试卷
+                List<PdfDto> cardPdfList = new ArrayList<>();//备份题卡
 
                 if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
                     //获取普通印品
@@ -215,15 +157,15 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         JSONObject jsonObjectOrdinary = jsonArrayOrdinary.getJSONObject(i);
                         Long attachmentId = (Long) jsonObjectOrdinary.get("attachmentId");
                         BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
-                        createCheckIn(basicAttachment, ordinaryPdfList, (Integer) jsonObjectOrdinary.get("backupCount"));
+                        createPdfUtil.createCheckIn(basicAttachment, ordinaryPdfList, (Integer) jsonObjectOrdinary.get("backupCount"));
                     }
                 }
 
                 for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
-                    List<String> paperPdfTempList = new ArrayList<>();//所有试卷
-                    List<String> examStudentTempPdfList = new ArrayList<>();//所有题卡
-                    List<String> backupPaperTempPdfList = new ArrayList<>();//备份试卷
-                    List<String> cardPdfTempList = new ArrayList<>();//备份题卡
+                    List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
+                    List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
+                    List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
+                    List<PdfDto> cardPdfTempList = new ArrayList<>();//备份题卡
 
                     //查询试卷
                     QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
@@ -256,23 +198,23 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
 
                         //抽取卷型
-                        String paperType = getPaperType(examPrintPlan, examTaskDetail);
+                        String paperType = createPdfUtil.getPaperType(examPrintPlan, examTaskDetail);
 
                         //获取试卷pdf
-                        getPaperPdf(examTaskDetail, examPrintPlan.getBackupCount(), paperPdfTempList, backupPaperTempPdfList);
+                        createPdfUtil.getPaperPdf(examTaskDetail, examPrintPlan.getBackupCount(), paperPdfTempList, backupPaperTempPdfList);
                         paperPdfList.addAll(paperPdfTempList);
                         backupPaperPdfList.addAll(backupPaperTempPdfList);
 
                         basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
                         for (ExamCardDetail examCardDetail : examCardDetailList) {
-                            getCardAttachmentId(examCardDetail, attachmentIds);
+                            createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
 
                             //把模板页面上的 ${} 替换成实际内容
-                            String cardContent = replaceHtmlTemplete(examCardDetail);
+                            String cardContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
                             String studentContent = cardContent;
 
                             for (int i = 1; i <= examPrintPlan.getBackupCount(); i++) {
-                                basicAttachmentList.add(cardHtml(cardContent, paperType, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList));
+                                basicAttachmentList.add(createPdfUtil.cardHtml(cardContent, paperType, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList));
                             }
                             cardPdfList.addAll(cardPdfTempList);
 
@@ -292,15 +234,15 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                     BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
                                     ftlList.add(commonService.getFile(basicAttachment.getPath(), false));
                                     if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
-                                        createSignBook(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
+                                        createPdfUtil.createSignBook(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
                                     } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAG")) {//卷袋贴
-                                        createPaperPackage(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
+                                        createPdfUtil.createPaperPackage(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
                                     }
                                 }
                             }
 
                             for (ExamStudent t : examStudentList) {
-                                basicAttachmentList.add(examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentTempPdfList));
+                                basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentTempPdfList));
                             }
                             examStudentPdfList.addAll(examStudentTempPdfList);
                             examStudentService.saveOrUpdateBatch(examStudentList);
@@ -313,18 +255,18 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
                     Integer paperPageA3 = 0;
                     Integer cardPageA3 = 0;
-                    paperPageA3 = paperPageA3 + paperPdfTempList.size() + backupPaperTempPdfList.size();
-                    cardPageA3 = cardPageA3 + examStudentTempPdfList.size() + cardPdfTempList.size();
+                    paperPageA3 = paperPageA3 + paperPdfTempList.stream().mapToInt(PdfDto::getPageCount).sum() + backupPaperTempPdfList.stream().mapToInt(PdfDto::getPageCount).sum();
+                    cardPageA3 = cardPageA3 + examStudentTempPdfList.stream().mapToInt(PdfDto::getPageCount).sum() + cardPdfTempList.stream().mapToInt(PdfDto::getPageCount).sum();
                     examDetailCourse.setPaperPagesA3(paperPageA3);
                     examDetailCourse.setCardPagesA3(cardPageA3);
                 }
                 detailCourseService.saveOrUpdateBatch(examDetailCourseList);
                 //合并pdf
-                basicAttachmentList.add(mergePdf(tbTask, examDetail, sysUser.getId(), variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
+                basicAttachmentList.add(createPdfUtil.mergePdf(tbTask, examDetail, sysUser.getId(), schoolId, variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
             }
             map.computeIfAbsent("size", v -> examDetailList.size());
             //最后一步删除附件
-            deleteAttachment(attachmentIds, ftlList);
+            createPdfUtil.deleteAttachment(attachmentIds, ftlList);
         } catch (Exception e) {
             log.error("请求出错", e);
             basicAttachmentService.batchDeleteAttachment(basicAttachmentList);
@@ -415,7 +357,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         }
 
         PrintPlanStatusEnum printPlanStatus = examPrintPlan.getStatus();
-        if (PrintPlanStatusEnum.NEW != printPlanStatus && PrintPlanStatusEnum.READY != printPlanStatus){
+        if (PrintPlanStatusEnum.NEW != printPlanStatus && PrintPlanStatusEnum.READY != printPlanStatus) {
             throw ExceptionResultEnum.ERROR.exception(printPlanStatus + "状态下的印刷计划不允许导入");
         }
 
@@ -529,10 +471,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 }
             }
             // 校验课程信息
-            basicCourseService.verifyCourseInfo(schoolId,courseCode,courseName,userId);
+            basicCourseService.verifyCourseInfo(schoolId, courseCode, courseName, userId);
 
             // 解析时间
-            Map<String,Object> timeMap = ConvertUtil.analyzeStartAndEndTime(examDate,examTime);
+            Map<String, Object> timeMap = ConvertUtil.analyzeStartAndEndTime(examDate, examTime);
             String examStartTime = String.valueOf(timeMap.get("startTime"));
             String examEndTime = String.valueOf(timeMap.get("endTime"));
 
@@ -572,386 +514,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             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"));
-            commonService.checkData(checkSchoolId,checkCourseCode,checkPaperNumber);
+            Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
+            String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
+            String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
+            commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber);
         }
         return null;
     }
-
-    /**
-     * 创建登记表
-     *
-     * @param basicAttachment
-     * @param ordinaryPdfList
-     * @param printCount
-     */
-    private void createCheckIn(BasicAttachment basicAttachment, List<String> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
-        String type = basicAttachment.getType();
-        JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
-        if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.PDF_PREFIX)) {
-            String filePath = (String) jsonObject.get(SystemConstant.PATH);
-            String url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
-            File localFile = ossUtil.ossDownload(filePath, url);
-            for (int i = 0; i < printCount; i++) {
-                ordinaryPdfList.add(localFile.getPath());
-            }
-        } else {
-            basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount);
-        }
-    }
-
-    /**
-     * 生成卷袋贴
-     *
-     * @param basicAttachment
-     * @param schoolName
-     * @param examDetailCourse
-     * @param examStudentList
-     * @param variablePdfList
-     * @param printCount
-     * @throws IOException
-     */
-    private void createPaperPackage(BasicAttachment basicAttachment, String schoolName, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<String> variablePdfList, Integer printCount) throws IOException {
-        Map<String, Object> htmlMap = new HashMap<>();
-        htmlMap.put("examDetailCourseId", examDetailCourse.getId());
-        htmlMap.put("schoolName", schoolName);
-        htmlMap.put("examName", "测试exam1");
-        htmlMap.put("courseName", examDetailCourse.getCourseName());
-        htmlMap.put("courseCode", examDetailCourse.getCourseCode());
-        htmlMap.put("examSite", "测试examSite1");
-        htmlMap.put("examRoom", "测试examRoom1");
-        htmlMap.put("startTime", "2021-04-13 00:00:00");
-        htmlMap.put("endTime", "2021-04-14 00:00:00");
-        htmlMap.put("paperCode", examDetailCourse.getPaperNumber());
-        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
-
-        htmlMap.put("startCollege", "测试startCollege1");
-        htmlMap.put("className", "测试className1");
-        htmlMap.put("proctorCollege", "测试proctorCollege1");
-        htmlMap.put("examManager", "测试examManager1");
-
-        htmlMap.put("minSite", "测试minSite1");
-        htmlMap.put("maxSite", "测试maxSite1");
-        htmlMap.put("studentCount", examStudentList.size());
-
-        htmlMap.put("tag", "测试tag1");
-
-        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
-        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
-        htmlMap.computeIfAbsent("printCount", v -> printCount);
-        freemarkerUtil.createPaperPackage(htmlMap);
-    }
-
-    /**
-     * 创建签到表
-     *
-     * @param basicAttachment
-     * @param schoolName
-     * @param examDetailCourse
-     * @param examStudentList
-     * @param variablePdfList
-     * @param printCount
-     */
-    private void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<String> variablePdfList, Integer printCount) throws IOException {
-        Map<String, Object> htmlMap = new HashMap<>();
-        htmlMap.put("examDetailCourseId", examDetailCourse.getId());
-        htmlMap.put("schoolName", schoolName);
-        htmlMap.put("courseName", examDetailCourse.getCourseName());
-        htmlMap.put("courseCode", examDetailCourse.getCourseCode());
-        htmlMap.put("examName", "测试exam1");
-        htmlMap.put("examRoom", "测试examRoom1");
-        htmlMap.put("classTeacher", "测试老师1");
-        htmlMap.put("startTime", "2021-04-13 00:00:00");
-        htmlMap.put("endTime", "2021-04-14 00:00:00");
-        htmlMap.put("paperCode", examDetailCourse.getPaperNumber());
-        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
-
-        int totalCount = examStudentList.size();
-        if (totalCount > 0) {
-            List<Map> subList = new ArrayList<>();
-            int pageCount = totalCount % 80 == 0 ? totalCount / 80 : totalCount / 80 + 1;
-            for (int i = 0; i < pageCount; i++) {
-                Map subMap = new HashMap();
-                subMap.put("index", i + 1);
-                int studentCount;
-                List<ExamStudent> subStudents;
-                if (pageCount == 1) {
-                    studentCount = totalCount;
-                    subStudents = examStudentList;
-                } else if (pageCount > 1 && i == pageCount - 1) {
-                    studentCount = totalCount - (pageCount - 1) * 80;
-                    subStudents = examStudentList.subList(80 * i, examStudentList.size());
-                } else {
-                    studentCount = 80;
-                    subStudents = examStudentList.subList(80 * i, 80 * (i + 1));
-                }
-                subMap.put("studentCount", studentCount);
-                List<ExamStudentDto> examStudentList1 = new ArrayList<>();
-                List<ExamStudentDto> examStudentList2 = new ArrayList<>();
-
-                Gson gson = new Gson();
-                int mod = subStudents.size() % 2;
-                int htmlTableCount = mod == 0 ? subStudents.size() / 2 : subStudents.size() / 2 + 1;
-                for (int j = 0; j < htmlTableCount; j++) {
-                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
-                    examStudentDto.setIndex(j + 1);
-                    examStudentList1.add(examStudentDto);
-                }
-                for (int j = htmlTableCount; j < subStudents.size(); j++) {
-                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
-                    examStudentDto.setIndex(j + 1);
-                    examStudentList2.add(examStudentDto);
-                }
-                if (examStudentList1.size() > examStudentList2.size()) {
-                    for (int j = subStudents.size() - htmlTableCount; j < examStudentList1.size(); j++) {
-                        examStudentList2.add(new ExamStudentDto());
-                    }
-                }
-                subMap.put("studentList1", examStudentList1);
-                subMap.put("studentList2", examStudentList2);
-                subList.add(subMap);
-            }
-            htmlMap.put("subList", subList);
-        }
-        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
-        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
-        htmlMap.computeIfAbsent("printCount", v -> printCount);
-        freemarkerUtil.createSignBook(htmlMap);
-    }
-
-
-    /**
-     * 替换html通用模版
-     *
-     * @param examCardDetail
-     * @return
-     */
-    public String replaceHtmlTemplete(ExamCardDetail examCardDetail) {
-        String content = examCardDetail.getHtmlContent();
-        log.info("contentTemp:{}", content);
-        content = content.replaceAll("<img src=\"data:image/png;base64,\\$\\{examNumber\\}\">", "");
-        content = content.replaceAll("\\$\\{examNumberStr\\}", "");
-        return content;
-    }
-
-    /**
-     * 获取题卡attachmentId
-     *
-     * @param examCardDetail
-     * @param attachmentIds
-     */
-    public void getCardAttachmentId(ExamCardDetail examCardDetail, Set<Long> attachmentIds) {
-        if (Objects.nonNull(examCardDetail.getAttachmentId())) {
-            JSONObject jsonObjectCard = JSONObject.parseObject(examCardDetail.getAttachmentId());
-            JSONArray jsonArrayCard = (JSONArray) jsonObjectCard.get("card");
-            for (int i = 0; i < jsonArrayCard.size(); i++) {
-                JSONObject object = (JSONObject) jsonArrayCard.get(i);
-                if (Objects.nonNull(object.get("attachmentId"))) {
-                    attachmentIds.add(Long.parseLong(String.valueOf(object.get("attachmentId"))));
-                }
-            }
-        }
-    }
-
-    /**
-     * 获取试卷pdf
-     *
-     * @param examTaskDetail
-     * @param backupCount
-     * @param pdfList
-     * @return
-     * @throws IOException
-     */
-    public void getPaperPdf(ExamTaskDetail examTaskDetail, Integer backupCount, List<String>... pdfList) throws IOException {
-        JSONObject jsonObjectPaper = JSONObject.parseObject(examTaskDetail.getPaperAttachmentIds());
-        JSONArray jsonArrayPaper = jsonObjectPaper.getJSONArray("paper");
-        for (int i = 0; i < jsonArrayPaper.size(); i++) {
-            JSONObject object = (JSONObject) jsonArrayPaper.get(i);
-            if (Objects.nonNull(object.get("attachmentId"))) {
-                Long attachmentId = Long.parseLong(String.valueOf(object.get("attachmentId")));
-                BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
-                String filePath = commonService.getFile(basicAttachment.getPath(), false).getPath();
-                pdfList[0].add(filePath);
-                for (int j = 1; j <= backupCount; j++) {
-                    pdfList[1].add(filePath);
-                }
-            }
-        }
-    }
-
-    /**
-     * 抽取试卷
-     *
-     * @param examPrintPlan
-     * @param examTaskDetail
-     * @return
-     */
-    public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail) {
-        //抽取卷型
-        DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
-        //未曝光卷型
-        String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
-        //已曝光卷型
-        String exposedPaperType = examTaskDetail.getExposedPaperType();
-        String[] paperTypes = null;
-        if (drawRule == DrawRuleEnum.ONE) {
-            if (Objects.isNull(unexposedPaperType)) {
-                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
-            } else {
-                paperTypes = unexposedPaperType.split("/");
-            }
-        } else {
-            if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
-                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
-            }
-            if (Objects.nonNull(unexposedPaperType)) {
-                paperTypes = unexposedPaperType.split("/");
-            } else {
-                paperTypes = exposedPaperType.split("/");
-            }
-        }
-        int paperRandom = new Random().nextInt(paperTypes.length);
-        String paperType = paperTypes[paperRandom];
-        examTaskDetail.setPaperType(paperType);
-        return paperType;
-    }
-
-    /**
-     * 合并pdf
-     *
-     * @param tbTask
-     * @param examDetail
-     * @param userId
-     * @param list
-     * @return
-     * @throws IOException
-     */
-    public BasicAttachment mergePdf(TBTask tbTask, ExamDetail examDetail, Long userId, List<String>... list) throws IOException {
-        StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
-        List<String> mergePdfList = new ArrayList<>();
-        int pageA3Count = 0;
-        int pageA4Count = 0;
-        for (int i = 0; i < list.length; i++) {
-            if (i < 2) {
-                pageA4Count = pageA4Count + list[i].size();
-            } else {
-                pageA3Count = pageA3Count + list[i].size();
-            }
-            mergePdfList.addAll(list[i]);
-        }
-        String dirName = PdfUtil.mergePdf(mergePdfList.toArray(new String[mergePdfList.size()]), null);
-        File localPdfFile = new File(stringJoiner.toString() + File.separator + dirName);
-        BasicAttachment basicAttachment = basicAttachmentService.saveAttachmentPdf(dirName, userId);
-        tbTask.setImportFileName(basicAttachment.getName());
-        tbTask.setImportFilePath(basicAttachment.getPath());
-        examDetail.setAttachmentId(basicAttachment.getId());
-        examDetail.setPagesA3(pageA3Count);
-        examDetail.setPagesA4(pageA4Count);
-        examDetail.setStatus(ExamDetailStatusEnum.READY);
-        detailService.saveOrUpdate(examDetail);
-        ossUtil.ossUpload(dirName, localPdfFile, DigestUtils.md5Hex(new FileInputStream(localPdfFile)));
-        localPdfFile.delete();
-        for (String s : mergePdfList) {
-            new File(s).delete();
-        }
-        return basicAttachment;
-    }
-
-    /**
-     * 删除附件
-     *
-     * @param attachmentIds
-     * @param ftlList
-     */
-    public void deleteAttachment(Set<Long> attachmentIds, Set<File> ftlList) {
-        if (Objects.nonNull(attachmentIds) && attachmentIds.size() > 0) {
-            QueryWrapper<BasicAttachment> basicAttachmentQueryWrapper = new QueryWrapper<>();
-            basicAttachmentQueryWrapper.lambda().in(BasicAttachment::getId, attachmentIds);
-            basicAttachmentService.batchDeleteAttachment(basicAttachmentService.list(basicAttachmentQueryWrapper));
-            basicAttachmentService.removeByIds(attachmentIds);
-        }
-        if (Objects.nonNull(ftlList) && ftlList.size() > 0) {
-            for (File file : ftlList) {
-                file.delete();
-            }
-        }
-    }
-
-    /**
-     * 考生题卡html
-     *
-     * @param attachmentIds
-     * @param studentContent
-     * @param t
-     * @param paperType
-     * @param examCard
-     * @param userId
-     * @param examStudentPdfList
-     * @return
-     * @throws IOException
-     */
-    public BasicAttachment examStudentHtml(Set<Long> attachmentIds, String studentContent, ExamStudent t, String paperType, ExamCard examCard, Long userId, List<String> examStudentPdfList) throws IOException {
-        if (Objects.nonNull(t.getAttachmentId())) {
-            attachmentIds.add(t.getAttachmentId());
-        }
-        String studentHtml = studentContent;
-        if (Objects.nonNull(t.getExtendFields())) {
-            JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(t.getExtendFields());//扩展字段
-            if (Objects.nonNull(jsonObjectExtend)) {
-                for (int i = 0; i < jsonObjectExtend.size(); i++) {
-                    JSONObject object = (JSONObject) jsonObjectExtend.get(i);
-                    studentHtml = studentHtml.replaceAll("\\$\\{" + object.get("code") + "\\}", String.valueOf(object.get("value")));
-                }
-            }
-        }
-        //生成学生考号条码并将图片转成base64
-        studentHtml = studentHtml.replaceAll("\\$\\{examNumber\\}", GoogleBarCodeUtil.createBarCode(t.getTicketNumber(), false));
-        studentHtml = studentHtml.replaceAll("\\$\\{examNumberStr\\}", t.getTicketNumber());
-        //随机生成学生试卷条码并将图片转成base64
-        studentHtml = studentHtml.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
-        studentHtml = studentHtml.replaceAll("\\$\\{paperTypeName\\}", paperType);
-        studentHtml = studentHtml.replaceAll("\\$\\{studentCode\\}", t.getStudentCode());
-        studentHtml = studentHtml.replaceAll("\\$\\{name\\}", t.getStudentName());
-        studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examCard.getCourseName());
-
-        //学生题卡
-        BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, userId, examStudentPdfList);
-        t.setAttachmentId(examStudentAttachment.getId());
-        return examStudentAttachment;
-    }
-
-    /**
-     * 通用题卡html
-     *
-     * @param cardContent
-     * @param paperType
-     * @param examDetailCourse
-     * @param examCard
-     * @param jsonArray
-     * @param userId
-     * @param cardPdfList
-     * @return
-     * @throws IOException
-     */
-    public BasicAttachment cardHtml(String cardContent, String paperType, ExamDetailCourse examDetailCourse, ExamCard examCard, JSONArray jsonArray, Long userId, List<String> cardPdfList) throws IOException {
-        //通用题卡
-        String cardTemp = cardContent;
-        cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", paperType);
-        //随机生成试卷条码并将图片转成base64
-        cardTemp = cardTemp.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
-        //通用题卡生成卷袋贴条码
-        String paperCode = examDetailCourse.getPaperNumber();
-        String paperCodeImg = GoogleBarCodeUtil.createBarCode(paperCode, false);
-        String paperCodeDiv = "<div class=\"page-box page-box-0\"><div class=\"package-number\" style=\"position: absolute;width: 200px;height: 40px;top: 80px;right: 35px;transform: rotate(-90deg);transform-origin: center right;text-align: center;z-index: 99;\"><img src=\"data:image/png;base64," + paperCodeImg + "\" style=\"display: block; height: 28px; width: 100%\" /><p style=\"line-height: 1; font-size: 12px; margin: 0;\">" + paperCode + "</p></div>";
-        cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", paperCodeDiv);
-        BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, userId, cardPdfList);
-        JSONObject object = new JSONObject();
-        object.put("name", paperType);
-        object.put("examDetailCourseId", examDetailCourse.getId());
-        object.put("attachmentId", cardAttachment.getId());
-        jsonArray.add(object);
-        return cardAttachment;
-    }
 }

+ 440 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -0,0 +1,440 @@
+package com.qmth.distributed.print.business.util;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.google.gson.Gson;
+import com.itextpdf.text.DocumentException;
+import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
+import com.qmth.distributed.print.business.bean.dto.PdfDto;
+import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.enums.DrawRuleEnum;
+import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
+import com.qmth.distributed.print.business.enums.PageSizeEnum;
+import com.qmth.distributed.print.business.enums.PrintMethodEnum;
+import com.qmth.distributed.print.business.service.BasicAttachmentService;
+import com.qmth.distributed.print.business.service.BasicExamRuleService;
+import com.qmth.distributed.print.business.service.CommonService;
+import com.qmth.distributed.print.business.service.ExamDetailService;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @Description: 创建pdf util
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/4/14
+ */
+@Component
+public class CreatePdfUtil {
+    private final static Logger log = LoggerFactory.getLogger(CreatePdfUtil.class);
+
+    @Resource
+    OssUtil ossUtil;
+
+    @Resource
+    BasicAttachmentService basicAttachmentService;
+
+    @Resource
+    FreemarkerUtil freemarkerUtil;
+
+    @Resource
+    CommonService commonService;
+
+    @Resource
+    ExamDetailService detailService;
+
+    @Resource
+    BasicExamRuleService basicExamRuleService;
+
+    /**
+     * 创建登记表
+     *
+     * @param basicAttachment
+     * @param ordinaryPdfList
+     * @param printCount
+     */
+    public void createCheckIn(BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
+        String type = basicAttachment.getType();
+        JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
+        if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.PDF_PREFIX)) {
+            String filePath = (String) jsonObject.get(SystemConstant.PATH);
+            String url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
+            File localFile = ossUtil.ossDownload(filePath, url);
+            int pageCount = PdfUtil.addPdfPage(localFile);
+            for (int i = 0; i < printCount; i++) {
+                ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pageCount));
+            }
+        } else {
+            basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount);
+        }
+    }
+
+    /**
+     * 生成卷袋贴
+     *
+     * @param basicAttachment
+     * @param schoolName
+     * @param examDetailCourse
+     * @param examStudentList
+     * @param variablePdfList
+     * @param printCount
+     * @throws IOException
+     */
+    public void createPaperPackage(BasicAttachment basicAttachment, String schoolName, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
+        Map<String, Object> htmlMap = new HashMap<>();
+        htmlMap.put("examDetailCourseId", examDetailCourse.getId());
+        htmlMap.put("schoolName", schoolName);
+        htmlMap.put("examName", "测试exam1");
+        htmlMap.put("courseName", examDetailCourse.getCourseName());
+        htmlMap.put("courseCode", examDetailCourse.getCourseCode());
+        htmlMap.put("examSite", "测试examSite1");
+        htmlMap.put("examRoom", "测试examRoom1");
+        htmlMap.put("startTime", "2021-04-13 00:00:00");
+        htmlMap.put("endTime", "2021-04-14 00:00:00");
+        htmlMap.put("paperCode", examDetailCourse.getPaperNumber());
+        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
+
+        htmlMap.put("startCollege", "测试startCollege1");
+        htmlMap.put("className", "测试className1");
+        htmlMap.put("proctorCollege", "测试proctorCollege1");
+        htmlMap.put("examManager", "测试examManager1");
+
+        htmlMap.put("minSite", "测试minSite1");
+        htmlMap.put("maxSite", "测试maxSite1");
+        htmlMap.put("studentCount", examStudentList.size());
+
+        htmlMap.put("tag", "测试tag1");
+
+        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
+        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
+        htmlMap.computeIfAbsent("printCount", v -> printCount);
+        freemarkerUtil.createPaperPackage(htmlMap);
+    }
+
+    /**
+     * 创建签到表
+     *
+     * @param basicAttachment
+     * @param schoolName
+     * @param examDetailCourse
+     * @param examStudentList
+     * @param variablePdfList
+     * @param printCount
+     */
+    public void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
+        Map<String, Object> htmlMap = new HashMap<>();
+        htmlMap.put("examDetailCourseId", examDetailCourse.getId());
+        htmlMap.put("schoolName", schoolName);
+        htmlMap.put("courseName", examDetailCourse.getCourseName());
+        htmlMap.put("courseCode", examDetailCourse.getCourseCode());
+        htmlMap.put("examName", "测试exam1");
+        htmlMap.put("examRoom", "测试examRoom1");
+        htmlMap.put("classTeacher", "测试老师1");
+        htmlMap.put("startTime", "2021-04-13 00:00:00");
+        htmlMap.put("endTime", "2021-04-14 00:00:00");
+        htmlMap.put("paperCode", examDetailCourse.getPaperNumber());
+        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
+
+        int totalCount = examStudentList.size();
+        if (totalCount > 0) {
+            List<Map> subList = new ArrayList<>();
+            int pageCount = totalCount % 80 == 0 ? totalCount / 80 : totalCount / 80 + 1;
+            for (int i = 0; i < pageCount; i++) {
+                Map subMap = new HashMap();
+                subMap.put("index", i + 1);
+                int studentCount;
+                List<ExamStudent> subStudents;
+                if (pageCount == 1) {
+                    studentCount = totalCount;
+                    subStudents = examStudentList;
+                } else if (pageCount > 1 && i == pageCount - 1) {
+                    studentCount = totalCount - (pageCount - 1) * 80;
+                    subStudents = examStudentList.subList(80 * i, examStudentList.size());
+                } else {
+                    studentCount = 80;
+                    subStudents = examStudentList.subList(80 * i, 80 * (i + 1));
+                }
+                subMap.put("studentCount", studentCount);
+                List<ExamStudentDto> examStudentList1 = new ArrayList<>();
+                List<ExamStudentDto> examStudentList2 = new ArrayList<>();
+
+                Gson gson = new Gson();
+                int mod = subStudents.size() % 2;
+                int htmlTableCount = mod == 0 ? subStudents.size() / 2 : subStudents.size() / 2 + 1;
+                for (int j = 0; j < htmlTableCount; j++) {
+                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+                    examStudentDto.setIndex(j + 1);
+                    examStudentList1.add(examStudentDto);
+                }
+                for (int j = htmlTableCount; j < subStudents.size(); j++) {
+                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+                    examStudentDto.setIndex(j + 1);
+                    examStudentList2.add(examStudentDto);
+                }
+                if (examStudentList1.size() > examStudentList2.size()) {
+                    for (int j = subStudents.size() - htmlTableCount; j < examStudentList1.size(); j++) {
+                        examStudentList2.add(new ExamStudentDto());
+                    }
+                }
+                subMap.put("studentList1", examStudentList1);
+                subMap.put("studentList2", examStudentList2);
+                subList.add(subMap);
+            }
+            htmlMap.put("subList", subList);
+        }
+        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
+        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
+        htmlMap.computeIfAbsent("printCount", v -> printCount);
+        freemarkerUtil.createSignBook(htmlMap);
+    }
+
+    /**
+     * 替换html通用模版
+     *
+     * @param examCardDetail
+     * @return
+     */
+    public String replaceHtmlTemplete(ExamCardDetail examCardDetail) {
+        String content = examCardDetail.getHtmlContent();
+        log.info("contentTemp:{}", content);
+        content = content.replaceAll("<img src=\"data:image/png;base64,\\$\\{examNumber\\}\">", "");
+        content = content.replaceAll("\\$\\{examNumberStr\\}", "");
+        return content;
+    }
+
+    /**
+     * 获取题卡attachmentId
+     *
+     * @param examCardDetail
+     * @param attachmentIds
+     */
+    public void getCardAttachmentId(ExamCardDetail examCardDetail, Set<Long> attachmentIds) {
+        if (Objects.nonNull(examCardDetail.getAttachmentId())) {
+            JSONObject jsonObjectCard = JSONObject.parseObject(examCardDetail.getAttachmentId());
+            JSONArray jsonArrayCard = (JSONArray) jsonObjectCard.get("card");
+            for (int i = 0; i < jsonArrayCard.size(); i++) {
+                JSONObject object = (JSONObject) jsonArrayCard.get(i);
+                if (Objects.nonNull(object.get("attachmentId"))) {
+                    attachmentIds.add(Long.parseLong(String.valueOf(object.get("attachmentId"))));
+                }
+            }
+        }
+    }
+
+    /**
+     * 获取试卷pdf
+     *
+     * @param examTaskDetail
+     * @param backupCount
+     * @param pdfList
+     * @return
+     * @throws IOException
+     */
+    public void getPaperPdf(ExamTaskDetail examTaskDetail, Integer backupCount, List<PdfDto>... pdfList) throws IOException {
+        JSONObject jsonObjectPaper = JSONObject.parseObject(examTaskDetail.getPaperAttachmentIds());
+        JSONArray jsonArrayPaper = jsonObjectPaper.getJSONArray("paper");
+        for (int i = 0; i < jsonArrayPaper.size(); i++) {
+            JSONObject object = (JSONObject) jsonArrayPaper.get(i);
+            if (Objects.nonNull(object.get("attachmentId"))) {
+                Long attachmentId = Long.parseLong(String.valueOf(object.get("attachmentId")));
+                BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
+                File file = commonService.getFile(basicAttachment.getPath(), false);
+                int pageCount = PdfUtil.addPdfPage(file);
+                pdfList[0].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pageCount));
+                for (int j = 1; j <= backupCount; j++) {
+                    pdfList[1].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pageCount));
+                }
+            }
+        }
+    }
+
+    /**
+     * 抽取试卷
+     *
+     * @param examPrintPlan
+     * @param examTaskDetail
+     * @return
+     */
+    public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail) {
+        //抽取卷型
+        DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
+        //未曝光卷型
+        String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
+        //已曝光卷型
+        String exposedPaperType = examTaskDetail.getExposedPaperType();
+        String[] paperTypes = null;
+        if (drawRule == DrawRuleEnum.ONE) {
+            if (Objects.isNull(unexposedPaperType)) {
+                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
+            } else {
+                paperTypes = unexposedPaperType.split("/");
+            }
+        } else {
+            if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
+                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
+            }
+            if (Objects.nonNull(unexposedPaperType)) {
+                paperTypes = unexposedPaperType.split("/");
+            } else {
+                paperTypes = exposedPaperType.split("/");
+            }
+        }
+        int paperRandom = new Random().nextInt(paperTypes.length);
+        String paperType = paperTypes[paperRandom];
+        examTaskDetail.setPaperType(paperType);
+        return paperType;
+    }
+
+    /**
+     * 合并pdf
+     *
+     * @param tbTask
+     * @param examDetail
+     * @param userId
+     * @param schoolId
+     * @param list
+     * @return
+     * @throws IOException
+     */
+    public BasicAttachment mergePdf(TBTask tbTask, ExamDetail examDetail, Long userId, Long schoolId, List<PdfDto>... list) throws IOException {
+        StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
+        List<PdfDto> mergePdfList = new ArrayList<>();
+        int pageA3Count = 0;
+        int pageA4Count = 0;
+        for (int i = 0; i < list.length; i++) {
+            if (list[i].get(0).getPageSize() == PageSizeEnum.A4) {
+                pageA4Count = pageA4Count + list[i].stream().mapToInt(PdfDto::getPageCount).sum();
+            } else {
+                pageA3Count = pageA3Count + list[i].stream().mapToInt(PdfDto::getPageCount).sum();
+            }
+            mergePdfList.addAll(list[i]);
+        }
+        List<String> pathList = mergePdfList.stream().map(PdfDto::getPath).collect(Collectors.toList());
+        String dirName = PdfUtil.mergePdf(pathList.toArray(new String[mergePdfList.size()]), null);
+        File localPdfFile = new File(stringJoiner.toString() + File.separator + dirName);
+        BasicAttachment basicAttachment = basicAttachmentService.saveAttachmentPdf(dirName, userId);
+        tbTask.setImportFileName(basicAttachment.getName());
+        tbTask.setImportFilePath(basicAttachment.getPath());
+        examDetail.setAttachmentId(basicAttachment.getId());
+        examDetail.setPagesA3(pageA3Count);
+        examDetail.setPagesA4(pageA4Count);
+        BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId(schoolId);
+        examDetail.setStatus(PrintMethodEnum.AUTO == basicExamRule.getPrintMethod() ? ExamDetailStatusEnum.WAITING : ExamDetailStatusEnum.READY);
+        detailService.saveOrUpdate(examDetail);
+        ossUtil.ossUpload(dirName, localPdfFile, DigestUtils.md5Hex(new FileInputStream(localPdfFile)));
+        localPdfFile.delete();
+        for (PdfDto pdfDto : mergePdfList) {
+            new File(pdfDto.getPath()).delete();
+        }
+        return basicAttachment;
+    }
+
+    /**
+     * 删除附件
+     *
+     * @param attachmentIds
+     * @param ftlList
+     */
+    public void deleteAttachment(Set<Long> attachmentIds, Set<File> ftlList) {
+        if (Objects.nonNull(attachmentIds) && attachmentIds.size() > 0) {
+            QueryWrapper<BasicAttachment> basicAttachmentQueryWrapper = new QueryWrapper<>();
+            basicAttachmentQueryWrapper.lambda().in(BasicAttachment::getId, attachmentIds);
+            basicAttachmentService.batchDeleteAttachment(basicAttachmentService.list(basicAttachmentQueryWrapper));
+            basicAttachmentService.removeByIds(attachmentIds);
+        }
+        if (Objects.nonNull(ftlList) && ftlList.size() > 0) {
+            for (File file : ftlList) {
+                file.delete();
+            }
+        }
+    }
+
+    /**
+     * 考生题卡html
+     *
+     * @param attachmentIds
+     * @param studentContent
+     * @param t
+     * @param paperType
+     * @param examCard
+     * @param userId
+     * @param examStudentPdfList
+     * @return
+     * @throws IOException
+     */
+    public BasicAttachment examStudentHtml(Set<Long> attachmentIds, String studentContent, ExamStudent t, String paperType, ExamCard examCard, Long userId, List<PdfDto> examStudentPdfList) throws IOException {
+        if (Objects.nonNull(t.getAttachmentId())) {
+            attachmentIds.add(t.getAttachmentId());
+        }
+        String studentHtml = studentContent;
+        if (Objects.nonNull(t.getExtendFields())) {
+            JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(t.getExtendFields());//扩展字段
+            if (Objects.nonNull(jsonObjectExtend)) {
+                for (int i = 0; i < jsonObjectExtend.size(); i++) {
+                    JSONObject object = (JSONObject) jsonObjectExtend.get(i);
+                    studentHtml = studentHtml.replaceAll("\\$\\{" + object.get("code") + "\\}", String.valueOf(object.get("value")));
+                }
+            }
+        }
+        //生成学生考号条码并将图片转成base64
+        studentHtml = studentHtml.replaceAll("\\$\\{examNumber\\}", GoogleBarCodeUtil.createBarCode(t.getTicketNumber(), false));
+        studentHtml = studentHtml.replaceAll("\\$\\{examNumberStr\\}", t.getTicketNumber());
+        //随机生成学生试卷条码并将图片转成base64
+        studentHtml = studentHtml.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
+        studentHtml = studentHtml.replaceAll("\\$\\{paperTypeName\\}", paperType);
+        studentHtml = studentHtml.replaceAll("\\$\\{studentCode\\}", t.getStudentCode());
+        studentHtml = studentHtml.replaceAll("\\$\\{name\\}", t.getStudentName());
+        studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examCard.getCourseName());
+
+        //学生题卡
+        BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, userId, examStudentPdfList);
+        t.setAttachmentId(examStudentAttachment.getId());
+        return examStudentAttachment;
+    }
+
+    /**
+     * 通用题卡html
+     *
+     * @param cardContent
+     * @param paperType
+     * @param examDetailCourse
+     * @param examCard
+     * @param jsonArray
+     * @param userId
+     * @param cardPdfList
+     * @return
+     * @throws IOException
+     */
+    public BasicAttachment cardHtml(String cardContent, String paperType, ExamDetailCourse examDetailCourse, ExamCard examCard, JSONArray jsonArray, Long userId, List<PdfDto> cardPdfList) throws IOException {
+        //通用题卡
+        String cardTemp = cardContent;
+        cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", paperType);
+        //随机生成试卷条码并将图片转成base64
+        cardTemp = cardTemp.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
+        //通用题卡生成卷袋贴条码
+        String paperCode = examDetailCourse.getPaperNumber();
+        String paperCodeImg = GoogleBarCodeUtil.createBarCode(paperCode, false);
+        String paperCodeDiv = "<div class=\"page-box page-box-0\"><div class=\"package-number\" style=\"position: absolute;width: 200px;height: 40px;top: 80px;right: 35px;transform: rotate(-90deg);transform-origin: center right;text-align: center;z-index: 99;\"><img src=\"data:image/png;base64," + paperCodeImg + "\" style=\"display: block; height: 28px; width: 100%\" /><p style=\"line-height: 1; font-size: 12px; margin: 0;\">" + paperCode + "</p></div>";
+        cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", paperCodeDiv);
+        BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, userId, cardPdfList);
+        JSONObject object = new JSONObject();
+        object.put("name", paperType);
+        object.put("examDetailCourseId", examDetailCourse.getId());
+        object.put("attachmentId", cardAttachment.getId());
+        jsonArray.add(object);
+        return cardAttachment;
+    }
+}

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.business.util;
 
 import com.alibaba.fastjson.JSONObject;
+import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.config.DictionaryConfig;
 import com.qmth.distributed.print.business.entity.BasicAttachment;
 import com.qmth.distributed.print.business.enums.UploadFileEnum;
@@ -115,7 +116,7 @@ public class FreemarkerUtil {
                         UploadFileEnum.HTML
                 });
                 basicAttachment.setPath(jsonObject.toJSONString());
-                basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<String>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"));
+                basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"));
             }
             log.info("{}文件创建成功", htmlFile.toString());
             htmlFile.delete();

+ 1 - 45
distributed-print-business/src/main/resources/mapper/SysUserMapper.xml

@@ -49,51 +49,7 @@
             </if>
         </where>
     </select>
-
-    <select id="queryByExport" resultType="com.qmth.distributed.print.business.bean.dto.excel.UserExportDto">
-        select
-            tbu.real_name as realName,
-            tbu.login_name as loginName,
-            tbr.name as roleName,
-            group_concat(tbs.name, CONCAT(CONCAT('(', tbs.code), ')')) as schoolNameCode,
-            if(tbu.enable = 1,
-            '启用',
-            '禁用') as enable,
-            FROM_UNIXTIME(tbu.update_time / 1000, '%Y-%m-%d %H:%i:%s') as updateTime,
-            (
-            select
-            t.real_name
-            from
-            sys_user t
-            where
-            t.id = tbu.update_id) as updateName
-            from
-            sys_user tbu
-            left join (
-            select
-            DISTINCT role_id,
-            user_id
-            from
-            sys_user_role) tburp on
-            tburp.user_id = tbu.id
-            left join sys_role tbr on
-            tbr.id = tburp.role_id
-            left join basic_school tbs on
-            tbs.id = tbu.school_id
-            <where>
-                and tbu.id in
-                <foreach collection="arraysParams.ids" item="id" index="index" open="(" close=")" separator=",">
-                    #{id}
-                </foreach>
-            </where>
-            group by
-                tbu.real_name,
-                tbu.login_name,
-                tbr.name,
-                tbu.enable,
-                tbu.update_time,
-                tbu.update_id
-    </select>
+    
     <select id="listUser" resultType="com.qmth.distributed.print.business.bean.dto.BlurryUserDto">
         SELECT
            distinct a.id, a.real_name name

+ 27 - 106
distributed-print/src/main/java/com/qmth/distributed/print/api/SysUserController.java

@@ -4,46 +4,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
-import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.BlurryUserDto;
 import com.qmth.distributed.print.business.bean.dto.UserDto;
-import com.qmth.distributed.print.business.bean.dto.excel.UserExportDto;
-import com.qmth.distributed.print.business.bean.params.ArraysParams;
-import com.qmth.distributed.print.business.bean.result.EditResult;
-import com.qmth.distributed.print.business.entity.BasicAttachment;
 import com.qmth.distributed.print.business.entity.SysUser;
-import com.qmth.distributed.print.business.entity.TBTask;
-import com.qmth.distributed.print.business.enums.TaskTypeEnum;
-import com.qmth.distributed.print.business.enums.UploadFileEnum;
-import com.qmth.distributed.print.business.service.BasicAttachmentService;
 import com.qmth.distributed.print.business.service.SysUserService;
-import com.qmth.distributed.print.business.service.TBTaskService;
-import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
-import com.qmth.distributed.print.business.templete.execute.AsyncUserImportTempleteService;
-import com.qmth.distributed.print.business.templete.execute.UserImportTempleteService;
-import com.qmth.distributed.print.business.util.ExcelUtil;
-import com.qmth.distributed.print.business.util.OssUtil;
-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 com.qmth.distributed.print.common.util.Result;
 import com.qmth.distributed.print.common.util.ResultUtil;
-import io.swagger.annotations.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
 
-import javax.annotation.Resource;
-import javax.validation.Valid;
-import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
-import java.util.Map;
-import java.util.Objects;
 
 /**
  * <p>
@@ -63,17 +37,11 @@ public class SysUserController {
     @Autowired
     private SysUserService sysUserService;
 
-    @Resource
-    BasicAttachmentService basicAttachmentService;
-
-    @Resource
-    UserImportTempleteService userImportTempleteService;
-
-    @Resource
-    AsyncUserImportTempleteService asyncUserImportTempleteService;
-
-    @Resource
-    TBTaskService tbTaskService;
+//    @Resource
+//    BasicAttachmentService basicAttachmentService;
+//
+//    @Resource
+//    TBTaskService tbTaskService;
 
     /**
      * 查询
@@ -175,72 +143,25 @@ public class SysUserController {
         return ResultUtil.ok(isSuccess);
     }
 
-    @ApiOperation(value = "用户批量导入接口")
-    @RequestMapping(value = "/import", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
-    @Transactional
-    public Result userImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) {
-        BasicAttachment basicAttachment = null;
-        try {
-            basicAttachment = basicAttachmentService.saveAttachment(file, ServletUtil.getRequestMd5(), UploadFileEnum.FILE);
-            if (Objects.isNull(basicAttachment)) {
-                throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
-            } else {
-                userImportTempleteService.importTask(Collections.singletonMap(SystemConstant.FILE, file));
-            }
-        } catch (Exception e) {
-            log.error("请求出错", e);
-            if (Objects.nonNull(basicAttachment)) {
-                basicAttachmentService.deleteAttachment(basicAttachment);
-            }
-            if (e instanceof ApiException) {
-                ResultUtil.error((ApiException) e, e.getMessage());
-            } else {
-                ResultUtil.error(e.getMessage());
-            }
-        }
-        return ResultUtil.ok();
-    }
-
-    @ApiOperation(value = "异步用户批量导入接口")
-    @RequestMapping(value = "/async/import", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
-    public Result userImportAysnc(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) throws IOException {
-        Map<String, Object> map = tbTaskService.saveTask(file, TaskTypeEnum.USER_IMPORT);
-        asyncUserImportTempleteService.importTask(map);
-        TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
-        return Objects.nonNull(tbTask) ? ResultUtil.ok(new EditResult(tbTask.getId())) : ResultUtil.error("创建任务失败");
-    }
-
-    @ApiOperation(value = "用户批量导出接口")
-    @RequestMapping(value = "/export", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
-    public void export(@ApiParam(value = "数组id", required = true) @Valid @RequestBody ArraysParams arraysParams, BindingResult bindingResult) throws Exception {
-        if (bindingResult.hasErrors()) {
-            ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
-        }
-        List<UserExportDto> userExportDtoList = sysUserService.queryByExport(arraysParams);
-        ExcelUtil.excelExport("用户列表", UserExportDto.class, userExportDtoList, ServletUtil.getResponse());
-    }
-
-    @Resource
-    AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
-
-    @Resource
-    OssUtil ossUtil;
-
-    @ApiOperation(value = "异步创建pdf接口")
-    @RequestMapping(value = "/async/create_pdf", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
-    public Result createPdfAysnc(@ApiParam(value = "印刷计划id", required = true) @RequestParam String printPlanId,
-                                 @ApiParam(value = "考务计划id", required = false) @RequestParam(required = false) String examDetailId) throws IOException {
-        Map<String, Object> map = tbTaskService.saveTask(TaskTypeEnum.CREATE_PDF, SystemConstant.convertIdToLong(printPlanId));
-        if (Objects.nonNull(examDetailId)) {
-            map.computeIfAbsent("examDetailId", v -> SystemConstant.convertIdToLong(examDetailId));
-        }
-        asyncCreatePdfTempleteService.createPdf(map);
-        TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
-        return Objects.nonNull(tbTask) ? ResultUtil.ok(new EditResult(tbTask.getId())) : ResultUtil.error("创建任务失败");
-    }
+//    @Resource
+//    AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
+//
+//    @Resource
+//    OssUtil ossUtil;
+//
+//    @ApiOperation(value = "异步创建pdf接口")
+//    @RequestMapping(value = "/async/create_pdf", method = RequestMethod.POST)
+//    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
+//    public Result createPdfAysnc(@ApiParam(value = "印刷计划id", required = true) @RequestParam String printPlanId,
+//                                 @ApiParam(value = "考务计划id", required = false) @RequestParam(required = false) String examDetailId) throws IOException {
+//        Map<String, Object> map = tbTaskService.saveTask(TaskTypeEnum.CREATE_PDF, SystemConstant.convertIdToLong(printPlanId));
+//        if (Objects.nonNull(examDetailId)) {
+//            map.computeIfAbsent("examDetailId", v -> SystemConstant.convertIdToLong(examDetailId));
+//        }
+//        map.computeIfAbsent("schoolId", v -> schoolId);
+//        asyncCreatePdfTempleteService.createPdf(map);
+//        TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
+//        return Objects.nonNull(tbTask) ? ResultUtil.ok(new EditResult(tbTask.getId())) : ResultUtil.error("创建任务失败");
+//    }
 }