提交修改
This commit is contained in:
parent
525e8dd14e
commit
b6858d489a
@ -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<String> words = new ArrayList<>();
|
||||||
|
ApiR<RecognizePdfResponse> 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<RecognizePdfResponseBody.RecognizePdfResponseBodyDataWordsInfo> wordsInfo = responseBodyData.getWordsInfo();
|
||||||
|
|
||||||
|
if(CollectionUtils.isNotEmpty(wordsInfo)){
|
||||||
|
for (RecognizePdfResponseBody.RecognizePdfResponseBodyDataWordsInfo dataWordsInfo : wordsInfo) {
|
||||||
|
words.add(dataWordsInfo.getWord());
|
||||||
|
}
|
||||||
|
resp.setWords(words);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return R.ok().setData(resp);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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<RecognizeQuotaInvoiceResponse> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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<RecognizeTicketInvoiceResponse> 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<RecognizeTicketInvoiceResponseBody.RecognizeTicketInvoiceResponseBodyDataResults> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@ -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 {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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 {
|
||||||
|
}
|
||||||
@ -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<String> words ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user