|
|
@@ -234,6 +234,12 @@ public class RateService {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成word模版
|
|
|
+ *
|
|
|
+ * @param rate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public String export(Rate rate) {
|
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
|
try {
|
|
|
@@ -266,7 +272,6 @@ public class RateService {
|
|
|
|
|
|
//单位概况
|
|
|
dataMap.put("introduction", rate.getIntroduction());
|
|
|
-
|
|
|
//等级
|
|
|
dataMap.put("grade", rate.getGrade().getDesc());
|
|
|
|
|
|
@@ -297,6 +302,10 @@ public class RateService {
|
|
|
this.addList(imageUrllist, rate.getFinance());
|
|
|
this.addList(imageUrllist, rate.getProperty());
|
|
|
|
|
|
+ if (CollUtil.isEmpty(imageUrllist)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
String filename = "img" + UUID.randomUUID() + ".pdf";
|
|
|
File file = null;
|
|
|
|
|
|
@@ -316,12 +325,13 @@ public class RateService {
|
|
|
png1.setAlignment(Image.MIDDLE);
|
|
|
png1.scalePercent(percent + 3);// 表示是原来图像的比例;
|
|
|
doc.add(png1);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
// b = os.toByteArray();
|
|
|
|
|
|
file = new File(filename);
|
|
|
-// System.out.println(filename);
|
|
|
-// System.out.println(file.getName());
|
|
|
+
|
|
|
InputStream is = new FileInputStream(file);
|
|
|
files.add(is);
|
|
|
|
|
|
@@ -464,11 +474,17 @@ public class RateService {
|
|
|
return url.substring(index + 1);
|
|
|
}
|
|
|
|
|
|
- public void exportPdf(Long id, HttpServletResponse response) throws IOException {
|
|
|
+ /**
|
|
|
+ * 合并并下载pdf
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param response
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public void exportPdf1(Long id, HttpServletResponse response) throws IOException {
|
|
|
Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
List<InputStream> files = this.upLoad1(rate);
|
|
|
|
|
|
-
|
|
|
// pdf合并工具类
|
|
|
PDFMergerUtility mergePdf = new PDFMergerUtility();
|
|
|
mergePdf.addSources(files);
|
|
|
@@ -479,10 +495,6 @@ public class RateService {
|
|
|
|
|
|
mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
|
|
|
|
|
|
- // 设置合并生成pdf文件名称
|
|
|
-// String targetPath = "/Users/qiufangchao/Desktop/result.pdf";
|
|
|
-// mergePdf.setDestinationFileName(targetPath);
|
|
|
-
|
|
|
for (InputStream is : files) {
|
|
|
is.close();
|
|
|
}
|
|
|
@@ -497,6 +509,70 @@ public class RateService {
|
|
|
outputStream.close();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 下载pdf
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param response
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public byte[] exportPdf(Long id, HttpServletResponse response) throws IOException {
|
|
|
+ Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
+
|
|
|
+ // 设置response的Header
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + "result.pdf");
|
|
|
+
|
|
|
+ String pdfUrl = rate.getPdfUrl();
|
|
|
+ File file = new File(pdfUrl);
|
|
|
+
|
|
|
+ // 以流的形式下载文件。
|
|
|
+ InputStream fis = new BufferedInputStream(new FileInputStream(file));
|
|
|
+ byte[] buffer = new byte[fis.available()];
|
|
|
+
|
|
|
+ fis.read(buffer);
|
|
|
+ fis.close();
|
|
|
+ return buffer;
|
|
|
+
|
|
|
+// OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
|
|
|
+// toClient.write(buffer);
|
|
|
+// toClient.flush();
|
|
|
+// toClient.close();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合并pdf
|
|
|
+ *
|
|
|
+ * @param rate
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public void mergePdf(Rate rate) throws IOException {
|
|
|
+ List<InputStream> files = this.upLoad1(rate);
|
|
|
+
|
|
|
+ String targetPath = "/Users/qiufangchao/Desktop/rate/material" + rate.getId() + ".pdf";
|
|
|
+ // pdf合并工具类
|
|
|
+ PDFMergerUtility mergePdf = new PDFMergerUtility();
|
|
|
+
|
|
|
+ mergePdf.addSources(files);
|
|
|
+ // 设置合并生成pdf文件名称
|
|
|
+ mergePdf.setDestinationFileName(targetPath);
|
|
|
+ try {
|
|
|
+ mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
|
|
|
+ for (InputStream is : files) {
|
|
|
+ is.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 选专家发消息
|
|
|
+ *
|
|
|
+ * @param rate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Map<String, String> reviewTimesMessage(Rate rate) {
|
|
|
List<Long> ids = new ArrayList<>(rate.getExpertMemberUserId());
|
|
|
ids.add(rate.getExpertUserId());
|