增加文件上传升级版本部分代码
This commit is contained in:
parent
2963028aa7
commit
26ce348466
@ -0,0 +1,90 @@
|
|||||||
|
package ink.wgink.module.file.controller.api;
|
||||||
|
|
||||||
|
import ink.wgink.common.base.DefaultBaseController;
|
||||||
|
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||||
|
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||||
|
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
|
||||||
|
import ink.wgink.module.file.service.v2.IFileV2Service;
|
||||||
|
import ink.wgink.pojo.result.ErrorResult;
|
||||||
|
import ink.wgink.pojo.result.SuccessResultData;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: FileController
|
||||||
|
* @Description: 文件处理
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2019/3/10 7:03 PM
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "文件接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(ISystemConstant.API_PREFIX + "/file/v2")
|
||||||
|
public class FileV2Controller extends DefaultBaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IFileV2Service fileV2Service;
|
||||||
|
|
||||||
|
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "file", value = "文件name", paramType = "query")
|
||||||
|
})
|
||||||
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@PostMapping("upload-file")
|
||||||
|
public SuccessResultData<FileUploadSuccessDTO> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||||
|
Map<String, Object> params = requestParams();
|
||||||
|
return uploadSingle(file, UploadTypeEnum.FILE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
|
||||||
|
})
|
||||||
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@PostMapping("upload-image")
|
||||||
|
public SuccessResultData<FileUploadSuccessDTO> uploadImage(@RequestParam("image") MultipartFile image) {
|
||||||
|
Map<String, Object> params = requestParams();
|
||||||
|
return uploadSingle(image, UploadTypeEnum.IMAGE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "上传视频", notes = "上传视频接口")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "video", value = "文件video", paramType = "query")
|
||||||
|
})
|
||||||
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@PostMapping("upload-video")
|
||||||
|
public SuccessResultData<FileUploadSuccessDTO> uploadVideo(@RequestParam("video") MultipartFile video) {
|
||||||
|
Map<String, Object> params = requestParams();
|
||||||
|
return uploadSingle(video, UploadTypeEnum.VIDEO, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "上传音频", notes = "上传音频接口")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "audio", value = "文件audio", paramType = "query")
|
||||||
|
})
|
||||||
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@PostMapping("upload-audio")
|
||||||
|
public SuccessResultData<FileUploadSuccessDTO> uploadAudio(@RequestParam("audio") MultipartFile audio) {
|
||||||
|
Map<String, Object> params = requestParams();
|
||||||
|
return uploadSingle(audio, UploadTypeEnum.AUDIO, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param uploadFile
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private SuccessResultData<FileUploadSuccessDTO> uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) {
|
||||||
|
return new SuccessResultData<>(fileV2Service.uploadSingle(uploadFile, uploadTypeEnum, params));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package ink.wgink.module.file.pojo.dtos;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: FileUploadSuccessDTO
|
||||||
|
* @Description: 文件上传成功
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2022/4/13 16:13
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@ApiModel
|
||||||
|
public class FileUploadSuccessDTO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -532164203878483022L;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "fileId", value = "文件ID")
|
||||||
|
private String fileId;
|
||||||
|
@ApiModelProperty(name = "fileName", value = "文件名称")
|
||||||
|
private String fileName;
|
||||||
|
@ApiModelProperty(name = "fileSize", value = "文件大小")
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
public String getFileId() {
|
||||||
|
return fileId == null ? "" : fileId.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileId(String fileId) {
|
||||||
|
this.fileId = fileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName == null ? "" : fileName.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileName(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getFileSize() {
|
||||||
|
return fileSize == null ? 0 : fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSize(Long fileSize) {
|
||||||
|
this.fileSize = fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder sb = new StringBuilder("{");
|
||||||
|
sb.append("\"fileId\":\"")
|
||||||
|
.append(fileId).append('\"');
|
||||||
|
sb.append(",\"fileName\":\"")
|
||||||
|
.append(fileName).append('\"');
|
||||||
|
sb.append(",\"fileSize\":")
|
||||||
|
.append(fileSize);
|
||||||
|
sb.append('}');
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ink.wgink.module.file.service.v2;
|
||||||
|
|
||||||
|
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||||
|
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: IFileV2Service
|
||||||
|
* @Description: 文件V2
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2022/4/13 16:15
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public interface IFileV2Service {
|
||||||
|
|
||||||
|
FileUploadSuccessDTO uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package ink.wgink.module.file.service.v2.impl;
|
||||||
|
|
||||||
|
import ink.wgink.common.base.DefaultBaseService;
|
||||||
|
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||||
|
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
|
||||||
|
import ink.wgink.module.file.service.IFileService;
|
||||||
|
import ink.wgink.module.file.service.v2.IFileV2Service;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: FileV2ServiceImpl
|
||||||
|
* @Description: 文件V2
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2022/4/13 16:15
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class FileV2ServiceImpl extends DefaultBaseService implements IFileV2Service {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IFileService fileService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileUploadSuccessDTO uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) {
|
||||||
|
fileService.uploadSingle(uploadFile, uploadTypeEnum, params);
|
||||||
|
FileUploadSuccessDTO fileUploadSuccessDTO = new FileUploadSuccessDTO();
|
||||||
|
fileUploadSuccessDTO.setFileId(params.get("fileId").toString());
|
||||||
|
fileUploadSuccessDTO.setFileName(params.get("fileName").toString());
|
||||||
|
fileUploadSuccessDTO.setFileSize(Long.valueOf(params.get("fileSize").toString()));
|
||||||
|
return fileUploadSuccessDTO;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user