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