|
|
|
@ -39,14 +39,14 @@ import java.util.Objects;
|
|
|
|
|
public class MailTaskServiceImpl implements MailTaskService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传的文件后缀
|
|
|
|
|
* ext 文件类型分隔符 - 通配
|
|
|
|
|
*/
|
|
|
|
|
private static final String FILE_END = ".xlsx";
|
|
|
|
|
private static final String FILE_SPLIT = ".";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件路径的分隔
|
|
|
|
|
*/
|
|
|
|
|
private static final String FILE_SPLIT = ",";
|
|
|
|
|
private static final String FILE_PATH_SPLIT = ",";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 完成建立的文件状态码
|
|
|
|
@ -100,9 +100,16 @@ public class MailTaskServiceImpl implements MailTaskService {
|
|
|
|
|
// 生成通用随机文件夹存放每次的文件
|
|
|
|
|
String baseStr = RandomUtil.randomString(11) + File.separator;
|
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
|
String eachFilePath = buildFileWritePath(baseStr);
|
|
|
|
|
// 获取原来的文件后缀
|
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
|
|
if (StringUtils.isBlank(originalFilename)){
|
|
|
|
|
log.error("===================== [input file name is empty, please check ]===================");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String extName = FileUtil.extName(originalFilename);
|
|
|
|
|
String eachFilePath = buildFileWritePath(baseStr, extName);
|
|
|
|
|
pathBuilder.append(eachFilePath);
|
|
|
|
|
pathBuilder.append(FILE_SPLIT);
|
|
|
|
|
pathBuilder.append(FILE_PATH_SPLIT);
|
|
|
|
|
if (StringUtils.isBlank(eachFilePath)){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
@ -140,22 +147,22 @@ public class MailTaskServiceImpl implements MailTaskService {
|
|
|
|
|
/**
|
|
|
|
|
* 构建文件上传保存路径
|
|
|
|
|
*/
|
|
|
|
|
private String buildFileWritePath(String baseStr){
|
|
|
|
|
private String buildFileWritePath(String baseStr, String extName){
|
|
|
|
|
// 获取环境配置信息
|
|
|
|
|
OsInfo osInfo = SystemUtil.getOsInfo();
|
|
|
|
|
// 生成一个随机文件夹目录,方便整理和打包
|
|
|
|
|
if (osInfo.isWindows()){
|
|
|
|
|
FileUtil.mkdir(remoteLinkFileBasePathWindows + baseStr);
|
|
|
|
|
// 构建存储文件
|
|
|
|
|
return remoteLinkFileBasePathWindows + baseStr + RandomUtil.randomString(11) + FILE_END;
|
|
|
|
|
return remoteLinkFileBasePathWindows + baseStr + RandomUtil.randomString(11) + FILE_SPLIT + extName;
|
|
|
|
|
}else if (osInfo.isLinux()){
|
|
|
|
|
FileUtil.mkdir(remoteLinkFileBasePathLinux + baseStr);
|
|
|
|
|
// 构建存储文件
|
|
|
|
|
return remoteLinkFileBasePathLinux + baseStr + RandomUtil.randomString(11) + FILE_END;
|
|
|
|
|
return remoteLinkFileBasePathLinux + baseStr + RandomUtil.randomString(11) + FILE_SPLIT + extName;
|
|
|
|
|
}else if (osInfo.isMac()){
|
|
|
|
|
FileUtil.mkdir(remoteLinkFileBasePathMac + baseStr);
|
|
|
|
|
// 构建存储文件
|
|
|
|
|
return remoteLinkFileBasePathMac + baseStr + RandomUtil.randomString(11) + FILE_END;
|
|
|
|
|
return remoteLinkFileBasePathMac + baseStr + RandomUtil.randomString(11) + FILE_SPLIT + extName;
|
|
|
|
|
}else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
@ -170,7 +177,7 @@ public class MailTaskServiceImpl implements MailTaskService {
|
|
|
|
|
if (tempFileRecord!= null){
|
|
|
|
|
String filePaths = tempFileRecord.getFilePaths();
|
|
|
|
|
if (StringUtils.isNotBlank(filePaths)){
|
|
|
|
|
String[] split = filePaths.split(FILE_SPLIT);
|
|
|
|
|
String[] split = filePaths.split(FILE_PATH_SPLIT);
|
|
|
|
|
if (split.length > 0 && StringUtils.isNotBlank(split[0])){
|
|
|
|
|
String tempPath = StringUtils.substringBeforeLast(split[0], File.separator);
|
|
|
|
|
String zipPath = tempPath + ".zip";
|
|
|
|
|