暂降治理一期工作内容
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package com.njcn.system.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.system.pojo.vo.FileVO;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年10月16日 19:34
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "文件控制管理器")
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
@RequiredArgsConstructor
|
||||
public class FileController extends BaseController {
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("文件上传")
|
||||
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
||||
public HttpResult<FileVO> upload(@RequestParam(value = "file") MultipartFile file, @RequestParam("path") String path) {
|
||||
String methodDescribe = getMethodDescribe("upload");
|
||||
String ossPath = fileStorageUtil.uploadMultipart(file, path);
|
||||
String url = fileStorageUtil.getFileUrl(ossPath);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, new FileVO(ossPath,url), methodDescribe);
|
||||
}
|
||||
|
||||
@ApiOperation("删除文件服务器文件")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||
public HttpResult<String> delete(String filePath) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
fileStorageUtil.deleteFile(filePath);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, CommonResponseEnum.SUCCESS.getMessage(), methodDescribe);
|
||||
}
|
||||
|
||||
@ApiOperation("下载文件")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@RequestMapping(value = "/download", method = RequestMethod.GET)
|
||||
public void download(String filePath, HttpServletResponse response) {
|
||||
fileStorageUtil.downloadStream(response, filePath);
|
||||
}
|
||||
|
||||
@ApiOperation("获取文件的一个短期url")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@RequestMapping(value = "/getFileUrl", method = RequestMethod.GET)
|
||||
public HttpResult<String> getFileUrl(String filePath) {
|
||||
String methodDescribe = getMethodDescribe("getFileUrl");
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, fileStorageUtil.getFileUrl(filePath), methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user