feat:阿里云oss接入
This commit is contained in:
parent
28a1ae7298
commit
071d9a97fd
@ -1,7 +1,7 @@
|
||||
package com.aircraft.modules.aircraft.domain;
|
||||
|
||||
import com.aircraft.base.BaseEntity;
|
||||
import com.aircraft.domain.dto.LocalAttachmentMaterialDTO;
|
||||
import com.aircraft.domain.dto.AttachmentMaterialDTO;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -96,6 +96,6 @@ public class AircraftDevice extends BaseEntity {
|
||||
@NotNull
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "设备图片")
|
||||
private List<LocalAttachmentMaterialDTO> deviceImages;
|
||||
private List<AttachmentMaterialDTO> deviceImages;
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.aircraft.modules.aircraft.domain;
|
||||
|
||||
import com.aircraft.base.BaseEntity;
|
||||
import com.aircraft.domain.dto.LocalAttachmentMaterialDTO;
|
||||
import com.aircraft.domain.dto.AttachmentMaterialDTO;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -71,7 +71,7 @@ public class AircraftInsurance extends BaseEntity {
|
||||
@NotNull
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "保险附件")
|
||||
private List<LocalAttachmentMaterialDTO> insuranceAttachment;
|
||||
private List<AttachmentMaterialDTO> insuranceAttachment;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.aircraft.modules.aircraft.service.impl;
|
||||
|
||||
import com.aircraft.domain.dto.LocalAttachmentMaterialDTO;
|
||||
import com.aircraft.domain.dto.AttachmentMaterialDTO;
|
||||
import com.aircraft.exception.BadRequestException;
|
||||
import com.aircraft.modules.aircraft.domain.AircraftDevice;
|
||||
import com.aircraft.modules.aircraft.domain.dto.AircraftDevicePageDTO;
|
||||
@ -113,14 +113,14 @@ public class AircraftDeviceServiceImpl extends ServiceImpl<AircraftDeviceMapper,
|
||||
public AircraftDevice findById(Long id) {
|
||||
AircraftDevice aircraftDevice = getById(id);
|
||||
if (null != aircraftDevice) {
|
||||
List<LocalAttachmentMaterialDTO> deviceImages = attachmentMaterialService
|
||||
List<AttachmentMaterialDTO> deviceImages = attachmentMaterialService
|
||||
.lambdaQuery()
|
||||
.eq(AttachmentMaterial::getBusinessType, BUSINESS_TYPE)
|
||||
.eq(AttachmentMaterial::getBusinessId, id)
|
||||
.list()
|
||||
.stream()
|
||||
.map(attachmentMaterial -> {
|
||||
LocalAttachmentMaterialDTO localAttachmentMaterialDTO = new LocalAttachmentMaterialDTO();
|
||||
AttachmentMaterialDTO localAttachmentMaterialDTO = new AttachmentMaterialDTO();
|
||||
BeanUtils.copyProperties(attachmentMaterial, localAttachmentMaterialDTO);
|
||||
return localAttachmentMaterialDTO;
|
||||
}).toList();
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.aircraft.modules.aircraft.service.impl;
|
||||
|
||||
import com.aircraft.domain.dto.LocalAttachmentMaterialDTO;
|
||||
import com.aircraft.domain.dto.AttachmentMaterialDTO;
|
||||
import com.aircraft.modules.aircraft.domain.AircraftInsurance;
|
||||
import com.aircraft.modules.aircraft.mapper.AircraftInsuranceMapper;
|
||||
import com.aircraft.modules.aircraft.service.AircraftInsuranceService;
|
||||
@ -102,14 +102,14 @@ public class AircraftInsuranceServiceImpl extends ServiceImpl<AircraftInsuranceM
|
||||
public AircraftInsurance findById(Long id) {
|
||||
AircraftInsurance aircraftInsurance = getById(id);
|
||||
if (null != aircraftInsurance) {
|
||||
List<LocalAttachmentMaterialDTO> insuranceAttachment = attachmentMaterialService
|
||||
List<AttachmentMaterialDTO> insuranceAttachment = attachmentMaterialService
|
||||
.lambdaQuery()
|
||||
.eq(AttachmentMaterial::getBusinessType, BUSINESS_TYPE)
|
||||
.eq(AttachmentMaterial::getBusinessId, id)
|
||||
.list()
|
||||
.stream()
|
||||
.map(attachmentMaterial -> {
|
||||
LocalAttachmentMaterialDTO localAttachmentMaterialDTO = new LocalAttachmentMaterialDTO();
|
||||
AttachmentMaterialDTO localAttachmentMaterialDTO = new AttachmentMaterialDTO();
|
||||
BeanUtils.copyProperties(attachmentMaterial, localAttachmentMaterialDTO);
|
||||
return localAttachmentMaterialDTO;
|
||||
}).toList();
|
||||
|
@ -127,15 +127,16 @@ file:
|
||||
amz:
|
||||
s3:
|
||||
# 地域
|
||||
region: test
|
||||
region: cn-wulanchabu
|
||||
# 地域对应的 endpoint
|
||||
endPoint: https://s3.test.com
|
||||
endPoint: https://oss-cn-wulanchabu.aliyuncs.com
|
||||
# 访问的域名
|
||||
domain: https://s3.test.com
|
||||
domain: https://aishangyun.oss-cn-wulanchabu.aliyuncs.com/
|
||||
# 账号的认证信息,或者子账号的认证信息
|
||||
accessKey: 填写你的AccessKey
|
||||
secretKey: 填写你的SecretKey
|
||||
accessKey: LTAI5tRK1mszQC82s2rCkowq
|
||||
secretKey: Ns8VAkRBauIuC207s3eGiqMrLbpF4e
|
||||
# 存储桶(Bucket)
|
||||
defaultBucket: 填写你的存储桶名称
|
||||
defaultBucket: aishangyun
|
||||
|
||||
# 文件存储路径
|
||||
timeformat: yyyy-MM
|
@ -6,8 +6,13 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.auth.signer.AwsS3V4Signer;
|
||||
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
|
||||
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
import software.amazon.awssdk.services.s3.S3Configuration;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
@ -72,6 +77,16 @@ public class AmzS3Config {
|
||||
return S3Client.builder().region(Region.of(region))
|
||||
.endpointOverride(URI.create(endPoint))
|
||||
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
|
||||
.overrideConfiguration(
|
||||
ClientOverrideConfiguration.builder()
|
||||
.putAdvancedOption(SdkAdvancedClientOption.SIGNER, AwsS3V4Signer.create())
|
||||
.build()
|
||||
)
|
||||
.serviceConfiguration(
|
||||
S3Configuration.builder()
|
||||
.chunkedEncodingEnabled(false) // 关闭chunked encoding
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -5,10 +5,10 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 本地附件材料DTO
|
||||
* 附件材料DTO
|
||||
*/
|
||||
@Data
|
||||
public class LocalAttachmentMaterialDTO {
|
||||
public class AttachmentMaterialDTO {
|
||||
|
||||
|
||||
@ApiModelProperty(value = "id")
|
@ -1,112 +1,112 @@
|
||||
/*
|
||||
* Copyright 2019-2025 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.aircraft.rest;
|
||||
|
||||
import com.aircraft.domain.dto.LocalAttachmentMaterialDTO;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.aircraft.annotation.Log;
|
||||
import com.aircraft.domain.LocalStorage;
|
||||
import com.aircraft.exception.BadRequestException;
|
||||
import com.aircraft.service.LocalStorageService;
|
||||
import com.aircraft.domain.dto.LocalStorageQueryCriteria;
|
||||
import com.aircraft.utils.FileUtil;
|
||||
import com.aircraft.utils.PageResult;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "工具:本地存储管理")
|
||||
@RequestMapping("/api/localStorage")
|
||||
public class LocalStorageController {
|
||||
|
||||
private final LocalStorageService localStorageService;
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation("查询文件")
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public ResponseEntity<PageResult<LocalStorage>> queryFile(LocalStorageQueryCriteria criteria){
|
||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(localStorageService.queryAll(criteria,page),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public void exportFile(HttpServletResponse response, LocalStorageQueryCriteria criteria) throws IOException {
|
||||
localStorageService.download(localStorageService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("上传文件")
|
||||
public ResponseEntity<Object> createFile(@RequestPart("file") MultipartFile file){
|
||||
LocalStorage localStorage = localStorageService.create(file.getOriginalFilename(), file);
|
||||
LocalAttachmentMaterialDTO localAttachmentMaterialDTO = new LocalAttachmentMaterialDTO();
|
||||
localAttachmentMaterialDTO.setFileType(localStorage.getSuffix());
|
||||
localAttachmentMaterialDTO.setFileSize(file.getSize());
|
||||
localAttachmentMaterialDTO.setNewFileName(localStorage.getRealName());
|
||||
localAttachmentMaterialDTO.setSourceFileName(localStorage.getName());
|
||||
localAttachmentMaterialDTO.setFileFullPath("/file/" + localStorage.getType() + "/" + localStorage.getRealName());
|
||||
return new ResponseEntity<>(localAttachmentMaterialDTO, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("上传图片")
|
||||
@PostMapping("/pictures")
|
||||
public ResponseEntity<LocalAttachmentMaterialDTO> uploadPicture(@RequestPart("file") MultipartFile file){
|
||||
// 判断文件是否为图片
|
||||
String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
||||
if(!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))){
|
||||
throw new BadRequestException("只能上传图片");
|
||||
}
|
||||
LocalStorage localStorage = localStorageService.create(file.getOriginalFilename(), file);
|
||||
LocalAttachmentMaterialDTO localAttachmentMaterialDTO = new LocalAttachmentMaterialDTO();
|
||||
localAttachmentMaterialDTO.setFileType(localStorage.getSuffix());
|
||||
localAttachmentMaterialDTO.setFileSize(file.getSize());
|
||||
localAttachmentMaterialDTO.setNewFileName(localStorage.getRealName());
|
||||
localAttachmentMaterialDTO.setSourceFileName(localStorage.getName());
|
||||
localAttachmentMaterialDTO.setFileFullPath("/file/" + localStorage.getType() + "/" + localStorage.getRealName());
|
||||
return new ResponseEntity<>(localAttachmentMaterialDTO, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// @PutMapping
|
||||
// @Log("修改文件")
|
||||
// @ApiOperation("修改文件")
|
||||
// public ResponseEntity<Object> updateFile(@Validated @RequestBody LocalStorage resources){
|
||||
// localStorageService.update(resources);
|
||||
// return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
///*
|
||||
// * Copyright 2019-2025 Zheng Jie
|
||||
// *
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * Unless required by applicable law or agreed to in writing, software
|
||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// * See the License for the specific language governing permissions and
|
||||
// * limitations under the License.
|
||||
// */
|
||||
//package com.aircraft.rest;
|
||||
//
|
||||
//import com.aircraft.domain.dto.LocalAttachmentMaterialDTO;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import com.aircraft.annotation.Log;
|
||||
//import com.aircraft.domain.LocalStorage;
|
||||
//import com.aircraft.exception.BadRequestException;
|
||||
//import com.aircraft.service.LocalStorageService;
|
||||
//import com.aircraft.domain.dto.LocalStorageQueryCriteria;
|
||||
//import com.aircraft.utils.FileUtil;
|
||||
//import com.aircraft.utils.PageResult;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.ResponseEntity;
|
||||
//import org.springframework.security.access.prepost.PreAuthorize;
|
||||
//import org.springframework.validation.annotation.Validated;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//import io.swagger.annotations.*;
|
||||
//import org.springframework.web.multipart.MultipartFile;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.io.IOException;
|
||||
//
|
||||
///**
|
||||
//* @author Zheng Jie
|
||||
//* @date 2019-09-05
|
||||
//*/
|
||||
//@RestController
|
||||
//@RequiredArgsConstructor
|
||||
//@Api(tags = "工具:本地存储管理")
|
||||
//@RequestMapping("/api/localStorage")
|
||||
//public class LocalStorageController {
|
||||
//
|
||||
// private final LocalStorageService localStorageService;
|
||||
//
|
||||
// @GetMapping
|
||||
// @ApiOperation("查询文件")
|
||||
// @PreAuthorize("@el.check('storage:list')")
|
||||
// public ResponseEntity<PageResult<LocalStorage>> queryFile(LocalStorageQueryCriteria criteria){
|
||||
// Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
// return new ResponseEntity<>(localStorageService.queryAll(criteria,page),HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// @Log("删除文件")
|
||||
// @DeleteMapping
|
||||
// @ApiOperation("多选删除")
|
||||
// @PreAuthorize("@el.check('storage:del')")
|
||||
// public ResponseEntity<Object> deleteFile(@RequestBody Long[] ids) {
|
||||
// localStorageService.deleteAll(ids);
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
// @ApiOperation("导出数据")
|
||||
// @GetMapping(value = "/download")
|
||||
// @PreAuthorize("@el.check('storage:list')")
|
||||
// public void exportFile(HttpServletResponse response, LocalStorageQueryCriteria criteria) throws IOException {
|
||||
// localStorageService.download(localStorageService.queryAll(criteria), response);
|
||||
// }
|
||||
}
|
||||
//
|
||||
// @PostMapping
|
||||
// @ApiOperation("上传文件")
|
||||
// public ResponseEntity<Object> createFile(@RequestPart("file") MultipartFile file){
|
||||
// LocalStorage localStorage = localStorageService.create(file.getOriginalFilename(), file);
|
||||
// LocalAttachmentMaterialDTO localAttachmentMaterialDTO = new LocalAttachmentMaterialDTO();
|
||||
// localAttachmentMaterialDTO.setFileType(localStorage.getSuffix());
|
||||
// localAttachmentMaterialDTO.setFileSize(file.getSize());
|
||||
// localAttachmentMaterialDTO.setNewFileName(localStorage.getRealName());
|
||||
// localAttachmentMaterialDTO.setSourceFileName(localStorage.getName());
|
||||
// localAttachmentMaterialDTO.setFileFullPath("/file/" + localStorage.getType() + "/" + localStorage.getRealName());
|
||||
// return new ResponseEntity<>(localAttachmentMaterialDTO, HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("上传图片")
|
||||
// @PostMapping("/pictures")
|
||||
// public ResponseEntity<LocalAttachmentMaterialDTO> uploadPicture(@RequestPart("file") MultipartFile file){
|
||||
// // 判断文件是否为图片
|
||||
// String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
||||
// if(!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))){
|
||||
// throw new BadRequestException("只能上传图片");
|
||||
// }
|
||||
// LocalStorage localStorage = localStorageService.create(file.getOriginalFilename(), file);
|
||||
// LocalAttachmentMaterialDTO localAttachmentMaterialDTO = new LocalAttachmentMaterialDTO();
|
||||
// localAttachmentMaterialDTO.setFileType(localStorage.getSuffix());
|
||||
// localAttachmentMaterialDTO.setFileSize(file.getSize());
|
||||
// localAttachmentMaterialDTO.setNewFileName(localStorage.getRealName());
|
||||
// localAttachmentMaterialDTO.setSourceFileName(localStorage.getName());
|
||||
// localAttachmentMaterialDTO.setFileFullPath("/file/" + localStorage.getType() + "/" + localStorage.getRealName());
|
||||
// return new ResponseEntity<>(localAttachmentMaterialDTO, HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
//// @PutMapping
|
||||
//// @Log("修改文件")
|
||||
//// @ApiOperation("修改文件")
|
||||
//// public ResponseEntity<Object> updateFile(@Validated @RequestBody LocalStorage resources){
|
||||
//// localStorageService.update(resources);
|
||||
//// return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
//// }
|
||||
////
|
||||
//// @Log("删除文件")
|
||||
//// @DeleteMapping
|
||||
//// @ApiOperation("多选删除")
|
||||
//// @PreAuthorize("@el.check('storage:del')")
|
||||
//// public ResponseEntity<Object> deleteFile(@RequestBody Long[] ids) {
|
||||
//// localStorageService.deleteAll(ids);
|
||||
//// return new ResponseEntity<>(HttpStatus.OK);
|
||||
//// }
|
||||
//}
|
@ -15,27 +15,18 @@
|
||||
*/
|
||||
package com.aircraft.rest;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.aircraft.domain.dto.AttachmentMaterialDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.aircraft.annotation.Log;
|
||||
import com.aircraft.config.AmzS3Config;
|
||||
import com.aircraft.domain.S3Storage;
|
||||
import com.aircraft.domain.dto.S3StorageQueryCriteria;
|
||||
import com.aircraft.service.S3StorageService;
|
||||
import com.aircraft.utils.PageResult;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* amz S3 协议云存储管理
|
||||
@ -51,55 +42,57 @@ public class S3StorageController {
|
||||
|
||||
private final AmzS3Config amzS3Config;
|
||||
private final S3StorageService s3StorageService;
|
||||
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public void exportS3Storage(HttpServletResponse response, S3StorageQueryCriteria criteria) throws IOException {
|
||||
s3StorageService.download(s3StorageService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation("查询文件")
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public ResponseEntity<PageResult<S3Storage>> queryS3Storage(S3StorageQueryCriteria criteria){
|
||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(s3StorageService.queryAll(criteria, page),HttpStatus.OK);
|
||||
}
|
||||
//
|
||||
// @ApiOperation("导出数据")
|
||||
// @GetMapping(value = "/download")
|
||||
// @PreAuthorize("@el.check('storage:list')")
|
||||
// public void exportS3Storage(HttpServletResponse response, S3StorageQueryCriteria criteria) throws IOException {
|
||||
// s3StorageService.download(s3StorageService.queryAll(criteria), response);
|
||||
// }
|
||||
//
|
||||
// @GetMapping
|
||||
// @ApiOperation("查询文件")
|
||||
// @PreAuthorize("@el.check('storage:list')")
|
||||
// public ResponseEntity<PageResult<S3Storage>> queryS3Storage(S3StorageQueryCriteria criteria){
|
||||
// Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
// return new ResponseEntity<>(s3StorageService.queryAll(criteria, page),HttpStatus.OK);
|
||||
// }
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("上传文件")
|
||||
public ResponseEntity<Object> uploadS3Storage(@RequestPart("file") MultipartFile file){
|
||||
public ResponseEntity<AttachmentMaterialDTO> uploadS3Storage(@RequestPart("file") MultipartFile file){
|
||||
S3Storage storage = s3StorageService.upload(file);
|
||||
Map<String,Object> map = new HashMap<>(3);
|
||||
map.put("id",storage.getId());
|
||||
map.put("errno",0);
|
||||
map.put("data",new String[]{amzS3Config.getDomain() + "/" + storage.getFilePath()});
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
AttachmentMaterialDTO attachmentMaterialDTO = new AttachmentMaterialDTO();
|
||||
attachmentMaterialDTO.setFileType(storage.getFileType());
|
||||
attachmentMaterialDTO.setFileSize(file.getSize());
|
||||
attachmentMaterialDTO.setNewFileName(storage.getFileRealName());
|
||||
attachmentMaterialDTO.setSourceFileName(storage.getFileName());
|
||||
attachmentMaterialDTO.setFileFullPath(storage.getFileFullPath());
|
||||
return new ResponseEntity<>(attachmentMaterialDTO, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("下载文件")
|
||||
@ApiOperation("下载文件")
|
||||
@GetMapping(value = "/download/{id}")
|
||||
public ResponseEntity<Object> downloadS3Storage(@PathVariable Long id){
|
||||
Map<String,Object> map = new HashMap<>(1);
|
||||
S3Storage storage = s3StorageService.getById(id);
|
||||
if (storage == null) {
|
||||
map.put("message", "文件不存在或已被删除");
|
||||
return new ResponseEntity<>(map, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
// 仅适合公开文件访问,私有文件可以使用服务中的 privateDownload 方法
|
||||
String url = amzS3Config.getDomain() + "/" + storage.getFilePath();
|
||||
map.put("url", url);
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("删除多个文件")
|
||||
@DeleteMapping
|
||||
@ApiOperation("删除多个文件")
|
||||
@PreAuthorize("@el.check('storage:del')")
|
||||
public ResponseEntity<Object> deleteAllS3Storage(@RequestBody List<Long> ids) {
|
||||
s3StorageService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
// @Log("下载文件")
|
||||
// @ApiOperation("下载文件")
|
||||
// @GetMapping(value = "/download/{id}")
|
||||
// public ResponseEntity<Object> downloadS3Storage(@PathVariable Long id){
|
||||
// Map<String,Object> map = new HashMap<>(1);
|
||||
// S3Storage storage = s3StorageService.getById(id);
|
||||
// if (storage == null) {
|
||||
// map.put("message", "文件不存在或已被删除");
|
||||
// return new ResponseEntity<>(map, HttpStatus.NOT_FOUND);
|
||||
// }
|
||||
// // 仅适合公开文件访问,私有文件可以使用服务中的 privateDownload 方法
|
||||
// String url = amzS3Config.getDomain() + "/" + storage.getFilePath();
|
||||
// map.put("url", url);
|
||||
// return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// @Log("删除多个文件")
|
||||
// @DeleteMapping
|
||||
// @ApiOperation("删除多个文件")
|
||||
// @PreAuthorize("@el.check('storage:del')")
|
||||
// public ResponseEntity<Object> deleteAllS3Storage(@RequestBody List<Long> ids) {
|
||||
// s3StorageService.deleteAll(ids);
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
// }
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.aircraft.utils.PageUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -129,9 +131,9 @@ public class S3StorageServiceImpl extends ServiceImpl<S3StorageMapper, S3Storage
|
||||
.build();
|
||||
// 创建 S3Storage 实例
|
||||
S3Storage s3Storage = new S3Storage();
|
||||
try {
|
||||
try (InputStream inputStream = file.getInputStream()){
|
||||
// 上传文件到 S3
|
||||
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(file.getInputStream(), file.getSize()));
|
||||
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(inputStream, file.getSize()));
|
||||
// 设置 S3Storage 属性
|
||||
s3Storage.setFileMimeType(FileUtil.getMimeType(originalName));
|
||||
s3Storage.setFileName(originalName);
|
||||
|
Loading…
Reference in New Issue
Block a user