Pārlūkot izejas kodu

3.2.0-印品管理

xiaof 2 gadi atpakaļ
vecāks
revīzija
47ef837bd4

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

@@ -21,7 +21,7 @@ public interface BasicTemplateService extends IService<BasicTemplate> {
 
     IPage<TemplateDto> list(Boolean enable, String type, String name, Long startTime, Long endTime, Integer pageNumber, Integer pageSize);
 
-    boolean saveTemplate(BasicTemplate template) throws Exception;
+    boolean saveTemplate(String data) throws Exception;
 
     boolean enable(BasicTemplate template);
 
@@ -37,5 +37,5 @@ public interface BasicTemplateService extends IService<BasicTemplate> {
      */
     List<TemplatePrintInfoResult> findTemplateInfoByOrgIds(List<Long> ids);
 
-    void preview(HttpServletResponse response, String data);
+    String preview(Long id);
 }

+ 3 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/PrintCommonService.java

@@ -21,6 +21,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
@@ -294,4 +295,6 @@ public interface PrintCommonService {
     public void updateGradeBatchStatus(Long schoolId, String paperNumber, String paperType);
 
     void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> variablePdfList, Integer printCount);
+
+    String uploadPdfFile(File pdfFile);
 }

+ 22 - 8
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicTemplateServiceImpl.java

@@ -1,7 +1,6 @@
 package com.qmth.distributed.print.business.service.impl;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -31,6 +30,7 @@ import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.service.TeachcloudCommonService;
 import com.qmth.teachcloud.common.util.ServletUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -75,7 +75,8 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
 
     @Transactional
     @Override
-    public boolean saveTemplate(BasicTemplate template) throws Exception {
+    public boolean saveTemplate(String data) throws Exception {
+        BasicTemplate template = JSON.parseObject(data, BasicTemplate.class);
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         template.setSchoolId(schoolId);
@@ -97,7 +98,7 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
             if (basicTemplate != null && basicTemplate.getId().longValue() != template.getId().longValue()) {
                 throw ExceptionResultEnum.ERROR.exception("模板名称已存在");
             }
-
+            template.setPreviewPath("");
             template.updateInfo(sysUser.getId());
             //删除权限
 //            basicTemplateOrgService.removeByRuleId(template.getId());
@@ -183,9 +184,9 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
     }
 
     @Override
-    public void preview(HttpServletResponse response, String data) {
-        JSONObject jsonObject = JSON.parseObject(data);
-        String classifyStr = jsonObject.getString("classify");
+    public String preview(Long id) {
+        BasicTemplate basicTemplate = basicTemplateMapper.selectById(id);
+        String classifyStr = basicTemplate.getClassify().name();
         List<String> stringList = ClassifyEnum.listTypes().stream().map(EnumResult::getName).collect(Collectors.toList());
         if (!stringList.contains(classifyStr)) {
             throw ExceptionResultEnum.ERROR.exception("模板类型有误");
@@ -193,9 +194,22 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
         ClassifyEnum classifyEnum = ClassifyEnum.valueOf(classifyStr);
         // 签到表
         if (ClassifyEnum.SIGN.equals(classifyEnum)) {
-            PdfFillUtils.parseSignTempData(response, jsonObject.getString("data"), "签到表预览.pdf");
+            if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
+                String json = PdfFillUtils.parseSignTempData(basicTemplate.getDisplayRange(), "签到表预览.pdf");
+                basicTemplate.setPreviewPath(json);
+                basicTemplateMapper.updateById(basicTemplate);
+            }
+            return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());
         } else if (ClassifyEnum.PACKAGE.equals(classifyEnum)) {
-            PdfFillUtils.packageTempData(response, jsonObject.getString("data"), "卷袋贴预览.pdf");
+            if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
+                String json = PdfFillUtils.packageTempData(basicTemplate.getDisplayRange(), "卷袋贴预览.pdf");
+                basicTemplate.setPreviewPath(json);
+                basicTemplateMapper.updateById(basicTemplate);
+            }
+            return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());
+        } else if (ClassifyEnum.CHECK_IN.equals(classifyEnum)) {
+            BasicAttachment attachment = basicAttachmentService.getById(basicTemplate.getAttachmentId());
+            return attachment == null ? null : teachcloudCommonService.filePreview(attachment.getPath());
         } else {
             throw ExceptionResultEnum.ERROR.exception("不支持当前模板预览");
         }

+ 43 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java

@@ -304,7 +304,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             String pdfDirNameStr = pdfStringJoiner.toString().replace("\\", "/");
             String destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
 
-            createPrintPdfUtil.createSignPdf(null, pdfFillDto, destUrl, true);
+            createPrintPdfUtil.createSignPdf(pdfFillDto, destUrl, true);
 
             File pdfFile = new File(destUrl);
             if (!pdfFile.exists()) {
@@ -1195,10 +1195,10 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             StudentClazzEnum studentClazzType = student.getStudentClazzType();
 
             BasicStudentResult basicStudentResult = basicStudentService.findById(studentId);
-            if (Objects.isNull(basicStudentResult)){
+            if (Objects.isNull(basicStudentResult)) {
                 throw ExceptionResultEnum.ERROR.exception("未找到基础学生信息");
             }
-            if (!Objects.equals(basicStudentResult.getClazzId(), basicClazzId)){
+            if (!Objects.equals(basicStudentResult.getClazzId(), basicClazzId)) {
                 throw ExceptionResultEnum.ERROR.exception("行政班数据不一致");
             }
             BasicClazz basicClazz = null;
@@ -1353,7 +1353,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             String pdfDirNameStr = pdfStringJoiner.toString().replace("\\", "/");
             String destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
 
-            createPrintPdfUtil.createPackagePdf(null, pdfPackageDto, destUrl, true);
+            createPrintPdfUtil.createPackagePdf(pdfPackageDto, destUrl, true);
 
             File pdfFile = new File(destUrl);
             if (!pdfFile.exists()) {
@@ -1401,4 +1401,43 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             }
         }
     }
+
+    /**
+     * 上传pdf文件
+     * @param file
+     * @return
+     */
+    @Override
+    public String uploadPdfFile(File pdfFile) {
+        try {
+            boolean oss = dictionaryConfig.sysDomain().isOss();
+            String pdfDirName = pdfFile.getPath();
+            String pdfDirNameStr = pdfDirName.replace("\\\\", "/");
+
+            byte[] data = ByteArray.fromFile(pdfFile).value();
+            String md5 = ByteArray.md5(data).toHexString();
+            InputStream ins = new ByteArrayInputStream(data);
+            if (oss) {//上传至oss
+                fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
+                ins.close();
+            }
+            JSONObject object = new JSONObject();
+            if (!oss) {
+                object.put(SystemConstant.PATH, pdfDirName);
+                object.put(SystemConstant.TYPE, SystemConstant.LOCAL);
+            } else {
+                object.put(SystemConstant.PATH, pdfDirNameStr);
+                object.put(SystemConstant.TYPE, SystemConstant.OSS);
+            }
+            return JSON.toJSONString(object);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return null;
+    }
 }

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

@@ -656,7 +656,7 @@ public class CreatePdfUtil {
             if (studentHeadPlateMap.containsKey("studentCode")) {
                 studentMap.put("studentCode", examStudentCourseDto.getStudentCode());
             }
-            if (studentHeadPlateMap.containsKey("className")) {
+            if (studentHeadPlateMap.containsKey("clazzName")) {
                 studentMap.put("className", StringUtils.isBlank(examStudentCourseDto.getTeachClazzName()) ? examStudentCourseDto.getClazzName() : examStudentCourseDto.getClazzName());
             }
             if (studentHeadPlateMap.containsKey("ticketNumber")) {

+ 65 - 33
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePrintPdfUtil.java

@@ -2,20 +2,23 @@ package com.qmth.distributed.print.business.util;
 
 import com.itextpdf.text.*;
 import com.itextpdf.text.pdf.*;
-import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
-import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.bean.dto.PdfPackageDto;
 import com.qmth.distributed.print.business.bean.dto.PdfSignDto;
-import com.qmth.distributed.print.business.entity.ExamDetail;
-import com.qmth.distributed.print.business.entity.ExamDetailCourse;
+import com.qmth.distributed.print.business.service.PrintCommonService;
+import com.qmth.teachcloud.common.config.DictionaryConfig;
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
+import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
-import com.qmth.teachcloud.common.util.ConvertUtil;
+import com.qmth.teachcloud.common.enums.UploadFileEnum;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
-import javax.servlet.http.HttpServletResponse;
-import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.*;
 
@@ -34,14 +37,16 @@ public class CreatePrintPdfUtil {
      * @param destFileName 文件名
      * @param saveLocal    是事保存本地文件
      */
-    public void createSignPdf(HttpServletResponse response, PdfSignDto pdfFillDto, String destFileName, boolean saveLocal) throws Exception {
+    public String createSignPdf(PdfSignDto pdfFillDto, String destFileName, boolean saveLocal) throws Exception {
 
         // 1:建立Document对象实例
         Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        File file = createFolder(SystemConstant.PDF_PREFIX);
         try {
             // 2:建立一个PDF 写入器与document对象关联通过书写器(Writer)可以将文档写入到磁盘中
-            PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
+            FileOutputStream fos = new FileOutputStream(file);
+            PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
 
             //3、设置pdf页眉和页脚和水印
             MyHeaderFooter headerFooter = new MyHeaderFooter();
@@ -53,32 +58,32 @@ public class CreatePrintPdfUtil {
             this.generateSignPDF(document, pdfWriter, pdfFillDto);
             // 5:关闭文档
             document.close();
+
+
         } catch (DocumentException e) {
             e.printStackTrace();
         }
-        if (saveLocal) {
-            PdfFillUtils.saveFile(baos, destFileName);
-        } else {
-            ConvertUtil.outputFile(response, baos, destFileName);
-        }
+        PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
+        return dictionaryConfig.uploadPdfFile(file);
     }
 
     /**
      * 卷袋贴生成
      *
-     * @param response      response
      * @param pdfPackageDto 卷袋贴参数
      * @param destFileName  保存文件名
      * @param saveLocal     是否保存本地
      */
-    public void createPackagePdf(HttpServletResponse response, PdfPackageDto pdfPackageDto, String destFileName, boolean saveLocal) throws Exception {
+    public String createPackagePdf(PdfPackageDto pdfPackageDto, String destFileName, boolean saveLocal) throws Exception {
 
         // 1:建立Document对象实例
         Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        File file = createFolder(SystemConstant.PDF_PREFIX);
         try {
             // 2:建立一个PDF 写入器与document对象关联通过书写器(Writer)可以将文档写入到磁盘中
-            PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
+            FileOutputStream fos = new FileOutputStream(file);
+            PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
             // 3:打开文档
             document.open();
             //生成pdf
@@ -88,11 +93,9 @@ public class CreatePrintPdfUtil {
         } catch (DocumentException e) {
             e.printStackTrace();
         }
-        if (saveLocal) {
-            PdfFillUtils.saveFile(baos, destFileName);
-        } else {
-            ConvertUtil.outputFile(response, baos, destFileName);
-        }
+
+        PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
+        return dictionaryConfig.uploadPdfFile(file);
     }
 
     /**
@@ -122,6 +125,9 @@ public class CreatePrintPdfUtil {
         for (Map<String, String> stringMap : basicPlate) {
             basicTable.addCell(PdfFillUtils.createCell(stringMap.get("name") + ":" + stringMap.get("value"), PdfFillUtils.textFont12, null, 16f, Element.ALIGN_LEFT, 0, 1, 3));
         }
+        if (basicPlate.size() % 2 > 0) {
+            basicTable.addCell(PdfFillUtils.createCell(" ", PdfFillUtils.textFont12, null, 16f, Element.ALIGN_LEFT, 0, 1, 3));
+        }
         document.add(basicTable);
 
         document.add(blank);
@@ -238,6 +244,30 @@ public class CreatePrintPdfUtil {
         }
     }
 
+    private File createFolder(String prefix) {
+        LocalDateTime nowTime = LocalDateTime.now();
+        StringJoiner pdfStringJoiner = new StringJoiner("");
+        pdfStringJoiner.add(UploadFileEnum.PDF.getTitle()).add(File.separator);
+        pdfStringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
+                .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
+                .add(String.format("%02d", nowTime.getDayOfMonth()));
+        pdfStringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(prefix);
+        String pdfDirName = pdfStringJoiner.toString();
+        DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
+        String destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
+        File file = new File(destUrl);
+        try {
+            if (!file.exists()) {
+                file.getParentFile().mkdirs();
+                file.createNewFile();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+        }
+        return file;
+    }
+
     /**
      * 签到表考生签到table表头宽度选择
      *
@@ -270,14 +300,16 @@ public class CreatePrintPdfUtil {
      * @param percent 宽度
      */
     private Font chooseFont(String value, float percent) {
-        if (value.length() < percent) {
-            return PdfFillUtils.textFont12;
-        } else if (value.length() >= percent && value.length() < 1.5 * percent) {
-            return PdfFillUtils.textFont10;
-        } else if (value.length() >= 1.5 * percent && value.length() < 2 * percent) {
-            return PdfFillUtils.textFont9;
+        if (StringUtils.isNotBlank(value)) {
+            if (value.length() < percent) {
+                return PdfFillUtils.textFont12;
+            } else if (value.length() >= percent && value.length() < 1.5 * percent) {
+                return PdfFillUtils.textFont10;
+            } else if (value.length() >= 1.5 * percent && value.length() < 2 * percent) {
+                return PdfFillUtils.textFont9;
+            }
         }
-        return PdfFillUtils.textFont8;
+        return PdfFillUtils.textFont12;
     }
 
     /**
@@ -452,8 +484,8 @@ public class CreatePrintPdfUtil {
 
         try {
             CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
-            createPrintPdfUtil.createSignPdf(null, pdfFillDto, "D:/sign.pdf", true);
-            createPrintPdfUtil.createPackagePdf(null, pdfPackageDto, "D:/package.pdf", true);
+            createPrintPdfUtil.createSignPdf(pdfFillDto, "D:/sign.pdf", true);
+            createPrintPdfUtil.createPackagePdf(pdfPackageDto, "D:/package.pdf", true);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 91 - 97
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfFillUtils.java

@@ -15,6 +15,7 @@ import java.io.*;
 import java.net.URLEncoder;
 import java.util.List;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * pdf模板内容填充
@@ -50,6 +51,96 @@ public class PdfFillUtils {
         }
     }
 
+    /**
+     * 签到表预览数据
+     *
+     * @param response response
+     * @param data     数据内容
+     * @param fileName 文件名
+     */
+    public static String parseSignTempData(String data, String fileName) {
+        PdfSignDto pdfFillDto = new PdfSignDto();
+        pdfFillDto.setTitle("签到表样例");
+        pdfFillDto.setPackageNumber("123456789");
+
+        JSONObject jsonObject = JSON.parseObject(data);
+        // 基础信息
+        List<Map<String, String>> basicPlate = new ArrayList<>();
+        String basicData = jsonObject.getString("basic");
+        List<JSONObject> basicObjectList = JSON.parseArray(basicData, JSONObject.class).stream().filter(m->m.getBoolean("enable")).collect(Collectors.toList());
+        Map<String, String> basicMap;
+        for (JSONObject object : basicObjectList) {
+            basicMap = new HashMap<>();
+            basicMap.put("code", object.getString("code"));
+            basicMap.put("name", object.getString("name"));
+            basicMap.put("value", "xxx");
+            basicPlate.add(basicMap);
+        }
+        pdfFillDto.setBasicPlate(basicPlate);
+
+        // 表头信息
+        String studentData = jsonObject.getString("table");
+        List<JSONObject> studentObjectList = JSON.parseArray(studentData, JSONObject.class).stream().filter(m -> m.getBoolean("enable")).collect(Collectors.toList());
+        Map<String, String> studentHeadPlateMap = new LinkedHashMap<>();
+        for (JSONObject object : studentObjectList) {
+            studentHeadPlateMap.put(object.getString("code"), object.getString("name"));
+        }
+        studentHeadPlateMap.put("studentSign", "签名");
+        pdfFillDto.setStudentHeadPlate(studentHeadPlateMap);
+
+
+        // 考生信息
+        List<Map<String, String>> studentPlate = new ArrayList<>();
+        for (int i = 0; i < 60; i++) {
+            Map<String, String> studentMap = new HashMap<>();
+            for (JSONObject object : studentObjectList) {
+                studentMap.put(object.getString("code"), "xxx");
+            }
+            studentMap.put("studentSign", "");
+            studentPlate.add(studentMap);
+        }
+        pdfFillDto.setStudentPlate(studentPlate);
+        try {
+            CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
+            return createPrintPdfUtil.createSignPdf(pdfFillDto, fileName, true);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    /**
+     * 卷袋贴临时数据
+     *
+     * @param data data
+     */
+    public static String packageTempData(String data, String fileName) {
+        PdfPackageDto pdfPackageDto = new PdfPackageDto();
+        pdfPackageDto.setTitle("卷袋贴样例");
+        pdfPackageDto.setPackageNumber("123456789");
+
+        List<JSONObject> basicObjectList = JSON.parseArray(data, JSONObject.class).stream().filter(m->m.getBoolean("enable")).collect(Collectors.toList());
+        // 基础信息
+        List<Map<String, String>> basicPlate = new ArrayList<>();
+        for (JSONObject object : basicObjectList) {
+            Map<String, String> basicMap = new HashMap<>();
+            basicMap.put("code", object.getString("code"));
+            basicMap.put("name", object.getString("name"));
+            basicMap.put("value", "xxx");
+            basicPlate.add(basicMap);
+        }
+        pdfPackageDto.setBasicPlate(basicPlate);
+
+        try {
+            CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
+            return createPrintPdfUtil.createPackagePdf(pdfPackageDto, fileName, false);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
     public static void saveFile(ByteArrayOutputStream baos, String fileName) {
         FileOutputStream fileOutputStream = null;
         try {
@@ -207,101 +298,4 @@ public class PdfFillUtils {
         return barcode128.createImageWithBarcode(writer.getDirectContent(), barColor, textColor);
     }
 
-
-    /**
-     * 卷袋贴临时数据
-     *
-     * @param data data
-     */
-    public static void packageTempData(HttpServletResponse response, String data, String fileName) {
-        PdfPackageDto pdfPackageDto = new PdfPackageDto();
-        pdfPackageDto.setTitle("测试卷袋贴");
-        pdfPackageDto.setPackageNumber("20000213134");
-
-        List<JSONObject> basicObjectList = JSON.parseArray(data, JSONObject.class);
-        // 基础信息
-        List<Map<String, String>> basicPlate = new ArrayList<>();
-        for (JSONObject object : basicObjectList) {
-            Map<String, String> basicMap = new HashMap<>();
-            basicMap.put("code", object.getString("code"));
-            basicMap.put("name", object.getString("name"));
-            basicMap.put("value", "XXXXXX");
-            basicPlate.add(basicMap);
-        }
-        pdfPackageDto.setBasicPlate(basicPlate);
-
-        try {
-            CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
-            createPrintPdfUtil.createPackagePdf(response, pdfPackageDto, fileName, false);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     * 签到表预览数据
-     *
-     * @param response response
-     * @param data     数据内容
-     * @param fileName 文件名
-     */
-    public static void parseSignTempData(HttpServletResponse response, String data, String fileName) {
-        PdfSignDto pdfFillDto = new PdfSignDto();
-        pdfFillDto.setTitle("XXXXX签到表");
-        pdfFillDto.setPackageNumber("123456789");
-
-        JSONObject jsonObject = JSON.parseObject(data);
-        // 基础信息
-        List<Map<String, String>> basicPlate = new ArrayList<>();
-        String basicData = jsonObject.getString("basic");
-        List<JSONObject> basicObjectList = JSON.parseArray(basicData, JSONObject.class);
-        Map<String, String> basicMap;
-        for (JSONObject object : basicObjectList) {
-            basicMap = new HashMap<>();
-            basicMap.put("code", object.getString("code"));
-            basicMap.put("name", object.getString("name"));
-            basicMap.put("value", "XXXXXX");
-            basicPlate.add(basicMap);
-        }
-        basicMap = new HashMap<>();
-        basicMap.put("code", "actualExamCount");
-        basicMap.put("name", "实考人数");
-        basicMap.put("value", "");
-        basicPlate.add(basicMap);
-
-        pdfFillDto.setBasicPlate(basicPlate);
-
-        // 表头信息
-        String studentData = jsonObject.getString("table");
-        List<JSONObject> studentObjectList = JSON.parseArray(studentData, JSONObject.class);
-        Map<String, String> studentHeadPlateMap = new LinkedHashMap<>();
-        for (JSONObject object : studentObjectList) {
-            studentHeadPlateMap.put(object.getString("code"), object.getString("name"));
-            studentHeadPlateMap.put("studentCode", "学号");
-            studentHeadPlateMap.put("studentName", "姓名");
-            studentHeadPlateMap.put("className", "班级");
-        }
-        studentHeadPlateMap.put("studentSign", "签名");
-        pdfFillDto.setStudentHeadPlate(studentHeadPlateMap);
-
-
-        // 考生信息
-        List<Map<String, String>> studentPlate = new ArrayList<>();
-        for (int i = 0; i < 55; i++) {
-            Map<String, String> studentMap = new HashMap<>();
-            for (JSONObject object : studentObjectList) {
-                studentMap.put(object.getString("code"), "XXXXXX");
-            }
-            studentMap.put("studentSign", "");
-            studentPlate.add(studentMap);
-        }
-        pdfFillDto.setStudentPlate(studentPlate);
-        try {
-            CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
-            createPrintPdfUtil.createSignPdf(response, pdfFillDto, fileName, false);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
 }

+ 6 - 14
distributed-print/src/main/java/com/qmth/distributed/print/api/BasicTemplateController.java

@@ -79,13 +79,13 @@ public class BasicTemplateController {
     /**
      * 新增/修改
      *
-     * @param template
+     * @param data
      * @return
      */
     @ApiOperation(value = "新增/修改")
     @RequestMapping(value = "/save", method = RequestMethod.POST)
-    public Result save(@RequestBody BasicTemplate template) throws Exception {
-        boolean isSuccess = basicTemplateService.saveTemplate(template);
+    public Result save(@RequestBody String data) throws Exception {
+        boolean isSuccess = basicTemplateService.saveTemplate(data);
         return ResultUtil.ok(isSuccess);
     }
 
@@ -105,21 +105,13 @@ public class BasicTemplateController {
     /**
      * 读取模板内容
      *
-     * @param attachmentId
+     * @param id
      * @return
      */
     @ApiOperation(value = "读取模板内容")
     @RequestMapping(value = "/read_content", method = RequestMethod.POST)
-    public Result enable(@RequestParam("attachmentId") Long attachmentId) {
-        Object content = basicTemplateService.readContent(attachmentId);
-        return ResultUtil.ok(content);
-    }
-
-    @ApiOperation(value = "预览")
-    @RequestMapping(value = "/preview", method = RequestMethod.POST)
-    public void preview(HttpServletResponse response,
-                        @RequestBody String data) {
-        basicTemplateService.preview(response, data);
+    public Result readContent(@RequestParam Long id) {
+        return ResultUtil.ok(basicTemplateService.preview(id), null);
     }
 
 }