From b6858d489a9c93cce01048d692194a6cebd85beb Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Sat, 15 Mar 2025 14:28:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/RecognizePdfController.java | 70 ++++++++++++++ .../tax/RecognizeQuotaInvoiceController.java | 71 ++++++++++++++ .../tax/RecognizeTicketInvoiceController.java | 84 +++++++++++++++++ .../request/file/RecognizePdfReq.java | 34 +++++++ .../request/tax/RecognizeQuotaInvoiceReq.java | 20 ++++ .../tax/RecognizeTicketInvoiceReq.java | 12 +++ .../resp/file/RecognizePdfResp.java | 21 +++++ .../resp/tax/RecognizeQuotaInvoiceResp.java | 62 +++++++++++++ .../resp/tax/RecognizeTicketInvoiceResp.java | 93 +++++++++++++++++++ 9 files changed, 467 insertions(+) create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/file/RecognizePdfController.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeQuotaInvoiceController.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeTicketInvoiceController.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/request/file/RecognizePdfReq.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeQuotaInvoiceReq.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeTicketInvoiceReq.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/resp/file/RecognizePdfResp.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeQuotaInvoiceResp.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeTicketInvoiceResp.java diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/file/RecognizePdfController.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/file/RecognizePdfController.java new file mode 100644 index 0000000..dfefb98 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/file/RecognizePdfController.java @@ -0,0 +1,70 @@ +package com.heyu.api.controller.certificate.file; + + +import com.aliyun.ocr20191230.models.RecognizePdfResponse; +import com.aliyun.ocr20191230.models.RecognizePdfResponseBody; +import com.heyu.api.alibaba.handle.common.text.ARecognizePdfHandle; +import com.heyu.api.alibaba.request.common.text.ARecognizePdfRequest; +import com.heyu.api.alibaba.request.common.text.ARecognizeQrCodeRequest; +import com.heyu.api.controller.BaseController; +import com.heyu.api.controller.request.file.RecognizePdfReq; +import com.heyu.api.controller.resp.file.RecognizePdfResp; +import com.heyu.api.data.annotation.CacheResult; +import com.heyu.api.data.annotation.NotIntercept; +import com.heyu.api.data.utils.ApiR; +import com.heyu.api.data.utils.R; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +/*** + *https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizePdf + * + * + * PDF 识别能力可以对 PDF 上的文字进行结构化识别。 + */ +@Slf4j +@RestController +@RequestMapping("/pdf") +@NotIntercept +public class RecognizePdfController extends BaseController { + + + @Autowired + private ARecognizePdfHandle recognizePdfHandle; + + + @RequestMapping("/recognize") + @CacheResult + public R recognize(RecognizePdfReq req) { + ARecognizePdfRequest aRecognizePdfRequest = new ARecognizePdfRequest(); + aRecognizePdfRequest.setImageUrl(req.getFileURL()); + aRecognizePdfRequest.setImageBase64(req.getFileBase64()); + RecognizePdfResp resp = new RecognizePdfResp(); + List words = new ArrayList<>(); + ApiR aR = recognizePdfHandle.handle(aRecognizePdfRequest); + if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) { + RecognizePdfResponse response = aR.getData(); + RecognizePdfResponseBody responseBody = response.getBody(); + RecognizePdfResponseBody.RecognizePdfResponseBodyData responseBodyData = responseBody.getData(); + + List wordsInfo = responseBodyData.getWordsInfo(); + + if(CollectionUtils.isNotEmpty(wordsInfo)){ + for (RecognizePdfResponseBody.RecognizePdfResponseBodyDataWordsInfo dataWordsInfo : wordsInfo) { + words.add(dataWordsInfo.getWord()); + } + resp.setWords(words); + } + } + return R.ok().setData(resp); + + + } + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeQuotaInvoiceController.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeQuotaInvoiceController.java new file mode 100644 index 0000000..f205bbf --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeQuotaInvoiceController.java @@ -0,0 +1,71 @@ +package com.heyu.api.controller.certificate.tax; + + +import com.aliyun.ocr20191230.models.RecognizeQuotaInvoiceResponse; +import com.aliyun.ocr20191230.models.RecognizeQuotaInvoiceResponseBody; +import com.heyu.api.alibaba.handle.common.text.ARecognizeQuotaInvoiceHandle; +import com.heyu.api.alibaba.request.common.text.ARecognizeQuotaInvoiceRequest; +import com.heyu.api.controller.BaseController; +import com.heyu.api.controller.request.tax.RecognizeQuotaInvoiceReq; +import com.heyu.api.controller.resp.tax.RecognizeQuotaInvoiceResp; +import com.heyu.api.data.annotation.CacheResult; +import com.heyu.api.data.annotation.NotIntercept; +import com.heyu.api.data.utils.ApiR; +import com.heyu.api.data.utils.R; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/*** + * + * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeQuotaInvoice?tab=DOC&lang=JAVA + * + * + * 功能描述 + * 定额发票识别能力可以对定额发票上的发票号码、发票代码、发票金额进行结构化识别。 + */ +@Slf4j +@RestController +@RequestMapping("/ticket/invoice") +@NotIntercept +public class RecognizeQuotaInvoiceController extends BaseController { + + + @Autowired + private ARecognizeQuotaInvoiceHandle recognizeQuotaInvoiceHandle; + + + @RequestMapping("/recognize") + @CacheResult + public R recognize(RecognizeQuotaInvoiceReq request) { + RecognizeQuotaInvoiceResp resp = new RecognizeQuotaInvoiceResp(); + + ARecognizeQuotaInvoiceRequest aRecognizeQuotaInvoiceRequest = new ARecognizeQuotaInvoiceRequest(); + aRecognizeQuotaInvoiceRequest.setImageBase64(request.getImageBase64()); + aRecognizeQuotaInvoiceRequest.setImageUrl(request.getImageUrl()); + + ApiR aR = recognizeQuotaInvoiceHandle.handle(aRecognizeQuotaInvoiceRequest); + if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) { + + RecognizeQuotaInvoiceResponseBody body = aR.getData().getBody(); + RecognizeQuotaInvoiceResponseBody.RecognizeQuotaInvoiceResponseBodyData responseBodyData = body.getData(); + RecognizeQuotaInvoiceResponseBody.RecognizeQuotaInvoiceResponseBodyDataContent responseBodyDataContent = responseBodyData.getContent(); + + + resp.setSumAmount(responseBodyDataContent.getSumAmount()); + resp.setInvoiceCode(responseBodyDataContent.getInvoiceCode()); + resp.setInvoiceNo(responseBodyDataContent.getInvoiceNo()); + resp.setInvoiceAmount(responseBodyDataContent.getInvoiceAmount()); + resp.setInvoiceDetails(responseBodyDataContent.getInvoiceDetails()); + + return R.ok().setData(resp); + + + } + return R.ok(); + } + + +} \ No newline at end of file diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeTicketInvoiceController.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeTicketInvoiceController.java new file mode 100644 index 0000000..df78ee0 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/certificate/tax/RecognizeTicketInvoiceController.java @@ -0,0 +1,84 @@ +package com.heyu.api.controller.certificate.tax; + + +import com.aliyun.ocr20191230.models.RecognizeTicketInvoiceResponse; +import com.aliyun.ocr20191230.models.RecognizeTicketInvoiceResponseBody; +import com.heyu.api.alibaba.handle.common.text.ARecognizeTicketInvoiceHandle; +import com.heyu.api.alibaba.request.common.text.ARecognizeTicketInvoiceRequest; +import com.heyu.api.alibaba.request.common.text.ARecognizeVATInvoiceRequest; +import com.heyu.api.controller.BaseController; +import com.heyu.api.controller.request.tax.RecognizeTicketInvoiceReq; +import com.heyu.api.controller.resp.tax.RecognizeTicketInvoiceResp; +import com.heyu.api.data.annotation.CacheResult; +import com.heyu.api.data.annotation.NotIntercept; +import com.heyu.api.data.utils.ApiR; +import com.heyu.api.data.utils.R; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collection; +import java.util.List; + +/*** + * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeTicketInvoice + * + * 增值税发票卷票识别 RecognizeTicketInvoice + */ + + +@Slf4j +@RestController +@RequestMapping("/ticket/invoice") +@NotIntercept +public class RecognizeTicketInvoiceController extends BaseController { + + + @Autowired + private ARecognizeTicketInvoiceHandle recognizeTicketInvoiceHandle; + + @RequestMapping("/recognize") + @CacheResult + public R recognize(RecognizeTicketInvoiceReq request) { + + + RecognizeTicketInvoiceResp resp = new RecognizeTicketInvoiceResp(); + + ARecognizeTicketInvoiceRequest + recognizeTicketInvoiceRequest = new ARecognizeTicketInvoiceRequest(); + recognizeTicketInvoiceRequest.setImageBase64(request.getImageBase64()); + recognizeTicketInvoiceRequest.setImageUrl(request.getImageUrl()); + ApiR aR = recognizeTicketInvoiceHandle.handle(recognizeTicketInvoiceRequest); + if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) { + RecognizeTicketInvoiceResponse response = aR.getData(); + + RecognizeTicketInvoiceResponseBody responseBody = response.getBody(); + RecognizeTicketInvoiceResponseBody.RecognizeTicketInvoiceResponseBodyData responseBodyData = responseBody.getData(); + List results = responseBodyData.getResults(); + + if (CollectionUtils.isNotEmpty(results)) { + RecognizeTicketInvoiceResponseBody.RecognizeTicketInvoiceResponseBodyDataResults responseBodyDataResults = results.get(0); + RecognizeTicketInvoiceResponseBody.RecognizeTicketInvoiceResponseBodyDataResultsContent responseBodyDataResultsContent = responseBodyDataResults.getContent(); + + resp.setInvoiceCode(responseBodyDataResultsContent.getInvoiceCode()); + resp.setInvoiceNumber(responseBodyDataResultsContent.getInvoiceNumber()); + resp.setInvoiceDate(responseBodyDataResultsContent.getInvoiceDate()); + resp.setAntiFakeCode(responseBodyDataResultsContent.getAntiFakeCode()); + resp.setPayeeName(responseBodyDataResultsContent.getPayeeName()); + resp.setPayerRegisterNo(responseBodyDataResultsContent.getPayerRegisterNo()); + resp.setSumAmount(responseBodyDataResultsContent.getSumAmount()); + resp.setType(responseBodyDataResults.getType()); + return R.ok().setData(resp); + } + + + } + + + return R.ok(); + } + + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/request/file/RecognizePdfReq.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/request/file/RecognizePdfReq.java new file mode 100644 index 0000000..49b9f75 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/request/file/RecognizePdfReq.java @@ -0,0 +1,34 @@ +package com.heyu.api.controller.request.file; + + +import com.heyu.api.data.dto.BaseRequest; +import lombok.Data; + + +/*** + * + * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizePdf + */ +@Data +public class RecognizePdfReq extends BaseRequest { + + + /*** + * 文件url + * + * 文件 URL 地址。推荐使用上海地域的 OSS 链接,对于文件在本地或者非上海地域 OSS 链接的情况,请参见文件 URL 处理。 + * + * 示例值: + * https://viapi-test.oss-cn-shanghai.aliyuncs.com/ocr/xxxx.pdf + * + * + * + */ + private String fileURL; + + /*** + * 文件base64 编码 + */ + private String fileBase64; + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeQuotaInvoiceReq.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeQuotaInvoiceReq.java new file mode 100644 index 0000000..0c37825 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeQuotaInvoiceReq.java @@ -0,0 +1,20 @@ +package com.heyu.api.controller.request.tax; + + +import com.heyu.api.controller.request.CommonRequest; +import com.heyu.api.data.dto.BaseRequest; + +/*** + * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeQuotaInvoice?tab=DEMO + *Recognizel icketinvoice + * + * 定额发票识别 + * + * RecognizeQuotalnvoice + * + */ +public class RecognizeQuotaInvoiceReq extends CommonRequest { + + + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeTicketInvoiceReq.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeTicketInvoiceReq.java new file mode 100644 index 0000000..90875af --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/request/tax/RecognizeTicketInvoiceReq.java @@ -0,0 +1,12 @@ +package com.heyu.api.controller.request.tax; + + +import com.heyu.api.controller.request.CommonRequest; +import lombok.Data; + +/*** + * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeTicketInvoice + */ +@Data +public class RecognizeTicketInvoiceReq extends CommonRequest { +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/file/RecognizePdfResp.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/file/RecognizePdfResp.java new file mode 100644 index 0000000..7dfbc2d --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/file/RecognizePdfResp.java @@ -0,0 +1,21 @@ +package com.heyu.api.controller.resp.file; + + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class RecognizePdfResp { + + + /*** + * 返回pdf 文件内容 + */ + private List words ; + + + + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeQuotaInvoiceResp.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeQuotaInvoiceResp.java new file mode 100644 index 0000000..13d7721 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeQuotaInvoiceResp.java @@ -0,0 +1,62 @@ +package com.heyu.api.controller.resp.tax; + + +import com.heyu.api.data.dto.BaseResp; +import lombok.Data; + +/*** + * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeQuotaInvoice?tab=DOC&lang=JAVA + * + * + * 定额发票识别 + * + * RecognizeQuotalnvoice + */ +@Data +public class RecognizeQuotaInvoiceResp extends BaseResp { + + + /*** + * 小写金额。 + * + * 示例值: + * 10 + */ + + public String invoiceAmount; + + + /*** + * 发票代码。 + * + * 示例值: + * 144031800103 + */ + public String invoiceCode; + + /*** + * 发票代码解析。 + * + * 示例值: + * 税务局代码:国税,行政区划代码:深圳市,年份:2018,发票行业代码:None,发票类别代码:None,金额版:万元版,批次号:03 + */ + public String invoiceDetails; + + /*** + * 发票号码。 + * + * 示例值: + * 40637706 + */ + public String invoiceNo; + + /*** + * 大写金额。 + * + * 示例值: + * 壹拾元整 + */ + public String sumAmount; + + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeTicketInvoiceResp.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeTicketInvoiceResp.java new file mode 100644 index 0000000..7888581 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/resp/tax/RecognizeTicketInvoiceResp.java @@ -0,0 +1,93 @@ +package com.heyu.api.controller.resp.tax; + + +import com.heyu.api.data.dto.BaseResp; +import lombok.Data; + + +/*** + * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeTicketInvoice + * + * + * 增值税发票卷票识别 RecognizeTicketInvoice + */ +@Data +public class RecognizeTicketInvoiceResp extends BaseResp { + + /*** + *发票代码。 + * + * 示例值: + * 044031860107 + */ + private String invoiceCode; + + + /**** + * 发票号码。 + * + * 示例值: + * 09267581 + */ + private String invoiceNumber; + + + /*** + * 开票日期。 + * + * 示例值: + * 2018-09-20 + */ + private String invoiceDate; + + + /*** + *校验码。 + * + * 示例值: + * 81931914902643039780 + */ + private String antiFakeCode; + + + /*** + * 销售方名称。 + * + * 示例值: + * 深圳市xxxx有限公司 + */ + private String payeeName; + + + /*** + *购买方税号。 + * + * 示例值: + * 91440300MA5EXWHW6F + */ + private String payerRegisterNo; + + + /*** + * 总价。 + * + * 示例值: + */ + private String sumAmount; + + + /*** + * 票据类型。支持识别以下几种: + * + * 增值税发票 + * 出租车票 + * 定额发票 + * 机动车销售发票 + * 卷票 + * 示例值: + * 卷票 + */ + private String type; + + +}