不同的对象存储渠道有不同的图片压缩规则。

This commit is contained in:
pikachu1995@126.com 2023-07-13 16:03:38 +08:00
parent 007b145c2e
commit af5e866853
6 changed files with 46 additions and 33 deletions

View File

@ -1,24 +0,0 @@
package cn.lili.modules.file.util;
/**
* FileUtil
*
* @author Chopper
* @version v1.0
* 2021-11-22 11:19
*/
public class FileUtil {
/**
* 根据原图生成规定尺寸的图片
*
* @param url 连接
* @param width
* @param height
* @return
*/
public static String getUrl(String url, Integer width, Integer height) {
//缩略图全路径
return url + "?x-oss-process=style/" + width + "X" + height;
}
}

View File

@ -1,12 +1,14 @@
package cn.lili.modules.goods.serviceimpl;
import cn.hutool.json.JSONUtil;
import cn.lili.modules.file.entity.enums.OssEnum;
import cn.lili.modules.file.util.FileUtil;
import cn.lili.modules.goods.entity.dos.GoodsGallery;
import cn.lili.modules.goods.mapper.GoodsGalleryMapper;
import cn.lili.modules.goods.service.GoodsGalleryService;
import cn.lili.modules.system.entity.dos.Setting;
import cn.lili.modules.system.entity.dto.GoodsSetting;
import cn.lili.modules.system.entity.dto.OssSetting;
import cn.lili.modules.system.entity.enums.SettingEnum;
import cn.lili.modules.system.service.SettingService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -59,9 +61,9 @@ public class GoodsGalleryServiceImpl extends ServiceImpl<GoodsGalleryMapper, Goo
Setting setting = settingService.get(SettingEnum.GOODS_SETTING.name());
GoodsSetting goodsSetting = JSONUtil.toBean(setting.getSettingValue(), GoodsSetting.class);
//缩略图
String thumbnail = FileUtil.getUrl(origin, goodsSetting.getAbbreviationPictureWidth(), goodsSetting.getAbbreviationPictureHeight());
String thumbnail = this.getUrl(origin, goodsSetting.getAbbreviationPictureWidth(), goodsSetting.getAbbreviationPictureHeight());
//小图
String small = FileUtil.getUrl(origin, goodsSetting.getSmallPictureWidth(), goodsSetting.getSmallPictureHeight());
String small = this.getUrl(origin, goodsSetting.getSmallPictureWidth(), goodsSetting.getSmallPictureHeight());
//赋值
goodsGallery.setSmall(small);
goodsGallery.setThumbnail(thumbnail);
@ -84,4 +86,34 @@ public class GoodsGalleryServiceImpl extends ServiceImpl<GoodsGalleryMapper, Goo
public void removeByGoodsId(String goodsId) {
this.baseMapper.delete(new QueryWrapper<GoodsGallery>().eq("goods_id", goodsId));
}
/**
* 根据原图生成规定尺寸的图片
*
* @param url 连接
* @param width
* @param height
* @return
*/
private String getUrl(String url, Integer width, Integer height) {
Setting setting = settingService.get(SettingEnum.OSS_SETTING.name());
OssSetting ossSetting = JSONUtil.toBean(setting.getSettingValue(), OssSetting.class);
switch (OssEnum.valueOf(ossSetting.getType())) {
case MINIO:
//缩略图全路径
return url + "?x-oss-process=style/" + width + "X" + height;
case ALI_OSS:
//缩略图全路径
return url + "?x-oss-process=style/" + width + "X" + height;
case HUAWEI_OBS:
//缩略图全路径
return url + "?image/resize,m_fixed,h_"+height+",w_"+width;
case TENCENT_COS:
//缩略图全路径
return url + "?imageMogr2/thumbnail/" + width + "x" + height;
}
return url;
}
}

View File

@ -63,7 +63,7 @@ public class KdniaoPlugin implements LogisticsPlugin {
Map<String, String> params = new HashMap<>(8);
params.put("RequestData", urlEncoder(requestData, "UTF-8"));
params.put("EBusinessID", logisticsSetting.getKdniaoEbusinessID());
params.put("RequestType", "1002");
params.put("RequestType", logisticsSetting.getRequestType());
String dataSign = encrypt(requestData, logisticsSetting.getKdniaoAppKey(), "UTF-8");
params.put("DataSign", urlEncoder(dataSign, "UTF-8"));
params.put("DataType", "2");

View File

@ -48,7 +48,7 @@ public class HuaweiSmsPlugin implements SmsPlugin {
@Override
public void sendSmsCode(String signName, String mobile, Map<String, String> param, String templateCode) {
try {
this.sendSms(signName, mobile, "[" + param.values() + "]", templateCode);
this.sendSms(signName, mobile, param.values() + "", templateCode);
} catch (Exception e) {
e.printStackTrace();
}
@ -115,7 +115,7 @@ public class HuaweiSmsPlugin implements SmsPlugin {
//条件必填,国内短信关注,当templateId指定的模板类型为通用模板时生效且必填,必须是已审核通过的,与模板类型一致的签名名称
//国际/港澳台短信不用关注该参数
String signature = signName; //签名名称
String signature = smsSetting.getHuaweiSignature(); //签名名称
//必填,全局号码格式(包含国家码),示例:+8615123456789,多个号码之间用英文逗号分隔
String receiver = mobile; //短信接收人号码

View File

@ -31,6 +31,11 @@ public class LogisticsSetting implements Serializable {
*/
private String kdniaoAppKey;
/**
* 调用端口
*/
private String requestType;
/**
* 快递100 授权码请申请企业版获取
*/

View File

@ -31,10 +31,10 @@ public class OssSetting implements Serializable {
* 阿里云-储存空间
*/
private String aliyunOSSBucketName = "";
/**
* 阿里云-存放路径路径
*/
private String aliyunOSSPicLocation = "";
// /**
// * 阿里云-存放路径路径
// */
// private String aliyunOSSPicLocation = "";
/**
* 阿里云-密钥id
*/