| | |
| | | |
| | | @Override |
| | | public ErpPurchaseInvoiceOcrRespVO ocrInvoice(ErpPurchaseInvoiceOcrReqVO reqVO) { |
| | | File tempFile = null; |
| | | try { |
| | | // 1. 下载文件 |
| | | SystemStorageBlobDO blob = blobService.getStorageBlob(reqVO.getBlobId()); |
| | |
| | | return errorResp("不支持的文件类型,请上传 PDF/图片文件"); |
| | | } |
| | | |
| | | // 3. 获取文件字节 |
| | | tempFile = blobService.getPublicFile(blob.getUidFilename(), blob.getResourceKey()); |
| | | if (tempFile == null || !tempFile.exists()) { |
| | | // 3. 获取文件字节。这里是磁盘上真实存储的那份 blob,不是临时副本,读完不能删。 |
| | | File blobFile = blobService.getPublicFile(blob.getUidFilename(), blob.getResourceKey()); |
| | | if (blobFile == null || !blobFile.exists()) { |
| | | return errorResp("文件读取失败"); |
| | | } |
| | | byte[] fileBytes = Files.readAllBytes(tempFile.toPath()); |
| | | byte[] fileBytes = Files.readAllBytes(blobFile.toPath()); |
| | | if (fileBytes.length == 0) { |
| | | return errorResp("文件内容为空,无法识别"); |
| | | } |
| | |
| | | } catch (Exception e) { |
| | | log.warn("AI OCR 识别发票失败,blobId={}", reqVO.getBlobId(), e); |
| | | return errorResp("AI 识别暂时不可用,请手动录入"); |
| | | } finally { |
| | | if (tempFile != null && tempFile.exists()) { |
| | | tempFile.delete(); |
| | | } |
| | | } |
| | | } |
| | | |