APP文件上传
This commit is contained in:
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,10 +72,10 @@ public class SysOssVo implements Serializable {
|
|||||||
* 服务商
|
* 服务商
|
||||||
*/
|
*/
|
||||||
private String service;
|
private String service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内容哈希
|
* 内容哈希
|
||||||
*/
|
*/
|
||||||
private String fileHash;
|
private String fileHash;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user