|
|
@@ -14,6 +14,8 @@ import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.HashSet;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@@ -26,6 +28,25 @@ public class FileService {
|
|
|
@Autowired
|
|
|
private PubConfigService pubConfigService;
|
|
|
|
|
|
+ private final static Set<String> allowedSuffixSet = new HashSet<String>() {{
|
|
|
+ add(".jpg");
|
|
|
+ add(".jpeg");
|
|
|
+ add(".png");
|
|
|
+ add(".gif");
|
|
|
+ add(".bmp");
|
|
|
+ add(".doc");
|
|
|
+ add(".docx");
|
|
|
+ add(".xls");
|
|
|
+ add(".xlsx");
|
|
|
+ add(".ppt");
|
|
|
+ add(".pptx");
|
|
|
+ add(".pdf");
|
|
|
+ add(".txt");
|
|
|
+ add(".zip");
|
|
|
+ add(".rar");
|
|
|
+ add(".7z");
|
|
|
+ }};
|
|
|
+
|
|
|
/**
|
|
|
* 添加合同文件
|
|
|
* @param file
|
|
|
@@ -70,6 +91,10 @@ public class FileService {
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
long fileSize = file.getSize();
|
|
|
String suffix = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
|
|
+ // 检查文件后缀是否在允许范围内
|
|
|
+ if (!allowedSuffixSet.contains(suffix)) {
|
|
|
+ throw new CodeException(AdminError.FILE_UPLOAD_ALLOW_ERROR);
|
|
|
+ }
|
|
|
String filePath;
|
|
|
if (CommConstant.FILE_TYPE_CONTRACT.equalsIgnoreCase(type)) {
|
|
|
filePath = CommConstant.PATH_CONTRACT;
|