新建目录和上传文件新增文件名校验。
This commit is contained in:
parent
3bddcc2437
commit
4e2c53f64e
|
|
@ -4,6 +4,7 @@
|
|||
package com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.impl;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
|
@ -48,6 +49,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author
|
||||
|
|
@ -152,9 +154,13 @@ public class EDDataServiceImpl implements EDDataService {
|
|||
public Boolean createDataInfo(EDDataInfo edDataInfo) throws Exception
|
||||
{
|
||||
// 获取上级目录的名称
|
||||
String fileName = edDataInfo.getDataName();
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), "文件名不符合规范,只能包含中文字符、下划线、连字符、加号、数字和英文字符");
|
||||
|
||||
Category categoryParent = new Category();
|
||||
categoryParent.setCategoryId(edDataInfo.getCategoryId());
|
||||
List<Category> categoryParentList = categoryRepository.selectCategories(categoryParent);
|
||||
|
||||
if(categoryParentList.size() < 1) {
|
||||
throw new Exception("上级文件夹不存在");
|
||||
}
|
||||
|
|
@ -293,8 +299,7 @@ public class EDDataServiceImpl implements EDDataService {
|
|||
* @param parames
|
||||
* @return
|
||||
*/
|
||||
public Boolean uploadFile(EDDataParams parames) throws Exception
|
||||
{
|
||||
public Boolean uploadFile(EDDataParams parames) throws Exception {
|
||||
|
||||
// 获取目录编码ID
|
||||
String categoryId = parames.getParentId();
|
||||
|
|
@ -313,7 +318,7 @@ public class EDDataServiceImpl implements EDDataService {
|
|||
String fileType = EleCommonUtil.getFileType(fileFullName);
|
||||
// 获取文件名称
|
||||
String fileName = EleCommonUtil.getFileName(fileFullName);
|
||||
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), "文件名不符合规范,只能包含中文字符、下划线、连字符、加号、数字和英文字符");
|
||||
// 判断文件名称是否存在
|
||||
EDDataParams folderParames = new EDDataParams();
|
||||
folderParames.setParentId(categoryId);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
package electromagnetic.data.framework.share.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class EleCommonUtil {
|
||||
|
||||
// 正则表达式模式,匹配中文字符、下划线、连字符、加号、数字和英文字符
|
||||
private static final String PATTERN = "^[\\u4e00-\\u9fa5a-zA-Z0-9._\\-+]+$";
|
||||
|
||||
// 编译正则表达式
|
||||
private static final Pattern pattern = Pattern.compile(PATTERN);
|
||||
|
||||
public static String getFileName(String fileFullName) {
|
||||
if (fileFullName == null) {
|
||||
return "";
|
||||
|
|
@ -22,4 +30,8 @@ public final class EleCommonUtil {
|
|||
return fileFullName.substring(index + 1);
|
||||
}
|
||||
|
||||
public static boolean isFileNameValid(String fileFullName) {
|
||||
return pattern.matcher(fileFullName).matches();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue