修复bug
This commit is contained in:
parent
9aef056550
commit
407eefd1ab
|
|
@ -4,6 +4,7 @@ import com.mdd.admin.LikeAdminThreadLocal;
|
|||
import com.mdd.admin.aop.Log;
|
||||
import com.mdd.admin.aop.aspect.RequestType;
|
||||
import com.mdd.admin.service.IFileService;
|
||||
import com.mdd.common.aop.NotPower;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.enums.AlbumEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
|
|
@ -14,6 +15,7 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
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 org.springframework.web.multipart.MultipartRequest;
|
||||
|
|
@ -33,23 +35,20 @@ public class UploadController {
|
|||
|
||||
@Log(title = "上传图片", requestType = RequestType.File)
|
||||
@PostMapping("/image")
|
||||
@NotPower
|
||||
@ApiOperation(value="上传图片")
|
||||
public AjaxResult<UploadFilesVo> image(HttpServletRequest request) {
|
||||
MultipartFile multipartFile;
|
||||
try {
|
||||
multipartFile = ((MultipartRequest) request).getFile("file");
|
||||
} catch (Exception e) {
|
||||
throw new OperateException("请正确选择上传图片!");
|
||||
}
|
||||
public AjaxResult image(@RequestParam("file") MultipartFile[] files, @RequestParam("cid") String requestCid) {
|
||||
|
||||
if (multipartFile == null) {
|
||||
String cid = StringUtils.isNotEmpty(requestCid) ? requestCid : "0";
|
||||
|
||||
if (files == null || files.length == 0) {
|
||||
throw new OperateException("请选择上传图片!");
|
||||
}
|
||||
|
||||
StorageDriver storageDriver = new StorageDriver();
|
||||
UploadFilesVo vo = storageDriver.upload(multipartFile, "image", AlbumEnum.IMAGE.getCode());
|
||||
String cid = StringUtils.isNotEmpty(request.getParameter("cid")) ? request.getParameter("cid") : "0";
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
StorageDriver storageDriver = new StorageDriver();
|
||||
UploadFilesVo vo = storageDriver.upload(files[i], "image", AlbumEnum.IMAGE.getCode());
|
||||
Map<String, String> album = new LinkedHashMap<>();
|
||||
album.put("aid", String.valueOf(LikeAdminThreadLocal.getAdminId()));
|
||||
album.put("cid", cid);
|
||||
|
|
@ -59,29 +58,59 @@ public class UploadController {
|
|||
album.put("url", vo.getUrl());
|
||||
album.put("name", vo.getName());
|
||||
Integer id = fileService.fileAdd(album);
|
||||
|
||||
vo.setId(id);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Log(title = "上传图片", requestType = RequestType.File)
|
||||
@PostMapping("/file")
|
||||
@NotPower
|
||||
@ApiOperation(value="上传文件")
|
||||
public AjaxResult file(@RequestParam("file") MultipartFile[] files, @RequestParam("cid") String requestCid) {
|
||||
|
||||
String cid = StringUtils.isNotEmpty(requestCid) ? requestCid : "0";
|
||||
|
||||
if (files == null || files.length == 0) {
|
||||
throw new OperateException("请选择上传文件!");
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
StorageDriver storageDriver = new StorageDriver();
|
||||
UploadFilesVo vo = storageDriver.upload(files[i], "image", AlbumEnum.Doc.getCode());
|
||||
Map<String, String> album = new LinkedHashMap<>();
|
||||
album.put("aid", String.valueOf(LikeAdminThreadLocal.getAdminId()));
|
||||
album.put("cid", cid);
|
||||
album.put("type", String.valueOf(AlbumEnum.Doc.getCode()));
|
||||
// album.put("size", vo.getSize().toString());
|
||||
// album.put("ext", vo.getExt());
|
||||
album.put("url", vo.getUrl());
|
||||
album.put("name", vo.getName());
|
||||
Integer id = fileService.fileAdd(album);
|
||||
vo.setId(id);
|
||||
}
|
||||
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Log(title = "上传视频", requestType = RequestType.File)
|
||||
@PostMapping("/video")
|
||||
@NotPower
|
||||
@ApiOperation(value="上传视频")
|
||||
public AjaxResult<UploadFilesVo> video(HttpServletRequest request) {
|
||||
MultipartFile multipartFile;
|
||||
try {
|
||||
multipartFile = ((MultipartRequest) request).getFile("file");
|
||||
} catch (Exception e) {
|
||||
throw new OperateException("请选择上传视频!");
|
||||
}
|
||||
public AjaxResult video(@RequestParam("file") MultipartFile[] files, @RequestParam("cid") String requestCid) {
|
||||
|
||||
if (multipartFile == null) {
|
||||
String cid = StringUtils.isNotEmpty(requestCid) ? requestCid : "0";
|
||||
|
||||
|
||||
if (files == null || files.length == 0) {
|
||||
throw new OperateException("请选择上传视频!");
|
||||
}
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
|
||||
StorageDriver storageDriver = new StorageDriver();
|
||||
UploadFilesVo vo = storageDriver.upload(multipartFile, "video", AlbumEnum.Video.getCode());
|
||||
String cid = StringUtils.isNotEmpty(request.getParameter("cid")) ? request.getParameter("cid") : "0";
|
||||
UploadFilesVo vo = storageDriver.upload(files[i], "video", AlbumEnum.Video.getCode());
|
||||
|
||||
Map<String, String> album = new LinkedHashMap<>();
|
||||
album.put("cid", cid);
|
||||
|
|
@ -94,7 +123,8 @@ public class UploadController {
|
|||
Integer id = fileService.fileAdd(album);
|
||||
|
||||
vo.setId(id);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ package com.mdd.common.enums;
|
|||
public enum AlbumEnum {
|
||||
|
||||
IMAGE(10, "图片"),
|
||||
Video(20, "视频");
|
||||
Video(20, "视频"),
|
||||
Doc(30, "文件");
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
|
|
|
|||
Loading…
Reference in New Issue