Search in sources :

Example 1 with ParameterDo

use of com.albedo.java.modules.sys.domain.ParameterDo 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 2 with ParameterDo

use of com.albedo.java.modules.sys.domain.ParameterDo 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)

Example 3 with ParameterDo

use of com.albedo.java.modules.sys.domain.ParameterDo in project albedo by somowhere.

the class ParameterServiceImpl method getValue.

@Override
public String getValue(String key, String defVal) {
    if (StrUtil.isEmpty(key)) {
        return defVal;
    }
    Function<CacheKey, String> loader = k -> {
        ParameterDo parameterDo = getOne(Wraps.<ParameterDo>lbQ().eq(ParameterDo::getKey, key));
        return parameterDo == null ? defVal : parameterDo.getValue();
    };
    CacheKey cacheKey = new ParameterKeyCacheKeyBuilder().key(key);
    return cacheOps.get(cacheKey, loader);
}
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) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) ParameterDo(com.albedo.java.modules.sys.domain.ParameterDo)

Aggregations

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