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