Преглед изворни кода

合并材料,下载材料

licailing пре 4 година
родитељ
комит
e055fb21cc

+ 18 - 5
src/main/java/com/izouma/wenlvju/service/RateService.java

@@ -15,6 +15,7 @@ import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.repo.*;
 import com.izouma.wenlvju.security.Authority;
 import com.izouma.wenlvju.service.sms.NjwlSmsService;
+import com.izouma.wenlvju.service.storage.StorageService;
 import com.izouma.wenlvju.utils.FileUtils;
 import com.izouma.wenlvju.utils.JpaUtils;
 import com.izouma.wenlvju.utils.ObjUtils;
@@ -63,6 +64,8 @@ public class RateService {
     private NjwlSmsService          njwlSmsService;
     @Autowired
     private OrganizationRepo        organizationRepo;
+    @Autowired
+    private StorageService          storageService;
     @Value("${storage.local_path}")
     private String                  localPath;
 
@@ -374,7 +377,9 @@ public class RateService {
 
     public List<InputStream> upLoad1(Rate rate) throws UnsupportedEncodingException {
         List<InputStream> files = new ArrayList<>();
-        String uri = "http://10.188.236.2/word2pdf";
+//        String uri = "http://10.188.236.2/word2pdf";
+
+        String uri = "http://convert.izouma.com/word2pdf";
 
         // 表格
         String export = this.export(rate);
@@ -399,6 +404,8 @@ public class RateService {
     }
 
     public void downloadFile1(List<InputStream> files, List<String> urls) {
+
+
         AtomicInteger num = new AtomicInteger(1);
         urls.forEach(privacy -> {
             num.getAndIncrement();
@@ -414,7 +421,7 @@ public class RateService {
                         throw new BusinessException("找不到文件");
                     }
                 }
-                InputStream stream = HttpRequest.post("http://10.188.236.2/word2pdf")
+                InputStream stream = HttpRequest.post("http://convert.izouma.com/word2pdf")
                         .accept("*/*")
                         .part("file", "审核材料.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", is1)
                         .stream();
@@ -440,6 +447,7 @@ public class RateService {
     public List<File> upLoad(Rate rate) {
         List<File> files = new ArrayList<>();
         String uri = "http://10.188.236.2/word2pdf";
+
         // 表格
         String export = this.export(rate);
         InputStream is = new ByteArrayInputStream(export.getBytes());
@@ -565,13 +573,14 @@ public class RateService {
         }
         List<InputStream> files = this.upLoad1(rate);
 
-        String targetPath = localPath + "/material" + rate.getId() + ".pdf";
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
         // pdf合并工具类
         PDFMergerUtility mergePdf = new PDFMergerUtility();
 
         mergePdf.addSources(files);
         // 设置合并生成pdf文件名称
-        mergePdf.setDestinationFileName(targetPath);
+        mergePdf.setDestinationStream(bos);
         try {
             mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
             for (InputStream is : files) {
@@ -580,7 +589,11 @@ public class RateService {
         } catch (IOException e) {
             e.printStackTrace();
         }
-        rate.setPdfUrl("http://yskj.njlyw.cn:8081/files/pdf/material" + rate.getId() + ".pdf");
+
+        String url = storageService.uploadFromInputStream(new ByteArrayInputStream(bos.toByteArray()),
+                "pdf/material" + rate.getId() + ".pdf");
+
+        rate.setPdfUrl(url);
         rateRepo.save(rate);
     }
 

+ 11 - 0
src/main/java/com/izouma/wenlvju/web/RateController.java

@@ -161,6 +161,17 @@ public class RateController extends BaseController {
         });
     }
 
+    @GetMapping("/mergePdf/{id}")
+    public void mergePdf(@PathVariable Long id) {
+        Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无等级评定"));
+        try {
+            rateService.mergePdf(rate);
+        } catch (IOException e) {
+            log.error(e.getMessage());
+        }
+
+    }
+
     @OperLog(value = "等级评定", type = "修改", desc = "对等级评定申请进行操作")
     @ApiOperation("设置审查时间")
     @GetMapping("/saveReviewTime")

+ 40 - 9
src/main/vue/src/views/rate/RateOrganizerList.vue

@@ -64,15 +64,26 @@
                         v-if="row.status == 'FIRST_REVIEW_PENDING' || row.status == 'FIRST_REVIEW_DENY'"
                         >撤回
                     </el-button>
-                    <el-button
-                        @click="aletrLog(row)"
-                        type="primary"
-                        :loading="downloading"
-                        size="mini"
-                        class="filter-item"
-                        v-if="row.status == 'SUBMIT_PAPER_MATERIALS'"
-                        >下载材料
-                    </el-button>
+                    <span v-if="row.status == 'SUBMIT_PAPER_MATERIALS'" style="margin-left:2px">
+                        <el-button
+                            @click="mergePdf(row)"
+                            type="primary"
+                            :loading="downloading"
+                            size="mini"
+                            class="filter-item"
+                            v-if="isMerge(row.pdfUrl)"
+                            >合并材料
+                        </el-button>
+                        <el-button
+                            @click="aletrLog(row)"
+                            type="primary"
+                            :loading="downloading"
+                            size="mini"
+                            class="filter-item"
+                            v-else
+                            >下载材料
+                        </el-button>
+                    </span>
                     <!-- <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button> -->
                 </template>
             </el-table-column>
@@ -307,6 +318,26 @@ export default {
                     this.$message.warning('复制失败');
                 }
             );
+        },
+        isMerge(url) {
+            if (typeof url == 'undefined' || url == '') {
+                return true;
+            }
+            return false;
+        },
+        mergePdf(row) {
+            this.downloading = true;
+            this.$http
+                .get('/rate/mergePdf/' + row.id)
+                .then(res => {
+                    this.downloading = false;
+                    this.getData();
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.downloading = false;
+                    // this.$message.error(e.error);
+                });
         }
     }
 };

+ 8 - 8
src/test/java/com/izouma/wenlvju/service/performance/ParticipantServiceTest.java

@@ -34,13 +34,13 @@ public class ParticipantServiceTest extends ApplicationTests {
 
     @Test
     public void test() throws IOException, WriterException {
-        String[] array = {"盛颖帆", "杨墨涵", "潘瑾汐", "朱建玥", "金兴蕾", "雷普", "王锦曦", "高嘉涵", "常彧嘉", "宋佳怡"};
-
+        String[] array = {"何雨田"};
+        String pid = "18971";
         for (String str : array) {
 
 
             BufferedImage shareImg = ImageIO.read(this.getClass()
-                    .getResourceAsStream("/static/certificate/2021-124-28198.png"));
+                    .getResourceAsStream("/static/certificate/2021-124-28197.png"));
             BufferedImage result = new BufferedImage(2480, 1748, BufferedImage.TYPE_INT_RGB);
             Graphics2D g = result.createGraphics();
             g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
@@ -54,7 +54,7 @@ public class ParticipantServiceTest extends ApplicationTests {
             Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
             hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
             hints.put(EncodeHintType.MARGIN, 1);
-            BitMatrix bitMatrix = new MultiFormatWriter().encode("http://yskj.njlyw.cn:8081/h5/home?programmeId=19798", BarcodeFormat.QR_CODE, 1000, 1000, hints);
+            BitMatrix bitMatrix = new MultiFormatWriter().encode("http://yskj.njlyw.cn:8081/h5/home?programmeId=" + pid, BarcodeFormat.QR_CODE, 1000, 1000, hints);
 //        BufferedImage image = new BufferedImage(240, 240, BufferedImage.TYPE_INT_RGB);
             BufferedImage code = MatrixToImageWriter.toBufferedImage(bitMatrix);
 //        BufferedImage avatar = ImageIO.read(new File("/Users/qiufangchao/Desktop/17824.png"));
@@ -79,10 +79,10 @@ public class ParticipantServiceTest extends ApplicationTests {
             // 文字
             g.setColor(new Color(48, 52, 82)); //根据图片的背景设置水印颜色
             // 编号
-            String small = "19798";
+//            String small = "18971";
             Font fontSmall = new Font("黑体", Font.PLAIN, 35);
             g.setFont(fontSmall);
-            g.drawString(small, 2000, 544);
+            g.drawString(pid, 2000, 544);
 
             // 姓名
             Font font = new Font("黑体", Font.BOLD, 60);
@@ -93,7 +93,7 @@ public class ParticipantServiceTest extends ApplicationTests {
             g.drawString(str, 400, 601);  //画出水印
 
             // 节目名称
-            String content1 = "我对月亮说句话";
+            String content1 = "月愿";
 
             if (content1.length() < 8) {
 //            String body1 = "多声部手风琴原创作品《最";
@@ -116,7 +116,7 @@ public class ParticipantServiceTest extends ApplicationTests {
                     .toOutputStream(out);
             ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
 
-            File file = new File("/Users/qiufangchao/Desktop/bu/我对月亮说句话-" + str + ".jpg");
+            File file = new File("/Users/qiufangchao/Desktop/补证书/月愿-" + str + ".jpg");
             byte[] buffer = new byte[in.available()];
             in.read(buffer);
             OutputStream outStream = new FileOutputStream(file);