|
|
|
@ -4,10 +4,12 @@ import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author: LeiJiaXin
|
|
|
|
@ -20,29 +22,36 @@ public class FileUtils {
|
|
|
|
|
|
|
|
|
|
// pdf地址
|
|
|
|
|
public static String pdfPath;
|
|
|
|
|
|
|
|
|
|
@Value("${file.pdfPath}")
|
|
|
|
|
public void setPdfPath(String pdfPath) {
|
|
|
|
|
FileUtils.pdfPath = pdfPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getPdfPath() {
|
|
|
|
|
return pdfPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// image地址
|
|
|
|
|
public static String imagePath;
|
|
|
|
|
|
|
|
|
|
@Value("${file.imagePath}")
|
|
|
|
|
public void setImagePath(String imagePath) {
|
|
|
|
|
FileUtils.imagePath = imagePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getImagePath() {
|
|
|
|
|
return imagePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 错误文件地址
|
|
|
|
|
public static String errorPath;
|
|
|
|
|
@Value("${file.errorPath}")
|
|
|
|
|
public void setErrorPath(String errorPath) {
|
|
|
|
|
FileUtils.errorPath = errorPath;
|
|
|
|
|
}
|
|
|
|
|
public static String getErrorPath() {
|
|
|
|
|
return errorPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static File createFile(String fileType, String inpNo, String visitId, String path) throws IOException {
|
|
|
|
|
File localFile = null;
|
|
|
|
|
try {
|
|
|
|
@ -82,6 +91,47 @@ public class FileUtils {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String createFile(String interfaceName, String param,String message) throws IOException {
|
|
|
|
|
File localFile = null;
|
|
|
|
|
OutputStreamWriter write = null;
|
|
|
|
|
BufferedWriter writer = null;
|
|
|
|
|
try {
|
|
|
|
|
//生成文件地址
|
|
|
|
|
LocalDate date = LocalDate.now();
|
|
|
|
|
String fileDirName = null;
|
|
|
|
|
fileDirName = errorPath+"/" + date.getYear() + "/" + date.getMonthValue() + "/" + interfaceName;
|
|
|
|
|
// 如果参数不为空时,再增加一级目录
|
|
|
|
|
if(!ObjectUtils.isEmpty(param)){
|
|
|
|
|
fileDirName += "_" + param;
|
|
|
|
|
}
|
|
|
|
|
//判断是否有该文件夹 否则创建
|
|
|
|
|
File fileDir = new File(fileDirName);
|
|
|
|
|
if (!fileDir.exists()) {
|
|
|
|
|
fileDir.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
String fileName = fileDir + "/" + UUID.randomUUID() + ".txt";
|
|
|
|
|
localFile = new File(fileName);
|
|
|
|
|
if (!localFile.exists()) {
|
|
|
|
|
localFile.createNewFile();
|
|
|
|
|
}
|
|
|
|
|
write = new OutputStreamWriter(new FileOutputStream(localFile));
|
|
|
|
|
writer = new BufferedWriter(write);
|
|
|
|
|
writer.write(message);
|
|
|
|
|
writer.flush();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}finally {
|
|
|
|
|
if(!ObjectUtils.isEmpty(write)){
|
|
|
|
|
write.close();
|
|
|
|
|
}
|
|
|
|
|
if(!ObjectUtils.isEmpty(writer)){
|
|
|
|
|
writer.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return localFile.getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void deleteImageFile(File file) {
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
System.out.println(file.getAbsolutePath() + "文件不存在");
|
|
|
|
|