新增app文件上传接口
This commit is contained in:
parent
b3f30b241b
commit
8142f5d5f1
@ -0,0 +1,92 @@
|
||||
package com.cm.common.plugin.controller.app.file;
|
||||
|
||||
import com.cm.common.base.AbstractController;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import com.cm.common.enums.UploadTypeEnum;
|
||||
import com.cm.common.exception.base.SystemException;
|
||||
import com.cm.common.plugin.service.file.IFileService;
|
||||
import com.cm.common.result.SuccessResultData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: FileAppController
|
||||
* @Description: APP文件上传
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019-08-02 15:38
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.APP_PREFIX + "/file")
|
||||
public class FileAppController extends AbstractController {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("uploadfile")
|
||||
public SuccessResultData<String> uploadFile(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) throws SystemException {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, file, UploadTypeEnum.FILE, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @param image
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("uploadimage")
|
||||
public SuccessResultData<String> uploadImage(@RequestHeader("token") String token, @RequestParam("image") MultipartFile image) throws SystemException {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, image, UploadTypeEnum.IMAGE, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传视频
|
||||
*
|
||||
* @param video
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("uploadvideo")
|
||||
public SuccessResultData<String> uploadVideo(@RequestHeader("token") String token, @RequestParam("video") MultipartFile video) throws SystemException {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, video, UploadTypeEnum.VIDEO, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传音频
|
||||
*
|
||||
* @param audio
|
||||
* @return
|
||||
* @throws SystemException
|
||||
*/
|
||||
@PostMapping("uploadaudio")
|
||||
public SuccessResultData<String> uploadAudio(@RequestHeader("token") String token, @RequestParam("audio") MultipartFile audio) throws SystemException {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, audio, UploadTypeEnum.AUDIO, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private SuccessResultData<String> uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
return fileService.uploadSingle(token, uploadFile, uploadTypeEnum, params);
|
||||
}
|
||||
|
||||
}
|
@ -87,13 +87,26 @@ public interface IFileService {
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param token
|
||||
* @param uploadFile
|
||||
* @param uploadTypeEnum
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SystemException
|
||||
* @throws IOException
|
||||
*/
|
||||
SuccessResultData<String> uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param token
|
||||
* @param uploadFile
|
||||
* @param uploadTypeEnum
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SystemException
|
||||
*/
|
||||
FileDTO uploadSingleForFileDTO(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException;
|
||||
FileDTO uploadSingleForFileDTO(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException;
|
||||
|
||||
/**
|
||||
* 文件下载
|
||||
@ -124,4 +137,6 @@ public interface IFileService {
|
||||
* @throws SearchException
|
||||
*/
|
||||
FilePO getFile(Map<String, Object> params) throws SearchException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -58,13 +58,19 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
|
||||
@Override
|
||||
public SuccessResultData<String> uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
uploadFile(uploadFile, uploadTypeEnum, params);
|
||||
uploadFile(null, uploadFile, uploadTypeEnum, params);
|
||||
return new SuccessResultData<>(params.get("fileId").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileDTO uploadSingleForFileDTO(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
uploadFile(uploadFile, uploadTypeEnum, params);
|
||||
public SuccessResultData<String> uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
uploadFile(token, uploadFile, uploadTypeEnum, params);
|
||||
return new SuccessResultData<>(params.get("fileId").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileDTO uploadSingleForFileDTO(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
uploadFile(token, uploadFile, uploadTypeEnum, params);
|
||||
FileDTO fileDTO = new FileDTO();
|
||||
fileDTO.setFileId(params.get("fileId").toString());
|
||||
fileDTO.setFileName(params.get("fileName").toString());
|
||||
@ -75,12 +81,13 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param token
|
||||
* @param uploadFile
|
||||
* @param uploadTypeEnum
|
||||
* @param params
|
||||
* @throws SystemException
|
||||
*/
|
||||
private void uploadFile(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
private void uploadFile(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
String baseUploadPath = fileProperties.getUploadPath();
|
||||
if (StringUtils.isBlank(baseUploadPath)) {
|
||||
throw new SystemException("上传路径未配置");
|
||||
@ -104,7 +111,11 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
params.put("fileType", fileType);
|
||||
params.put("fileSize", fileSize);
|
||||
params.put("isBack", 0);
|
||||
setSaveInfo(params);
|
||||
if (StringUtils.isBlank(token)) {
|
||||
setSaveInfo(params);
|
||||
} else {
|
||||
setSaveInfo(token, params);
|
||||
}
|
||||
fileDao.saveFile(params);
|
||||
}
|
||||
|
||||
@ -168,6 +179,7 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
return fileDao.getFile(params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* uEditor文件列表
|
||||
*
|
||||
@ -216,11 +228,11 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
LOG.debug("UEditor上传文件");
|
||||
FileDTO fileDTO = null;
|
||||
if (UEDITOR_UPLOAD_IMAGE.equals(action)) {
|
||||
fileDTO = uploadSingleForFileDTO(file, UploadTypeEnum.IMAGE, params);
|
||||
fileDTO = uploadSingleForFileDTO(null, file, UploadTypeEnum.IMAGE, params);
|
||||
} else if (UEDITOR_UPLOAD_VIDEO.equals(action)) {
|
||||
fileDTO = uploadSingleForFileDTO(file, UploadTypeEnum.VIDEO, params);
|
||||
fileDTO = uploadSingleForFileDTO(null, file, UploadTypeEnum.VIDEO, params);
|
||||
} else if (UEDITOR_UPLOAD_FILE.equals(action)) {
|
||||
fileDTO = uploadSingleForFileDTO(file, UploadTypeEnum.FILE, params);
|
||||
fileDTO = uploadSingleForFileDTO(null, file, UploadTypeEnum.FILE, params);
|
||||
}
|
||||
if (fileDTO == null) {
|
||||
throw new SystemException("文件上传失败");
|
||||
|
Loading…
Reference in New Issue
Block a user