|
|
@@ -679,4 +679,50 @@ public class CommonController {
|
|
|
return R.ok().put("isSmsVerification",0);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation("上传TXT文件")
|
|
|
+ @PostMapping("/uploadTxt")
|
|
|
+ public R uploadTxt(@RequestParam("file") MultipartFile file)
|
|
|
+ {
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ return R.error("上传文件不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ if (originalFilename == null || !originalFilename.toLowerCase().endsWith(".txt")) {
|
|
|
+ return R.error("仅支持上传txt文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileNameWithoutExt = originalFilename.substring(0, originalFilename.lastIndexOf("."));
|
|
|
+
|
|
|
+ if (fileNameWithoutExt.matches(".*[\\u4e00-\\u9fa5].*")) {
|
|
|
+ return R.error("文件名不允许包含中文");
|
|
|
+ }
|
|
|
+
|
|
|
+ String cleanedFileName = fileNameWithoutExt
|
|
|
+ .replaceAll("\\s+", "")
|
|
|
+ .replaceAll("\\(\\d+\\)$", "");
|
|
|
+
|
|
|
+ String finalFileName = cleanedFileName + ".txt";
|
|
|
+ String savePath = "C:\\Tools\\txt";
|
|
|
+ File directory = new File(savePath);
|
|
|
+
|
|
|
+ if (!directory.exists()) {
|
|
|
+ directory.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ File targetFile = new File(directory, finalFileName);
|
|
|
+
|
|
|
+ if (targetFile.exists()) {
|
|
|
+ return R.ok().put("data", finalFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ file.transferTo(targetFile);
|
|
|
+ } catch (IOException e) {
|
|
|
+ return R.error("文件上传失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("data", finalFileName);
|
|
|
+ }
|
|
|
}
|