发票文件存储:本地上传修改为调用已有方法

beta
路明慧 1 year ago
parent d4f8db9c61
commit 09d9d173ed
  1. 2
      jianshui-admin/src/main/resources/application.yml
  2. 27
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java

@ -122,7 +122,5 @@ srm:
invoice: invoice:
file: file:
save: save:
#本地存储时配置路径使用
path: /invoice/file/upload
# 文件上传方式 0:数据库 1:oss 2:本地 # 文件上传方式 0:数据库 1:oss 2:本地
type: 1 type: 1

@ -626,7 +626,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
saveFileUseOss(defaultStorage,invoice,ddfpxx); saveFileUseOss(defaultStorage,invoice,ddfpxx);
//配置文件存储类型2为本地存储 //配置文件存储类型2为本地存储
}else if (Constants.STRING_2.equals(type)){ }else if (Constants.STRING_2.equals(type)){
saveFileUseLocal(environment,invoice,ddfpxx,fileName); saveFileUseLocal(invoice,ddfpxx);
} }
} }
} }
@ -724,26 +724,29 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
return response; return response;
} }
private void saveFileUseLocal(Environment environment,Invoice invoice,DDFPXX ddfpxx,String fileName) { private void saveFileUseLocal(Invoice invoice,DDFPXX ddfpxx) {
try { try {
IStorageService service = storageFactory.getStorageInstance(Constants.LOCAL);
byte[] pdfBytes = Base64.decode(ddfpxx.getPDFZJL()); byte[] pdfBytes = Base64.decode(ddfpxx.getPDFZJL());
AjaxResult upload = service.upload(pdfBytes, "");
//文件名称 //文件名称
fileName = fileName+ Constants.POINT + (StringUtils.equals(ddfpxx.getZJLLX(), Constants.PDF_UPCASE) ? Constants.PDF : Constants.OFD); // 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; // String targetFilePath = environment.getProperty(Constants.INVOICE_FILE_SAVE_PATH) + fileName;
// 创建一个输出流对象,用于将数据写入到本地文件,如果文件存在则会覆盖 // 创建一个输出流对象,用于将数据写入到本地文件,如果文件存在则会覆盖
FileOutputStream fileOutputStream = new FileOutputStream(targetFilePath, false); // FileOutputStream fileOutputStream = new FileOutputStream(targetFilePath, false);
// 直接将字节数组写入到输出流(即本地文件) // 直接将字节数组写入到输出流(即本地文件)
fileOutputStream.write(pdfBytes); // fileOutputStream.write(pdfBytes);
// 完成写入后关闭流 // 完成写入后关闭流
fileOutputStream.close(); // fileOutputStream.close();
//拼接url //拼接url
IStorageService service = storageFactory.getStorageInstance(Constants.LOCAL);
AjaxResult upload = service.upload(targetFilePath, "");
StorageUrlDTO uploadResultDTO = (StorageUrlDTO) upload.get(Constants.DATA); StorageUrlDTO uploadResultDTO = (StorageUrlDTO) upload.get(Constants.DATA);
@ -760,10 +763,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
if (StringUtils.equals(ddfpxx.getZJLLX(), Constants.OFD_UPCASE)) { if (StringUtils.equals(ddfpxx.getZJLLX(), Constants.OFD_UPCASE)) {
invoice.setcOfdUrl(pdfUrl); invoice.setcOfdUrl(pdfUrl);
} }
}catch (UnsupportedEncodingException e){
log.error("编码转换异常",e);
}catch (IOException e){
log.error("文件写入异常",e);
}catch (Exception e){ }catch (Exception e){
log.error("文件保存异常",e); log.error("文件保存异常",e);
} }

Loading…
Cancel
Save