|
|
@ -1,14 +1,15 @@ |
|
|
|
/** |
|
|
|
* Copyright (c) 2018 人人开源 All rights reserved. |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* https://www.renren.io
|
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 版权所有,侵权必究! |
|
|
|
*/ |
|
|
|
|
|
|
|
package com.elink.esua.epdc.controller; |
|
|
|
|
|
|
|
import com.elink.esua.epdc.commons.tools.annotation.LogOperation; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; |
|
|
@ -16,28 +17,17 @@ import com.elink.esua.epdc.commons.tools.validator.group.AliyunGroup; |
|
|
|
import com.elink.esua.epdc.commons.tools.validator.group.QcloudGroup; |
|
|
|
import com.elink.esua.epdc.commons.tools.validator.group.QiniuGroup; |
|
|
|
import com.elink.esua.epdc.dto.UploadFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.UploadToOssDTO; |
|
|
|
import com.elink.esua.epdc.entity.OssEntity; |
|
|
|
import com.elink.esua.epdc.exception.ModuleErrorCode; |
|
|
|
import com.elink.esua.epdc.remote.ParamsRemoteService; |
|
|
|
import com.elink.esua.epdc.service.OssService; |
|
|
|
import com.elink.esua.epdc.utils.ModuleConstant; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.elink.esua.epdc.commons.tools.annotation.LogOperation; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.elink.esua.epdc.cloud.CloudStorageConfig; |
|
|
|
import com.elink.esua.epdc.cloud.OssFactory; |
|
|
|
import com.elink.esua.epdc.commons.tools.validator.group.AliyunGroup; |
|
|
|
import com.elink.esua.epdc.commons.tools.validator.group.QcloudGroup; |
|
|
|
import com.elink.esua.epdc.commons.tools.validator.group.QiniuGroup; |
|
|
|
import com.elink.esua.epdc.dto.UploadDTO; |
|
|
|
import com.elink.esua.epdc.entity.OssEntity; |
|
|
|
import com.elink.esua.epdc.enums.OssTypeEnum; |
|
|
|
import com.elink.esua.epdc.exception.ModuleErrorCode; |
|
|
|
import com.elink.esua.epdc.service.OssService; |
|
|
|
import com.elink.esua.epdc.utils.ModuleConstant; |
|
|
|
import com.elink.esua.epdc.remote.ParamsRemoteService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.io.FilenameUtils; |
|
|
@ -49,7 +39,6 @@ import springfox.documentation.annotations.ApiIgnore; |
|
|
|
import sun.misc.BASE64Decoder; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
@ -59,10 +48,12 @@ import java.util.Map; |
|
|
|
*/ |
|
|
|
@RestController |
|
|
|
@RequestMapping("file") |
|
|
|
@Api(tags="文件上传") |
|
|
|
@Api(tags = "文件上传") |
|
|
|
public class OssController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private OssService ossService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ParamsRemoteService paramsRemoteService; |
|
|
|
|
|
|
@ -70,7 +61,7 @@ public class OssController { |
|
|
|
|
|
|
|
@GetMapping("page") |
|
|
|
@ApiOperation(value = "分页") |
|
|
|
public Result<PageData<OssEntity>> page(@ApiIgnore @RequestParam Map<String, Object> params){ |
|
|
|
public Result<PageData<OssEntity>> page(@ApiIgnore @RequestParam Map<String, Object> params) { |
|
|
|
PageData<OssEntity> page = ossService.page(params); |
|
|
|
|
|
|
|
return new Result<PageData<OssEntity>>().ok(page); |
|
|
@ -78,7 +69,7 @@ public class OssController { |
|
|
|
|
|
|
|
@GetMapping("info") |
|
|
|
@ApiOperation(value = "云存储配置信息") |
|
|
|
public Result<CloudStorageConfig> info(){ |
|
|
|
public Result<CloudStorageConfig> info() { |
|
|
|
CloudStorageConfig config = paramsRemoteService.getValueObject(KEY, CloudStorageConfig.class); |
|
|
|
|
|
|
|
return new Result<CloudStorageConfig>().ok(config); |
|
|
@ -87,17 +78,17 @@ public class OssController { |
|
|
|
@PostMapping |
|
|
|
@ApiOperation(value = "保存云存储配置信息") |
|
|
|
@LogOperation("保存云存储配置信息") |
|
|
|
public Result saveConfig(@RequestBody CloudStorageConfig config){ |
|
|
|
public Result saveConfig(@RequestBody CloudStorageConfig config) { |
|
|
|
//校验类型
|
|
|
|
ValidatorUtils.validateEntity(config); |
|
|
|
|
|
|
|
if(config.getType() == OssTypeEnum.QINIU.value()){ |
|
|
|
if (config.getType() == OssTypeEnum.QINIU.value()) { |
|
|
|
//校验七牛数据
|
|
|
|
ValidatorUtils.validateEntity(config, QiniuGroup.class); |
|
|
|
}else if(config.getType() == OssTypeEnum.ALIYUN.value()){ |
|
|
|
} else if (config.getType() == OssTypeEnum.ALIYUN.value()) { |
|
|
|
//校验阿里云数据
|
|
|
|
ValidatorUtils.validateEntity(config, AliyunGroup.class); |
|
|
|
}else if(config.getType() == OssTypeEnum.QCLOUD.value()){ |
|
|
|
} else if (config.getType() == OssTypeEnum.QCLOUD.value()) { |
|
|
|
//校验腾讯云数据
|
|
|
|
ValidatorUtils.validateEntity(config, QcloudGroup.class); |
|
|
|
} |
|
|
@ -118,24 +109,13 @@ public class OssController { |
|
|
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
|
|
|
String url = OssFactory.build().uploadSuffix(file.getBytes(), extension); |
|
|
|
|
|
|
|
//保存文件信息
|
|
|
|
OssEntity ossEntity = new OssEntity(); |
|
|
|
ossEntity.setUrl(url); |
|
|
|
ossEntity.setCreateDate(new Date()); |
|
|
|
ossService.insert(ossEntity); |
|
|
|
|
|
|
|
//文件信息
|
|
|
|
UploadDTO dto = new UploadDTO(); |
|
|
|
dto.setUrl(url); |
|
|
|
dto.setSize(file.getSize()); |
|
|
|
|
|
|
|
return new Result<UploadDTO>().ok(dto); |
|
|
|
return ossService.afterUpload(url, file.getSize()); |
|
|
|
} |
|
|
|
|
|
|
|
@DeleteMapping |
|
|
|
@ApiOperation(value = "删除") |
|
|
|
@LogOperation("删除") |
|
|
|
public Result delete(@RequestBody Long[] ids){ |
|
|
|
public Result delete(@RequestBody Long[] ids) { |
|
|
|
ossService.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
|
|
|
|
return new Result(); |
|
|
@ -152,9 +132,20 @@ public class OssController { |
|
|
|
String suffix = suffixTmp.substring(11, suffixTmp.indexOf(";")); |
|
|
|
byte[] imgBytes = new BASE64Decoder().decodeBuffer(base64ImgArr[1]); |
|
|
|
String url = OssFactory.build().uploadSuffix(imgBytes, suffix); |
|
|
|
System.out.println("base64:"+formDTO.getBase64String()); |
|
|
|
System.out.println("url:"+url); |
|
|
|
return new Result<String>().ok(url); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("uploadFile") |
|
|
|
public Result<String> uploadFile(@RequestBody UploadToOssDTO dto) { |
|
|
|
byte[] fileByte = dto.getFileByte(); |
|
|
|
if (null == fileByte || fileByte.length == NumConstant.ZERO) { |
|
|
|
return new Result().error(ModuleErrorCode.UPLOAD_FILE_EMPTY); |
|
|
|
} |
|
|
|
//上传文件
|
|
|
|
String extension = FilenameUtils.getExtension(dto.getFileName()); |
|
|
|
String url = OssFactory.build().uploadSuffix(fileByte, extension); |
|
|
|
|
|
|
|
return new Result().ok(url); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|