refactor 系统配置
parent
f152e95010
commit
ebbb930a06
|
@ -10,4 +10,5 @@ import cc.iotkit.model.system.SysConfig;
|
|||
*/
|
||||
public interface ISysConfigData extends ICommonData<SysConfig, Long> {
|
||||
|
||||
SysConfig findByConfigKey(String configKey);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ import cc.iotkit.data.model.TbSysConfig;
|
|||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface SysConfigRepository extends JpaRepository<TbSysConfig, Long>, QuerydslPredicateExecutor<TbSysConfig> {
|
||||
|
||||
Optional<TbSysConfig> findByConfigKey(String configKey);
|
||||
}
|
||||
|
|
|
@ -15,10 +15,13 @@ import cc.iotkit.data.util.PredicateBuilder;
|
|||
import cc.iotkit.model.system.SysConfig;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections.IteratorUtils;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig;
|
||||
|
@ -46,7 +49,9 @@ public class SysConfigDataImpl implements ISysConfigData {
|
|||
|
||||
@Override
|
||||
public List<SysConfig> findByIds(Collection<Long> id) {
|
||||
throw new BizException(ErrCode.UNSUPPORTED_OPERATION_EXCEPTION);
|
||||
Iterable<TbSysConfig> allById = alertConfigRepository.findAllById(id);
|
||||
Iterator<TbSysConfig> iterator = allById.iterator();
|
||||
return MapstructUtils.convert(IteratorUtils.toList(iterator), SysConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,19 +89,35 @@ public class SysConfigDataImpl implements ISysConfigData {
|
|||
|
||||
// TODO: 2023/5/26 抽成通用工具类方法
|
||||
|
||||
alertConfigRepository.findAll(predicate, PageBuilder.toPageable(pageRequest));
|
||||
Page<TbSysConfig> all = alertConfigRepository.findAll(predicate, PageBuilder.toPageable(pageRequest));
|
||||
return PageBuilder.toPaging(all, SysConfig.class);
|
||||
|
||||
|
||||
throw new BizException(ErrCode.UNSUPPORTED_OPERATION_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SysConfig> findAllByCondition(SysConfig data) {
|
||||
throw new BizException(ErrCode.UNSUPPORTED_OPERATION_EXCEPTION);
|
||||
Predicate predicate = PredicateBuilder.instance()
|
||||
.and(StringUtils.isNotEmpty(data.getConfigKey()), () -> tbSysConfig.configKey.eq(data.getConfigKey()))
|
||||
.build();
|
||||
Iterator<TbSysConfig> iterator = alertConfigRepository.findAll(predicate).iterator();
|
||||
return MapstructUtils.convert(IteratorUtils.toList(iterator), SysConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysConfig findOneByCondition(SysConfig data) {
|
||||
throw new BizException(ErrCode.UNSUPPORTED_OPERATION_EXCEPTION);
|
||||
Predicate predicate = PredicateBuilder.instance()
|
||||
.and(StringUtils.isNotEmpty(data.getConfigKey()), () -> tbSysConfig.configKey.eq(data.getConfigKey()))
|
||||
.build();
|
||||
TbSysConfig tbSysConfig = alertConfigRepository.findOne(predicate).orElseThrow(() -> new BizException(ErrCode.DATA_NOT_EXIST));
|
||||
return MapstructUtils.convert(tbSysConfig, SysConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysConfig findByConfigKey(String configKey) {
|
||||
TbSysConfig tbSysConfig = alertConfigRepository.findByConfigKey(configKey).orElseThrow(() ->
|
||||
new BizException(ErrCode.DATA_NOT_EXIST));
|
||||
return MapstructUtils.convert(tbSysConfig, SysConfig.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,13 @@ package cc.iotkit.data.util;
|
|||
|
||||
import cc.iotkit.common.api.PageRequest;
|
||||
import cc.iotkit.common.api.PageRequestEmpty;
|
||||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.common.utils.MapstructUtils;
|
||||
import cc.iotkit.data.model.TbSysConfig;
|
||||
import cc.iotkit.model.product.Product;
|
||||
import cc.iotkit.model.system.SysConfig;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
|
@ -59,4 +64,8 @@ public class PageBuilder {
|
|||
return orders;
|
||||
}
|
||||
|
||||
public static Paging<SysConfig> toPaging(Page all, Class clz) {
|
||||
return new Paging<>(all.getTotalElements(),
|
||||
MapstructUtils.convert(all.getContent(), clz));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class SysConfigController extends BaseController {
|
|||
if (!configService.checkConfigKeyUnique(request.getData())) {
|
||||
fail("新增参数'" + request.getData().getConfigName() + "'失败,参数键名已存在");
|
||||
}
|
||||
configService.insertConfig(request.getData());
|
||||
configService.insertConfig(request.getData());
|
||||
}
|
||||
|
||||
@ApiOperation("修改参数配置")
|
||||
|
|
|
@ -7,6 +7,7 @@ import cc.iotkit.common.constant.UserConstants;
|
|||
import cc.iotkit.common.exception.BizException;
|
||||
import cc.iotkit.common.redis.utils.CacheUtils;
|
||||
import cc.iotkit.common.service.ConfigService;
|
||||
import cc.iotkit.common.utils.MapstructUtils;
|
||||
import cc.iotkit.common.utils.SpringUtils;
|
||||
import cc.iotkit.common.utils.StringUtils;
|
||||
import cc.iotkit.data.system.ISysConfigData;
|
||||
|
@ -93,7 +94,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
|
|||
*/
|
||||
@Override
|
||||
public List<SysConfigVo> selectConfigList(SysConfigBo config) {
|
||||
return new ArrayList<>();
|
||||
|
||||
List<SysConfig> allByCondition = sysConfigData.findAllByCondition(MapstructUtils.convert(config, SysConfig.class));
|
||||
return MapstructUtils.convert(allByCondition, SysConfigVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,7 +107,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
|
|||
*/
|
||||
@Override
|
||||
public String insertConfig(SysConfigBo bo) {
|
||||
throw new BizException("操作失败");
|
||||
SysConfig to = bo.to(SysConfig.class);
|
||||
sysConfigData.save(to);
|
||||
return String.valueOf(to.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,18 +121,17 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
|
|||
// @CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#bo.configKey")
|
||||
@Override
|
||||
public String updateConfig(SysConfigBo bo) {
|
||||
// SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
|
||||
// if (config.getId() == null) {
|
||||
// SysConfig old = sysConfigData.findByConfigKey(bo.getConfigKey());
|
||||
// if (old == null) {
|
||||
// throw new BizException("操作失败,key不存在");
|
||||
// }
|
||||
// config.setId(old.getId());
|
||||
// }
|
||||
//
|
||||
// sysConfigData.save(config);
|
||||
// return config.getConfigValue();
|
||||
return "";
|
||||
SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
|
||||
if (config.getId() == null) {
|
||||
SysConfig old = sysConfigData.findByConfigKey(config.getConfigKey());
|
||||
if (old == null) {
|
||||
throw new BizException("操作失败,key不存在");
|
||||
}
|
||||
config.setId(old.getId());
|
||||
}
|
||||
|
||||
sysConfigData.save(config);
|
||||
return config.getConfigValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue