From dba2de2ddb4df0c631a3470f5f80e099f2418b4b Mon Sep 17 00:00:00 2001 From: xingze <13153582609@163.com> Date: Wed, 9 Apr 2025 11:53:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feature:=20=E6=BD=8D=E7=84=A6=E5=8F=91?= =?UTF-8?q?=E7=A5=A8=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../http/invoice/v1/InvoiceController.java | 53 +++++++++ .../framework/config/SecurityConfig.java | 1 + .../domain/dto/api/elephant/DDFPZXX.java | 11 ++ .../domain/dto/api/elephant/FILEITEMLIST.java | 25 +++++ ...ephantInvoiceApiV6ByInspurServiceImpl.java | 101 +++++++++++++++++- .../api/ElephantInvoiceApiV6ServiceImpl.java | 99 ++++++++++++++++- 6 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/FILEITEMLIST.java diff --git a/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java b/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java index ebcf097..7130ce9 100644 --- a/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java +++ b/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java @@ -447,6 +447,59 @@ public class InvoiceController { } + /** + * xml文件下载 + * @param id + * @param response + * @throws Exception + */ + @ApiImplicitParams({ + @ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.Void", example = "1130", required = true), + @ApiImplicitParam(name = "order", value = "请求体", dataType = "java.lang.Void", required = true)}) + @GetMapping("/invoice/xmlFileUrl/{id}") + public void xmlFileUrl(@PathVariable String id, HttpServletResponse response) throws Exception { + + if (StrUtil.isEmpty(id)) { + return; + } + InvoiceFile invoiceFile = invoiceFileMapper.selectInvoiceFileById(id); + if (BeanUtil.isEmpty(invoiceFile)) { + return; + } + if (StringUtils.isNotBlank(invoiceFile.getFileContent())){ + String fileName = invoiceFile.getFileName(); + String content = invoiceFile.getFileContent(); + + try { + byte[] buffer = Base64Decoder.decode(content); // 将文件流字符串转换为字节数组 + response.reset(); + response.setCharacterEncoding("UTF-8"); + response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xml"); + response.addHeader("Content-Length", "" + buffer.length); + response.setContentType("application/xml"); + OutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); + outputStream.write(buffer); + outputStream.flush(); + outputStream.close(); // 关闭输出流 + } catch (IOException ex) { + ex.printStackTrace(); + } + }else if (StringUtils.isBlank(invoiceFile.getFileContent()) && invoiceFile.getFileName().contains(Constants.DB_SAVE)){ + String fileUrl = invoiceFile.getFileName(); + StorageBaseAbstractService storageInstance = storageFactory.getStorageInstance(Constants.MINIO); + StorageUrlDTO storageUrlDTO = new StorageUrlDTO(); + storageUrlDTO.setStoragePath(fileUrl); + storageUrlDTO.setServiceProvider(Constants.MINIO); + storageUrlDTO.setContentType(Constants.APPLICATION_PDF); + AjaxResult file = storageInstance.getFile(storageUrlDTO); + if (file.isSuccess()){ + response.sendRedirect((String) file.getData()); + } + } + + } + + /** * 开票查询接口(订单号) */ diff --git a/jianshui-framework/src/main/java/com/jianshui/framework/config/SecurityConfig.java b/jianshui-framework/src/main/java/com/jianshui/framework/config/SecurityConfig.java index 15e7ecc..a2cbdc5 100644 --- a/jianshui-framework/src/main/java/com/jianshui/framework/config/SecurityConfig.java +++ b/jianshui-framework/src/main/java/com/jianshui/framework/config/SecurityConfig.java @@ -121,6 +121,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/invoice/deleteInvoice", "/invoice/findRedInfo", "/invoice/fileUrl/**", + "/invoice/xmlFileUrl/**", "/invoice/filePreview/**", "/invoice/queryRedConfirmationList", "/invoice/queryRedConfirmationItemList", diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/DDFPZXX.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/DDFPZXX.java index c4f9548..3aeea06 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/DDFPZXX.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/DDFPZXX.java @@ -17,6 +17,17 @@ public class DDFPZXX { private JDCTXX JDCTXX; // 机动车头信息 private List DDKZXX; // 订单扩展信息 private List DDMXXX; // 发票明细 + private List FILEITEMLIST; // 板式文件 + + + public List getFILEITEMLIST() { + return FILEITEMLIST; + } + + public void setFILEITEMLIST(List FILEITEMLIST) { + this.FILEITEMLIST = FILEITEMLIST; + } + public void setDDFPXX(DDFPXX DDFPXX) { this.DDFPXX = DDFPXX; } diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/FILEITEMLIST.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/FILEITEMLIST.java new file mode 100644 index 0000000..c25b624 --- /dev/null +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/FILEITEMLIST.java @@ -0,0 +1,25 @@ +package com.jianshui.invoice.domain.dto.api.elephant; + +public class FILEITEMLIST { + // 文件内容 + private String FILECONTENT; + // 文件类型 + private String WJLX; + + + public String getFILECONTENT() { + return FILECONTENT; + } + + public void setFILECONTENT(String FILECONTENT) { + this.FILECONTENT = FILECONTENT; + } + + public String getWJLX() { + return WJLX; + } + + public void setWJLX(String WJLX) { + this.WJLX = WJLX; + } +} diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java index beec2a7..3c544eb 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java @@ -498,6 +498,18 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi + // todo 潍焦获取服务信息 + List companyservicePropList = companyservicePropMapper.selectCompanyservicePropByCompanyid(companyservice.getCompanyid()); + if (CollectionUtils.isNotEmpty(companyservicePropList) && companyservicePropList.size() > 0) { + for (CompanyserviceProp companyserviceProp : companyservicePropList) { + if ("weijiao_invoice_key".equals(companyserviceProp.getKey())) { + queryBody.put("BSWJ", "0"); + queryBody.put("WJLX", "ALL"); + } + } + } + + // TODO kk:2024/7/8 寿仙谷定制 不需要文件流 // queryBody.put("BSWJ", "1"); @@ -663,7 +675,21 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi //配置文件存储类型0为数据库存储 if (Constants.STRING_0.equals(type)){ - saveFileUseDb(invoice, fileId, fileName,companyservice, ddfpxx); + // todo 潍焦单独处理 + boolean flag = false; + if (CollectionUtils.isNotEmpty(companyservicePropList) && companyservicePropList.size() > 0) { + for (CompanyserviceProp companyserviceProp : companyservicePropList) { + if ("weijiao_invoice_key".equals(companyserviceProp.getKey())) { + flag = true; + break; + } + } + } + if (flag){ + saveFileUseDbWeijiao(invoice, fileId, fileName, companyservice, ddfpxx,ddfpzxx); + }else { + saveFileUseDb(invoice, fileId, fileName, companyservice, ddfpxx); + } //配置文件存储类型1为oss存储 }else if (Constants.STRING_1.equals(type)){ saveFileUseOss(defaultStorage,invoice,ddfpxx); @@ -824,6 +850,79 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi } + + + + private void saveFileUseDbWeijiao(Invoice invoice, String fileId, String fileName, Companyservice companyservice, DDFPXX ddfpxx, DDFPZXX ddfpzxx) { + InvoiceFile invoiceFile = new InvoiceFile(); + List fileitemlist = ddfpzxx.getFILEITEMLIST(); + String pdfFileId = ""; + String xmlFileId = ""; + for (FILEITEMLIST fileitem : fileitemlist) { + if ("PDF".equals(fileitem.getWJLX())) { + pdfFileId = fileId + "pdf"; + invoiceFile.setFphm(ddfpxx.getFPHM() + "pdf"); + List invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); + if (invoiceFileList != null && invoiceFileList.size() > 0) { + invoiceFile = invoiceFileList.get(0); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + pdfFileId = invoiceFile.getFileId(); + invoiceFileMapper.updateInvoiceFile(invoiceFile); + } else { + invoiceFile.setId(pdfFileId); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileId(pdfFileId); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + invoiceFileMapper.insertInvoiceFile(invoiceFile); + } + } + + + if ("XML".equals(fileitem.getWJLX())) { + xmlFileId = fileId + "xml"; + invoiceFile.setFphm(ddfpxx.getFPHM() + "xml"); + List invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); + if (invoiceFileList != null && invoiceFileList.size() > 0) { + invoiceFile = invoiceFileList.get(0); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + xmlFileId = invoiceFile.getFileId(); + invoiceFileMapper.updateInvoiceFile(invoiceFile); + } else { + invoiceFile.setId(xmlFileId); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileId(xmlFileId); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + invoiceFileMapper.insertInvoiceFile(invoiceFile); + } + } + } + + + // 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流 + invoice.setInvoicePdfUrl(ELE_File_URL + pdfFileId + ";" + "http://127.0.0.1:8081/invoice/xmlFileUrl/" + xmlFileId); + ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); + CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc"); + if (secretIdProp != null) { + invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); + } + } + + + private void saveFileUseOss(String defaultStorage,Invoice invoice,DDFPXX ddfpxx) { if (StringUtils.isNotEmpty(defaultStorage) && StringUtils.isEmpty(invoice.getInvoicePdfUrl())) { try { diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java index 9acf43c..645e80e 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java @@ -542,6 +542,16 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { queryBody.put("NSRSBH", companyservice.getSellertax()); queryBody.put("DDQQLSH", originBillInfo.getSystemOrderno()); + // todo 潍焦获取服务信息 + List companyservicePropList = companyservicePropMapper.selectCompanyservicePropByCompanyid(companyservice.getCompanyid()); + if (CollectionUtils.isNotEmpty(companyservicePropList) && companyservicePropList.size() > 0) { + for (CompanyserviceProp companyserviceProp : companyservicePropList) { + if ("weijiao_invoice_key".equals(companyserviceProp.getKey())) { + queryBody.put("BSWJ", "0"); + queryBody.put("WJLX", "ALL"); + } + } + } debugLog("断点4", uuid, timestamp); @@ -706,7 +716,22 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { //配置文件存储类型0为数据库存储 if (Constants.STRING_0.equals(type)) { - saveFileUseDb(invoice, fileId, fileName, companyservice, ddfpxx); + + // todo 潍焦单独处理 + boolean flag = false; + if (CollectionUtils.isNotEmpty(companyservicePropList) && companyservicePropList.size() > 0) { + for (CompanyserviceProp companyserviceProp : companyservicePropList) { + if ("weijiao_invoice_key".equals(companyserviceProp.getKey())) { + flag = true; + break; + } + } + } + if (flag){ + saveFileUseDbWeijiao(invoice, fileId, fileName, companyservice, ddfpxx,ddfpzxx); + }else { + saveFileUseDb(invoice, fileId, fileName, companyservice, ddfpxx); + } //配置文件存储类型1为oss存储 } else if (Constants.STRING_1.equals(type)) { saveFileUseOss(defaultStorage, invoice, ddfpxx); @@ -934,6 +959,78 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } } + + private void saveFileUseDbWeijiao(Invoice invoice, String fileId, String fileName, Companyservice companyservice, DDFPXX ddfpxx, DDFPZXX ddfpzxx) { + InvoiceFile invoiceFile = new InvoiceFile(); + List fileitemlist = ddfpzxx.getFILEITEMLIST(); + String pdfFileId = ""; + String xmlFileId = ""; + for (FILEITEMLIST fileitem : fileitemlist) { + if ("PDF".equals(fileitem.getWJLX())) { + pdfFileId = fileId + "pdf"; + invoiceFile.setFphm(ddfpxx.getFPHM() + "pdf"); + List invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); + if (invoiceFileList != null && invoiceFileList.size() > 0) { + invoiceFile = invoiceFileList.get(0); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + pdfFileId = invoiceFile.getFileId(); + invoiceFileMapper.updateInvoiceFile(invoiceFile); + } else { + invoiceFile.setId(pdfFileId); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileId(pdfFileId); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + invoiceFileMapper.insertInvoiceFile(invoiceFile); + } + } + + + if ("XML".equals(fileitem.getWJLX())) { + xmlFileId = fileId + "xml"; + invoiceFile.setFphm(ddfpxx.getFPHM() + "xml"); + List invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); + if (invoiceFileList != null && invoiceFileList.size() > 0) { + invoiceFile = invoiceFileList.get(0); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + xmlFileId = invoiceFile.getFileId(); + invoiceFileMapper.updateInvoiceFile(invoiceFile); + } else { + invoiceFile.setId(xmlFileId); + invoiceFile.setFileContent(fileitem.getFILECONTENT()); + invoiceFile.setFileId(xmlFileId); + invoiceFile.setFileName(fileName); + invoiceFile.setCreateTime(new Date()); + invoiceFile.setIdentity(companyservice.getIdentity()); + invoiceFile.setTax(companyservice.getSellertax()); + invoiceFileMapper.insertInvoiceFile(invoiceFile); + } + } + } + + + // 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流 + invoice.setInvoicePdfUrl(ELE_File_URL + pdfFileId + ";" + "http://127.0.0.1:8081/invoice/xmlFileUrl/" + xmlFileId); + ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); + CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc"); + if (secretIdProp != null) { + invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); + } + } + + + + private void saveFileUseDb(Invoice invoice, String fileId, String fileName, Companyservice companyservice, DDFPXX ddfpxx) { InvoiceFile invoiceFile = new InvoiceFile(); invoiceFile.setFphm(ddfpxx.getFPHM()); From 75895d518d0187c62a4ff820c2abbb49af2d6c24 Mon Sep 17 00:00:00 2001 From: xingze <13153582609@163.com> Date: Wed, 9 Apr 2025 14:10:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feature:=20=E6=BD=8D=E7=84=A6=E5=8F=91?= =?UTF-8?q?=E7=A5=A8=E6=9F=A5=E8=AF=A2url=E5=8F=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/ElephantInvoiceApiV6ByInspurServiceImpl.java | 9 ++++----- .../impl/api/ElephantInvoiceApiV6ServiceImpl.java | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java index 3c544eb..c485ab4 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java @@ -912,13 +912,12 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi } - // 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流 - invoice.setInvoicePdfUrl(ELE_File_URL + pdfFileId + ";" + "http://127.0.0.1:8081/invoice/xmlFileUrl/" + xmlFileId); ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); - CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc"); - if (secretIdProp != null) { + CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "weijiao_invoice_key"); + invoice.setInvoicePdfUrl(ELE_File_URL + pdfFileId + ";" + secretIdProp.getValue() + xmlFileId); + /*if (secretIdProp != null) { invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); - } + }*/ } diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java index 645e80e..9d285e8 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java @@ -1019,13 +1019,13 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } - // 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流 - invoice.setInvoicePdfUrl(ELE_File_URL + pdfFileId + ";" + "http://127.0.0.1:8081/invoice/xmlFileUrl/" + xmlFileId); + ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); - CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc"); - if (secretIdProp != null) { + CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "weijiao_invoice_key"); + invoice.setInvoicePdfUrl(ELE_File_URL + pdfFileId + ";" + secretIdProp.getValue() + xmlFileId); + /*if (secretIdProp != null) { invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); - } + }*/ }