|
|
|
@ -80,6 +80,8 @@ import org.springframework.stereotype.Component; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.security.InvalidKeyException; |
|
|
|
@ -612,70 +614,24 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
if(ddfpxx.getPDFZJL() != null && StrUtil.isNotEmpty(ddfpxx.getPDFZJL())){ |
|
|
|
|
String fphm = ddfpxx.getFPHM(); |
|
|
|
|
if(StrUtil.isNotEmpty(fphm)){ |
|
|
|
|
InvoiceFile invoiceFile = new InvoiceFile(); |
|
|
|
|
invoiceFile.setFphm(ddfpxx.getFPHM()); |
|
|
|
|
List<InvoiceFile> invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); |
|
|
|
|
if(invoiceFileList != null && invoiceFileList.size() > 0){ |
|
|
|
|
invoiceFile = invoiceFileList.get(0); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileName(fileName); |
|
|
|
|
invoiceFile.setCreateTime(new Date()); |
|
|
|
|
invoiceFile.setIdentity(companyservice.getIdentity()); |
|
|
|
|
invoiceFile.setTax(companyservice.getSellertax()); |
|
|
|
|
fileId = invoiceFile.getFileId(); |
|
|
|
|
fileName = invoiceFile.getFileName(); |
|
|
|
|
invoiceFileMapper.updateInvoiceFile(invoiceFile); |
|
|
|
|
}else{ |
|
|
|
|
invoiceFile.setId(fileId); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileId(fileId); |
|
|
|
|
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 + 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); |
|
|
|
|
Environment environment = SpringUtils.getBean(Environment.class); |
|
|
|
|
|
|
|
|
|
String type = environment.getProperty(Constants.INVOICE_FILE_SAVE_TYPE); |
|
|
|
|
|
|
|
|
|
//配置文件存储类型0为数据库存储
|
|
|
|
|
if (Constants.STRING_0.equals(type)){ |
|
|
|
|
saveFileUseDb(invoice, fileId, fileName,companyservice, ddfpxx); |
|
|
|
|
//配置文件存储类型1为oss存储
|
|
|
|
|
}else if (Constants.STRING_1.equals(type)){ |
|
|
|
|
saveFileUseOss(defaultStorage,invoice,ddfpxx); |
|
|
|
|
//配置文件存储类型2为本地存储
|
|
|
|
|
}else if (Constants.STRING_2.equals(type)){ |
|
|
|
|
saveFileUseLocal(environment,invoice,ddfpxx,fileName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*if (StringUtils.isNotEmpty(defaultStorage) && StringUtils.isEmpty(invoice.getInvoicePdfUrl())) { |
|
|
|
|
try { |
|
|
|
|
IStorageService service = storageFactory.getStorageInstance(defaultStorage); |
|
|
|
|
String pdfzjl = ddfpxx.getPDFZJL(); |
|
|
|
|
String zjllx = ddfpxx.getZJLLX(); |
|
|
|
|
String pdfName = IdUtils.fastSimpleUUID() + "." + (StringUtils.equals(zjllx, "PDF") ? "pdf" : "ofd"); |
|
|
|
|
if (StringUtils.isNotEmpty(pdfzjl)) { |
|
|
|
|
byte[] pdfBytes = Base64.decode(pdfzjl); |
|
|
|
|
String invoicePath = Constants.RESOURCE_PREFIX + "/invoice/" + pdfName; |
|
|
|
|
AjaxResult uploadResult = service.upload(pdfBytes, invoicePath); |
|
|
|
|
if (uploadResult.isSuccess()) { |
|
|
|
|
StorageUrlDTO uploadResultDTO = (StorageUrlDTO) uploadResult.get("data"); |
|
|
|
|
String fileUrl = configService.selectConfigByKey("file_url"); |
|
|
|
|
if (StringUtils.isNotEmpty(fileUrl)) { |
|
|
|
|
uploadResultDTO.setContentType(zjllx.toLowerCase()); |
|
|
|
|
String pdfUrl = fileUrl + "/" + Base64.encode(JSONObject.toJSONString(uploadResultDTO)); |
|
|
|
|
invoice.setInvoicePdfUrl(pdfUrl); |
|
|
|
|
invoice.setInvoiceFileStorage(uploadResultDTO.getServiceProvider()); |
|
|
|
|
if (StringUtils.equals(zjllx, "OFD")) { |
|
|
|
|
invoice.setcOfdUrl(pdfUrl); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (JianshiSystemErrorException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
debugLog("断点13", uuid, timestamp); |
|
|
|
|
|
|
|
|
|
if (invoice.getId() != null) { |
|
|
|
@ -768,6 +724,117 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
return response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void saveFileUseLocal(Environment environment,Invoice invoice,DDFPXX ddfpxx,String fileName) { |
|
|
|
|
try { |
|
|
|
|
byte[] pdfBytes = Base64.decode(ddfpxx.getPDFZJL()); |
|
|
|
|
//文件名称
|
|
|
|
|
fileName = fileName+ Constants.POINT + (StringUtils.equals(ddfpxx.getZJLLX(), Constants.PDF_UPCASE) ? Constants.PDF : Constants.OFD); |
|
|
|
|
//文件写入路径
|
|
|
|
|
String targetFilePath = environment.getProperty(Constants.INVOICE_FILE_SAVE_PATH) + fileName; |
|
|
|
|
// 创建一个输出流对象,用于将数据写入到本地文件,如果文件存在则会覆盖
|
|
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(targetFilePath, false); |
|
|
|
|
|
|
|
|
|
// 直接将字节数组写入到输出流(即本地文件)
|
|
|
|
|
fileOutputStream.write(pdfBytes); |
|
|
|
|
|
|
|
|
|
// 完成写入后关闭流
|
|
|
|
|
fileOutputStream.close(); |
|
|
|
|
//拼接url
|
|
|
|
|
|
|
|
|
|
IStorageService service = storageFactory.getStorageInstance(Constants.LOCAL); |
|
|
|
|
|
|
|
|
|
AjaxResult upload = service.upload(targetFilePath, ""); |
|
|
|
|
|
|
|
|
|
StorageUrlDTO uploadResultDTO = (StorageUrlDTO) upload.get(Constants.DATA); |
|
|
|
|
|
|
|
|
|
String fileUrl = configService.selectConfigByKey(Constants.FILE_URL); |
|
|
|
|
|
|
|
|
|
// uploadResultDTO.setStoragePath(targetFilePath);
|
|
|
|
|
uploadResultDTO.setContentType(ddfpxx.getZJLLX().toLowerCase()); |
|
|
|
|
|
|
|
|
|
Base64.encode(JSONObject.toJSONString(uploadResultDTO)); |
|
|
|
|
|
|
|
|
|
String pdfUrl = fileUrl + Constants.ESCAPE + Base64.encode(JSONObject.toJSONString(uploadResultDTO)); |
|
|
|
|
invoice.setInvoicePdfUrl(pdfUrl); |
|
|
|
|
invoice.setInvoiceFileStorage(uploadResultDTO.getServiceProvider()); |
|
|
|
|
if (StringUtils.equals(ddfpxx.getZJLLX(), Constants.OFD_UPCASE)) { |
|
|
|
|
invoice.setcOfdUrl(pdfUrl); |
|
|
|
|
} |
|
|
|
|
}catch (UnsupportedEncodingException e){ |
|
|
|
|
log.error("编码转换异常",e); |
|
|
|
|
}catch (IOException e){ |
|
|
|
|
log.error("文件写入异常",e); |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
log.error("文件保存异常",e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void saveFileUseOss(String defaultStorage,Invoice invoice,DDFPXX ddfpxx) { |
|
|
|
|
if (StringUtils.isNotEmpty(defaultStorage) && StringUtils.isEmpty(invoice.getInvoicePdfUrl())) { |
|
|
|
|
try { |
|
|
|
|
IStorageService service = storageFactory.getStorageInstance(defaultStorage); |
|
|
|
|
String pdfzjl = ddfpxx.getPDFZJL(); |
|
|
|
|
String zjllx = ddfpxx.getZJLLX(); |
|
|
|
|
String pdfName = IdUtils.fastSimpleUUID() + "." + (StringUtils.equals(zjllx, "PDF") ? "pdf" : "ofd"); |
|
|
|
|
if (StringUtils.isNotEmpty(pdfzjl)) { |
|
|
|
|
byte[] pdfBytes = Base64.decode(pdfzjl); |
|
|
|
|
String invoicePath = Constants.RESOURCE_PREFIX + "/invoice/" + pdfName; |
|
|
|
|
AjaxResult uploadResult = service.upload(pdfBytes, invoicePath); |
|
|
|
|
if (uploadResult.isSuccess()) { |
|
|
|
|
StorageUrlDTO uploadResultDTO = (StorageUrlDTO) uploadResult.get("data"); |
|
|
|
|
String fileUrl = configService.selectConfigByKey("file_url"); |
|
|
|
|
if (StringUtils.isNotEmpty(fileUrl)) { |
|
|
|
|
uploadResultDTO.setContentType(zjllx.toLowerCase()); |
|
|
|
|
String pdfUrl = fileUrl + "/" + Base64.encode(JSONObject.toJSONString(uploadResultDTO)); |
|
|
|
|
invoice.setInvoicePdfUrl(pdfUrl); |
|
|
|
|
invoice.setInvoiceFileStorage(uploadResultDTO.getServiceProvider()); |
|
|
|
|
if (StringUtils.equals(zjllx, "OFD")) { |
|
|
|
|
invoice.setcOfdUrl(pdfUrl); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (JianshiSystemErrorException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void saveFileUseDb(Invoice invoice,String fileId,String fileName,Companyservice companyservice,DDFPXX ddfpxx) { |
|
|
|
|
InvoiceFile invoiceFile = new InvoiceFile(); |
|
|
|
|
invoiceFile.setFphm(ddfpxx.getFPHM()); |
|
|
|
|
List<InvoiceFile> invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); |
|
|
|
|
if(invoiceFileList != null && invoiceFileList.size() > 0){ |
|
|
|
|
invoiceFile = invoiceFileList.get(0); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileName(fileName); |
|
|
|
|
invoiceFile.setCreateTime(new Date()); |
|
|
|
|
invoiceFile.setIdentity(companyservice.getIdentity()); |
|
|
|
|
invoiceFile.setTax(companyservice.getSellertax()); |
|
|
|
|
fileId = invoiceFile.getFileId(); |
|
|
|
|
fileName = invoiceFile.getFileName(); |
|
|
|
|
invoiceFileMapper.updateInvoiceFile(invoiceFile); |
|
|
|
|
}else{ |
|
|
|
|
invoiceFile.setId(fileId); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileId(fileId); |
|
|
|
|
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 + 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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 批量发票查询接口 |
|
|
|
|
* |
|
|
|
|