sakuya 3 лет назад
Родитель
Сommit
38b46efc97

+ 8 - 7
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/NotaryNoteController.java

@@ -1,16 +1,15 @@
 package me.zhengjie.application.admin.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import me.zhengjie.annotation.rest.AnonymousGetMapping;
 import me.zhengjie.application.admin.controller.vo.NotaryNoteVo;
 import me.zhengjie.application.admin.service.NotaryNoteService;
 import me.zhengjie.base.AppBaseResponse;
 import me.zhengjie.base.util.HtmlConvertPdf;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.io.File;
@@ -19,6 +18,7 @@ import java.io.IOException;
 
 @RestController
 @RequestMapping("/api/note")
+@Api(tags = "管理平台: 面谈笔录")
 public class NotaryNoteController {
     @Autowired
     NotaryNoteService notaryNoteService;
@@ -40,7 +40,8 @@ public class NotaryNoteController {
      * @param notary
      * @return
      */
-    @RequestMapping("/save")
+    @ApiOperation("保存面谈笔录")
+    @PostMapping("/save")
     public AppBaseResponse<?> save(@Valid @RequestBody NotaryNoteVo notary) {
         return notaryNoteService.saveNotaryNote(notary);
     }
@@ -52,8 +53,8 @@ public class NotaryNoteController {
 
     public static void main(String[] args) {
         try {
-            String html = readString("/Users/sakuya/Downloads/notary-model.html");
-            HtmlConvertPdf.createPdfFile(html, "/Users/sakuya/Downloads/notary-model.pdf");
+            String html = readString("/Users/sakuya/Downloads/dbfdfd566ef94895805c67ceb5f9bd05.html");
+            HtmlConvertPdf.converPdf(html, "/Users/sakuya/Downloads/eaf26674fdce450e85591e1ad74fe6e9.pdf");
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 5 - 0
eladmin-system/src/main/java/me/zhengjie/application/bank/controller/BankAuthController.java

@@ -1,6 +1,8 @@
 package me.zhengjie.application.bank.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.annotation.rest.AnonymousPostMapping;
@@ -41,6 +43,7 @@ import java.util.List;
 @RequestMapping("${fqgz.bank.app.url-prefix}")
 @Slf4j
 @RequiredArgsConstructor
+@Api(tags = "客户经理APP: 认证模块")
 public class BankAuthController extends BaseController {
     private final BankLoginService bankLoginService;
     private final FileInfoService fileInfoService;
@@ -52,6 +55,7 @@ public class BankAuthController extends BaseController {
      * @param loginVo
      * @return
      */
+    @ApiOperation("登录")
     @AnonymousPostMapping("/login")
     public ResponseDTO<BankLoginVO> login(@Valid @RequestBody BankLoginVO loginVo) {
         return bankLoginService.login(loginVo);
@@ -62,6 +66,7 @@ public class BankAuthController extends BaseController {
      *
      * @return
      */
+    @ApiOperation("退出")
     @GetMapping("/logout")
     public ResponseDTO logout() {
         bankLoginService.logout(getAuthorization());

+ 6 - 0
eladmin-system/src/main/java/me/zhengjie/application/bank/controller/BankNotarizeController.java

@@ -7,6 +7,8 @@ import com.arcsoft.face.enums.DetectMode;
 import com.arcsoft.face.enums.DetectOrient;
 import com.arcsoft.face.enums.ErrorInfo;
 import com.arcsoft.face.toolkit.ImageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.annotation.rest.AnonymousGetMapping;
@@ -40,6 +42,7 @@ import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
 @RequestMapping("${fqgz.bank.app.url-prefix}")
 @Slf4j
 @RequiredArgsConstructor
+@Api(tags = "客户经理APP: 公证流程")
 public class BankNotarizeController extends BaseController {
 	private final OrderFileRepository orderFileRepository;
 	private final UserAXQInfoService userAXQInfoService;
@@ -161,12 +164,15 @@ public class BankNotarizeController extends BaseController {
 		}
 		return userAXQInfoService.getAuthStatus(idCard);
 	}
+
 	/**
 	 * 当事人签名
+	 *
 	 * @param json
 	 * @return
 	 */
 	@AnonymousPostMapping("/uploadSeal")
+	@ApiOperation("当事人签名")
 	public ResponseDTO<?> uploadSeal(@RequestBody String json) {
 		JSONObject jsonObj = JSONObject.parseObject(json);
 		String businessNo = jsonObj.getString("businessNo");

+ 7 - 2
eladmin-system/src/main/java/me/zhengjie/application/bank/controller/BankOrderController.java

@@ -1,6 +1,8 @@
 package me.zhengjie.application.bank.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.application.bank.BaseController;
@@ -27,6 +29,7 @@ import java.util.List;
 @RequestMapping("${fqgz.bank.app.url-prefix}/order")
 @Slf4j
 @RequiredArgsConstructor
+@Api(tags = "客户经理APP: 订单管理")
 public class BankOrderController extends BaseController {
     private final BankOrderService bankOrderService;
 
@@ -96,17 +99,19 @@ public class BankOrderController extends BaseController {
     }
 
     /**
-         * 提交订单
+     * 提交订单
      *
      * @param json
      * @return
      */
-    @RequestMapping("/submit")
+    @ApiOperation("提交订单")
+    @PostMapping(value = "/submit")
     public ResponseDTO<String> submitOrder(@RequestBody String json) {
         JSONObject jsonObj = JSONObject.parseObject(json);
         String businessNo = jsonObj.getString("businessNo");
         return bankOrderService.submitContractOrder(businessNo, getCurrentUser());
     }
+
     /**
 	 * 删除订单
 	 *

+ 4 - 43
eladmin-system/src/main/java/me/zhengjie/base/pdf/PdfUtils.java

@@ -1,56 +1,17 @@
 package me.zhengjie.base.pdf;
 
+import cn.hutool.core.io.FileUtil;
+import org.apache.pdfbox.io.MemoryUsageSetting;
+import org.apache.pdfbox.multipdf.PDFMergerUtility;
+
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
 import java.util.List;
 
-import org.apache.pdfbox.Loader;
-import org.apache.pdfbox.io.MemoryUsageSetting;
-import org.apache.pdfbox.multipdf.PDFMergerUtility;
-import org.apache.pdfbox.pdmodel.PDDocument;
-
-import cn.hutool.core.io.FileUtil;
-
 public class PdfUtils {
-//	private static String[] getPdfs(String fileAddress) throws IOException {
-//		File file = new File(fileAddress);
-//		String[] pdfs;
-//
-//		if (file.isDirectory()) {
-//			pdfs = file.list();
-//			return pdfs;
-//		} else {
-//			throw new IOException("输入的路径有问题");
-//		}
-//	}
-
-	public static void split() throws Exception {
-		File infile = new File("E:\\home\\image\\pdf\\javaweb2020.pdf");
-		// load pdf file
-		PDDocument document = Loader.loadPDF(infile);
-		// instantiating Splitter
-		CustomPageSplitter splitter = new CustomPageSplitter();
-		splitter.setSplitAtPage(2);
-		splitter.setSplitAtPage(1, 5, 2, 4);
-		// split the pages of a PDF document
-		List<PDDocument> Pages = splitter.split(document);
-		// Creating an iterator
-		Iterator<PDDocument> iterator = Pages.listIterator();
-		// saving splits as pdf
-		int i = 0;
-		while (iterator.hasNext()) {
-			PDDocument pd = iterator.next();
-			pd.save("E:\\home\\image\\pdf\\sample_part_" + ++i + ".pdf");
-			System.out.println("Saved /home/tk/pdfs/sample_part_" + i + ".pdf");
-		}
-		document.close();
-	}
 
 	public static byte[] mergePdf(List<InputStream> sourcesList) throws Exception {
 		PDFMergerUtility mergePdf = new PDFMergerUtility();

+ 5 - 5
eladmin-system/src/main/java/me/zhengjie/base/util/FileUploadUtil.java

@@ -329,7 +329,7 @@ public class FileUploadUtil {
 	/**
 	 * 上传文件通过文件的流
 	 * 
-	 * @param filePath
+	 * @param uploadPath
 	 * @param contentType
 	 * @param inputSteam
 	 * @throws Exception
@@ -359,9 +359,9 @@ public class FileUploadUtil {
 	/**
 	 * 上传文件通过文件的流
 	 * 
-	 * @param filePath
+	 * @param uploadPath
 	 * @param contentType
-	 * @param inputSteam
+	 * @param targetFile
 	 * @throws Exception
 	 */
 	public static void uploadFile(String uploadPath, String contentType, File targetFile) throws Exception {
@@ -448,7 +448,7 @@ public class FileUploadUtil {
 		InputStream inputStream = null;
 		try {
 			// File file, String data, Charset charset
-			HtmlConvertPdf.createPdfFile(html, sourceFilePath);
+			HtmlConvertPdf.converPdf(html, sourceFilePath);
 			inputStream = new FileInputStream(sourceFilePath);
 			// 这里需要把转换完成的删除掉
 			String contentType = "application/pdf";
@@ -481,7 +481,7 @@ public class FileUploadUtil {
 		InputStream inputStream = null;
 		try {
 			// File file, String data, Charset charset
-			HtmlConvertPdf.createPdfFile(html, sourceFilePath);
+			HtmlConvertPdf.converPdf(html, sourceFilePath);
 			inputStream = new FileInputStream(sourceFilePath);
 			// 这里需要把转换完成的删除掉
 			String contentType = "application/pdf";

+ 58 - 99
eladmin-system/src/main/java/me/zhengjie/base/util/HtmlConvertPdf.java

@@ -1,13 +1,21 @@
 package me.zhengjie.base.util;
 
+import com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder;
+import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
 import lombok.extern.slf4j.Slf4j;
-
 import org.apache.commons.io.FileUtils;
+import org.jsoup.Jsoup;
+import org.jsoup.helper.W3CDom;
+import org.jsoup.nodes.Document;
 import org.zefer.pd4ml.PD4Constants;
 import org.zefer.pd4ml.PD4ML;
 
 import java.awt.*;
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.StringReader;
+import java.nio.file.FileSystems;
 
 /**
  * https://pd4ml.com/api/org/zefer/pd4ml/PD4ML.html api文档
@@ -19,78 +27,43 @@ import java.io.*;
  */
 @Slf4j
 public class HtmlConvertPdf {
-
-	private static int width = 585;
-	private static int height = 822;
-
-	/**
-	 * 获取PDF的宽度
-	 * 
-	 * @return
-	 */
-	public int getWidth() {
-		return width;
-	}
-
-	/**
-	 * 设置PDF的宽度
-	 * 
-	 * @return
-	 */
-	public void setWidth(int width) {
-		HtmlConvertPdf.width = width;
-	}
-
-	/**
-	 * 获取PDF的高度
-	 * 
-	 * @return
-	 */
-	public int getHeight() {
-		return height;
-	}
+	private static final String CONVERT_TYPE_PD4ML = "PD4ML";
+	private static final String CONVERT_TYPE_OPENPDF = "OPENPDF";
+	private static final String CONVERT_TYPE_CURRENT = CONVERT_TYPE_OPENPDF;
 
 	/**
-	 * 设置PDF的高度
-	 * 
-	 * @return
+	 * 将html转换成pdf
+	 *
+	 * @param html
+	 * @param destPath
+	 * @throws Exception
 	 */
-	public void setHeight(int height) {
-		HtmlConvertPdf.height = height;
+	public static void converPdf(String html, String destPath) throws Exception {
+		if (CONVERT_TYPE_OPENPDF.equals(CONVERT_TYPE_CURRENT)) {
+			convertPdfWithOpenPDF(html, destPath);
+		} else if (CONVERT_TYPE_PD4ML.equals(CONVERT_TYPE_CURRENT)) {
+			convertPdfWithPD4ML(html, destPath);
+		}
 	}
 
 	/**
-	 * 创建PDF文件
-	 * 
-	 * @param html    html字符串
-	 * @param desPath 输出的PDF文件路径
+	 * 使用PD4ML将html转换成pdf
+	 *
+	 * @param html     html字符串
+	 * @param destPath 输出的PDF文件路径
 	 * @throws Exception
 	 */
-	public static void createPdfFile(String html, String desPath) throws Exception {
-		File file = new File(desPath);
+	private static void convertPdfWithPD4ML(String html, String destPath) throws Exception {
+		File file = new File(destPath);
 		FileUtils.writeStringToFile(file, "", "UTF-8");
 		FileOutputStream outFile = new FileOutputStream(file);
+		//
 		PD4ML pdf = new PD4ML();
-		// 设置html的宽度
-		pdf.setHtmlWidth(width);
-		// 设置字体的数据
-		int topValue = 20;
-		int leftValue = 15;
-		int rightValue = 10;
-		int bottomValue = 25;
-
-		pdf.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
-		// 设置页面的标准
+		pdf.setHtmlWidth(585);
+		pdf.setPageInsetsMM(new Insets(20, 15, 25, 10));
 		pdf.setPageSizeMM(PD4Constants.A4);
-		// 设置字体
 		pdf.useTTF("java:fonts", true);
-		// pd4ml.useTTF("F:/Test/fonts", true); //F:/Test/fonts文件夹可自定义,保持一致即可
-//		String path = AppRun.class.getResource("/fonts").getPath();
-//		System.out.println("pd4fonts字体:" + path);
-//		pdf.useTTF(path, true);
-		// 设置默认的字体
 		pdf.setDefaultTTFs("simfang", "simfang", "simfang");
-		// 设置HTML全局样式
 		pdf.addStyle("body,html {margin: 0 auto;}", true);
 		// 测试开启,上线的时候关闭
 		pdf.enableDebugInfo();
@@ -98,45 +71,31 @@ public class HtmlConvertPdf {
 	}
 
 	/**
-	 * 读取文件路径
-	 * 
-	 * @param path     路径
-	 * @param encoding 编码
-	 * @return string
-	 * @throws IOException
+	 * 使用OpenPDF将html转换成pdf
+	 *
+	 * @param html
+	 * @param destPath
+	 * @throws Exception
 	 */
-	public String readFile(String path, String encoding) throws IOException {
-
-		FileInputStream is = new FileInputStream(path);
-		BufferedInputStream bis = new BufferedInputStream(is);
-		ByteArrayOutputStream fos = new ByteArrayOutputStream();
-		byte[] buffer = new byte[2048];
-		int read;
-		do {
-			read = is.read(buffer, 0, buffer.length);
-			if (read > 0) {
-				fos.write(buffer, 0, read);
-			}
-		} while (read > -1);
-
-		fos.close();
-		bis.close();
-		is.close();
-
-		return fos.toString(encoding);
-	}
-
-	public static void main(String[] args) {
-		System.out.println(HtmlConvertPdf.class.getResource("/fonts").getPath());
-		;
-
-//		HtmlConvertPdf util = new HtmlConvertPdf();
-//		try {
-//			String str = UUID.randomUUID().toString().replace("-", "");
-//			String html = util.readFile("/Users/bakerzp/Downloads/other/html/promise.html", "utf-8");
-//			createPdfFile(html, "/Users/bakerzp/Downloads/other/" + str + ".pdf");
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//		}
+	private static void convertPdfWithOpenPDF(String html, String destPath) throws Exception {
+		//加载html文件
+		Document document = Jsoup.parse(html);
+		document.outputSettings().syntax(Document.OutputSettings.Syntax.html);
+		//引入资源目录,可以单独引入css,图片文件等
+		String baseUri = FileSystems.getDefault().getPath("eladmin-system/src/main/resources/css").toUri().toString();
+		//
+		File file = new File(destPath);
+		FileUtils.writeStringToFile(file, "", "UTF-8");
+		OutputStream os = new FileOutputStream(file);
+		PdfRendererBuilder builder = new PdfRendererBuilder();
+		builder.withUri(destPath);
+		builder.toStream(os);
+		builder.withW3cDocument(new W3CDom().fromJsoup(document), baseUri);
+
+		//引入指定字体,注意字体名需要和css样式中指定的字体名相同
+		String fontPath = HtmlConvertPdf.class.getClassLoader().getResource("").getPath().concat("font");
+		builder.useFont(new File(fontPath + "/simsun.ttf"), "SimSun", 1, BaseRendererBuilder.FontStyle.NORMAL, true);
+		builder.useFont(new File(fontPath + "/simfang.ttf"), "simfang", 1, BaseRendererBuilder.FontStyle.NORMAL, true);
+		builder.run();
 	}
 }

+ 1 - 0
eladmin-system/src/main/java/me/zhengjie/domain/model/ModelSynthesizerDomain.java

@@ -431,6 +431,7 @@ public class ModelSynthesizerDomain {
      */
     private String composeCommonTemplateWithData(String businessNo, String content, String userName, boolean hasSignImg, JSONArray signUser) {
         String replaceContent = TextTempletUtil.replaceContent(content, prepareCommonTemplateData(businessNo, userName, hasSignImg, signUser));
+        replaceContent = replaceContent.replace("宋体;", "SimSun;").replace("仿宋;", "simfang;");
         String result = "";
         try {
             InputStream inputStream = ModelSynthesizerDomain.class.getClassLoader().getResourceAsStream("template/note/notary-model.html");