更新优化提示,优化分类图片返回

This commit is contained in:
lhd
2024-04-23 10:07:49 +08:00
parent 37bffbd11c
commit d7efa6b244
3 changed files with 23 additions and 10 deletions

View File

@@ -13,6 +13,8 @@ package com.yami.shop.bean.model;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.yami.shop.common.serializer.json.ImgJsonSerializer;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@@ -25,7 +27,7 @@ import java.util.List;
@Data @Data
@TableName("tz_category") @TableName("tz_category")
public class Category implements Serializable { public class Category implements Serializable {
/** /**
* 类目ID * 类目ID
* *
@@ -38,7 +40,7 @@ public class Category implements Serializable {
* 店铺id * 店铺id
*/ */
private Long shopId; private Long shopId;
/** /**
* 父节点 * 父节点
*/ */
@@ -57,6 +59,7 @@ public class Category implements Serializable {
/** /**
* 类目的显示图片 * 类目的显示图片
*/ */
@JsonSerialize(using = ImgJsonSerializer.class)
private String pic; private String pic;
/** /**
@@ -83,13 +86,13 @@ public class Category implements Serializable {
* 更新时间 * 更新时间
*/ */
private Date updateTime; private Date updateTime;
/** /**
* 品牌id * 品牌id
*/ */
@TableField(exist=false) @TableField(exist=false)
private List<Long> brandIds; private List<Long> brandIds;
/** /**
* 参数id * 参数id
*/ */
@@ -101,19 +104,19 @@ public class Category implements Serializable {
*/ */
@TableField(exist=false) @TableField(exist=false)
private List<Brand> brands; private List<Brand> brands;
/** /**
* 参数列表 * 参数列表
*/ */
@TableField(exist=false) @TableField(exist=false)
private List<ProdProp> prodProps; private List<ProdProp> prodProps;
/** /**
* 商品列表 * 商品列表
*/ */
@TableField(exist=false) @TableField(exist=false)
private List<Product> products; private List<Product> products;
@TableField(exist=false) @TableField(exist=false)
private List<Category> categories; private List<Category> categories;
} }

View File

@@ -21,6 +21,8 @@ import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* @author lanhai * @author lanhai
@@ -42,13 +44,21 @@ public class ImgJsonSerializer extends JsonSerializer<String> {
String[] imgs = value.split(StrUtil.COMMA); String[] imgs = value.split(StrUtil.COMMA);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String resourceUrl = ""; String resourceUrl = "";
String rule="^((http[s]{0,1})://)";
Pattern pattern= Pattern.compile(rule);
if (Objects.equals(imgUploadUtil.getUploadType(), 2)) { if (Objects.equals(imgUploadUtil.getUploadType(), 2)) {
resourceUrl = qiniu.getResourcesUrl(); resourceUrl = qiniu.getResourcesUrl();
} else if (Objects.equals(imgUploadUtil.getUploadType(), 1)) { } else if (Objects.equals(imgUploadUtil.getUploadType(), 1)) {
resourceUrl = imgUploadUtil.getResourceUrl(); resourceUrl = imgUploadUtil.getResourceUrl();
} }
for (String img : imgs) { for (String img : imgs) {
sb.append(resourceUrl).append(img).append(StrUtil.COMMA); Matcher matcher = pattern.matcher(img);
//若图片以http或https开头直接返回
if (matcher.find()){
sb.append(img).append(StrUtil.COMMA);
}else {
sb.append(resourceUrl).append(img).append(StrUtil.COMMA);
}
} }
sb.deleteCharAt(sb.length()-1); sb.deleteCharAt(sb.length()-1);
gen.writeString(sb.toString()); gen.writeString(sb.toString());

View File

@@ -155,7 +155,7 @@ public class TokenStore {
public TokenInfoVO storeAndGetVo(UserInfoInTokenBO userInfoInToken) { public TokenInfoVO storeAndGetVo(UserInfoInTokenBO userInfoInToken) {
if (!userInfoInToken.getEnabled()){ if (!userInfoInToken.getEnabled()){
// 用户已禁用,请联系客服 // 用户已禁用,请联系客服
throw new YamiShopBindException("yami.user.disabled"); throw new YamiShopBindException("用户已禁用,请联系客服");
} }
TokenInfoBO tokenInfoBO = storeAccessSaToken(userInfoInToken); TokenInfoBO tokenInfoBO = storeAccessSaToken(userInfoInToken);
// 数据封装返回 // 数据封装返回