邮件支持任意格式的打包上传下载

master
土豆兄弟 4 years ago
parent 46495d9e10
commit c377c2ca51

@ -62,7 +62,7 @@ public class SendBigDataTask {
/**
* ,
*/
public static final String BASE_URL_CHAR_NUMBER = "123456789";
public static final String BASE_URL_CHAR_NUMBER = "12345678910";
/**
* url
@ -235,7 +235,7 @@ public class SendBigDataTask {
private String preSendReqAddress(String tag) {
StringBuilder builder = new StringBuilder();
// 处理环境选择问题, 只接受单个 a, b, c 中的任意一个输入,如果不输入就进行随机返回
tag = (StringUtils.isNotBlank(tag) && StringUtils.countMatches(BASE_URL_CHAR_NUMBER, tag.trim()) == 1)?
tag = (StringUtils.isNotBlank(tag) && StringUtils.countMatches(BASE_URL_CHAR_NUMBER, tag.trim()) >= 1)?
tag.trim(): String.valueOf(RandomUtil.randomChar(BASE_URL_CHAR_NUMBER));
// 拼接成需要的URL进行返回
builder.append(host)

@ -42,11 +42,12 @@ public class MailTaskController {
}
// 构建一次性链接
String result = mailTaskService.buildOnceLinkForInputFile(files);
return getOnceLinktResponseEntity(result);
}
/**
* ,
* ,
*
* @param filePath
* @return

@ -1,6 +1,5 @@
package me.zhengjie.modules.mailtask.service;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
@ -12,7 +11,7 @@ public interface MailTaskService {
/**
*
*
* @param files
* @param files -
* @return
*/
String buildOnceLinkForInputFile(MultipartFile[] files);

@ -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";

@ -56,7 +56,7 @@ public class SendRecordTask {
/**
* ,
*/
public static final String BASE_URL_CHAR_NUMBER = "123456789";
public static final String BASE_URL_CHAR_NUMBER = "12345678910";
/**
* url
@ -191,7 +191,7 @@ public class SendRecordTask {
private String preSendReqAddress(String tag) {
StringBuilder builder = new StringBuilder();
// 处理环境选择问题, 只接受单个 a, b, c 中的任意一个输入,如果不输入就进行随机返回
tag = (StringUtils.isNotBlank(tag) && StringUtils.countMatches(BASE_URL_CHAR_NUMBER, tag.trim()) == 1)?
tag = (StringUtils.isNotBlank(tag) && StringUtils.countMatches(BASE_URL_CHAR_NUMBER, tag.trim()) >= 1)?
tag.trim(): String.valueOf(RandomUtil.randomChar(BASE_URL_CHAR_NUMBER));
// 拼接成需要的URL进行返回
builder.append(host)

@ -5,7 +5,7 @@ spring:
freemarker:
check-template-location: false
profiles:
active: test
active: dev
jackson:
time-zone: GMT+8
data:

@ -77,7 +77,7 @@
<root level="INFO">
<!-- TODO prod 环境去掉std -->
<!--<appender-ref ref="stdAppender"/>-->
<appender-ref ref="fileAppender"/>
<appender-ref ref="stdAppender"/>
<!--<appender-ref ref="fileAppender"/>-->
</root>
</configuration>

@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON;
import me.zhengjie.modules.abmessage.domain.AbMessage;
import me.zhengjie.utils.DateUtil;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.StringUtils;
import org.junit.Test;
import java.io.File;
@ -159,6 +160,10 @@ public class TempTest {
@Test
public void testZip(){
String BASE_URL_CHAR_NUMBER = "1234510";
String tag = "1";
System.out.println(StringUtils.countMatches(BASE_URL_CHAR_NUMBER, tag.trim()));
}
}

Loading…
Cancel
Save