枚举问题
This commit is contained in:
@@ -29,11 +29,6 @@ dubbo:
|
|||||||
name: account-server
|
name: account-server
|
||||||
qos-port: 22221
|
qos-port: 22221
|
||||||
qos-enable: true
|
qos-enable: true
|
||||||
serialize-check-status: WARN
|
|
||||||
# 或者使用以下配置添加白名单
|
|
||||||
serialize-allow-list:
|
|
||||||
- com.czg.service.market.service.impl.GbWareServiceImpl
|
|
||||||
- com.czg.service.account.service.impl.ShopInfoServiceImpl
|
|
||||||
registry:
|
registry:
|
||||||
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
||||||
group: server-dev
|
group: server-dev
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ spring:
|
|||||||
dubbo:
|
dubbo:
|
||||||
application:
|
application:
|
||||||
name: order-server
|
name: order-server
|
||||||
serialize-check-status: WARN
|
|
||||||
# 或者使用以下配置添加白名单
|
|
||||||
serialize-allow-list:
|
|
||||||
- com.czg.service.market.service.impl.GbWareServiceImpl
|
|
||||||
- com.czg.service.account.service.impl.ShopInfoServiceImpl
|
|
||||||
qos-port: 22231
|
qos-port: 22231
|
||||||
qos-enable: true
|
qos-enable: true
|
||||||
registry:
|
registry:
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import cn.hutool.core.exceptions.ValidateException;
|
|||||||
import com.czg.account.dto.PageDTO;
|
import com.czg.account.dto.PageDTO;
|
||||||
import com.czg.account.dto.shopinfo.*;
|
import com.czg.account.dto.shopinfo.*;
|
||||||
import com.czg.account.entity.ShopInfo;
|
import com.czg.account.entity.ShopInfo;
|
||||||
|
import com.czg.constants.ShopSwitchTypeEnum;
|
||||||
import com.czg.exception.CzgException;
|
import com.czg.exception.CzgException;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.mybatisflex.core.util.LambdaGetter;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,10 +24,10 @@ public interface ShopInfoService extends IService<ShopInfo> {
|
|||||||
/**
|
/**
|
||||||
* 检测开关
|
* 检测开关
|
||||||
* @param shopId 店铺id
|
* @param shopId 店铺id
|
||||||
* @param switchGetter ShopInfo的某列 开关
|
* @param switchType ShopInfo的某列 开关
|
||||||
* @return true:开启 false:关闭
|
* @return true:开启 false:关闭
|
||||||
*/
|
*/
|
||||||
<T> boolean checkSwitch(Long shopId, Function<ShopInfo, T> switchGetter) throws ValidateException;
|
boolean checkSwitch(Long shopId, ShopSwitchTypeEnum switchType) throws ValidateException;
|
||||||
|
|
||||||
Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status, Integer isHeadShop);
|
Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status, Integer isHeadShop);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.czg.constants;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可序列化的函数式接口
|
||||||
|
* 用于在Dubbo等需要序列化的场景中传递Lambda表达式
|
||||||
|
*
|
||||||
|
* @param <T> 输入类型
|
||||||
|
* @param <R> 输出类型
|
||||||
|
* @author ww
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SerializableFunction<T, R> extends Function<T, R>, Serializable {
|
||||||
|
// serialVersionUID 不能是private
|
||||||
|
@Serial
|
||||||
|
long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.czg.constants;
|
||||||
|
|
||||||
|
import com.czg.account.entity.ShopInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺开关枚举
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
*/
|
||||||
|
public enum ShopSwitchTypeEnum {
|
||||||
|
GROUP_BUY("groupBuy", "拼团开关", ShopInfo::getIsGroupBuy),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String description;
|
||||||
|
private final SerializableFunction<ShopInfo, Integer> getter;
|
||||||
|
|
||||||
|
ShopSwitchTypeEnum(String code, String description,
|
||||||
|
SerializableFunction<ShopInfo, Integer> getter) {
|
||||||
|
this.code = code;
|
||||||
|
this.description = description;
|
||||||
|
this.getter = getter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getValue(ShopInfo shopInfo) {
|
||||||
|
if (shopInfo == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return getter.apply(shopInfo) == 1;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SerializableFunction<ShopInfo, Integer> getGetter() {
|
||||||
|
return getter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据code获取枚举
|
||||||
|
public static ShopSwitchTypeEnum getByCode(String code) {
|
||||||
|
for (ShopSwitchTypeEnum type : values()) {
|
||||||
|
if (type.code.equals(code)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("未知的开关类型: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package com.czg.service.account.service.impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import com.czg.account.dto.PageDTO;
|
import com.czg.account.dto.PageDTO;
|
||||||
@@ -14,6 +13,7 @@ import com.czg.account.enums.ShopTypeEnum;
|
|||||||
import com.czg.account.service.*;
|
import com.czg.account.service.*;
|
||||||
import com.czg.config.RabbitPublisher;
|
import com.czg.config.RabbitPublisher;
|
||||||
import com.czg.config.RedisCst;
|
import com.czg.config.RedisCst;
|
||||||
|
import com.czg.constants.ShopSwitchTypeEnum;
|
||||||
import com.czg.enums.StatusEnum;
|
import com.czg.enums.StatusEnum;
|
||||||
import com.czg.enums.YesNoEnum;
|
import com.czg.enums.YesNoEnum;
|
||||||
import com.czg.exception.CzgException;
|
import com.czg.exception.CzgException;
|
||||||
@@ -32,10 +32,6 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.core.table.TableInfo;
|
|
||||||
import com.mybatisflex.core.table.TableInfoFactory;
|
|
||||||
import com.mybatisflex.core.util.LambdaGetter;
|
|
||||||
import com.mybatisflex.core.util.LambdaUtil;
|
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -47,14 +43,12 @@ import org.springframework.cache.annotation.Cacheable;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.invoke.SerializedLambda;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +57,7 @@ import java.util.stream.Collectors;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@DubboService
|
@DubboService
|
||||||
@CacheConfig(cacheNames = "shopInfo")
|
@CacheConfig(cacheNames = "shopInfo")
|
||||||
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService, Serializable {
|
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService{
|
||||||
@Resource
|
@Resource
|
||||||
private RabbitPublisher rabbitPublisher;
|
private RabbitPublisher rabbitPublisher;
|
||||||
@Resource
|
@Resource
|
||||||
@@ -101,17 +95,11 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean checkSwitch(Long shopId, Function<ShopInfo, T> switchGetter) throws ValidateException {
|
public boolean checkSwitch(Long shopId, ShopSwitchTypeEnum switchType) throws ValidateException {
|
||||||
AssertUtil.isNull(shopId, "店铺ID不能为空");
|
AssertUtil.isNull(shopId, "店铺ID不能为空");
|
||||||
ShopInfo shopInfo = getById(shopId);
|
ShopInfo shopInfo = getById(shopId);
|
||||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||||
T switchValue = switchGetter.apply(shopInfo);
|
return switchType.getValue(shopInfo);
|
||||||
|
|
||||||
if (switchValue == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertToBoolean(switchValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShopInfo getShopInfo(Long shopId) {
|
private ShopInfo getShopInfo(Long shopId) {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package com.czg.service.market.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.czg.account.entity.ShopInfo;
|
|
||||||
import com.czg.account.service.ShopInfoService;
|
import com.czg.account.service.ShopInfoService;
|
||||||
|
import com.czg.constants.ShopSwitchTypeEnum;
|
||||||
import com.czg.market.dto.GbWareDTO;
|
import com.czg.market.dto.GbWareDTO;
|
||||||
import com.czg.market.dto.GbWareQueryParamDTO;
|
import com.czg.market.dto.GbWareQueryParamDTO;
|
||||||
import com.czg.market.entity.GbWare;
|
import com.czg.market.entity.GbWare;
|
||||||
@@ -17,8 +17,6 @@ import com.mybatisflex.spring.service.impl.ServiceImpl;
|
|||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拼团商品 服务层实现。
|
* 拼团商品 服务层实现。
|
||||||
*
|
*
|
||||||
@@ -26,14 +24,14 @@ import java.io.Serializable;
|
|||||||
* @since 2025-12-15
|
* @since 2025-12-15
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class GbWareServiceImpl extends ServiceImpl<GbWareMapper, GbWare> implements GbWareService, Serializable {
|
public class GbWareServiceImpl extends ServiceImpl<GbWareMapper, GbWare> implements GbWareService {
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopInfoService shopInfoService;
|
private ShopInfoService shopInfoService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<GbWare> getGbWarePage(GbWareQueryParamDTO param, Long shopId) {
|
public Page<GbWare> getGbWarePage(GbWareQueryParamDTO param, Long shopId) {
|
||||||
if (!shopInfoService.checkSwitch(shopId, ShopInfo::getIsGroupBuy)) {
|
if (!shopInfoService.checkSwitch(shopId, ShopSwitchTypeEnum.GROUP_BUY)) {
|
||||||
return new Page<>();
|
return new Page<>();
|
||||||
}
|
}
|
||||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||||
|
|||||||
Reference in New Issue
Block a user