1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
@Service public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType> implements IShopTypeService {
@Resource private StringRedisTemplate stringRedisTemplate; @Autowired private IShopTypeService shopTypeService;
@Override public Result queryTypeList() { String shopTypeList = stringRedisTemplate.opsForValue().get(SHOP_TYPE_KEY); if (StrUtil.isNotBlank(shopTypeList)) { List<ShopType> list = JSONUtil.toList(shopTypeList, ShopType.class); return Result.ok(list); } List<ShopType> typeList = shopTypeService .query().orderByAsc("sort").list(); if (typeList==null) { return Result.fail("店铺不存在!"); } stringRedisTemplate.opsForValue().set(SHOP_TYPE_KEY, JSONUtil.toJsonStr(typeList)); stringRedisTemplate.expire(SHOP_TYPE_KEY, SHOP_TYPE_TTL, TimeUnit.MINUTES); return Result.ok(typeList); } }
|