Search in sources :

Example 1 with TenantCodeCacheKeyBuilder

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());
}
Also used : TenantCodeCacheKeyBuilder(com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder) Tenant(com.albedo.java.modules.tenant.domain.Tenant) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TenantCodeCacheKeyBuilder

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);
}
Also used : Wraps(com.albedo.java.plugins.database.mybatis.conditions.Wraps) TenantConnectDto(com.albedo.java.modules.tenant.domain.dto.TenantConnectDto) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) InitSystemContext(com.albedo.java.modules.tenant.strategy.InitSystemContext) Tenant(com.albedo.java.modules.tenant.domain.Tenant) TenantService(com.albedo.java.modules.tenant.service.TenantService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BeanUtil(com.albedo.java.common.core.util.BeanUtil) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) TenantRepository(com.albedo.java.modules.tenant.repository.TenantRepository) Function(java.util.function.Function) TenantDto(com.albedo.java.modules.tenant.domain.dto.TenantDto) TenantCacheKeyBuilder(com.albedo.java.modules.tenant.TenantCacheKeyBuilder) TenantTypeEnum(com.albedo.java.modules.tenant.enumeration.TenantTypeEnum) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) AbstractDataCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractDataCacheServiceImpl) Convert(cn.hutool.core.convert.Convert) AppendixService(com.albedo.java.modules.file.service.AppendixService) TenantStatusEnum(com.albedo.java.modules.tenant.enumeration.TenantStatusEnum) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) TenantCodeCacheKeyBuilder(com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder) Transactional(org.springframework.transaction.annotation.Transactional) TenantCodeCacheKeyBuilder(com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder) Tenant(com.albedo.java.modules.tenant.domain.Tenant) Convert(cn.hutool.core.convert.Convert) CacheKey(com.albedo.java.common.core.cache.model.CacheKey)

Aggregations

CacheKey (com.albedo.java.common.core.cache.model.CacheKey)2 TenantCodeCacheKeyBuilder (com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder)2 Tenant (com.albedo.java.modules.tenant.domain.Tenant)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Convert (cn.hutool.core.convert.Convert)1 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)1 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)1 BeanUtil (com.albedo.java.common.core.util.BeanUtil)1 AppendixService (com.albedo.java.modules.file.service.AppendixService)1 TenantCacheKeyBuilder (com.albedo.java.modules.tenant.TenantCacheKeyBuilder)1 TenantConnectDto (com.albedo.java.modules.tenant.domain.dto.TenantConnectDto)1 TenantDto (com.albedo.java.modules.tenant.domain.dto.TenantDto)1 TenantStatusEnum (com.albedo.java.modules.tenant.enumeration.TenantStatusEnum)1 TenantTypeEnum (com.albedo.java.modules.tenant.enumeration.TenantTypeEnum)1 TenantRepository (com.albedo.java.modules.tenant.repository.TenantRepository)1 TenantService (com.albedo.java.modules.tenant.service.TenantService)1 InitSystemContext (com.albedo.java.modules.tenant.strategy.InitSystemContext)1 Wraps (com.albedo.java.plugins.database.mybatis.conditions.Wraps)1 AbstractDataCacheServiceImpl (com.albedo.java.plugins.database.mybatis.service.impl.AbstractDataCacheServiceImpl)1 List (java.util.List)1