1. 修改 oss删除
This commit is contained in:
parent
1d2d50d17e
commit
1a844ffa44
|
|
@ -0,0 +1,16 @@
|
|||
package com.chushang.oss.entity.dto;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @auther: zhao
|
||||
* @date: 2024/6/29 18:11
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class UploadBytesDTO {
|
||||
|
||||
private byte[] bytes;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.chushang.oss.entity.dto;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @auther: zhao
|
||||
* @date: 2024/6/29 18:09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class UploadFileDTO {
|
||||
|
||||
private MultipartFile[] files;
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ import com.chushang.common.core.constant.SecurityConstants;
|
|||
import com.chushang.common.core.web.AjaxResult;
|
||||
import com.chushang.common.core.web.Result;
|
||||
import com.chushang.oss.constants.OssConstants;
|
||||
import com.chushang.oss.entity.dto.UploadBytesDTO;
|
||||
import com.chushang.oss.entity.dto.UploadFileDTO;
|
||||
import com.chushang.oss.entity.vo.FileSourceVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -11,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@FeignClient(contextId = "ossFeign",
|
||||
value = OssConstants.OSS_SERVICE,
|
||||
|
|
@ -19,7 +22,7 @@ import java.util.List;
|
|||
public interface RemoteOssService {
|
||||
|
||||
@PostMapping(value = "/upload")
|
||||
Result<List<FileSourceVo>> uploadFile(@RequestParam(value = "files") MultipartFile[] files,
|
||||
Result<List<FileSourceVo>> uploadFile(@RequestBody UploadFileDTO uploadFile,
|
||||
@RequestParam(value = "ocrType", required = false) String ocrType,
|
||||
@RequestParam(value = "sealFlag", required = false, defaultValue= "false") Boolean sealFlag,
|
||||
@RequestParam(value = "formats", required = false) String formats,
|
||||
|
|
@ -28,7 +31,7 @@ public interface RemoteOssService {
|
|||
|
||||
|
||||
@PostMapping(value = "/uploadqccode")
|
||||
Result<String> uploadQcCode() throws Exception;
|
||||
Result<String> uploadQcCode(@RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;
|
||||
|
||||
/**
|
||||
* 通过 文件字节上传,
|
||||
|
|
@ -38,7 +41,7 @@ public interface RemoteOssService {
|
|||
*
|
||||
*/
|
||||
@PostMapping(value = "/upload/bytes")
|
||||
Result<List<FileSourceVo>> uploadFile(@RequestParam(value = "bytes") byte[] bytes,
|
||||
Result<List<FileSourceVo>> uploadFile(@RequestBody UploadBytesDTO uploadBytes,
|
||||
@RequestParam(value = "fileName") String fileName,
|
||||
@RequestParam(value = "sealFlag", required = false, defaultValue= "false") Boolean sealFlag,
|
||||
@RequestParam(value = "formats", required = false) String formats,
|
||||
|
|
@ -48,5 +51,12 @@ public interface RemoteOssService {
|
|||
@GetMapping("/file/{fid}")
|
||||
Result<byte[]> getFile(@PathVariable(name = "fid") String fid,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
@DeleteMapping(value = "/del/{fid}")
|
||||
|
||||
Result<String> delFile(@PathVariable(name = "fid") String fid, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
@PostMapping(value = "/del/batch")
|
||||
Result<String> delFile(@RequestBody Set<String> fids,
|
||||
@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
|
@ -104,7 +105,7 @@ public class FileController {
|
|||
@SysLog(value = "批量文件", businessType = BusinessType.DELETE)
|
||||
@PostMapping(value = "/del/batch")
|
||||
@RequiresPermissions("system:file:del")
|
||||
public AjaxResult delFile(@RequestBody List<String> fids) {
|
||||
public AjaxResult delFile(@RequestBody Set<String> fids) {
|
||||
return AjaxResult.success( fileSourceService.delFileBatch(fids));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
package com.chushang.oss.remote;
|
||||
|
||||
import com.chushang.common.core.constant.SecurityConstants;
|
||||
import com.chushang.common.core.web.AjaxResult;
|
||||
import com.chushang.common.core.web.Result;
|
||||
import com.chushang.common.log.annotation.SysLog;
|
||||
import com.chushang.common.log.enums.BusinessType;
|
||||
import com.chushang.oss.entity.dto.UploadBytesDTO;
|
||||
import com.chushang.oss.entity.dto.UploadFileDTO;
|
||||
import com.chushang.oss.entity.vo.FileSourceVo;
|
||||
import com.chushang.oss.feign.RemoteOssService;
|
||||
import com.chushang.oss.service.FileSourceService;
|
||||
import com.chushang.security.annotation.InnerAuth;
|
||||
import com.chushang.security.annotation.RequiresPermissions;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -13,6 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
|
@ -23,12 +30,14 @@ public class RemoteFileController implements RemoteOssService {
|
|||
@Override
|
||||
@SysLog(value = "feign文件上传", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/upload")
|
||||
public Result<List<FileSourceVo>> uploadFile(@RequestParam(value = "files") MultipartFile[] files,
|
||||
@InnerAuth
|
||||
public Result<List<FileSourceVo>> uploadFile(@RequestBody UploadFileDTO uploadFile,
|
||||
@RequestParam(value = "ocrType", required = false) String ocrType,
|
||||
@RequestParam(value = "sealFlag", required = false, defaultValue= "false") Boolean sealFlag,
|
||||
@RequestParam(value = "formats", required = false) String formats,
|
||||
String source,
|
||||
@RequestHeader(SecurityConstants.FROM_SOURCE)String source,
|
||||
@RequestParam(value = "fileType", required = false) String fileType) {
|
||||
MultipartFile[] files = uploadFile.getFiles();
|
||||
return Result.ok(fileSourceService.addFile(files, ocrType, sealFlag, formats, fileType));
|
||||
}
|
||||
|
||||
|
|
@ -37,29 +46,64 @@ public class RemoteFileController implements RemoteOssService {
|
|||
@Override
|
||||
@SysLog(value = "feign文件上传File类型", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/uploadqccode")
|
||||
public Result<String> uploadQcCode() throws Exception{
|
||||
@InnerAuth
|
||||
public Result<String> uploadQcCode(@RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception{
|
||||
return Result.ok(fileSourceService.uploadQcCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件导出, 有可能是 excel, word, zip, 单图片等
|
||||
* @param bytes 字节
|
||||
* @param uploadBytes 字节
|
||||
*/
|
||||
@Override
|
||||
@SysLog(value = "feign文件", businessType = BusinessType.EXPORT)
|
||||
@PostMapping(value = "/upload/bytes")
|
||||
public Result<List<FileSourceVo>> uploadFile(byte[] bytes, String fileName, Boolean sealFlag, String formats, String fileType, String source)
|
||||
@InnerAuth
|
||||
public Result<List<FileSourceVo>> uploadFile(@RequestBody UploadBytesDTO uploadBytes,
|
||||
String fileName,
|
||||
Boolean sealFlag,
|
||||
String formats,
|
||||
String fileType,
|
||||
@RequestHeader(SecurityConstants.FROM_SOURCE) String source)
|
||||
{
|
||||
byte[] bytes = uploadBytes.getBytes();
|
||||
return Result.ok(fileSourceService.uploadFile(bytes, fileName, sealFlag, formats, fileType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SysLog(value = "feign文件", businessType = BusinessType.DOWNLOAD)
|
||||
@GetMapping("/getFile/{fid}")
|
||||
public Result<byte[]> getFile(@PathVariable String fid,String source)
|
||||
@InnerAuth
|
||||
public Result<byte[]> getFile(@PathVariable String fid,@RequestHeader(SecurityConstants.FROM_SOURCE) String source)
|
||||
{
|
||||
return Result.ok(fileSourceService.getFile(fid));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param fid 文件id
|
||||
*/
|
||||
@SysLog(value = "文件", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping(value = "/del/{fid}")
|
||||
@InnerAuth
|
||||
public Result<String> delFile(@PathVariable String fid, @RequestHeader(SecurityConstants.FROM_SOURCE) String source) {
|
||||
fileSourceService.delFile(fid);
|
||||
return Result.ok("success");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param fids 文件fid
|
||||
*/
|
||||
@SysLog(value = "批量文件", businessType = BusinessType.DELETE)
|
||||
@PostMapping(value = "/del/batch")
|
||||
@InnerAuth
|
||||
public Result<String> delFile(@RequestBody Set<String> fids,
|
||||
@RequestHeader(SecurityConstants.FROM_SOURCE) String source) {
|
||||
return Result.ok( fileSourceService.delFileBatch(fids));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ public class FileSourceService
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public String delFileBatch(List<String> fids)
|
||||
public String delFileBatch(Set<String> fids)
|
||||
{
|
||||
// 文件信息
|
||||
List<FileSourceInfo> list = list(new LambdaQueryWrapper<FileSourceInfo>()
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ public interface OssService {
|
|||
default String upload(byte[] data, FileSourceInfo info, Boolean sealFlag, String formats){
|
||||
InputStream inputStream = new ByteArrayInputStream(data);
|
||||
// 为true 时 添加水印
|
||||
if (sealFlag){
|
||||
if (StringUtils.isEmpty(formats)) throw new ResultException("添加水印时, 水印内容不能为空");
|
||||
if (sealFlag && StringUtils.isNotEmpty(formats)){
|
||||
// if (StringUtils.isEmpty(formats)) throw new ResultException("添加水印时, 水印内容不能为空");
|
||||
inputStream = FileUtils.waterSeal(Arrays.stream(formats.split(",")).toList(), inputStream);
|
||||
}
|
||||
return upload(inputStream, info);
|
||||
|
|
|
|||
Loading…
Reference in New Issue