| @@ -50,7 +50,9 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| @Override | @Override | ||||
| public WxMall getById(Long id) { | public WxMall getById(Long id) { | ||||
| String key = Constant.MALL_KEY_PREV + String.valueOf(id); | |||||
| String key = getRedisKeyByTenantInfo(new TenantEntity(){{ | |||||
| setTenantId(String.valueOf(id)); | |||||
| }}); | |||||
| ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue(); | ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue(); | ||||
| // 缓存 | // 缓存 | ||||
| @@ -82,7 +84,7 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| int ret = wxMallMapper.insert(record); | int ret = wxMallMapper.insert(record); | ||||
| String key = Constant.MALL_KEY_PREV + String.valueOf(record.getId()); | |||||
| String key = getRedisKeyByTenantInfo(record.getTenantInfo()); | |||||
| // 缓存已存在,删除 | // 缓存已存在,删除 | ||||
| boolean hasKey = mallRedisTemplate.hasKey(key); | boolean hasKey = mallRedisTemplate.hasKey(key); | ||||
| if(hasKey) { | if(hasKey) { | ||||
| @@ -96,7 +98,7 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| public int update(WxMall record) { | public int update(WxMall record) { | ||||
| int ret = wxMallMapper.updateById(record); | int ret = wxMallMapper.updateById(record); | ||||
| String key = Constant.MALL_KEY_PREV + String.valueOf(record.getId()); | |||||
| String key = getRedisKeyByTenantInfo(record.getTenantInfo()); | |||||
| // 缓存已存在,删除 | // 缓存已存在,删除 | ||||
| boolean hasKey = mallRedisTemplate.hasKey(key); | boolean hasKey = mallRedisTemplate.hasKey(key); | ||||
| if(hasKey) { | if(hasKey) { | ||||
| @@ -110,7 +112,9 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxMallMapper.deleteById(id); | wxMallMapper.deleteById(id); | ||||
| String key = Constant.MALL_KEY_PREV + String.valueOf(id); | |||||
| String key = getRedisKeyByTenantInfo(new TenantEntity() {{ | |||||
| setTenantId(String.valueOf(id)); | |||||
| }}); | |||||
| // 缓存已存在,删除 | // 缓存已存在,删除 | ||||
| boolean hasKey = mallRedisTemplate.hasKey(key); | boolean hasKey = mallRedisTemplate.hasKey(key); | ||||
| if(hasKey) { | if(hasKey) { | ||||
| @@ -121,12 +125,7 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| @Override | @Override | ||||
| public WxMall getByTenantInfo(TenantEntity tenantEntity) { | public WxMall getByTenantInfo(TenantEntity tenantEntity) { | ||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(Constant.TENANT_KEY_PREV).append(tenantEntity.getTenantId()); | |||||
| if (StringUtils.isBlank(tenantEntity.getSubTenantId())) { | |||||
| sb.append("-").append(tenantEntity.getSubTenantId()); | |||||
| } | |||||
| String key = sb.toString(); | |||||
| String key = getRedisKeyByTenantInfo(tenantEntity); | |||||
| ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue(); | ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue(); | ||||
| // 缓存 | // 缓存 | ||||
| @@ -195,7 +194,9 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| @Override | @Override | ||||
| public WxMall getByTenantId(String id) { | public WxMall getByTenantId(String id) { | ||||
| String key = Constant.MALL_KEY_PREV + String.valueOf(id); | |||||
| String key = getRedisKeyByTenantInfo(new TenantEntity() {{ | |||||
| setTenantId(id); | |||||
| }}); | |||||
| ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue(); | ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue(); | ||||
| // 缓存 | // 缓存 | ||||
| @@ -255,4 +256,13 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| return mallList; | return mallList; | ||||
| } | } | ||||
| private String getRedisKeyByTenantInfo(TenantEntity tenantEntity) { | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(Constant.TENANT_KEY_PREV).append(tenantEntity.getTenantId()); | |||||
| if (StringUtils.isBlank(tenantEntity.getSubTenantId())) { | |||||
| sb.append("-").append(tenantEntity.getSubTenantId()); | |||||
| } | |||||
| return sb.toString(); | |||||
| } | |||||
| } | } | ||||