|
|
@@ -251,29 +251,25 @@ public class FileServiceImpl implements FileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String delete(String filePath) {
|
|
|
- logger.info("request... " + filePath);
|
|
|
- if (StringUtils.isEmpty(filePath)) {
|
|
|
+ public String delete(String fileAbsolutePath) {
|
|
|
+ logger.info("request... " + fileAbsolutePath);
|
|
|
+ if (StringUtils.isEmpty(fileAbsolutePath)) {
|
|
|
throw new ReportException("参数不能为空:filePath");
|
|
|
}
|
|
|
- File file = new File(filePath);
|
|
|
+ File file = new File(fileAbsolutePath);
|
|
|
if (!file.exists()) {
|
|
|
- throw new ReportException("文件不存在,不必删除:" + filePath);
|
|
|
+ throw new ReportException("文件不存在,不必删除:" + fileAbsolutePath);
|
|
|
}
|
|
|
FileUtils.deleteDir(file);
|
|
|
- return filePath;
|
|
|
+ return fileAbsolutePath;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Map<String, Object>> listFiles(String fileRelativePath) {
|
|
|
- logger.info("request... " + fileRelativePath);
|
|
|
- // 初始目录为本地资源根路径
|
|
|
- String filePath = sysConf.getLocalBaseDir();
|
|
|
- if (!StringUtils.isEmpty(fileRelativePath)) {
|
|
|
- if (!fileRelativePath.startsWith("/")) {
|
|
|
- filePath += "/";
|
|
|
- }
|
|
|
- filePath += fileRelativePath;
|
|
|
+ public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) {
|
|
|
+ logger.info("request... " + filePath);
|
|
|
+ if (isAbsolutePath == null || !isAbsolutePath) {
|
|
|
+ // 初始目录为本地资源根路径
|
|
|
+ filePath = sysConf.getLocalBaseDir() + "/" + filePath;
|
|
|
}
|
|
|
final File file = new File(filePath);
|
|
|
if (!file.exists()) {
|
|
|
@@ -283,7 +279,7 @@ public class FileServiceImpl implements FileService {
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
// 如果是文件,直接获取文件信息
|
|
|
if (file.isFile()) {
|
|
|
- result.add(getFileInformation(file));
|
|
|
+ result.add(getFileInformation(file, isAbsolutePath));
|
|
|
} else {
|
|
|
File[] files = file.listFiles(fileFilter);
|
|
|
// 文件夹放在前面展示
|
|
|
@@ -296,8 +292,8 @@ public class FileServiceImpl implements FileService {
|
|
|
fileList.add(f);
|
|
|
}
|
|
|
}
|
|
|
- result.addAll(getFileInformations(directoryList));
|
|
|
- result.addAll(getFileInformations(fileList));
|
|
|
+ result.addAll(getFileInformations(directoryList, isAbsolutePath));
|
|
|
+ result.addAll(getFileInformations(fileList, isAbsolutePath));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
@@ -307,13 +303,15 @@ public class FileServiceImpl implements FileService {
|
|
|
*
|
|
|
* @param files
|
|
|
* 文件
|
|
|
- * @return 文件信息,包括name(String)、lastModified(String)、size(Long)、relativePath(
|
|
|
- * String)、isDirectory(Boolean)
|
|
|
+ * @param isAbsolutePath
|
|
|
+ * 文件路径是否为绝对路径
|
|
|
+ * @return 文件信息,包括name(String)、lastModified(String)、size(Long)、filePath(
|
|
|
+ * String,可能是相对路径,也可能是绝对路径,具体取决于isAbsolutePath)、isDirectory(Boolean)
|
|
|
*/
|
|
|
- private List<Map<String, Object>> getFileInformations(List<File> files) {
|
|
|
+ private List<Map<String, Object>> getFileInformations(List<File> files, Boolean isAbsolutePath) {
|
|
|
List<Map<String, Object>> informationList = new ArrayList<>();
|
|
|
for (File file : files) {
|
|
|
- informationList.add(getFileInformation(file));
|
|
|
+ informationList.add(getFileInformation(file, isAbsolutePath));
|
|
|
}
|
|
|
return informationList;
|
|
|
}
|
|
|
@@ -323,16 +321,22 @@ public class FileServiceImpl implements FileService {
|
|
|
*
|
|
|
* @param file
|
|
|
* 文件
|
|
|
- * @return 文件信息,包括name(String)、lastModified(String)、size(Long)、relativePath(
|
|
|
- * String)、isDirectory(Boolean)
|
|
|
+ * @param isAbsolutePath
|
|
|
+ * 文件路径是否为绝对路径
|
|
|
+ * @return 文件信息,包括name(String)、lastModified(String)、size(Long)、filePath(
|
|
|
+ * String,可能是相对路径,也可能是绝对路径,具体取决于isAbsolutePath)、isDirectory(Boolean)
|
|
|
*/
|
|
|
- private Map<String, Object> getFileInformation(File file) {
|
|
|
+ private Map<String, Object> getFileInformation(File file, Boolean isAbsolutePath) {
|
|
|
if (file == null || !file.exists()) {
|
|
|
return null;
|
|
|
}
|
|
|
Map<String, Object> information = new HashMap<>();
|
|
|
information.put("name", file.getName());
|
|
|
- information.put("relativePath", getRelativePath(file));
|
|
|
+ if (isAbsolutePath == null || !isAbsolutePath) {
|
|
|
+ information.put("filePath", getRelativePath(file));
|
|
|
+ } else {
|
|
|
+ information.put("filePath", file.getPath());
|
|
|
+ }
|
|
|
information.put("lastModified",
|
|
|
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified())));
|
|
|
if (file.isFile()) {
|
|
|
@@ -360,10 +364,10 @@ public class FileServiceImpl implements FileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean isFileValid(String filePath, String jrxmlFilePath) {
|
|
|
- if (!StringUtils.isEmpty(filePath) && !StringUtils.isEmpty(jrxmlFilePath)) {
|
|
|
- File file = new File(filePath);
|
|
|
- File jrxmlFile = new File(jrxmlFilePath);
|
|
|
+ public boolean isFileValid(String fileAbsolutePath, String jrxmlFileAbsolutePath) {
|
|
|
+ if (!StringUtils.isEmpty(fileAbsolutePath) && !StringUtils.isEmpty(jrxmlFileAbsolutePath)) {
|
|
|
+ File file = new File(fileAbsolutePath);
|
|
|
+ File jrxmlFile = new File(jrxmlFileAbsolutePath);
|
|
|
if (file.exists() && jrxmlFile.exists()) {
|
|
|
long interval = new Date().getTime() - file.lastModified();
|
|
|
// 剩余的有效期(最高为10分钟)
|
|
|
@@ -402,21 +406,22 @@ public class FileServiceImpl implements FileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int getPageSize(String pdfFilePath) {
|
|
|
+ public int getPageSize(String pdfFileAbsolutePath) {
|
|
|
try {
|
|
|
- return new PdfReader(pdfFilePath).getNumberOfPages();
|
|
|
+ return new PdfReader(pdfFileAbsolutePath).getNumberOfPages();
|
|
|
} catch (IOException e) {
|
|
|
throw new ReportException(e).setDetailedMessage(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void createPagedPdfFiles(String pdfFilePath) {
|
|
|
+ public void createPagedPdfFiles(String pdfFileAbsolutePath) {
|
|
|
try {
|
|
|
- PdfReader pdfReader = new PdfReader(pdfFilePath);
|
|
|
+ PdfReader pdfReader = new PdfReader(pdfFileAbsolutePath);
|
|
|
for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
|
|
|
Document document = new Document();
|
|
|
- FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath.replace(".pdf", "_" + i + ".pdf"));
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(
|
|
|
+ pdfFileAbsolutePath.replace(".pdf", "_" + i + ".pdf"));
|
|
|
PdfCopy pdfCopy = new PdfCopy(document, fileOutputStream);
|
|
|
document.open();
|
|
|
// 原pdf文件的每一页生成新的pdf
|