Browse Source

修改临时文件输出路径

master
CMM 1 year ago
parent
commit
0bda38035e
2 changed files with 13 additions and 11 deletions
  1. +6
    -5
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java
  2. +7
    -6
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/utils/PdfUtils.java

+ 6
- 5
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java View File

@@ -2,6 +2,7 @@ package com.ningdatech.pmapi.todocenter.manage;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -1059,11 +1060,11 @@ public class TodoCenterManage {
}

// 删除输出文件夹下的临时文件
java.io.File resourcesPath = new java.io.File("pmapi/src/main/resources");
String reportPath = resourcesPath.getCanonicalPath();
String path = reportPath + "/template/fileout";
java.io.File directory = new java.io.File(path);
FileUtils.cleanDirectory(directory);
java.io.File directory = new java.io.File("");
//pdf输出路径
String filePath = directory.getAbsolutePath() + java.io.File.separator + "fileout";
java.io.File directoryPath = new java.io.File(filePath);
FileUtils.cleanDirectory(directoryPath);
} catch (IOException e) {
log.error(e.getMessage());
}


+ 7
- 6
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/utils/PdfUtils.java View File

@@ -1,6 +1,8 @@
package com.ningdatech.pmapi.todocenter.utils;


import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.StrUtil;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
@@ -43,14 +45,13 @@ public class PdfUtils {
try {
File directory = new File("");
//pdf输出路径
String absolutePath = directory.getAbsolutePath();
String linkPath = File.separator + "pmapi" + File.separator + "src" + File.separator + "main" + File.separator + "resources";
String filePath = absolutePath + linkPath + File.separator + "template" + File.separator + "fileout";
String filePath = directory.getAbsolutePath() + File.separator + "fileout";
String templatePath = ResourceUtil.getResource("").getPath();
if(!new File(filePath).exists()){
new File(filePath).mkdir();
}
//字体格式
String FONT = absolutePath + linkPath + File.separator + "template" + File.separator + "simsun.ttc";
String FONT = templatePath + File.separator + "template" + File.separator + "simsun.ttc";
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(templateHtmlInputStream, StandardCharsets.UTF_8));
String line;
@@ -103,9 +104,9 @@ public class PdfUtils {
// 返回生成的pdf文件字节数组
return readBytes(inputStream);
} catch (IOException e) {
throw new BizException("生成pdf文件失败!");
throw new BizException("生成pdf文件失败!" + e.getMessage());
} catch (DocumentException e) {
throw new BizException("生成pdf文件失败!");
throw new BizException("生成pdf文件失败!" +e.getMessage());
} finally {
try {
if (null != inputStream) {


Loading…
Cancel
Save