缓存失效问题

店铺开关枚举
This commit is contained in:
2025-12-19 09:24:51 +08:00
parent 47f28d7bbb
commit babf3609c9
6 changed files with 24 additions and 38 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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