|
@@ -4844,6 +4844,70 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public R getExcelPdf(ExcelEditCallback callback) throws Exception {
|
|
|
|
+
|
|
|
|
+ //以id查询清表 生成pdf
|
|
|
|
+ if(StringUtils.isEmpty(callback.getKey())){
|
|
|
|
+ return R.fail("没有清表id");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String id = callback.getKey();
|
|
|
|
+
|
|
|
|
+ String file_path = FileUtils.getSysLocalFileUrl();
|
|
|
|
+ String pdfPath = file_path + "/pdf//" + id + ".pdf";
|
|
|
|
+ String excelPath = file_path + "/pdf//" + id + ".xlsx";
|
|
|
|
+ File tabPdf = ResourceUtil.getFile(pdfPath);
|
|
|
|
+ if (tabPdf.exists()) {
|
|
|
|
+ tabPdf.delete();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取清表信息
|
|
|
|
+ ExcelTab excelTab = this.getById(id);
|
|
|
|
+ if (excelTab == null) {
|
|
|
|
+ return R.fail("未获取到清表信息");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取excel流 和 html流
|
|
|
|
+ InputStream exceInp = null;
|
|
|
|
+ if(StringUtils.isNotEmpty(callback.getUrl())){
|
|
|
|
+ exceInp = Files.newInputStream(new File(callback.getUrl()).toPath());
|
|
|
|
+ }else{
|
|
|
|
+ exceInp = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Workbook workbook = null;
|
|
|
|
+ int index = excelTab.getFileUrl().lastIndexOf(".");
|
|
|
|
+ String suffix = excelTab.getFileUrl().substring(index);
|
|
|
|
+
|
|
|
|
+ if (".xls".equalsIgnoreCase(suffix)) {
|
|
|
|
+ workbook = new XSSFWorkbook(exceInp);
|
|
|
|
+ } else if (".xlsx".equalsIgnoreCase(suffix)) {
|
|
|
|
+ workbook = new XSSFWorkbook(exceInp);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //输出流
|
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(excelPath);
|
|
|
|
+ workbook.write(outputStream);
|
|
|
|
+ FileUtils.excelToPdf(excelPath, pdfPath);
|
|
|
|
+
|
|
|
|
+ //如果有临时文件 先删除临时文件
|
|
|
|
+ if(StringUtils.isNotEmpty(callback.getUrl())){
|
|
|
|
+ File file = new File(callback.getUrl());
|
|
|
|
+ if(file.exists()){
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //把pdf上传到oss 以清表id为文件名称,确保一个清表只有一个pdf
|
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFile(callback.getKey() + "_excel.pdf",pdfPath);
|
|
|
|
+ if(bladeFile != null){
|
|
|
|
+ return R.data(bladeFile.getLink());
|
|
|
|
+ }
|
|
|
|
+ return R.fail("上传oss失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
// @Override
|
|
// @Override
|
|
// public R getPriWbsPdfByPId(Long pkeyId) throws Exception {
|
|
// public R getPriWbsPdfByPId(Long pkeyId) throws Exception {
|
|
// // 1. 获取文件存储路径
|
|
// // 1. 获取文件存储路径
|