use of com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder in project albedo by somowhere.
the class TenantServiceImpl method saveOrUpdate.
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(TenantDto tenantDto) {
// defaults 库
ArgumentAssert.isTrue(check(tenantDto.getCode()), "编码重复,请重新输入");
Tenant tenant = BeanUtil.toBean(tenantDto, Tenant.class);
if (tenantDto.getId() == null) {
// 1, 保存租户 (默认库)
tenant.setStatus(TenantStatusEnum.WAIT_INIT);
tenant.setType(TenantTypeEnum.CREATE);
// defaults 库
save(tenant);
} else {
updateById(tenant);
}
appendixService.save(tenant.getId(), tenantDto.getLogos());
CacheKey cacheKey = new TenantCodeCacheKeyBuilder().key(tenant.getCode());
super.cacheOps.set(cacheKey, tenant.getId());
}
use of com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder in project albedo by somowhere.
the class TenantServiceImpl method getByCode.
/**
* tenant_name:{tenantCode} -> id 只存租户的id,然后根据id再次查询缓存,这样子的好处是,删除或者修改租户信息时,只需要根据id淘汰缓存即可
* 缺点就是 每次查询,需要多查一次缓存
*
* @param tenant
* @return
*/
@Override
public Tenant getByCode(String tenant) {
Function<CacheKey, Object> loader = (k) -> getObj(Wraps.<Tenant>lbQ().select(Tenant::getId).eq(Tenant::getCode, tenant), Convert::toLong);
CacheKey cacheKey = new TenantCodeCacheKeyBuilder().key(tenant);
return getByKey(cacheKey, loader);
}
Aggregations