缓存失效问题
店铺开关枚举
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.czg.account.service;
|
||||
|
||||
import com.czg.account.entity.ShopConfig;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -13,6 +15,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface ShopConfigService extends IService<ShopConfig> {
|
||||
|
||||
ShopInfo getShopInfoAndConfig(Serializable id);
|
||||
|
||||
void editStatusByShopIdList(Long mainShopId, Integer isEnable, boolean onyUpValid, String name, String useShopType, List<Long> shopIdList);
|
||||
|
||||
boolean editConfig(Long shopId, ShopConfig shopConfig);
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface ShopInfoService extends IService<ShopInfo> {
|
||||
/**
|
||||
* 检测开关
|
||||
* @param shopId 店铺id
|
||||
* @param switchType ShopInfo的某列 开关
|
||||
* @param switchType ShopInfo的某列 开关 目前只支持Integer类型字段
|
||||
* @return true:开启 false:关闭
|
||||
*/
|
||||
boolean checkSwitch(Long shopId, ShopSwitchTypeEnum switchType) throws ValidateException;
|
||||
|
||||
@@ -8,24 +8,18 @@ import com.czg.account.entity.ShopInfo;
|
||||
* @author ww
|
||||
*/
|
||||
public enum ShopSwitchTypeEnum {
|
||||
GROUP_BUY("groupBuy", "拼团开关", ShopInfo::getIsGroupBuy),
|
||||
GROUP_BUY("拼团开关", ShopInfo::getIsGroupBuy),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
private final String description;
|
||||
private final SerializableFunction<ShopInfo, Integer> getter;
|
||||
|
||||
ShopSwitchTypeEnum(String code, String description,
|
||||
ShopSwitchTypeEnum(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;
|
||||
}
|
||||
@@ -44,14 +38,4 @@ public enum ShopSwitchTypeEnum {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.czg.account.dto.ShopConfigDTO;
|
||||
import com.czg.account.entity.ShopConfig;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.service.ShopConfigService;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.account.mapper.ShopConfigMapper;
|
||||
@@ -14,7 +15,9 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -34,17 +37,18 @@ public class ShopConfigServiceImpl extends ServiceImpl<ShopConfigMapper, ShopCon
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ShopConfigDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
/*if (StrUtil.isNotEmpty(param.getName())) {
|
||||
queryWrapper.like(ShopConfig::getName, param.getName());
|
||||
}*/
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
queryWrapper.eq(ShopConfig::getMainId, shopId);
|
||||
queryWrapper.orderBy(ShopConfig::getId, false);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "shopInfo",key = "#id")
|
||||
public ShopInfo getShopInfoAndConfig(Serializable id) throws CzgException {
|
||||
ShopInfo shopInfo = shopInfoMapper.selectOneById(id);
|
||||
if (shopInfo == null) {
|
||||
throw new CzgException("店铺不存在");
|
||||
}
|
||||
ShopConfig shopConfig = getById(shopInfo.getId());
|
||||
BeanUtil.copyProperties(shopConfig, shopInfo);
|
||||
return shopInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean editConfig(Long shopId, ShopConfig shopConfig) {
|
||||
|
||||
@@ -57,7 +57,7 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
@DubboService
|
||||
@CacheConfig(cacheNames = "shopInfo")
|
||||
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService{
|
||||
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService {
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@Resource
|
||||
@@ -83,15 +83,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "#id")
|
||||
public ShopInfo getById(Serializable id) throws CzgException {
|
||||
ShopInfo shopInfo = super.getById(id);
|
||||
if (shopInfo == null) {
|
||||
throw new CzgException("店铺不存在");
|
||||
}
|
||||
ShopConfig shopConfig = shopConfigService.getById(shopInfo.getId());
|
||||
BeanUtil.copyProperties(shopConfig, shopInfo);
|
||||
return shopInfo;
|
||||
return shopConfigService.getShopInfoAndConfig(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user