Search in sources :

Example 6 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class ParameterServiceImpl method updateById.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateById(ParameterDo model) {
    long count = count(Wraps.<ParameterDo>lbQ().eq(ParameterDo::getKey, model.getKey()).ne(ParameterDo::getId, model.getId()));
    ArgumentAssert.isFalse(count > 0, StrUtil.format("参数key[{}]已经存在,请勿重复创建", model.getKey()));
    boolean bool = SqlHelper.retBool(getBaseMapper().updateById(model));
    if (bool) {
        CacheKey cacheKey = new ParameterKeyCacheKeyBuilder().key(model.getKey());
        cacheOps.set(cacheKey, model.getValue());
        SpringContextHolder.publishEvent(new ParameterUpdateEvent(new ParameterUpdate(model.getKey(), model.getValue(), null, ContextUtil.getTenant())));
    }
    return bool;
}
Also used : ParameterKeyCacheKeyBuilder(com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder) ParameterUpdate(com.albedo.java.common.event.model.ParameterUpdate) ParameterUpdateEvent(com.albedo.java.common.event.listener.ParameterUpdateEvent) ParameterDo(com.albedo.java.modules.sys.domain.ParameterDo) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey 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 8 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class LogLoginServiceImpl method save.

@Override
public boolean save(LogLoginDo logLoginDo) {
    UserVo user;
    Long userId = logLoginDo.getUserId();
    String username = logLoginDo.getUsername();
    if (userId != null) {
        user = this.userService.findUserVoById(userId);
    } else {
        user = this.userService.findVoByUsername(username);
    }
    if (user != null) {
        logLoginDo.setUsername(user.getUsername()).setUserId(user.getId()).setNickname(user.getNickname()).setCreatedBy(user.getId());
    }
    super.save(logLoginDo);
    LocalDate now = LocalDate.now();
    String tenDaysAgo = LocalDateTimeUtil.formatNormal(now.plusDays(-9));
    CacheKey totalLoginPvKey = TotalLoginPvCacheKeyBuilder.build();
    CacheKey todayLoginPvKey = TodayLoginPvCacheKeyBuilder.build(now);
    // 登录IV
    CacheKey totalLoginIvKey = TotalLoginIvCacheKeyBuilder.build();
    CacheKey todayLoginIvKey = TodayLoginIvCacheKeyBuilder.build(now);
    CacheKey logLoginTenDayKey = new LogLoginTenDayCacheKeyBuilder().key(tenDaysAgo);
    CacheKey logLoginBrowserKey = new LogLoginBrowserCacheKeyBuilder().key();
    CacheKey logLoginSystemKey = new LogLoginSystemCacheKeyBuilder().key();
    cacheOps.del(totalLoginPvKey);
    cacheOps.del(todayLoginPvKey);
    cacheOps.del(todayLoginIvKey);
    cacheOps.del(totalLoginIvKey);
    cacheOps.del(logLoginTenDayKey);
    cacheOps.del(logLoginBrowserKey);
    cacheOps.del(logLoginSystemKey);
    if (user != null) {
        CacheKey logLoginTenDayUserKey = new LogLoginTenDayCacheKeyBuilder().key(tenDaysAgo, user.getUsername());
        cacheOps.del(logLoginTenDayUserKey);
    }
    return true;
}
Also used : UserVo(com.albedo.java.modules.sys.domain.vo.UserVo) LocalDate(java.time.LocalDate) CacheKey(com.albedo.java.common.core.cache.model.CacheKey)

Example 9 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class LogLoginServiceImpl method getTodayLoginPv.

@Override
public Long getTodayLoginPv() {
    LocalDate now = LocalDate.now();
    CacheKey logLoginTodayKey = TodayLoginPvCacheKeyBuilder.build(now);
    return Convert.toLong(cacheOps.get(logLoginTodayKey, k -> repository.getTodayLoginPv(now)), 0L);
}
Also used : RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) LogLoginService(com.albedo.java.modules.sys.service.LogLoginService) Service(org.springframework.stereotype.Service) Map(java.util.Map) LocalTime(java.time.LocalTime) MapHelper(com.albedo.java.common.core.util.MapHelper) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) com.albedo.java.modules.sys.cache(com.albedo.java.modules.sys.cache) CacheOps(com.albedo.java.plugins.cache.repository.CacheOps) BaseServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.BaseServiceImpl) Collectors(java.util.stream.Collectors) UserService(com.albedo.java.modules.sys.service.UserService) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) UserVo(com.albedo.java.modules.sys.domain.vo.UserVo) Stream(java.util.stream.Stream) LocalDateTimeUtil(cn.hutool.core.date.LocalDateTimeUtil) LocalDate(java.time.LocalDate) Convert(cn.hutool.core.convert.Convert) LogLoginRepository(com.albedo.java.modules.sys.repository.LogLoginRepository) DatePattern(cn.hutool.core.date.DatePattern) Transactional(org.springframework.transaction.annotation.Transactional) LocalDate(java.time.LocalDate) CacheKey(com.albedo.java.common.core.cache.model.CacheKey)

Example 10 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class LogLoginServiceImpl method getTodayLoginIv.

@Override
public Long getTodayLoginIv() {
    LocalDate now = LocalDate.now();
    CacheKey logLoginTodayIpKey = TodayLoginIvCacheKeyBuilder.build(now);
    return Convert.toLong(cacheOps.get(logLoginTodayIpKey, k -> repository.getTodayLoginIv(now)), 0L);
}
Also used : RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) LogLoginService(com.albedo.java.modules.sys.service.LogLoginService) Service(org.springframework.stereotype.Service) Map(java.util.Map) LocalTime(java.time.LocalTime) MapHelper(com.albedo.java.common.core.util.MapHelper) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) com.albedo.java.modules.sys.cache(com.albedo.java.modules.sys.cache) CacheOps(com.albedo.java.plugins.cache.repository.CacheOps) BaseServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.BaseServiceImpl) Collectors(java.util.stream.Collectors) UserService(com.albedo.java.modules.sys.service.UserService) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) UserVo(com.albedo.java.modules.sys.domain.vo.UserVo) Stream(java.util.stream.Stream) LocalDateTimeUtil(cn.hutool.core.date.LocalDateTimeUtil) LocalDate(java.time.LocalDate) Convert(cn.hutool.core.convert.Convert) LogLoginRepository(com.albedo.java.modules.sys.repository.LogLoginRepository) DatePattern(cn.hutool.core.date.DatePattern) Transactional(org.springframework.transaction.annotation.Transactional) LocalDate(java.time.LocalDate) CacheKey(com.albedo.java.common.core.cache.model.CacheKey)

Aggregations

CacheKey (com.albedo.java.common.core.cache.model.CacheKey)17 Transactional (org.springframework.transaction.annotation.Transactional)12 Service (org.springframework.stereotype.Service)8 RequiredArgsConstructor (lombok.RequiredArgsConstructor)6 Convert (cn.hutool.core.convert.Convert)5 StrUtil (cn.hutool.core.util.StrUtil)5 CacheOps (com.albedo.java.plugins.cache.repository.CacheOps)5 List (java.util.List)5 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)4 ParameterKeyCacheKeyBuilder (com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder)4 UserVo (com.albedo.java.modules.sys.domain.vo.UserVo)4 Wraps (com.albedo.java.plugins.database.mybatis.conditions.Wraps)4 LocalDate (java.time.LocalDate)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 DatePattern (cn.hutool.core.date.DatePattern)3 LocalDateTimeUtil (cn.hutool.core.date.LocalDateTimeUtil)3 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)3 MapHelper (com.albedo.java.common.core.util.MapHelper)3 ParameterUpdateEvent (com.albedo.java.common.event.listener.ParameterUpdateEvent)3