package cn.lili.controller.lmk;
|
|
import cn.lili.base.Result;
|
import cn.lili.modules.lmk.domain.vo.LmkFileVO;
|
import cn.lili.modules.lmk.service.ActivityService;
|
import cn.lili.modules.lmk.service.LmkFileService;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.ibatis.annotations.Delete;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
@RestController
|
@RequiredArgsConstructor
|
@RequestMapping("/manager/lmk/common")
|
@Slf4j
|
public class ManagerUploadController {
|
|
|
|
private final ActivityService activityService;
|
|
@PostMapping("/upload")
|
public Result handleFileUpload(@RequestPart("file") MultipartFile file) throws Exception {
|
System.out.println("开始上传");
|
if (file == null) {
|
return Result.error("上传文件不能为空");
|
}
|
System.out.println(file.getSize());
|
System.out.println(file.getName());
|
// 上传到云服务器
|
Result result = activityService.uploadObject(file);
|
Object object = result.get("data");
|
LmkFileVO lmkFileVO = null;
|
if (object != null) {
|
if (object instanceof LmkFileVO) {
|
lmkFileVO = (LmkFileVO) object;
|
//插入数据库
|
return Result.ok().data(lmkFileVO);
|
|
} else {
|
log.error("类型不匹配,期望:{} 实际:{}",
|
LmkFileVO.class.getName(),
|
object.getClass().getName());
|
return Result.error("类型不匹配");
|
}
|
}
|
return Result.error("上传云服务器异常");
|
}
|
|
@GetMapping("/getUrl/{fileKey}")
|
public Result getUrl(@PathVariable(value = "fileKey") String fileKey){
|
return Result.ok().data(activityService.getPreviewUrl(fileKey));
|
}
|
|
@DeleteMapping("/delByKey")
|
@ApiOperation(value = "删除某个文件")
|
public Result delByKey(@RequestBody String fileKey) {
|
return activityService.deleteObject(fileKey);
|
}
|
|
}
|