Merge remote-tracking branch 'origin/master'

This commit is contained in:
温文静WWW 2025-07-23 10:17:59 +08:00
commit b5566cdfe4
13 changed files with 248 additions and 204 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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();

View File

@ -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

View File

@ -31,7 +31,7 @@ spring:
check-template-location: false
profiles:
# 激活的环境,如果需要 quartz 分布式支持,需要修改 active: dev,quartz
active: dev
active: dev,quartz
data:
redis:
repositories:

View File

@ -1,29 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" debug="false">
<contextName>elAdmin</contextName>
<property name="log.charset" value="utf-8" />
<property name="log.pattern" value="%contextName- %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %msg%n" />
<configuration scan="true" scanPeriod="10 seconds">
<!--输出到控制台-->
<!-- 彩色日志 -->
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!-- 格式化输出:%date表示日期%thread表示线程名%-5level级别从左显示5个字符宽度 %msg日志消息%n是换行符-->
<property name="LOG_PATTERN" value="%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
<!-- 定义日志存储的路径,不要配置相对路径 -->
<property name="FILE_PATH" value="/var/log/aircraft-server/spring-log.%d{yyyy-MM-dd}.%i.log" />
<!-- 控制台输出日志 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志级别过滤INFO以下 -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<pattern>${log.pattern}</pattern>
<charset>${log.charset}</charset>
<!-- 按照上面配置的LOG_PATTERN来打印日志 -->
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!--普通日志输出到控制台-->
<root level="info">
<!--每天生成一个日志文件保存15天的日志文件。rollingFile用来切分文件的 -->
<appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${FILE_PATH}</fileNamePattern>
<!-- keep 15 days' worth of history -->
<maxHistory>15</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- 日志文件的最大大小 -->
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- 超出删除老文件 -->
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="console" />
<appender-ref ref="rollingFile" />
</root>
<!-- Spring 日志级别控制 -->
<logger name="org.springframework" level="warn" />
<!-- DnsServerAddressStreamProviders调整为ERROR -->
<logger name="io.netty.resolver.dns.DnsServerAddressStreamProviders" level="ERROR"/>
<!-- 设置其他类的日志级别为 ERROR -->
<logger name="org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]" level="ERROR"/>
<logger name="org.springframework.web.servlet.DispatcherServlet" level="ERROR"/>
</configuration>
</configuration>

View File

@ -15,6 +15,6 @@ outagedetectioninterval=2
# 是否过滤 Log
filter=true
# 过滤 Log 时所排除的 sql 关键字,以逗号分隔
exclude=SELECT 1,INSERT INTO sys_log
exclude=SELECT 1,INSERT INTO sys_log,qrtz_
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
excludecategories=info,debug,result,commit,resultset

View File

@ -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();
}
}

View File

@ -5,10 +5,10 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 本地附件材料DTO
* 附件材料DTO
*/
@Data
public class LocalAttachmentMaterialDTO {
public class AttachmentMaterialDTO {
@ApiModelProperty(value = "id")

View File

@ -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);
//// }
//}

View File

@ -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);
// }
}

View File

@ -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);