1 Commits

Author SHA1 Message Date
b33ee00dbd APP文件上传 2025-12-01 10:34:41 +08:00
6 changed files with 37 additions and 18 deletions

View File

@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -39,7 +40,7 @@ public class AppFileController extends BaseController {
* 上传文件 * 上传文件
*/ */
@PostMapping("/upload") @PostMapping("/upload")
public R<Void> upload(@Validated @ModelAttribute AppFileDto bo) { public R<Void> upload(@Validated @ModelAttribute AppFileDto bo) throws IOException {
return toAjax(appFileService.add(bo)); return toAjax(appFileService.add(bo));
} }

View File

@ -8,6 +8,7 @@ import com.fuyuanshen.common.core.exception.ServiceException;
import com.fuyuanshen.common.oss.core.OssClient; import com.fuyuanshen.common.oss.core.OssClient;
import com.fuyuanshen.common.oss.factory.OssFactory; import com.fuyuanshen.common.oss.factory.OssFactory;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper; import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.equipment.utils.FileHashUtil;
import com.fuyuanshen.system.domain.vo.SysOssVo; import com.fuyuanshen.system.domain.vo.SysOssVo;
import com.fuyuanshen.system.service.ISysOssService; import com.fuyuanshen.system.service.ISysOssService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -15,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -31,24 +33,38 @@ public class AppFileService {
private final IAppBusinessFileService appBusinessFileService; private final IAppBusinessFileService appBusinessFileService;
private final FileHashUtil fileHashUtil;
private final ISysOssService ossService;
public List<AppFileVo> list(AppBusinessFileBo bo) { public List<AppFileVo> list(AppBusinessFileBo bo) {
// bo.setCreateBy(AppLoginHelper.getUserId()); // bo.setCreateBy(AppLoginHelper.getUserId());
return appBusinessFileService.queryAppFileList(bo); return appBusinessFileService.queryAppFileList(bo);
} }
public Boolean add(AppFileDto bo) {
/**
* APP文件上传
*/
public Boolean add(AppFileDto bo) throws IOException {
MultipartFile[] files = bo.getFiles(); MultipartFile[] files = bo.getFiles();
if(files == null || files.length == 0){ if (files == null || files.length == 0) {
throw new ServiceException("请选择要上传的文件"); throw new ServiceException("请选择要上传的文件");
} }
if(files.length > 5){ if (files.length > 5) {
throw new ServiceException("最多只能上传5个文件"); throw new ServiceException("最多只能上传5个文件");
} }
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i]; MultipartFile file = files[i];
// 上传文件 // 上传文件
SysOssVo upload = sysOssService.upload(file); // SysOssVo upload = sysOssService.upload(file);
String fileHash = fileHashUtil.hash(file);
SysOssVo upload = ossService.updateHash(file, fileHash);
// 强制将HTTP替换为HTTPS
if (upload.getUrl() != null && upload.getUrl().startsWith("http://")) {
upload.setUrl(upload.getUrl().replaceFirst("^http://", "https://"));
}
if (upload == null) { if (upload == null) {
return false; return false;
@ -66,6 +82,7 @@ public class AppFileService {
return true; return true;
} }
public Boolean delete(Long[] ids) { public Boolean delete(Long[] ids) {
AppBusinessFileBo bo = new AppBusinessFileBo(); AppBusinessFileBo bo = new AppBusinessFileBo();
// bo.setCreateBy(AppLoginHelper.getUserId()); // bo.setCreateBy(AppLoginHelper.getUserId());
@ -79,4 +96,5 @@ public class AppFileService {
} }
return appBusinessFileService.deleteWithValidByIds(List.of(ids), true); return appBusinessFileService.deleteWithValidByIds(List.of(ids), true);
} }
} }

View File

@ -8,8 +8,8 @@ spring.boot.admin.client:
metadata: metadata:
username: ${spring.boot.admin.client.username} username: ${spring.boot.admin.client.username}
userpassword: ${spring.boot.admin.client.password} userpassword: ${spring.boot.admin.client.password}
username: ${monitor.username} username: @monitor.username@
password: ${monitor.password} password: @monitor.password@
--- # snail-job 配置 --- # snail-job 配置
snail-job: snail-job:

View File

@ -11,8 +11,8 @@ spring.boot.admin.client:
metadata: metadata:
username: ${spring.boot.admin.client.username} username: ${spring.boot.admin.client.username}
userpassword: ${spring.boot.admin.client.password} userpassword: ${spring.boot.admin.client.password}
username: ${monitor.username} username: @monitor.username@
password: ${monitor.password} password: @monitor.password@
--- # snail-job 配置 --- # snail-job 配置
snail-job: snail-job:

View File

@ -72,10 +72,10 @@ public class SysOssVo implements Serializable {
* 服务商 * 服务商
*/ */
private String service; private String service;
/** /**
* 内容哈希 * 内容哈希
*/ */
private String fileHash; private String fileHash;
} }

16
pom.xml
View File

@ -85,10 +85,10 @@
<monitor.username>fys</monitor.username> <monitor.username>fys</monitor.username>
<monitor.password>123456</monitor.password> <monitor.password>123456</monitor.password>
</properties> </properties>
<!-- <activation> --> <activation>
<!-- &lt;!&ndash; 默认环境 &ndash;&gt; --> <!-- 默认环境 -->
<!-- <activeByDefault>true</activeByDefault> --> <activeByDefault>true</activeByDefault>
<!-- </activation> --> </activation>
</profile> </profile>
<profile> <profile>
<id>prod</id> <id>prod</id>
@ -98,10 +98,10 @@
<monitor.username>fys</monitor.username> <monitor.username>fys</monitor.username>
<monitor.password>123456</monitor.password> <monitor.password>123456</monitor.password>
</properties> </properties>
<activation> <!-- <activation> -->
<!-- 默认环境 --> <!-- &lt;!&ndash; 默认环境 &ndash;&gt; -->
<activeByDefault>true</activeByDefault> <!-- <activeByDefault>true</activeByDefault> -->
</activation> <!-- </activation> -->
</profile> </profile>
<profile> <profile>
<id>jingquan</id> <id>jingquan</id>