修改文件访问地址
This commit is contained in:
parent
07d569c99e
commit
63bab38f8b
|
|
@ -10,6 +10,7 @@ import com.bonus.business.service.ProductScreenService;
|
|||
import com.bonus.common.config.MinioConfig;
|
||||
import com.bonus.common.core.domain.AjaxResult;
|
||||
import com.bonus.common.utils.StringUtils;
|
||||
import com.bonus.file.minio.MinioUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -31,6 +32,9 @@ public class ProductScreenImpl implements ProductScreenService {
|
|||
@Resource
|
||||
private MinioConfig minioConfig;
|
||||
|
||||
@Autowired
|
||||
public MinioUtil minioUtil;
|
||||
|
||||
|
||||
@Override
|
||||
public AjaxResult getProductList(TbProduct product) {
|
||||
|
|
@ -38,7 +42,8 @@ public class ProductScreenImpl implements ProductScreenService {
|
|||
List<TbProduct> list=mapper.getProductList(product);
|
||||
if(StringUtils.isNotEmpty(list)){
|
||||
list.forEach(vo->{
|
||||
vo.setLinkImage(minioConfig.getUrl()+"/"+minioConfig.getBucketName()+vo.getLinkImage());
|
||||
String url = minioUtil.getFileUrl(minioConfig.getBucketName(),vo.getLinkImage(),60*60*12);
|
||||
vo.setLinkImage(url);
|
||||
});
|
||||
}
|
||||
return AjaxResult.success(list);
|
||||
|
|
@ -60,27 +65,20 @@ public class ProductScreenImpl implements ProductScreenService {
|
|||
TbProduct vo=mapper.getProductDetails(product);
|
||||
if(vo!=null){
|
||||
//封面图
|
||||
vo.setLinkImage(minioConfig.getUrl()+"/"+minioConfig.getBucketName()+vo.getLinkImage());
|
||||
List<TbProductCase> productCases=productMapper.getProductCaseList(product.getId());
|
||||
for (TbProductCase productCase:productCases) {
|
||||
//产品案例
|
||||
List<ProductCaseImage> caseImages=productMapper.getCaseImageByTable(productCase.getId(),"tb_product_case");
|
||||
if(StringUtils.isNotEmpty(caseImages)){
|
||||
caseImages.forEach(image->{
|
||||
image.setUrl(minioConfig.getUrl()+"/"+image.getBucketName()+image.getFilePath());
|
||||
});
|
||||
productCase.setImageList(caseImages);
|
||||
}
|
||||
}
|
||||
vo.setList(productCases);
|
||||
String url = minioUtil.getFileUrl(minioConfig.getBucketName(),vo.getLinkImage(),60*60*12);
|
||||
vo.setLinkImage(url);
|
||||
// vo.setLinkImage(minioConfig.getUrl()+"/"+minioConfig.getBucketName()+vo.getLinkImage());
|
||||
getProductDetails(product, vo, productMapper, minioUtil);
|
||||
//查询 宣传手册和宣传视频
|
||||
List<ProductScreenVo> list=mapper.getMaterialList(vo);
|
||||
List<ProductScreenVo> videoList=new ArrayList<>();
|
||||
List<ProductScreenVo> fileList=new ArrayList<>();
|
||||
if(StringUtils.isNotEmpty(list)){
|
||||
list.forEach(vo1->{
|
||||
vo1.setImage(minioConfig.getUrl()+"/"+minioConfig.getBucketName()+vo1.getImage());
|
||||
vo1.setUrl(minioConfig.getUrl()+"/"+minioConfig.getBucketName()+vo1.getFilePath());
|
||||
String imageUlr = minioUtil.getFileUrl(minioConfig.getBucketName(),vo1.getImage(),60*60*12);
|
||||
String path = minioUtil.getFileUrl(minioConfig.getBucketName(),vo1.getFilePath(),60*60*12);
|
||||
vo1.setImage(imageUlr);
|
||||
vo1.setUrl(path);
|
||||
if("0".equals(vo1.getFileType())){
|
||||
videoList.add(vo1);
|
||||
}else {
|
||||
|
|
@ -97,4 +95,20 @@ public class ProductScreenImpl implements ProductScreenService {
|
|||
}
|
||||
return AjaxResult.success(product);
|
||||
}
|
||||
|
||||
public static void getProductDetails(TbProduct product, TbProduct vo, ProductMapper productMapper, MinioUtil minioUtil) {
|
||||
List<TbProductCase> productCases= productMapper.getProductCaseList(product.getId());
|
||||
for (TbProductCase productCase:productCases) {
|
||||
//产品案例
|
||||
List<ProductCaseImage> caseImages= productMapper.getCaseImageByTable(productCase.getId(),"tb_product_case");
|
||||
if(StringUtils.isNotEmpty(caseImages)){
|
||||
caseImages.forEach(image->{
|
||||
String path = minioUtil.getFileUrl(image.getBucketName(),image.getFilePath(),60*60*12);
|
||||
image.setUrl(path);
|
||||
});
|
||||
productCase.setImageList(caseImages);
|
||||
}
|
||||
}
|
||||
vo.setList(productCases);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.bonus.common.core.domain.AjaxResult;
|
|||
import com.bonus.common.utils.DateUtils;
|
||||
import com.bonus.common.utils.SecurityUtils;
|
||||
import com.bonus.common.utils.StringUtils;
|
||||
import com.bonus.file.minio.MinioUtil;
|
||||
import com.bonus.file.service.FileUploadService;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Table;
|
||||
|
|
@ -40,6 +41,10 @@ public class ProductServiceImpl implements ProductService {
|
|||
@Resource
|
||||
private MinioConfig minioConfig;
|
||||
|
||||
@Autowired
|
||||
public MinioUtil minioUtil;
|
||||
|
||||
|
||||
public String day= DateUtils.getCurrentYear();
|
||||
|
||||
public String month=DateUtils.getCurrentMonth();
|
||||
|
|
@ -56,7 +61,9 @@ public class ProductServiceImpl implements ProductService {
|
|||
List<TbProduct> list=mapper.selectProductList(product);
|
||||
if(StringUtils.isNotEmpty(list)){
|
||||
list.forEach(vo->{
|
||||
vo.setLinkImage(minioConfig.getUrl()+"/"+minioConfig.getBucketName()+vo.getLinkImage());
|
||||
String url = minioUtil.getFileUrl(minioConfig.getBucketName(),vo.getLinkImage(),60*60*12);
|
||||
vo.setLinkImage(url);
|
||||
// vo.setLinkImage(minioConfig.getUrl()+"/"+minioConfig.getBucketName()+vo.getLinkImage());
|
||||
});
|
||||
}
|
||||
return list;
|
||||
|
|
@ -235,20 +242,12 @@ public class ProductServiceImpl implements ProductService {
|
|||
List<ProductCaseImage> list=mapper.getCaseImageByTable(product.getId(),"tb_product");
|
||||
if(StringUtils.isNotEmpty(list)){
|
||||
ProductCaseImage vo1=list.get(0);
|
||||
vo1.setUrl(minioConfig.getUrl()+"/"+vo1.getBucketName()+vo1.getFilePath());
|
||||
String url=minioUtil.getFileUrl(vo1.getBucketName(),vo1.getFilePath(),60*60*12);
|
||||
vo1.setUrl(url);
|
||||
// vo1.setUrl(minioConfig.getUrl()+"/"+vo1.getBucketName()+vo1.getFilePath());
|
||||
vo.setImage(vo1);
|
||||
}
|
||||
List<TbProductCase> productCases=mapper.getProductCaseList(product.getId());
|
||||
for (TbProductCase productCase:productCases) {
|
||||
List<ProductCaseImage> caseImages=mapper.getCaseImageByTable(productCase.getId(),"tb_product_case");
|
||||
if(StringUtils.isNotEmpty(caseImages)){
|
||||
caseImages.forEach(image->{
|
||||
image.setUrl(minioConfig.getUrl()+"/"+image.getBucketName()+image.getFilePath());
|
||||
});
|
||||
productCase.setImageList(caseImages);
|
||||
}
|
||||
}
|
||||
vo.setList(productCases);
|
||||
ProductScreenImpl.getProductDetails(product, vo, mapper, minioUtil);
|
||||
}
|
||||
return AjaxResult.success(vo);
|
||||
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ public class MinioUtil {
|
|||
* @throws Exception 若生成 URL 过程中发生异常
|
||||
*/
|
||||
@SneakyThrows(Exception.class)
|
||||
public String getFileUrl(String bucketName, String objectName, int expiryTimeInSeconds) throws Exception {
|
||||
public String getFileUrl(String bucketName, String objectName, int expiryTimeInSeconds) {
|
||||
return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
|
|
@ -392,6 +392,7 @@ public class MinioUtil {
|
|||
return getFileUrl(bucketName, objectName, 604800);
|
||||
}
|
||||
|
||||
|
||||
public String getFileUrl(String bucketName, String objectName,long time) throws Exception {
|
||||
// 604800 秒 = 7 天
|
||||
return getFileUrl(bucketName, objectName, time);
|
||||
|
|
|
|||
Loading…
Reference in New Issue