Search in sources :

Example 1 with ParameterUpdate

use of com.albedo.java.common.event.model.ParameterUpdate in project albedo by somowhere.

the class ParameterUpdateListener method saveSysLog.

@Async
@EventListener({ ParameterUpdateEvent.class })
public void saveSysLog(ParameterUpdateEvent event) {
    ParameterUpdate source = (ParameterUpdate) event.getSource();
    ContextUtil.setTenant(source.getTenant());
    if (ParameterKey.LOGIN_POLICY.equals(source.getKey())) {
        onlineService.reset();
    }
}
Also used : ParameterUpdate(com.albedo.java.common.event.model.ParameterUpdate) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Example 2 with ParameterUpdate

use of com.albedo.java.common.event.model.ParameterUpdate 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 3 with ParameterUpdate

use of com.albedo.java.common.event.model.ParameterUpdate in project albedo by somowhere.

the class ParameterServiceImpl method removeByIds.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeByIds(Collection<?> idList) {
    if (CollectionUtils.isEmpty(idList)) {
        return true;
    }
    List<ParameterDo> parameterDoList = super.listByIds((Collection<? extends Serializable>) idList);
    if (parameterDoList.isEmpty()) {
        return true;
    }
    boolean bool = SqlHelper.retBool(getBaseMapper().deleteBatchIds(idList));
    CacheKey[] keys = parameterDoList.stream().map(item -> new ParameterKeyCacheKeyBuilder().key(item.getKey())).toArray(CacheKey[]::new);
    cacheOps.del(keys);
    parameterDoList.forEach(model -> SpringContextHolder.publishEvent(new ParameterUpdateEvent(new ParameterUpdate(model.getKey(), model.getValue(), null, ContextUtil.getTenant()))));
    return bool;
}
Also used : Wraps(com.albedo.java.plugins.database.mybatis.conditions.Wraps) CacheOps(com.albedo.java.plugins.cache.repository.CacheOps) java.util(java.util) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) ParameterRepository(com.albedo.java.modules.sys.repository.ParameterRepository) SpringContextHolder(com.albedo.java.common.core.util.SpringContextHolder) SqlHelper(com.baomidou.mybatisplus.extension.toolkit.SqlHelper) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ParameterDo(com.albedo.java.modules.sys.domain.ParameterDo) ParameterDto(com.albedo.java.modules.sys.domain.dto.ParameterDto) DataServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.DataServiceImpl) Function(java.util.function.Function) Serializable(java.io.Serializable) ParameterUpdate(com.albedo.java.common.event.model.ParameterUpdate) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) ParameterUpdateEvent(com.albedo.java.common.event.listener.ParameterUpdateEvent) ParameterKeyCacheKeyBuilder(com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder) ParameterService(com.albedo.java.modules.sys.service.ParameterService) Service(org.springframework.stereotype.Service) CollectionUtils(com.baomidou.mybatisplus.core.toolkit.CollectionUtils) ContextUtil(com.albedo.java.common.core.context.ContextUtil) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Transactional(org.springframework.transaction.annotation.Transactional) 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)

Aggregations

ParameterUpdate (com.albedo.java.common.event.model.ParameterUpdate)3 CacheKey (com.albedo.java.common.core.cache.model.CacheKey)2 ParameterUpdateEvent (com.albedo.java.common.event.listener.ParameterUpdateEvent)2 ParameterKeyCacheKeyBuilder (com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder)2 ParameterDo (com.albedo.java.modules.sys.domain.ParameterDo)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CollUtil (cn.hutool.core.collection.CollUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 ContextUtil (com.albedo.java.common.core.context.ContextUtil)1 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)1 SpringContextHolder (com.albedo.java.common.core.util.SpringContextHolder)1 ParameterDto (com.albedo.java.modules.sys.domain.dto.ParameterDto)1 ParameterRepository (com.albedo.java.modules.sys.repository.ParameterRepository)1 ParameterService (com.albedo.java.modules.sys.service.ParameterService)1 CacheOps (com.albedo.java.plugins.cache.repository.CacheOps)1 Wraps (com.albedo.java.plugins.database.mybatis.conditions.Wraps)1 DataServiceImpl (com.albedo.java.plugins.database.mybatis.service.impl.DataServiceImpl)1 CollectionUtils (com.baomidou.mybatisplus.core.toolkit.CollectionUtils)1 SqlHelper (com.baomidou.mybatisplus.extension.toolkit.SqlHelper)1 Serializable (java.io.Serializable)1