Merge branch 'feature/bug-1369' into prod/20260316
This commit is contained in:
commit
5e38841aae
|
|
@ -23,6 +23,7 @@ import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -36,14 +37,9 @@ import java.util.Objects;
|
||||||
@RequestMapping("/file")
|
@RequestMapping("/file")
|
||||||
public class FileController extends ControllerBase {
|
public class FileController extends ControllerBase {
|
||||||
|
|
||||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IGongfuFileService fileService;
|
private IGongfuFileService fileService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private FileUploadService fileUploadService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件搜索
|
* 文件搜索
|
||||||
*/
|
*/
|
||||||
|
|
@ -59,35 +55,24 @@ public class FileController extends ControllerBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
* @param type 类型,1:服务月报
|
* @param type 类型,1:服务月报
|
||||||
* @param fileName 文件名称
|
* @param fileName 文件名称
|
||||||
* @param file 文件
|
* @param fileUrl 文件地址
|
||||||
*/
|
*/
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public ApiResult<Void> upload(@RequestParam Integer type,@RequestParam String fileName,@RequestParam MultipartFile file) throws IOException {
|
public ApiResult<Void> upload(@RequestParam Integer type, @RequestParam String fileName, @RequestParam String fileUrl) throws IOException {
|
||||||
String url = fileUploadService.upload(buildFilePath(getFileType(file.getOriginalFilename())), file);
|
|
||||||
fileService.save(
|
fileService.save(
|
||||||
new GongfuFile()
|
new GongfuFile()
|
||||||
.setType(type)
|
.setType(type)
|
||||||
.setFileName(fileName)
|
.setFileName(fileName)
|
||||||
.setFileSize(file.getSize())
|
.setFileSuffix(FilenameUtils.getExtension(new URL(fileUrl).getPath()))
|
||||||
.setFileSuffix(FilenameUtils.getExtension(file.getOriginalFilename()))
|
.setFileUrl(fileUrl)
|
||||||
.setFileUrl(url)
|
|
||||||
.setCreateBy(AdminUserUtil.getUserName())
|
.setCreateBy(AdminUserUtil.getUserName())
|
||||||
.setCreateTime(LocalDateTime.now())
|
.setCreateTime(LocalDateTime.now())
|
||||||
);
|
);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildFilePath(String fileType) {
|
|
||||||
return StrUtil.format("gongfu/{}/{}/{}/{}{}", LocalDateTime.now().format(FORMATTER), AdminUserUtil.getUserId()
|
|
||||||
, RandomUtil.randomString(4), IdUtil.fastUUID(), fileType);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFileType(String fileName) {
|
|
||||||
return "." + FilenameUtils.getExtension(fileName).toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件删除
|
* 文件删除
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue