|
|
@ -71,64 +71,64 @@ public class OssController { |
|
|
|
|
|
|
|
private final static String KEY = ModuleConstant.CLOUD_STORAGE_CONFIG_KEY; |
|
|
|
|
|
|
|
@GetMapping("page") |
|
|
|
public Result<PageData<OssEntity>> page(@RequestParam Map<String, Object> params){ |
|
|
|
PageData<OssEntity> page = ossService.page(params); |
|
|
|
|
|
|
|
return new Result<PageData<OssEntity>>().ok(page); |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("info") |
|
|
|
public Result<CloudStorageConfig> info(){ |
|
|
|
CloudStorageConfig config = paramsRemoteService.getValueObject(KEY, CloudStorageConfig.class); |
|
|
|
|
|
|
|
return new Result<CloudStorageConfig>().ok(config); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping |
|
|
|
// @LogOperation("保存云存储配置信息")
|
|
|
|
public Result saveConfig(@RequestBody CloudStorageConfig config){ |
|
|
|
//校验类型
|
|
|
|
ValidatorUtils.validateEntity(config); |
|
|
|
|
|
|
|
if(config.getType() == OssTypeEnum.QINIU.value()){ |
|
|
|
//校验七牛数据
|
|
|
|
ValidatorUtils.validateEntity(config, QiniuGroup.class); |
|
|
|
}else if(config.getType() == OssTypeEnum.ALIYUN.value()){ |
|
|
|
//校验阿里云数据
|
|
|
|
ValidatorUtils.validateEntity(config, AliyunGroup.class); |
|
|
|
}else if(config.getType() == OssTypeEnum.QCLOUD.value()){ |
|
|
|
//校验腾讯云数据
|
|
|
|
ValidatorUtils.validateEntity(config, QcloudGroup.class); |
|
|
|
} |
|
|
|
|
|
|
|
paramsRemoteService.updateValueByCode(KEY, new Gson().toJson(config)); |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("upload") |
|
|
|
public Result<UploadDTO> upload(@RequestPart("file") MultipartFile file) throws Exception { |
|
|
|
if (file.isEmpty()) { |
|
|
|
return new Result<UploadDTO>().error(ModuleErrorCode.UPLOAD_FILE_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
//上传文件
|
|
|
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
|
|
|
String url = OssFactory.build().uploadSuffix(file.getBytes(), extension, null); |
|
|
|
|
|
|
|
//保存文件信息
|
|
|
|
OssEntity ossEntity = new OssEntity(); |
|
|
|
ossEntity.setUrl(url); |
|
|
|
ossService.insertOssEntity(ossEntity); |
|
|
|
|
|
|
|
//文件信息
|
|
|
|
UploadDTO dto = new UploadDTO(); |
|
|
|
dto.setUrl(url); |
|
|
|
dto.setSize(file.getSize()); |
|
|
|
|
|
|
|
return new Result<UploadDTO>().ok(dto); |
|
|
|
} |
|
|
|
// @GetMapping("page")
|
|
|
|
// public Result<PageData<OssEntity>> page(@RequestParam Map<String, Object> params){
|
|
|
|
// PageData<OssEntity> page = ossService.page(params);
|
|
|
|
//
|
|
|
|
// return new Result<PageData<OssEntity>>().ok(page);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @GetMapping("info")
|
|
|
|
// public Result<CloudStorageConfig> info(){
|
|
|
|
// CloudStorageConfig config = paramsRemoteService.getValueObject(KEY, CloudStorageConfig.class);
|
|
|
|
//
|
|
|
|
// return new Result<CloudStorageConfig>().ok(config);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @PostMapping
|
|
|
|
//// @LogOperation("保存云存储配置信息")
|
|
|
|
// public Result saveConfig(@RequestBody CloudStorageConfig config){
|
|
|
|
// //校验类型
|
|
|
|
// ValidatorUtils.validateEntity(config);
|
|
|
|
//
|
|
|
|
// if(config.getType() == OssTypeEnum.QINIU.value()){
|
|
|
|
// //校验七牛数据
|
|
|
|
// ValidatorUtils.validateEntity(config, QiniuGroup.class);
|
|
|
|
// }else if(config.getType() == OssTypeEnum.ALIYUN.value()){
|
|
|
|
// //校验阿里云数据
|
|
|
|
// ValidatorUtils.validateEntity(config, AliyunGroup.class);
|
|
|
|
// }else if(config.getType() == OssTypeEnum.QCLOUD.value()){
|
|
|
|
// //校验腾讯云数据
|
|
|
|
// ValidatorUtils.validateEntity(config, QcloudGroup.class);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// paramsRemoteService.updateValueByCode(KEY, new Gson().toJson(config));
|
|
|
|
//
|
|
|
|
// return new Result();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @PostMapping("upload")
|
|
|
|
// public Result<UploadDTO> upload(@RequestPart("file") MultipartFile file) throws Exception {
|
|
|
|
// if (file.isEmpty()) {
|
|
|
|
// return new Result<UploadDTO>().error(ModuleErrorCode.UPLOAD_FILE_EMPTY);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //上传文件
|
|
|
|
// String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
|
// String url = OssFactory.build().uploadSuffix(file.getBytes(), extension, null);
|
|
|
|
//
|
|
|
|
// //保存文件信息
|
|
|
|
// OssEntity ossEntity = new OssEntity();
|
|
|
|
// ossEntity.setUrl(url);
|
|
|
|
// ossService.insertOssEntity(ossEntity);
|
|
|
|
//
|
|
|
|
// //文件信息
|
|
|
|
// UploadDTO dto = new UploadDTO();
|
|
|
|
// dto.setUrl(url);
|
|
|
|
// dto.setSize(file.getSize());
|
|
|
|
//
|
|
|
|
// return new Result<UploadDTO>().ok(dto);
|
|
|
|
// }
|
|
|
|
|
|
|
|
@DeleteMapping |
|
|
|
// @LogOperation("删除")
|
|
|
@ -150,182 +150,182 @@ public class OssController { |
|
|
|
return ossService.uploadImg(file, null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 压缩上传 |
|
|
|
* |
|
|
|
* @param file |
|
|
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UploadImgResultDTO> |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/24 13:32 |
|
|
|
*/ |
|
|
|
@PostMapping("compressuploadimg") |
|
|
|
public Result<UploadImgResultDTO> compressUploadImg(@RequestParam("file") MultipartFile file) { |
|
|
|
return ossService.compressUploadImg(file, null,200L); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("uploadwximg") |
|
|
|
public Result<UploadImgResultDTO> uploadWxImg(@RequestPart("media") MultipartFile media) { |
|
|
|
return ossService.uploadImg(media, null); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("uploadqrcode") |
|
|
|
public Result<UploadImgResultDTO> uploadQrCode(@RequestPart(value = "file") MultipartFile file) { |
|
|
|
return ossService.uploadImg(file, null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 上传客户logo(考虑到以后可能会针对不同的业务有不同的限制条件,这里不再使用通用的接口 |
|
|
|
* 针对每一个业务新建上传接口) |
|
|
|
* @param file |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("customerlogo/upload") |
|
|
|
public Result uploadCustomerLogo(@RequestParam("file") MultipartFile file) { |
|
|
|
|
|
|
|
// 校验文件类型
|
|
|
|
if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType())) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
// 校验文件体积,不超过1m
|
|
|
|
long maxSize = 1024 * 1024; |
|
|
|
long size = file.getSize(); |
|
|
|
if (size > maxSize) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
return ossService.uploadImg(file, null); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("function/upload") |
|
|
|
public Result uploadFunctionLogo(@RequestParam("file") MultipartFile file) { |
|
|
|
|
|
|
|
// 校验文件类型
|
|
|
|
if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType())) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
// 校验文件体积,不超过1m
|
|
|
|
long maxSize = 1024 * 1024; |
|
|
|
long size = file.getSize(); |
|
|
|
if (size > maxSize) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
return ossService.uploadImg(file, null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc: 党建声音模块 上传图片(2M)或附件(5M) |
|
|
|
* |
|
|
|
* @param file |
|
|
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UploadImgResultDTO> |
|
|
|
* @author LiuJanJun |
|
|
|
* @date 2021/3/29 4:56 下午 |
|
|
|
*/ |
|
|
|
@PostMapping("article/upload") |
|
|
|
public Result<UploadImgResultDTO> uploadArticleImg(@RequestParam("file") MultipartFile file) { |
|
|
|
|
|
|
|
// 校验文件类型 图片或pdf
|
|
|
|
if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType()) |
|
|
|
&& !MediaType.IMAGE_JPEG_VALUE.equals(file.getContentType()) |
|
|
|
&& !ModuleConstant.FILE_CONTENT_TYPE_JPG.equals(file.getContentType()) |
|
|
|
&& !ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType()) |
|
|
|
&& !file.getContentType().startsWith(ModuleConstant.FILE_CONTENT_TYPE_VEDIO_PREFIX) |
|
|
|
) { |
|
|
|
log.error("uploadArticleImg file type:{} is not support 2 upload", file.getContentType()); |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); |
|
|
|
} |
|
|
|
long size = file.getSize(); |
|
|
|
if (ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType())) { |
|
|
|
// 校验文件大小,不超过5m
|
|
|
|
long maxSize = 5 * 1024 * 1024; |
|
|
|
if (size > maxSize) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
|
} |
|
|
|
} else if (file.getContentType().startsWith(ModuleConstant.FILE_CONTENT_TYPE_VEDIO_PREFIX)) { |
|
|
|
// 校验文件大小,不超过5m
|
|
|
|
long maxSize = 25 * 1024 * 1024; |
|
|
|
if (size > maxSize) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
Result<UploadImgResultDTO> result =null; |
|
|
|
String originFileName = file.getOriginalFilename(); |
|
|
|
String format = "-" + originFileName.substring(originFileName.lastIndexOf(".") + NumConstant.ONE) + "-"; |
|
|
|
format = format.toLowerCase(); |
|
|
|
int compressSize = 2 * 1024 * 1024; |
|
|
|
// 如果是图片,超过2M的压缩一下
|
|
|
|
if (ModuleConstant.PROJECT_FILE_IMAGE.contains(format) && file.getSize() > compressSize) { |
|
|
|
// 单个图片10M
|
|
|
|
result= ossService.compressUploadImg(file, null, 2 * 1024); |
|
|
|
} else { |
|
|
|
result=ossService.uploadImg(file, null); |
|
|
|
} |
|
|
|
if (result != null && result.success() ){ |
|
|
|
UploadImgResultDTO data = result.getData(); |
|
|
|
if ( data!= null && StringUtils.isNotBlank(data.getUrl())){ |
|
|
|
String path = data.getUrl().replace(data.getDomain(), StrConstant.EPMETY_STR); |
|
|
|
if (path.startsWith(StrConstant.SEPARATOR)){ |
|
|
|
path = path.replaceFirst(StrConstant.SEPARATOR,StrConstant.EPMETY_STR); |
|
|
|
} |
|
|
|
String fileName = data.getUrl().substring(data.getUrl().lastIndexOf(StrConstant.SEPARATOR)+1); |
|
|
|
redisUtils.set(RedisKeys.getOssFileKey(fileName),path,RedisUtils.MINUTE_THIRTY_EXPIRE); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("uploadimg/badgeicon") |
|
|
|
public Result<UploadImgResultDTO> badgeIcon(@RequestParam("file") MultipartFile file) throws IOException { |
|
|
|
|
|
|
|
// 校验文件类型
|
|
|
|
if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType())) { |
|
|
|
log.error("uploadArticleImg file type:{} is not support 2 upload", file.getContentType()); |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_IMG_TYPE_ERROR.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_IMG_TYPE_ERROR.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
// 校验文件体积,不超过2m
|
|
|
|
long maxSize = 2 * 1024 * 1024; |
|
|
|
long size = file.getSize(); |
|
|
|
if (size > maxSize) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); |
|
|
|
int width = bufferedImage.getWidth(); |
|
|
|
int height = bufferedImage.getHeight(); |
|
|
|
if (width != 200 || height != 200) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_IMG_SIZE_ERROR.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_IMG_SIZE_ERROR.getMsg()); |
|
|
|
|
|
|
|
} |
|
|
|
return ossService.uploadImg(file, null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param byteFile fileName |
|
|
|
* @Description 外挂-文件上传 |
|
|
|
* @Author sun |
|
|
|
**/ |
|
|
|
@PostMapping("ext/upload") |
|
|
|
public Result<UploadImgResultDTO> extUpload(@RequestParam("byteFile") byte[] byteFile, @RequestParam("fileName") String fileName) throws IOException { |
|
|
|
//public Result<UploadImgResultDTO> extUpload(@RequestParam("file") MultipartFile file, @RequestParam("fileName") String fileName) throws IOException {
|
|
|
|
//byte[] byteFile = file.getBytes();
|
|
|
|
InputStream inputStream = new ByteArrayInputStream(byteFile); |
|
|
|
MultipartFile filse = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream); |
|
|
|
return ossService.extUpload(filse,fileName, null); |
|
|
|
} |
|
|
|
// /**
|
|
|
|
// * 压缩上传
|
|
|
|
// *
|
|
|
|
// * @param file
|
|
|
|
// * @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UploadImgResultDTO>
|
|
|
|
// * @author zhy
|
|
|
|
// * @date 2022/5/24 13:32
|
|
|
|
// */
|
|
|
|
// @PostMapping("compressuploadimg")
|
|
|
|
// public Result<UploadImgResultDTO> compressUploadImg(@RequestParam("file") MultipartFile file) {
|
|
|
|
// return ossService.compressUploadImg(file, null,200L);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @PostMapping("uploadwximg")
|
|
|
|
// public Result<UploadImgResultDTO> uploadWxImg(@RequestPart("media") MultipartFile media) {
|
|
|
|
// return ossService.uploadImg(media, null);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @PostMapping("uploadqrcode")
|
|
|
|
// public Result<UploadImgResultDTO> uploadQrCode(@RequestPart(value = "file") MultipartFile file) {
|
|
|
|
// return ossService.uploadImg(file, null);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * 上传客户logo(考虑到以后可能会针对不同的业务有不同的限制条件,这里不再使用通用的接口
|
|
|
|
// * 针对每一个业务新建上传接口)
|
|
|
|
// * @param file
|
|
|
|
// * @return
|
|
|
|
// */
|
|
|
|
// @PostMapping("customerlogo/upload")
|
|
|
|
// public Result uploadCustomerLogo(@RequestParam("file") MultipartFile file) {
|
|
|
|
//
|
|
|
|
// // 校验文件类型
|
|
|
|
// if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType())) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // 校验文件体积,不超过1m
|
|
|
|
// long maxSize = 1024 * 1024;
|
|
|
|
// long size = file.getSize();
|
|
|
|
// if (size > maxSize) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return ossService.uploadImg(file, null);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @PostMapping("function/upload")
|
|
|
|
// public Result uploadFunctionLogo(@RequestParam("file") MultipartFile file) {
|
|
|
|
//
|
|
|
|
// // 校验文件类型
|
|
|
|
// if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType())) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // 校验文件体积,不超过1m
|
|
|
|
// long maxSize = 1024 * 1024;
|
|
|
|
// long size = file.getSize();
|
|
|
|
// if (size > maxSize) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return ossService.uploadImg(file, null);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * desc: 党建声音模块 上传图片(2M)或附件(5M)
|
|
|
|
// *
|
|
|
|
// * @param file
|
|
|
|
// * @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UploadImgResultDTO>
|
|
|
|
// * @author LiuJanJun
|
|
|
|
// * @date 2021/3/29 4:56 下午
|
|
|
|
// */
|
|
|
|
// @PostMapping("article/upload")
|
|
|
|
// public Result<UploadImgResultDTO> uploadArticleImg(@RequestParam("file") MultipartFile file) {
|
|
|
|
//
|
|
|
|
// // 校验文件类型 图片或pdf
|
|
|
|
// if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType())
|
|
|
|
// && !MediaType.IMAGE_JPEG_VALUE.equals(file.getContentType())
|
|
|
|
// && !ModuleConstant.FILE_CONTENT_TYPE_JPG.equals(file.getContentType())
|
|
|
|
// && !ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType())
|
|
|
|
// && !file.getContentType().startsWith(ModuleConstant.FILE_CONTENT_TYPE_VEDIO_PREFIX)
|
|
|
|
// ) {
|
|
|
|
// log.error("uploadArticleImg file type:{} is not support 2 upload", file.getContentType());
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg());
|
|
|
|
// }
|
|
|
|
// long size = file.getSize();
|
|
|
|
// if (ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType())) {
|
|
|
|
// // 校验文件大小,不超过5m
|
|
|
|
// long maxSize = 5 * 1024 * 1024;
|
|
|
|
// if (size > maxSize) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg());
|
|
|
|
// }
|
|
|
|
// } else if (file.getContentType().startsWith(ModuleConstant.FILE_CONTENT_TYPE_VEDIO_PREFIX)) {
|
|
|
|
// // 校验文件大小,不超过5m
|
|
|
|
// long maxSize = 25 * 1024 * 1024;
|
|
|
|
// if (size > maxSize) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Result<UploadImgResultDTO> result =null;
|
|
|
|
// String originFileName = file.getOriginalFilename();
|
|
|
|
// String format = "-" + originFileName.substring(originFileName.lastIndexOf(".") + NumConstant.ONE) + "-";
|
|
|
|
// format = format.toLowerCase();
|
|
|
|
// int compressSize = 2 * 1024 * 1024;
|
|
|
|
// // 如果是图片,超过2M的压缩一下
|
|
|
|
// if (ModuleConstant.PROJECT_FILE_IMAGE.contains(format) && file.getSize() > compressSize) {
|
|
|
|
// // 单个图片10M
|
|
|
|
// result= ossService.compressUploadImg(file, null, 2 * 1024);
|
|
|
|
// } else {
|
|
|
|
// result=ossService.uploadImg(file, null);
|
|
|
|
// }
|
|
|
|
// if (result != null && result.success() ){
|
|
|
|
// UploadImgResultDTO data = result.getData();
|
|
|
|
// if ( data!= null && StringUtils.isNotBlank(data.getUrl())){
|
|
|
|
// String path = data.getUrl().replace(data.getDomain(), StrConstant.EPMETY_STR);
|
|
|
|
// if (path.startsWith(StrConstant.SEPARATOR)){
|
|
|
|
// path = path.replaceFirst(StrConstant.SEPARATOR,StrConstant.EPMETY_STR);
|
|
|
|
// }
|
|
|
|
// String fileName = data.getUrl().substring(data.getUrl().lastIndexOf(StrConstant.SEPARATOR)+1);
|
|
|
|
// redisUtils.set(RedisKeys.getOssFileKey(fileName),path,RedisUtils.MINUTE_THIRTY_EXPIRE);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return result;
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// @PostMapping("uploadimg/badgeicon")
|
|
|
|
// public Result<UploadImgResultDTO> badgeIcon(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
|
//
|
|
|
|
// // 校验文件类型
|
|
|
|
// if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType())) {
|
|
|
|
// log.error("uploadArticleImg file type:{} is not support 2 upload", file.getContentType());
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_IMG_TYPE_ERROR.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_IMG_TYPE_ERROR.getMsg());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // 校验文件体积,不超过2m
|
|
|
|
// long maxSize = 2 * 1024 * 1024;
|
|
|
|
// long size = file.getSize();
|
|
|
|
// if (size > maxSize) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
|
|
|
|
// int width = bufferedImage.getWidth();
|
|
|
|
// int height = bufferedImage.getHeight();
|
|
|
|
// if (width != 200 || height != 200) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_IMG_SIZE_ERROR.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_IMG_SIZE_ERROR.getMsg());
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// return ossService.uploadImg(file, null);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @param byteFile fileName
|
|
|
|
// * @Description 外挂-文件上传
|
|
|
|
// * @Author sun
|
|
|
|
// **/
|
|
|
|
// @PostMapping("ext/upload")
|
|
|
|
// public Result<UploadImgResultDTO> extUpload(@RequestParam("byteFile") byte[] byteFile, @RequestParam("fileName") String fileName) throws IOException {
|
|
|
|
// //public Result<UploadImgResultDTO> extUpload(@RequestParam("file") MultipartFile file, @RequestParam("fileName") String fileName) throws IOException {
|
|
|
|
// //byte[] byteFile = file.getBytes();
|
|
|
|
// InputStream inputStream = new ByteArrayInputStream(byteFile);
|
|
|
|
// MultipartFile filse = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
|
|
|
|
// return ossService.extUpload(filse,fileName, null);
|
|
|
|
// }
|
|
|
|
|
|
|
|
/** |
|
|
|
* @param file |
|
|
@ -388,16 +388,16 @@ public class OssController { |
|
|
|
return new Result<Boolean>().ok(ossService.articleRemoveFile(formDTO)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 运营端生成小程序体验码,传递客户Id [开发、测试环境会直接访问生产third,没有token,需要业务中传递客户Id值] |
|
|
|
* @param file 文件 |
|
|
|
* @param file 文件 |
|
|
|
* @author sun |
|
|
|
*/ |
|
|
|
@PostMapping("uploadqrcodeV2") |
|
|
|
public Result<UploadImgResultDTO> uploadQrCodeV2(@RequestPart(value = "file") MultipartFile file, @RequestParam("customerId") String customerId) { |
|
|
|
return ossService.uploadImgV2(file, null, customerId); |
|
|
|
} |
|
|
|
// /**
|
|
|
|
// * 运营端生成小程序体验码,传递客户Id [开发、测试环境会直接访问生产third,没有token,需要业务中传递客户Id值]
|
|
|
|
// * @param file 文件
|
|
|
|
// * @param file 文件
|
|
|
|
// * @author sun
|
|
|
|
// */
|
|
|
|
// @PostMapping("uploadqrcodeV2")
|
|
|
|
// public Result<UploadImgResultDTO> uploadQrCodeV2(@RequestPart(value = "file") MultipartFile file, @RequestParam("customerId") String customerId) {
|
|
|
|
// return ossService.uploadImgV2(file, null, customerId);
|
|
|
|
// }
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 上传报事文件(目前只有图片) |
|
|
@ -432,51 +432,51 @@ public class OssController { |
|
|
|
return ossService.uploadImgV2(file, PrivacyType.EXTERNAL, customerId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 办事指南上传附件 |
|
|
|
* @Param file |
|
|
|
* @Param customerId |
|
|
|
* @Return {@link Result< UploadImgResultDTO>} |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2021/9/8 17:14 |
|
|
|
*/ |
|
|
|
@PostMapping("upload-guide-file") |
|
|
|
public Result<UploadImgResultDTO> uploadGuideFile(@RequestPart(value = "file") MultipartFile file, @RequestParam("customerId") String customerId) { |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
String format = "-" + fileName.substring(fileName.lastIndexOf(".") + NumConstant.ONE) + "-"; |
|
|
|
format = format.toLowerCase(); |
|
|
|
// 体积限制
|
|
|
|
int sizeMb = 10; |
|
|
|
// 大小限制10m
|
|
|
|
int sizeThreshold = sizeMb * 1024 * 1024; |
|
|
|
if (file.getSize() > sizeThreshold) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode(), |
|
|
|
EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg().concat(",限制在").concat(String.valueOf(sizeMb)).concat("M以内")); |
|
|
|
} |
|
|
|
|
|
|
|
// 格式限制,只允许png和jpeg
|
|
|
|
if (!ModuleConstant.GUIDE_FILE_DOC.contains(format)) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() |
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
return ossService.uploadImgV2(file, PrivacyType.EXTERNAL, customerId); |
|
|
|
} |
|
|
|
// /**
|
|
|
|
// * @Description 办事指南上传附件
|
|
|
|
// * @Param file
|
|
|
|
// * @Param customerId
|
|
|
|
// * @Return {@link Result< UploadImgResultDTO>}
|
|
|
|
// * @Author zhaoqifeng
|
|
|
|
// * @Date 2021/9/8 17:14
|
|
|
|
// */
|
|
|
|
// @PostMapping("upload-guide-file")
|
|
|
|
// public Result<UploadImgResultDTO> uploadGuideFile(@RequestPart(value = "file") MultipartFile file, @RequestParam("customerId") String customerId) {
|
|
|
|
// String fileName = file.getOriginalFilename();
|
|
|
|
// String format = "-" + fileName.substring(fileName.lastIndexOf(".") + NumConstant.ONE) + "-";
|
|
|
|
// format = format.toLowerCase();
|
|
|
|
// // 体积限制
|
|
|
|
// int sizeMb = 10;
|
|
|
|
// // 大小限制10m
|
|
|
|
// int sizeThreshold = sizeMb * 1024 * 1024;
|
|
|
|
// if (file.getSize() > sizeThreshold) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode(),
|
|
|
|
// EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg().concat(",限制在").concat(String.valueOf(sizeMb)).concat("M以内"));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // 格式限制,只允许png和jpeg
|
|
|
|
// if (!ModuleConstant.GUIDE_FILE_DOC.contains(format)) {
|
|
|
|
// throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode()
|
|
|
|
// , EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return ossService.uploadImgV2(file, PrivacyType.EXTERNAL, customerId);
|
|
|
|
// }
|
|
|
|
|
|
|
|
@GetMapping("getOssFileUrl") |
|
|
|
public Result<String> download(@RequestParam(required = false) String filePath,@RequestParam(required = false) String privacy){ |
|
|
|
return new Result<String>().ok(ossService.getOssFileUrl(filePath,privacy)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 上传任务描述文件 |
|
|
|
* 不限制大小 |
|
|
|
* @param file |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/importTaskDescFile/upload") |
|
|
|
public Result<UploadImgResultDTO> uploadImportTaskDescFile(@RequestPart("file") MultipartFile file) { |
|
|
|
return ossService.uploadImg(file, null); |
|
|
|
} |
|
|
|
// /**
|
|
|
|
// * 上传任务描述文件
|
|
|
|
// * 不限制大小
|
|
|
|
// * @param file
|
|
|
|
// * @return
|
|
|
|
// */
|
|
|
|
// @PostMapping("/importTaskDescFile/upload")
|
|
|
|
// public Result<UploadImgResultDTO> uploadImportTaskDescFile(@RequestPart("file") MultipartFile file) {
|
|
|
|
// return ossService.uploadImg(file, null);
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|