中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

一般找人做網(wǎng)站多少錢(qián)全球搜是什么公司

一般找人做網(wǎng)站多少錢(qián),全球搜是什么公司,真空電鍍技術(shù)支持 東莞網(wǎng)站建設(shè),找人做網(wǎng)站文章目錄 參考文章技術(shù)棧需求解析發(fā)票類(lèi)型 1. 最終項(xiàng)目結(jié)構(gòu)1.1 說(shuō)明 2. 相關(guān)代碼2.1 導(dǎo)入相應(yīng)的maven依賴(lài)2.2 實(shí)體類(lèi)2.3 工具類(lèi)2.4 三層架構(gòu)controllerservicemapper 參考文章 參考文章 技術(shù)棧 SpringBootVue 需求 本文主要是實(shí)現(xiàn)提取發(fā)票中的部分內(nèi)容,并實(shí)現(xiàn)自…

文章目錄

  • 參考文章
    • 技術(shù)棧
    • 需求
    • 解析發(fā)票類(lèi)型
  • 1. 最終項(xiàng)目結(jié)構(gòu)
    • 1.1 說(shuō)明
  • 2. 相關(guān)代碼
    • 2.1 導(dǎo)入相應(yīng)的maven依賴(lài)
    • 2.2 實(shí)體類(lèi)
    • 2.3 工具類(lèi)
    • 2.4 三層架構(gòu)
      • controller
      • service
      • mapper

參考文章

參考文章

技術(shù)棧

SpringBoot+Vue

需求

本文主要是實(shí)現(xiàn)提取發(fā)票中的部分內(nèi)容,并實(shí)現(xiàn)自動(dòng)回填到頁(yè)面中對(duì)應(yīng)位置。

解析發(fā)票類(lèi)型

在這里插入圖片描述

1. 最終項(xiàng)目結(jié)構(gòu)

新建一個(gè)Springboot項(xiàng)目

在這里插入圖片描述

1.1 說(shuō)明

  1. 實(shí)體 entity 包下
    • 主要有兩個(gè)實(shí)體,分別是發(fā)票實(shí)體NewInvoice,和發(fā)票備注實(shí)體Note
  2. 工具 utils 包下
    • PDF類(lèi)用于解析PDF文件
    • InvoiceRegexEnum 類(lèi)是發(fā)票信息的正則表達(dá)式枚舉類(lèi),提取發(fā)票信息所用到的正則表達(dá)式都在這個(gè)枚舉類(lèi)中

2. 相關(guān)代碼

2.1 導(dǎo)入相應(yīng)的maven依賴(lài)

<!--        添加依賴(lài)開(kāi)始位置--><dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>2.0.21</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>fontbox</artifactId><version>2.0.21</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>jempbox</artifactId><version>1.8.13</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>xmpbox</artifactId><version>2.0.0</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>preflight</artifactId><version>2.0.0</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox-tools</artifactId><version>2.0.0</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.0.0</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.0.0</version></dependency><dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.1.0</version></dependency><dependency><groupId>com.google.zxing</groupId><artifactId>javase</artifactId><version>3.1.0</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.12.0</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.11.0</version></dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId></dependency><!--        添加依賴(lài)結(jié)束位置-->

2.2 實(shí)體類(lèi)

電子發(fā)票實(shí)體類(lèi)NewInvoice

package com.example.pdf.entity;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.math.BigDecimal;/*** 電子發(fā)票實(shí)體類(lèi)*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class NewInvoice {
//    private String  fileAbsolutePath;   // 文件絕對(duì)路徑private String number;  // 發(fā)票號(hào)碼private String date;    // 開(kāi)票日期
//    private String sellerName;  // 銷(xiāo)售方名稱(chēng)private BigDecimal amount;  // 合計(jì)金額private BigDecimal taxAmount;   // 合計(jì)稅額private BigDecimal totalAmount; // 價(jià)稅合計(jì)金額private Note Detail;    //  發(fā)票備注信息private String note;    //  備注}

備注實(shí)體類(lèi)Note

package com.example.pdf.entity;import lombok.Data;/*** 發(fā)票備注信息*/
@Data
public class Note {private String buyer; // 購(gòu)方private String buyerAccount; // 購(gòu)方銀行賬號(hào)private String seller; // 銷(xiāo)方private String sellerAccount; // 銷(xiāo)方銀行賬號(hào)private String payee; // 收款人private String checker; // 復(fù)核人
//    @Override
//    public String toString() {
//        return  "購(gòu)方開(kāi)戶(hù)銀行:" + buyer + ";    "+
//                "銀行賬號(hào):" + buyerAccount + ";" +"\n"+
//                "銷(xiāo)方開(kāi)戶(hù)銀行:" + seller + ";    "+
//                "銀行賬號(hào):" + sellerAccount +";" +"\n\n"+
//                " 收款人:" + payee + ";" +"    "+
//                " 復(fù)核人:" + checker +";";
//    }
}

2.3 工具類(lèi)

正則表達(dá)式枚舉類(lèi)

package com.example.pdf.utils;/*** 正則表達(dá)式枚舉類(lèi)*/
public enum InvoiceRegexEnum {/*** 機(jī)器編碼、發(fā)票代碼、發(fā)票號(hào)碼、開(kāi)票日期和校驗(yàn)碼的提取正則*/REGULAR_A("機(jī)器編號(hào):(?<machineNumber>\\d{12})|發(fā)票代碼:(?<code>\\d{12})|發(fā)票號(hào)碼:(?<number>\\d{8})|:(?<date>\\d{4}年\\d{2}月\\d{2}日)|校驗(yàn)碼:(?<checksum>\\d{20}|\\S{4,})"),/*** 新版發(fā)票的機(jī)器編碼、發(fā)票代碼、發(fā)票號(hào)碼、開(kāi)票日期和校驗(yàn)碼的提取正則*/REGULAR_A_NEW("發(fā)票號(hào)碼:(?<number>\\d{20})|:(?<date>\\d{4}年\\d{2}月\\d{2}日)|(售名稱(chēng)|銷(xiāo)名稱(chēng)):(?<name>\\S*)"),/*** 發(fā)票號(hào)碼備用提取正則*/REGULAR_A_1("(國(guó)制|制普通發(fā)票)(?<number>\\d{8})"),/*** 發(fā)票號(hào)碼跨行提取正則*/REGULAR_A_1R("發(fā)票號(hào)碼:(?<number>\\d{7})[\\s\\S]*?(\\d+)"),/*** 開(kāi)票日期備用提取正則*/REGULAR_A_2("開(kāi)票日期:(?<date>\\d{4}\\d{2}月\\d{2}日)"),/*** 發(fā)票代碼備用提取正則*/REGULAR_A_3("發(fā)票代碼(?<code>\\d{12})"),/*** 發(fā)票代碼跨行提取正則*/REGULAR_A_3R("發(fā)票代碼:(?<code>\\d{10})[\\s\\S]*?(\\d+)"),/*** 金額、稅額提取正則,匹配形如 "合計(jì)¥?金額¥?稅額" 的文本*/REGULAR_B("合計(jì)¥?(?<amount>[^ \\f\\n\\r\\t\\v*]*)(?:¥?(?<taxAmount>\\S*)|\\*+)\\s"),/*** 金額提取正則,用于匹配結(jié)果有誤的修正*/REGULAR_BR("合計(jì)¥(?<amount>\\d+\\.\\d+)"),/*** 金額、稅額備用提取正則*/REGULAR_B_1("合\\u0020*計(jì)\\u0020*¥?(?<amount>[^ ]*)\\u0020+¥?(?:(?<taxAmount>\\S*)|\\*+)\\s"),/*** 價(jià)稅合計(jì)提取正則,匹配“價(jià)稅合計(jì)(大寫(xiě))XXX(小寫(xiě))¥YYY”格式的文本*/REGULAR_C("價(jià)稅合計(jì)\\u0028大寫(xiě)\\u0029(?<amountString>\\S*)\\u0028小寫(xiě)\\u0029¥?(?<amount>\\S*)\\s"),/*** 收款人、復(fù)核、開(kāi)票人、銷(xiāo)售方提取正則,匹配格式為“收款人:xxx復(fù)核:xxx開(kāi)票人:xxx銷(xiāo)售方”的字符串*/REGULAR_D("收款人:(?<payee>\\S*)復(fù)核:(?<reviewer>\\S*)開(kāi)票人:(?<drawer>\\S*)銷(xiāo)售方"),/*** 發(fā)票類(lèi)型提取正則,匹配"xxx通發(fā)票"格式的發(fā)票類(lèi)型*/REGULAR_E("(?<p>\\S*)通發(fā)票"),/*** 發(fā)票類(lèi)型提取正則,匹配"xxx用發(fā)票"格式的發(fā)票類(lèi)型*/REGULAR_E_1("(?<p>\\S*)用發(fā)票"),/*** 發(fā)票類(lèi)型提取 - 輔助正則*/REGULAR_E_AUX("(?:國(guó)|統(tǒng)|一|發(fā)|票|監(jiān)|制)"),/*** 購(gòu)買(mǎi)方信息提取正則*/REGULAR_F("名稱(chēng):(?<name>\\S*)|納稅人識(shí)別號(hào):(?<code>\\S*)|地址、電話(huà):(?<address>\\S*)|開(kāi)戶(hù)行及賬號(hào):(?<account>\\S*)|電子支付標(biāo)識(shí):(?<account2>\\S*)"),/*** 針對(duì)深圳發(fā)票的銷(xiāo)售方名稱(chēng)提取正則*/REGULAR_FR("名稱(chēng):(?<name>\\S*)"),/*** 處理除了金額和稅額之外的其他文本元素正則*/REGULAR_G("^(-?\\d+)(\\.\\d+)?$"),/*** 備注信息提取正則*/REGULAR_A_NOTE_BUYER("購(gòu)方開(kāi)戶(hù)銀行:(?<buyer>[^;]+);"),REGULAR_A_NOTE_BUYERACCOUNT("銀行賬號(hào):(?<buyerAccount>\\d+)(?=[,;])"),REGULAR_A_NOTE_SELLER("銷(xiāo)方開(kāi)戶(hù)銀行:(?<seller>.*?)(?=[,;]|\\Z)"),REGULAR_A_NOTE_SELLERACCOUNT("銀行賬號(hào):(?<sellerAccount>\\d+)(?=[,;]|\\Z)"),REGULAR_A_NOTE_PAYEE("收款人:(?<payee>.*?)(?=[,;]|\\Z)"),REGULAR_A_NOTE_CHECKER("復(fù)核人:(?<checker>.*?)(?=[,;]|\\Z)"),/*** 檢查當(dāng)前詳細(xì)項(xiàng)字符串是否符合特定條件正則*/REGULAR_H("\\S+\\d*(%|免稅|不征稅|出口零稅率|普通零稅率)\\S*"),REGULAR_H_1("^ *\\d*(%|免稅|不征稅|出口零稅率|普通零稅率)\\S*"),REGULAR_H_2("\\S+\\d+%[\\-\\d]+\\S*"),REGULAR_H_3("^ *\\d*(%|免稅|不征稅|出口零稅率|普通零稅率)\\S*");private final String regex;InvoiceRegexEnum(String regex) {this.regex = regex;}public String getRegex() {return regex;}
}

解析PDF工具類(lèi)

package com.example.pdf.utils;import com.example.pdf.entity.NewInvoice;
import com.example.pdf.entity.Note;
import lombok.extern.slf4j.Slf4j;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripper;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import static com.example.pdf.utils.InvoiceRegexEnum.*;@Slf4j
public class PDF {private static final String PDF_EXTENSION = ".pdf";/*** 調(diào)用該方法將前端接受到的文件暫存** @param file*/public static NewInvoice parsePdfFile(MultipartFile file) {NewInvoice newInvoice = new NewInvoice();try {// 創(chuàng)建一個(gè)臨時(shí)文件Path tempFile = Files.createTempFile("tempPrefix", ".pdf");File tempFilePath = tempFile.toFile();// 將MultipartFile的內(nèi)容寫(xiě)入到臨時(shí)文件try (FileOutputStream fos = new FileOutputStream(tempFilePath)) {fos.write(file.getBytes());}// 現(xiàn)在你可以使用臨時(shí)文件的路徑來(lái)調(diào)用你的解析方法newInvoice = extractInvoiceInformation(tempFilePath.getAbsolutePath());// 刪除臨時(shí)文件,或者在某些情況下保留它tempFilePath.delete();} catch (IOException e) {// 處理異常e.printStackTrace();}// 返回值return newInvoice;}/*** 提取發(fā)票信息*//*** 提取發(fā)票信息** @param filePath 發(fā)票地址* @return*/public static NewInvoice extractInvoiceInformation(String filePath) {// 指定要處理的文件夾路徑NewInvoice newInvoice1 = newPdfProcessInvoicesInFile(filePath);String note = "";if (newInvoice1.getDetail().getBuyer() != null) {note = "購(gòu)方開(kāi)戶(hù)銀行:" + newInvoice1.getDetail().getBuyer() + ";    ";} else {note = "";}if (newInvoice1.getDetail().getBuyerAccount() != null) {note = note + "銀行賬號(hào):" + newInvoice1.getDetail().getBuyerAccount() + ";    ";} else {note = note + "";}if (newInvoice1.getDetail().getSeller() != null) {note = note + "銷(xiāo)方開(kāi)戶(hù)銀行:" + newInvoice1.getDetail().getSeller() + ";    ";} else {note = note + "";}if (newInvoice1.getDetail().getSellerAccount() != null) {note = note + "銀行賬號(hào):" + newInvoice1.getDetail().getSellerAccount() + ";    ";} else {note = note + "";}if (newInvoice1.getDetail().getPayee() != null) {note = note + " 收款人:" + newInvoice1.getDetail().getPayee() + ";" + "    ";} else {note = note + "";}if (newInvoice1.getDetail().getChecker() != null) {note = note + " 復(fù)核人:" + newInvoice1.getDetail().getChecker() + ";";} else {note = note + "";}newInvoice1.setNote(note);return newInvoice1;}/*** 處理指定的PDF發(fā)票文件** @param filePath 文件路徑* @return 包含提取信息的 NewInvoice 列表*/public static NewInvoice newPdfProcessInvoicesInFile(String filePath) {File file = new File(filePath);NewInvoice returnResult = new NewInvoice();if (isPdfFile(file)) {NewInvoice result = extractInvoice(file.getAbsolutePath()); // 提取文件內(nèi)容if (result != null) {returnResult = createProcessedInvoice(result);// 創(chuàng)建一個(gè)新的發(fā)票對(duì)象} else {handleExtractionError(file);}}return returnResult;}/*** 創(chuàng)建一個(gè)處理后的 NewInvoice 對(duì)象** @param result 原始的 NewInvoice 對(duì)象* @return 處理后的 NewInvoice 對(duì)象*/private static NewInvoice createProcessedInvoice(NewInvoice result) {NewInvoice returnResult = new NewInvoice();returnResult.setNumber(result.getNumber());returnResult.setDate(result.getDate());returnResult.setTotalAmount(result.getTotalAmount());returnResult.setAmount(result.getAmount());returnResult.setTaxAmount(result.getTaxAmount());returnResult.setDetail(result.getDetail());return returnResult;}/*** 處理提取失敗的情況,輸出錯(cuò)誤信息** @param file 提取失敗的文件*/private static void handleExtractionError(File file) {log.warn("文件: {}\t提取失敗~~~\n", file.getName());}/*** 檢查文件是否為PDF文件** @param file 要檢查的文件* @return 如果是PDF文件,返回 true,否則返回 false*/private static boolean isPdfFile(File file) {return file.isFile() && file.getName().toLowerCase().endsWith(PDF_EXTENSION);}/*** 從本地文件或URL中提取發(fā)票信息。** @param filePath 本地文件路徑或發(fā)票的URL。* @return 包含提取信息的 NewInvoice 對(duì)象。*/private static NewInvoice extractInvoice(String filePath) {File sourceFile = new File(filePath);if (!sourceFile.exists()) {log.error("指定的源文件不存在");}NewInvoice result = null;try {// 調(diào)用函數(shù)解析PDF ,返回 發(fā)票對(duì)象【基本信息】result = extract(sourceFile);} catch (Exception e) {e.printStackTrace();result = new NewInvoice();}return result;}/*** 解析PDF 文件,返回發(fā)票對(duì)象** @param file PDF文件* @return* @throws IOException*/public static NewInvoice extract(File file) throws IOException {NewInvoice invoice = new NewInvoice();  // 新建發(fā)票對(duì)象// 接收一個(gè)表示 PDF 文件路徑的字符串作為參數(shù),并返回一個(gè) PDDocument 對(duì)象。// 這個(gè)對(duì)象代表了整個(gè)PDF 文檔,可以通過(guò)這個(gè)對(duì)象來(lái)訪問(wèn)文檔的各個(gè)部分PDDocument doc = PDDocument.load(file);// 從 PDDocument 對(duì)象 doc 中獲取第一頁(yè),并將這個(gè)頁(yè)面對(duì)象賦值給PDPage類(lèi)型的變量// PDPage 對(duì)象代表了文檔中的一個(gè)頁(yè)面PDPage firstPage = doc.getPage(0);// 獲取頁(yè)面裁剪框?qū)挾?#xff0c;并將寬度四舍五入為整數(shù)// 【頁(yè)面裁剪寬度定義了頁(yè)面上用于顯示內(nèi)容的區(qū)域】int pageWidth = Math.round(firstPage.getCropBox().getWidth());// PDFTextStripper 用于從PDF文檔中提取文本的工具PDFTextStripper textStripper = new PDFTextStripper(); // 創(chuàng)建一個(gè)實(shí)例textStripper.setSortByPosition(true); // 提取文本時(shí)按照物理位置進(jìn)行排序// 提取整個(gè)文檔的所有文本內(nèi)容,并將這些文本內(nèi)容作為一個(gè)長(zhǎng)字符串返回String fullText = textStripper.getText(doc);// 頁(yè)面翻轉(zhuǎn)? 不重要if (firstPage.getRotation() != 0) {pageWidth = Math.round(firstPage.getCropBox().getHeight());}// 處理文本中可能有錯(cuò)誤的符號(hào)String allText = replace(fullText).replaceAll("(", "(").replaceAll(")", ")").replaceAll("¥", "¥");// 提取 新版發(fā)票的機(jī)器編碼、發(fā)票代碼、發(fā)票號(hào)碼、開(kāi)票日期和檢驗(yàn)碼{Pattern pattern = Pattern.compile(REGULAR_A_NEW.getRegex()); // 新版發(fā)票的機(jī)器編碼、發(fā)票代碼、發(fā)票號(hào)碼、開(kāi)票日期和檢驗(yàn)碼的提取正則Pattern patternNumber = Pattern.compile(REGULAR_A_1.getRegex());// 發(fā)票號(hào)碼備用提取正則Pattern patternDate = Pattern.compile(REGULAR_A_2.getRegex()); // 開(kāi)票日期備用提取正則// matcer 類(lèi)對(duì)于輸入字符串進(jìn)行解釋和匹配操作,這些操作是基于某個(gè)Pattern對(duì)象定義的規(guī)則(正則表達(dá)式)進(jìn)行的。// 檢查allText 字符串中是否匹配pattern中定義的正則表達(dá)式的文本Matcher matcher = pattern.matcher(allText);while (matcher.find()) {// 在輸入字符串a(chǎn)llText中查找與模式匹配的第一個(gè)子序列// 如果 提取到發(fā)票號(hào)碼,則設(shè)置發(fā)票號(hào)碼if (matcher.group("number") != null) {invoice.setNumber(matcher.group("number"));} else if (matcher.group("date") != null) {String rawDate = matcher.group("date"); // 發(fā)票日期,解析日期并設(shè)置日期try {SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy年MM月dd日");SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd");Date parsedDate = inputDateFormat.parse(rawDate);String formattedDate = outputDateFormat.format(parsedDate);invoice.setDate(formattedDate);} catch (ParseException e) {System.out.println("無(wú)法解析日期:" + rawDate);}}// 如果沒(méi)有提取到的話(huà)使用備用在進(jìn)行提取if (matcher.group("number") == null) {Matcher matcher2 = patternNumber.matcher(allText);if (matcher2.find()) {invoice.setNumber(matcher2.group("number"));}}if (matcher.group("date") == null) {Matcher matcher3 = patternDate.matcher(allText);if (matcher3.find()) {String rawDate = matcher3.group("date");try {SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyyMM月dd日");SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd");Date parsedDate = inputDateFormat.parse(rawDate);String formattedDate = outputDateFormat.format(parsedDate);invoice.setDate(formattedDate);} catch (Exception e) {System.out.println("無(wú)法解析日期:" + rawDate);}}}}}// 提取 金額、稅額等{Pattern pattern = Pattern.compile(REGULAR_B.getRegex()); // 金額、稅額提取正則,匹配形如“合計(jì)¥?金額¥?稅額”的文本Matcher matcher = pattern.matcher(allText);if (matcher.find()) {try {invoice.setAmount(new BigDecimal(matcher.group("amount")));} catch (Exception e) {// 不處理}try {invoice.setTaxAmount(new BigDecimal(matcher.group("taxAmount")));} catch (Exception e) {invoice.setTaxAmount(new BigDecimal(0));}}}// 如果沒(méi)有提取到,則再使用備用的正則進(jìn)行提取if (null == invoice.getAmount()) {Pattern pattern = Pattern.compile(REGULAR_B_1.getRegex());Matcher matcher = pattern.matcher(fullText);if (matcher.find()) {try {invoice.setAmount(new BigDecimal(matcher.group("amount")));} catch (Exception e) {invoice.setAmount(new BigDecimal(0));}try {invoice.setTaxAmount(new BigDecimal(matcher.group("taxAmount")));} catch (Exception e) {invoice.setTaxAmount(new BigDecimal(0));}}}invoice.setTotalAmount(invoice.getAmount().add(invoice.getTaxAmount()));// 先創(chuàng)建一個(gè)發(fā)票備注實(shí)例Note note = new Note();// 提取發(fā)票備注信息{// 提取購(gòu)方開(kāi)戶(hù)銀行Pattern patternBuyer = Pattern.compile(REGULAR_A_NOTE_BUYER.getRegex()); // 提取備注信息Pattern patternBuyerAccount = Pattern.compile(REGULAR_A_NOTE_BUYERACCOUNT.getRegex()); // 提取備注信息Pattern patternSeller = Pattern.compile(REGULAR_A_NOTE_SELLER.getRegex()); // 提取備注信息Pattern patternSellerAccount = Pattern.compile(REGULAR_A_NOTE_SELLERACCOUNT.getRegex()); // 提取備注信息Pattern patternPayee = Pattern.compile(REGULAR_A_NOTE_PAYEE.getRegex()); // 提取備注信息Pattern patternChecker = Pattern.compile(REGULAR_A_NOTE_CHECKER.getRegex()); // 提取備注信息Matcher matcher0 = patternBuyer.matcher(allText);if (matcher0.find()) {// 如果查詢(xún)到的話(huà)就設(shè)置備注信息try {note.setBuyer(new String(matcher0.group("buyer")));} catch (Exception e) {// 不處理}}Matcher matcher1 = patternBuyerAccount.matcher(allText);if (matcher1.find()) {// 如果查詢(xún)到的話(huà)就設(shè)置備注信息try {note.setBuyerAccount(new String(matcher1.group("buyerAccount")));} catch (Exception e) {// 不處理}}Matcher matcher2 = patternSeller.matcher(allText);if (matcher2.find()) {// 如果查詢(xún)到的話(huà)就設(shè)置備注信息try {note.setSeller(new String(matcher2.group("seller")));} catch (Exception e) {// 不處理}}Matcher matcher3 = patternSellerAccount.matcher(allText);if (matcher3.find()) {// 如果查詢(xún)到的話(huà)就設(shè)置備注信息try {note.setSellerAccount(new String(matcher3.group("sellerAccount")));} catch (Exception e) {// 不處理}}Matcher matcher4 = patternPayee.matcher(allText);if (matcher4.find()) {// 如果查詢(xún)到的話(huà)就設(shè)置備注信息try {note.setPayee(new String(matcher4.group("payee")));} catch (Exception e) {// 不處理}}Matcher matcher5 = patternChecker.matcher(allText);if (matcher5.find()) {// 如果查詢(xún)到的話(huà)就設(shè)置備注信息try {note.setChecker(new String(matcher5.group("checker")));} catch (Exception e) {// 不處理}}}invoice.setDetail(note);return invoice;}/*** 替換字符串中的空格、全角空格、冒號(hào)和特殊空白字符為標(biāo)準(zhǔn)字符。** @param str 要進(jìn)行替換的字符串* @return 替換后的字符串*/private static String replace(String str) {return str.replaceAll(" ", "").replaceAll(" ", "").replaceAll(":", ":").replaceAll(" ", "");}}

2.4 三層架構(gòu)

controller

package com.example.pdf.controller;import com.example.pdf.entity.NewInvoice;
import com.example.pdf.service.InvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;@RestController
@RequestMapping("/invoice")
public class InvoiceController {@AutowiredInvoiceService invoiceService;/*** @param*/
//    @PostMapping
//    public void insert() {
//        invoiceService.save();
//    }@CrossOrigin(origins = "http://localhost:8081", allowedHeaders = "*", allowCredentials = "true")@PostMapping("/upload")public ResponseEntity<Object> uploadFile(@RequestParam("file") MultipartFile file) {try {// 調(diào)用你的文件解析服務(wù)NewInvoice parsedData = invoiceService.parsePdfFile(file);// 返回解析后的數(shù)據(jù)return ResponseEntity.ok(parsedData);} catch (Exception e) {return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error parsing file");}}}

service

service

package com.example.pdf.service;import com.example.pdf.entity.NewInvoice;
import org.springframework.web.multipart.MultipartFile;public interface InvoiceService {
//     void save();NewInvoice parsePdfFile(MultipartFile file);
}

serviceImpl

package com.example.pdf.service.impl;import com.example.pdf.entity.NewInvoice;
import com.example.pdf.mapper.InvoiceMapper;
import com.example.pdf.service.InvoiceService;
import com.example.pdf.utils.PDF;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;@Service
public class InvoiceServiceImpl implements InvoiceService {@AutowiredInvoiceMapper invoiceMapper;
//
//    @Override
//    public void save(){
//        //獲得發(fā)票對(duì)象
//        InvoiceSubset invoiceSubset = extractInvoiceInformation("D:\\00-sqq\\idea\\test\\dzfp_24952000000116465179_深圳必維華法商品檢定有限公司東莞分公司_20240726105216.pdf");
//        //調(diào)用mapper將發(fā)票對(duì)象存入到數(shù)據(jù)庫(kù)中
//        invoiceMapper.save(invoiceSubset);
//    }/*** 調(diào)用解析文件的方法,解析上傳的文件* @param file* @return*/@Overridepublic NewInvoice parsePdfFile(MultipartFile file) {NewInvoice newInvoice = PDF.parsePdfFile(file);return newInvoice;}
}

mapper

因?yàn)闆](méi)有操作數(shù)據(jù)庫(kù),所以沒(méi)有使用到mapper層

http://www.risenshineclean.com/news/45234.html

相關(guān)文章:

  • 怎么查網(wǎng)站死鏈谷歌關(guān)鍵詞優(yōu)化怎么做
  • 廊坊seo網(wǎng)站管理seo是什么專(zhuān)業(yè)的課程
  • 網(wǎng)站地圖什么意思優(yōu)化seo軟件
  • wordpress圖標(biāo)代碼網(wǎng)站優(yōu)化排名資源
  • 中鐵建門(mén)戶(hù)網(wǎng)登錄入口優(yōu)化公司哪家好
  • 網(wǎng)站平臺(tái)推廣百度一下瀏覽器下載安裝
  • 做網(wǎng)站做好用的軟件網(wǎng)絡(luò)營(yíng)銷(xiāo)中的seo是指
  • java課程建設(shè)網(wǎng)站怎么做好網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣
  • 網(wǎng)站做第三方支付給企業(yè)做網(wǎng)站的公司
  • 網(wǎng)站建設(shè)前言和背景公司網(wǎng)站注冊(cè)流程和費(fèi)用
  • 大連網(wǎng)站建設(shè)方法寧波seo推廣推薦
  • 內(nèi)部網(wǎng)站搭建什么是白帽seo
  • 微信上發(fā)的鏈接網(wǎng)站怎么做的新聞?lì)^條今日新聞
  • 網(wǎng)站怎么制作成軟件青島百度網(wǎng)站排名優(yōu)化
  • 用vps做網(wǎng)站的流程三亞百度推廣公司電話(huà)
  • 怎么做淘寶網(wǎng)站賺錢(qián)技巧百度推廣技巧方法
  • 合肥市城鄉(xiāng)建設(shè)委員會(huì)網(wǎng)站無(wú)錫網(wǎng)站排名公司
  • 電子商務(wù)主要干什么seo推廣怎么做
  • 政府網(wǎng)站建設(shè)發(fā)展指引軟文吧
  • 怎樣用eclipse做網(wǎng)站品牌營(yíng)銷(xiāo)推廣方案怎么做
  • 網(wǎng)站建設(shè)需要會(huì)西安seo外包行者seo
  • 溫州電子商務(wù)網(wǎng)站建設(shè)windows優(yōu)化大師有哪些功能
  • 做網(wǎng)站內(nèi)容來(lái)源百度收錄提交網(wǎng)站后多久收錄
  • 宜春網(wǎng)站建設(shè)公司聯(lián)系方式百度seo 站長(zhǎng)工具
  • 沈陽(yáng)百度首頁(yè)優(yōu)化安徽seo優(yōu)化規(guī)則
  • 哈爾濱cms網(wǎng)站建設(shè)廣州網(wǎng)站建設(shè)系統(tǒng)
  • 建設(shè)一個(gè)導(dǎo)航網(wǎng)站百度搜索怎么優(yōu)化
  • 添加網(wǎng)站到百度中國(guó)十大軟件外包公司
  • 網(wǎng)站logo怎么做透明網(wǎng)絡(luò)運(yùn)營(yíng)課程培訓(xùn)班
  • 貴州有網(wǎng)站的企業(yè)杭州seo推廣服務(wù)