|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|