feat[订单图片模块]:缩略图生成访问url,订单图片上传等逻辑
This commit is contained in:
@@ -58,4 +58,9 @@ public class FileController {
|
||||
public PageResult<FileInfo> findFiles(@RequestParam Map<String, Object> params) {
|
||||
return fileService.findList(params);
|
||||
}
|
||||
|
||||
@GetMapping("/files/{id}")
|
||||
public String getViewUrl(@PathVariable String id) {
|
||||
return fileService.getViewUrl(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.central.file.service;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.file.model.FileInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.central.file.model.FileInfo;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件service
|
||||
@@ -16,10 +15,12 @@ import com.central.file.model.FileInfo;
|
||||
*/
|
||||
public interface IFileService extends IService<FileInfo> {
|
||||
FileInfo upload(MultipartFile file ) throws Exception;
|
||||
|
||||
|
||||
PageResult<FileInfo> findList(Map<String, Object> params);
|
||||
|
||||
void delete(String id);
|
||||
|
||||
void out(String id, OutputStream os);
|
||||
|
||||
String getViewUrl(String id);
|
||||
}
|
||||
|
||||
+12
-7
@@ -7,8 +7,6 @@ import com.central.oss.model.ObjectInfo;
|
||||
import com.central.oss.properties.FileServerProperties;
|
||||
import com.central.oss.template.CosTemplate;
|
||||
import com.qcloud.cos.model.COSObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -53,11 +51,13 @@ public class CosService extends AbstractIFileService {
|
||||
}
|
||||
}
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private class S3Object {
|
||||
private String bucketName;
|
||||
private String objectName;
|
||||
@Override
|
||||
public String getViewUrl(String fileId) {
|
||||
FileInfo fileInfo = baseMapper.selectById(fileId);
|
||||
if (fileInfo != null) {
|
||||
return cosTemplate.getViewUrl(fileInfo.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private COSObject parsePath(String path) {
|
||||
@@ -71,4 +71,9 @@ public class CosService extends AbstractIFileService {
|
||||
}
|
||||
return cosObject;
|
||||
}
|
||||
|
||||
private String getThumbnailFile(COSObject cosObject) {
|
||||
|
||||
return cosTemplate.getViewUrl(cosObject.getBucketName(),cosObject.getKey(),1000);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -41,4 +41,9 @@ public class FastdfsService extends AbstractIFileService {
|
||||
@Override
|
||||
public void out(String id, OutputStream os) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrl(String id) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,11 @@ public class S3Service extends AbstractIFileService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrl(String id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private class S3Object {
|
||||
|
||||
Reference in New Issue
Block a user