|
|
|
@ -11,6 +11,7 @@ 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.baomidou.mybatisplus.extension.api.R; |
|
|
|
|
import com.google.gson.Gson; |
|
|
|
|
import com.google.gson.JsonArray; |
|
|
|
|
import com.google.gson.JsonObject; |
|
|
|
@ -53,6 +54,7 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument; |
|
|
|
|
import org.apache.pdfbox.rendering.PDFRenderer; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
|
import org.springframework.ui.Model; |
|
|
|
@ -2087,10 +2089,10 @@ 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 void QuerySdInvoiceFileDownload(HttpServletResponse response, @RequestBody JSONObject jsonParam) throws Exception { |
|
|
|
|
public R QuerySdInvoiceFileDownload(HttpServletResponse response, @RequestBody JSONObject jsonParam) throws Exception { |
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(jsonParam)) { |
|
|
|
|
return; |
|
|
|
|
return R.failed("参数为空!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String ty = jsonParam.get("ty") != null ? jsonParam.get("ty").toString() : ""; |
|
|
|
@ -2099,52 +2101,76 @@ public class InvoiceController { |
|
|
|
|
|
|
|
|
|
InvoiceFile invoiceFile = invoiceFileMapper.selectInvoiceFileById(id); |
|
|
|
|
if (BeanUtil.isEmpty(invoiceFile) || StrUtil.isEmpty(invoiceFile.getFileContent())) { |
|
|
|
|
return; |
|
|
|
|
return R.failed("发票未查询到!"); |
|
|
|
|
} |
|
|
|
|
String fileName = invoiceFile.getFileName(); |
|
|
|
|
String fphm = invoiceFile.getFphm(); |
|
|
|
|
String tax = invoiceFile.getTax(); |
|
|
|
|
String identity = invoiceFile.getIdentity(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
JSONObject decryptResult = new JSONObject(); |
|
|
|
|
decryptResult.put("XHFSBH", tax); |
|
|
|
|
decryptResult.put("ENTID", ""); |
|
|
|
|
decryptResult.put("SDFPHM", fphm); |
|
|
|
|
decryptResult.put("WJLX", ty); |
|
|
|
|
JSONObject decryptResult = new JSONObject(); |
|
|
|
|
decryptResult.put("XHFSBH", tax); |
|
|
|
|
decryptResult.put("ENTID", ""); |
|
|
|
|
decryptResult.put("SDFPHM", fphm); |
|
|
|
|
decryptResult.put("WJLX", ty); |
|
|
|
|
|
|
|
|
|
IInvoiceApiService invoiceService = new ElephantInvoiceApiV6ServiceImpl(); |
|
|
|
|
Companyservice companyservice = new Companyservice(); |
|
|
|
|
companyservice.setCompanyid(Long.valueOf(identity)); |
|
|
|
|
HXResponse result = invoiceService.QuerySdInvoiceFile(decryptResult, companyservice); |
|
|
|
|
|
|
|
|
|
IInvoiceApiService invoiceService = new ElephantInvoiceApiV6ServiceImpl(); |
|
|
|
|
Companyservice companyservice = new Companyservice(); |
|
|
|
|
companyservice.setCompanyid(Long.valueOf(identity)); |
|
|
|
|
HXResponse result = invoiceService.QuerySdInvoiceFile(decryptResult, companyservice); |
|
|
|
|
String data = result.get("data") != null ? result.get("data").toString() : ""; |
|
|
|
|
|
|
|
|
|
String data = result.get("data") != null ? result.get("data").toString() : ""; |
|
|
|
|
Gson gson = new Gson(); |
|
|
|
|
JsonObject jsonObject = gson.fromJson(data, JsonObject.class); |
|
|
|
|
|
|
|
|
|
Gson gson = new Gson(); |
|
|
|
|
JsonObject jsonObject = gson.fromJson(data, JsonObject.class); |
|
|
|
|
JsonArray fileItemList = jsonObject.getAsJsonArray("fileitemlist"); |
|
|
|
|
|
|
|
|
|
JsonArray fileItemList = jsonObject.getAsJsonArray("FILEITEMLIST"); |
|
|
|
|
String fileContent = ""; |
|
|
|
|
if(!fileItemList.isEmpty()){ |
|
|
|
|
JsonObject fileItem = fileItemList.get(0).getAsJsonObject(); |
|
|
|
|
fileContent = fileItem.get("FILECONTENT").getAsString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String fileContent = ""; |
|
|
|
|
if(!fileItemList.isEmpty()){ |
|
|
|
|
JsonObject fileItem = fileItemList.get(0).getAsJsonObject(); |
|
|
|
|
fileContent = fileItem.get("FILECONTENT").getAsString(); |
|
|
|
|
} |
|
|
|
|
Map<String,Object> resMap = new HashMap<>(); |
|
|
|
|
resMap.put("fileContent",fileContent); |
|
|
|
|
resMap.put("ty","." + ty); |
|
|
|
|
return R.ok(resMap); |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 根据文件类型获取文件扩展名
|
|
|
|
|
private String getFileExtensionByType(String type) { |
|
|
|
|
if (StringUtils.isEmpty(type)) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
switch (type) { |
|
|
|
|
case "pdf": |
|
|
|
|
return ".pdf"; |
|
|
|
|
case "odf": |
|
|
|
|
return ".odf"; |
|
|
|
|
case "xml": |
|
|
|
|
return ".xml"; |
|
|
|
|
default: |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 根据文件类型获取Content-Type
|
|
|
|
|
private String getContentTypeByType(String type) { |
|
|
|
|
if (StringUtils.isEmpty(type)) { |
|
|
|
|
return MediaType.APPLICATION_OCTET_STREAM_VALUE; |
|
|
|
|
} |
|
|
|
|
switch (type) { |
|
|
|
|
case "pdf": |
|
|
|
|
return MediaType.APPLICATION_PDF_VALUE; |
|
|
|
|
case "odf": |
|
|
|
|
return "application/vnd.oasis.opendocument.text"; |
|
|
|
|
case "xml": |
|
|
|
|
return MediaType.APPLICATION_XML_VALUE; |
|
|
|
|
default: |
|
|
|
|
return MediaType.APPLICATION_OCTET_STREAM_VALUE; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|