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 75937d7..6cbfc82 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 @@ -5,12 +5,15 @@ import cn.hutool.core.codec.Base64Decoder; import cn.hutool.core.codec.Base64Encoder; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.jianshui.common.core.domain.AjaxResult; import com.jianshui.common.core.domain.entity.Companyservice; import com.jianshui.common.enums.ErrorCode; @@ -28,6 +31,7 @@ import com.jianshui.invoice.domain.ele.FindRedInfoDTO; import com.jianshui.invoice.domain.ele.HZSQDMessage; import com.jianshui.invoice.mapper.InvoiceBackMapper; import com.jianshui.invoice.mapper.InvoiceFileMapper; +import com.jianshui.invoice.service.impl.api.ElephantInvoiceApiV6ServiceImpl; import com.jianshui.invoice.task.AddInvoiceBatchTask; import com.jianshui.invoice.task.InvoiceBackTask; import com.jianshui.invoice.utils.elephant.ElephantUtils; @@ -2083,33 +2087,63 @@ public class InvoiceController { @ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.Void", example = "1130", required = true), @ApiImplicitParam(name = "order", value = "请求体", dataType = "java.lang.Void", required = true)}) @PostMapping({"/api/invoice/v1/QuerySdInvoiceFileDownload/{identity}", "/api/invoice/v1/QuerySdInvoiceFileDownload", "/invoice/QuerySdInvoiceFileDownload"}) - public Object QuerySdInvoiceFileDownload(HttpServletRequest request, String identity) throws Exception { + public void QuerySdInvoiceFileDownload(HttpServletResponse response, @RequestBody JSONObject jsonParam) throws Exception { - if (StringUtils.isEmpty(identity)) { - return AjaxResult.error(ErrorCode.EMPTY_IDENTITY); + if (ObjectUtil.isEmpty(jsonParam)) { + return; } - Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity); - if (companyservice == null) { - return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND); + String ty = jsonParam.get("ty") != null ? jsonParam.get("ty").toString() : ""; + String id = jsonParam.get("id") != null ? jsonParam.get("id").toString() : ""; + + + InvoiceFile invoiceFile = invoiceFileMapper.selectInvoiceFileById(id); + if (BeanUtil.isEmpty(invoiceFile) || StrUtil.isEmpty(invoiceFile.getFileContent())) { + return; } + String fileName = invoiceFile.getFileName(); + String fphm = invoiceFile.getFphm(); + String tax = invoiceFile.getTax(); + String identity = invoiceFile.getIdentity(); - // 获得入口报文适配器 - String requestAdapterKey = serviceManageService.getRequestAdapterKey("invoice", companyservice.getCompanyid()); - IInvoiceRequestService invoiceRequestService = invoiceRequestFactory.getService(requestAdapterKey); - JSONObject decryptResult = invoiceRequestService.decrypt(request, companyservice, ""); + try { + JSONObject decryptResult = new JSONObject(); + decryptResult.put("XHFSBH", tax); + decryptResult.put("ENTID", ""); + decryptResult.put("SDFPHM", fphm); + decryptResult.put("WJLX", ty); - // 获得请求实例,并且进行扣费 - String serviceKey = serviceManageService.getCompanyServiceSupplier("invoice", companyservice.getCompanyid()); - serviceManageService.companyConsume("invoice", companyservice.getCompanyid()); + IInvoiceApiService invoiceService = new ElephantInvoiceApiV6ServiceImpl(); + Companyservice companyservice = new Companyservice(); + companyservice.setCompanyid(Long.valueOf(identity)); + HXResponse result = invoiceService.QuerySdInvoiceFile(decryptResult, companyservice); - IInvoiceApiService invoiceService = invoiceServiceFactory.getService(serviceKey); - HXResponse result = invoiceService.QuerySdInvoiceFile(decryptResult, companyservice); + String data = result.get("data") != null ? result.get("data").toString() : ""; - String responseAdapterKey = serviceManageService.getResponseAdapterKey("invoice", companyservice.getCompanyid()); - IInvoiceResponseService invoiceResponseService = invoiceResponseFactory.getService(responseAdapterKey); + Gson gson = new Gson(); + JsonObject jsonObject = gson.fromJson(data, JsonObject.class); - return invoiceResponseService.response(result, companyservice, ""); + JsonArray fileItemList = jsonObject.getAsJsonArray("FILEITEMLIST"); + + String fileContent = ""; + if(!fileItemList.isEmpty()){ + JsonObject fileItem = fileItemList.get(0).getAsJsonObject(); + fileContent = fileItem.get("FILECONTENT").getAsString(); + } + + byte[] buffer = Base64Decoder.decode(fileContent); // 将文件流字符串转换为字节数组 + response.reset(); + response.setCharacterEncoding("UTF-8"); + response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".pdf"); + response.addHeader("Content-Length", "" + buffer.length); + response.setContentType("application/pdf"); + OutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); + outputStream.write(buffer); + outputStream.flush(); + outputStream.close(); // 关闭输出流 + } catch (IOException ex) { + ex.printStackTrace(); + } } @@ -2135,7 +2169,7 @@ public class InvoiceController { String content = invoiceFile.getFileContent(); String co = convertPdfBase64ToImageBase64(content); - return "data:image/jpeg;base64,"+co; + return "data:image/jpeg;base64," + co; } diff --git a/jianshui-admin/src/main/resources/application-dev.yml b/jianshui-admin/src/main/resources/application-dev.yml index 8b86b47..fe1cfe0 100644 --- a/jianshui-admin/src/main/resources/application-dev.yml +++ b/jianshui-admin/src/main/resources/application-dev.yml @@ -91,6 +91,8 @@ ele_check_url: https://openapi.zncspt.com/api/ elephant_entcode_check: 91370102MA3UD2FG21 # 文件下载地址 elephant_invoice_file: http://127.0.0.1:8081/invoice/fileUrl/ +# 德才定制 放到数据库 +#elephant_invoice_file_dc: http://127.0.0.1:8088/sdFile/ # 大象V6数电对应平台地址 ele_url_v6: https://js.ele12.com/order-api #ele_url_v6: http://192.168.3.60:18108/order-api diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/InvoiceFile.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/InvoiceFile.java index d5b29ca..500308f 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/InvoiceFile.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/InvoiceFile.java @@ -38,7 +38,18 @@ public class InvoiceFile extends BaseEntity @Excel(name = "税号") private String tax; - public void setId(String id) + @Excel(name = "发票号码") + private String fphm; + + public String getFphm() { + return fphm; + } + + public void setFphm(String fphm) { + this.fphm = fphm; + } + + public void setId(String id) { this.id = id; } 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 40b33e0..bde248a 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 @@ -65,6 +65,7 @@ import com.jianshui.system.domain.InvoiceAllApiLog; import com.jianshui.system.mapper.CompanyserviceMapper; import com.jianshui.system.mapper.CompanyservicePropMapper; import com.jianshui.system.mapper.InvoiceAllApiLogMapper; +import com.jianshui.system.service.ICompanyservicePropService; import com.jianshui.system.service.ISysConfigService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; @@ -128,10 +129,12 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { private InvoiceFileMapper invoiceFileMapper; private static String ELE_File_URL; + private static String ELE_File_URL_DC; static { Environment environment = SpringUtils.getBean(Environment.class); ELE_File_URL = environment.getProperty("elephant_invoice_file"); + ELE_File_URL_DC = environment.getProperty("elephant_invoice_file_dc"); } /** @@ -619,6 +622,13 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流 invoice.setInvoicePdfUrl(ELE_File_URL + fileId); + ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); + CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc"); + if (secretIdProp != null) { + invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); + } + + } // end @@ -1294,10 +1304,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { */ @Override public HXResponse uploadRedInfo(Redinfo redinfo, Companyservice companyservice) { - - // TODO: 2023/10/23 一步的红字上传接口 - - // 处理redinfo redinfo.setCompanyId(companyservice.getCompanyid()); redinfo.setSystemOrderno(IdUtils.randomSystemOrderno()); diff --git a/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceFileMapper.xml b/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceFileMapper.xml index 1b75f3a..c2e74c3 100644 --- a/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceFileMapper.xml +++ b/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceFileMapper.xml @@ -12,10 +12,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, file_id, file_name, file_content, create_time, identity, tax from invoice_file + select id, file_id, file_name, file_content, create_time, identity, tax,fphm from invoice_file @@ -44,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time, identity, tax, + fphm, #{id}, @@ -53,6 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{createTime}, #{identity}, #{tax}, + #{fphm}, @@ -65,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time = #{createTime}, identity = #{identity}, tax = #{tax}, + fphm = #{fphm}, where id = #{id} diff --git a/jianshui-ui/src/api/sdInvoicefile/sdinvoicefile.js b/jianshui-ui/src/api/sdInvoicefile/sdinvoicefile.js index 475a87e..0550122 100644 --- a/jianshui-ui/src/api/sdInvoicefile/sdinvoicefile.js +++ b/jianshui-ui/src/api/sdInvoicefile/sdinvoicefile.js @@ -8,3 +8,12 @@ export function getFilePreview(data) { data: data }) } + +// 下载文件 +export function downloadFile(data) { + return request({ + url: '/invoice/QuerySdInvoiceFileDownload', + method: 'post', + data: data + }) +} diff --git a/jianshui-ui/src/views/sdinvoicefile/index.vue b/jianshui-ui/src/views/sdinvoicefile/index.vue index 2b385ba..fee16c2 100644 --- a/jianshui-ui/src/views/sdinvoicefile/index.vue +++ b/jianshui-ui/src/views/sdinvoicefile/index.vue @@ -5,9 +5,9 @@
- 下载PDF - 下载OFD - 下载XML + 下载PDF + 下载OFD + 下载XML
发票图片损坏 @@ -17,13 +17,14 @@