🔨 系统设置模块优化.
This commit is contained in:
@@ -32,16 +32,18 @@ import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
|
|||||||
import org.dromara.visor.framework.web.core.annotation.DemoDisableApi;
|
import org.dromara.visor.framework.web.core.annotation.DemoDisableApi;
|
||||||
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
||||||
import org.dromara.visor.module.infra.define.operator.SystemSettingOperatorType;
|
import org.dromara.visor.module.infra.define.operator.SystemSettingOperatorType;
|
||||||
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdatePartialRequest;
|
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateBatchRequest;
|
||||||
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||||
import org.dromara.visor.module.infra.entity.vo.AppInfoVO;
|
import org.dromara.visor.module.infra.entity.vo.AppInfoVO;
|
||||||
|
import org.dromara.visor.module.infra.entity.vo.SystemSettingAggregateVO;
|
||||||
|
import org.dromara.visor.module.infra.handler.setting.model.EncryptSystemSettingModel;
|
||||||
import org.dromara.visor.module.infra.service.SystemSettingService;
|
import org.dromara.visor.module.infra.service.SystemSettingService;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
import javax.annotation.security.PermitAll;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统设置服务
|
* 系统设置服务
|
||||||
@@ -68,30 +70,49 @@ public class SystemSettingController {
|
|||||||
return systemSettingService.getAppInfo();
|
return systemSettingService.getAppInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PermitAll
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@GetMapping("/setting")
|
@GetMapping("/setting")
|
||||||
|
@Operation(summary = "获取系统聚合设置")
|
||||||
|
public SystemSettingAggregateVO getSystemAggregateSetting() {
|
||||||
|
return systemSettingService.getSystemAggregateSetting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DemoDisableApi
|
||||||
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
|
@GetMapping("/generator-keypair")
|
||||||
|
@Operation(summary = "生成密钥对")
|
||||||
|
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
||||||
|
public EncryptSystemSettingModel generatorKeypair() {
|
||||||
|
return systemSettingService.generatorKeypair();
|
||||||
|
}
|
||||||
|
|
||||||
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
|
@GetMapping("/get")
|
||||||
@Operation(summary = "查询系统设置")
|
@Operation(summary = "查询系统设置")
|
||||||
@Parameter(name = "type", description = "type", required = true)
|
@Parameter(name = "type", description = "type", required = true)
|
||||||
public Map<String, Object> getSystemSettingByType(@RequestParam("type") String type) {
|
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
||||||
|
public Object getSystemSettingByType(@RequestParam("type") String type) {
|
||||||
return systemSettingService.getSystemSettingByType(type);
|
return systemSettingService.getSystemSettingByType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DemoDisableApi
|
@DemoDisableApi
|
||||||
@OperatorLog(SystemSettingOperatorType.UPDATE)
|
@OperatorLog(SystemSettingOperatorType.UPDATE)
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "更新系统设置")
|
@Operation(summary = "更新系统设置-单个")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
||||||
public Integer updateSystemSetting(@Validated @RequestBody SystemSettingUpdateRequest request) {
|
public Boolean updateSystemSetting(@Validated @RequestBody SystemSettingUpdateRequest request) {
|
||||||
return systemSettingService.updateSystemSetting(request);
|
systemSettingService.updateSystemSetting(request);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DemoDisableApi
|
@DemoDisableApi
|
||||||
@OperatorLog(SystemSettingOperatorType.UPDATE)
|
@OperatorLog(SystemSettingOperatorType.UPDATE)
|
||||||
@PutMapping("/update-partial")
|
@PutMapping("/update-batch")
|
||||||
@Operation(summary = "更新部分系统设置")
|
@Operation(summary = "更新系统设置-多个")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
||||||
public Boolean updatePartialSystemSetting(@Validated @RequestBody SystemSettingUpdatePartialRequest request) {
|
public Boolean updateSystemSettingBatch(@Validated @RequestBody SystemSettingUpdateBatchRequest request) {
|
||||||
systemSettingService.updatePartialSystemSetting(request);
|
systemSettingService.updateSystemSettingBatch(request);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ package org.dromara.visor.module.infra.convert;
|
|||||||
import org.dromara.visor.module.infra.entity.domain.SystemSettingDO;
|
import org.dromara.visor.module.infra.entity.domain.SystemSettingDO;
|
||||||
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +39,6 @@ public interface SystemSettingConvert {
|
|||||||
|
|
||||||
SystemSettingConvert MAPPER = Mappers.getMapper(SystemSettingConvert.class);
|
SystemSettingConvert MAPPER = Mappers.getMapper(SystemSettingConvert.class);
|
||||||
|
|
||||||
@Mapping(target = "value", ignore = true)
|
|
||||||
SystemSettingDO to(SystemSettingUpdateRequest request);
|
SystemSettingDO to(SystemSettingUpdateRequest request);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ package org.dromara.visor.module.infra.define.cache;
|
|||||||
import cn.orionsec.kit.lang.define.cache.key.CacheKeyBuilder;
|
import cn.orionsec.kit.lang.define.cache.key.CacheKeyBuilder;
|
||||||
import cn.orionsec.kit.lang.define.cache.key.CacheKeyDefine;
|
import cn.orionsec.kit.lang.define.cache.key.CacheKeyDefine;
|
||||||
import cn.orionsec.kit.lang.define.cache.key.struct.RedisCacheStruct;
|
import cn.orionsec.kit.lang.define.cache.key.struct.RedisCacheStruct;
|
||||||
import cn.orionsec.kit.lang.define.wrapper.Ref;
|
import org.dromara.visor.module.infra.entity.vo.SystemSettingAggregateVO;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -39,10 +39,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public interface SystemSettingKeyDefine {
|
public interface SystemSettingKeyDefine {
|
||||||
|
|
||||||
CacheKeyDefine SETTING = new CacheKeyBuilder()
|
CacheKeyDefine SETTING = new CacheKeyBuilder()
|
||||||
.key("system:setting:{}")
|
.key("system:setting:agg")
|
||||||
.desc("系统设置 ${type}")
|
.desc("系统聚合设置")
|
||||||
.type(Ref.class)
|
.type(SystemSettingAggregateVO.class)
|
||||||
.struct(RedisCacheStruct.HASH)
|
.struct(RedisCacheStruct.STRING)
|
||||||
.timeout(8, TimeUnit.HOURS)
|
.timeout(8, TimeUnit.HOURS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class SystemSettingOperatorType extends InitializingOperatorTypes {
|
|||||||
|
|
||||||
public static final String UPDATE_TEXT = "<sb>{}</sb> - <sb>{}</sb> - <sb>{}</sb>";
|
public static final String UPDATE_TEXT = "<sb>{}</sb> - <sb>{}</sb> - <sb>{}</sb>";
|
||||||
|
|
||||||
public static final String UPDATE_PARTIAL_TEXT = "<sb>{}</sb>";
|
public static final String UPDATE_BATCH_TEXT = "<sb>{}</sb>";
|
||||||
|
|
||||||
public static final String UPDATE = "system-setting:update";
|
public static final String UPDATE = "system-setting:update";
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ public class SystemSettingDO extends BaseDO {
|
|||||||
@TableId(value = "id", type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "配置key")
|
||||||
|
@TableField("config_key")
|
||||||
|
private String configKey;
|
||||||
|
|
||||||
@Schema(description = "配置类型")
|
@Schema(description = "配置类型")
|
||||||
@TableField("type")
|
@TableField("type")
|
||||||
private String type;
|
private String type;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import java.io.Serializable;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统设置部分 更新请求对象
|
* 系统设置 批量更新请求对象
|
||||||
*
|
*
|
||||||
* @author Jiahang Li
|
* @author Jiahang Li
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
@@ -45,8 +45,8 @@ import java.util.Map;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Schema(name = "SystemSettingUpdatePartialRequest", description = "系统设置部分 更新请求对象")
|
@Schema(name = "SystemSettingUpdateBatchRequest", description = "系统设置 批量更新请求对象")
|
||||||
public class SystemSettingUpdatePartialRequest implements Serializable {
|
public class SystemSettingUpdateBatchRequest implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@@ -57,6 +57,6 @@ public class SystemSettingUpdatePartialRequest implements Serializable {
|
|||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
@Schema(description = "配置")
|
@Schema(description = "配置")
|
||||||
private Map<String, Object> settings;
|
private Map<String, String> settings;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,6 @@ public class SystemSettingUpdateRequest implements Serializable {
|
|||||||
private String item;
|
private String item;
|
||||||
|
|
||||||
@Schema(description = "配置值")
|
@Schema(description = "配置值")
|
||||||
private Object value;
|
private String value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,37 +20,34 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.dromara.visor.module.infra.handler.setting.strategy;
|
package org.dromara.visor.module.infra.entity.vo;
|
||||||
|
|
||||||
import cn.orionsec.kit.lang.utils.Exceptions;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import org.dromara.visor.common.handler.data.strategy.AbstractGenericsDataStrategy;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.dromara.visor.module.infra.handler.setting.model.EncryptSystemSettingModel;
|
||||||
import org.dromara.visor.module.infra.handler.setting.model.SftpSystemSettingModel;
|
import org.dromara.visor.module.infra.handler.setting.model.SftpSystemSettingModel;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SFTP 系统配置策略
|
* 系统设置 聚合响应对象
|
||||||
*
|
*
|
||||||
* @author Jiahang Li
|
* @author Jiahang Li
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 2024/10/9 11:44
|
* @since 2025/1/3 17:46
|
||||||
*/
|
*/
|
||||||
@Component
|
@Data
|
||||||
public class SftpSystemSettingStrategy extends AbstractGenericsDataStrategy<SftpSystemSettingModel> {
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "SystemSettingAggregateVO", description = "系统设置 聚合响应对象")
|
||||||
|
public class SystemSettingAggregateVO {
|
||||||
|
|
||||||
public SftpSystemSettingStrategy() {
|
@Schema(description = "SFTP 设置")
|
||||||
super(SftpSystemSettingModel.class);
|
private SftpSystemSettingModel sftp;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Schema(description = "加密设置")
|
||||||
public SftpSystemSettingModel getDefault() {
|
private EncryptSystemSettingModel encrypt;
|
||||||
return SftpSystemSettingModel.builder()
|
|
||||||
.previewSize(2)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public SftpSystemSettingModel parse(String serialModel) {
|
|
||||||
throw Exceptions.unsupported();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -22,12 +22,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.dromara.visor.module.infra.enums;
|
package org.dromara.visor.module.infra.enums;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.dromara.visor.common.handler.data.GenericsStrategyDefinition;
|
import org.dromara.visor.common.constant.Const;
|
||||||
import org.dromara.visor.common.handler.data.model.GenericsDataModel;
|
import org.dromara.visor.module.infra.handler.setting.model.EncryptSystemSettingModel;
|
||||||
import org.dromara.visor.common.handler.data.strategy.GenericsDataStrategy;
|
import org.dromara.visor.module.infra.handler.setting.model.SftpSystemSettingModel;
|
||||||
import org.dromara.visor.module.infra.handler.setting.strategy.SftpSystemSettingStrategy;
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统配置类型枚举
|
* 系统配置类型枚举
|
||||||
@@ -38,34 +40,55 @@ import org.dromara.visor.module.infra.handler.setting.strategy.SftpSystemSetting
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum SystemSettingTypeEnum implements GenericsStrategyDefinition {
|
public enum SystemSettingTypeEnum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SFTP 配置
|
* SFTP 配置
|
||||||
*/
|
*/
|
||||||
SFTP(SftpSystemSettingStrategy.class),
|
SFTP("sftp", SftpSystemSettingModel.class),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密配置
|
||||||
|
*/
|
||||||
|
ENCRYPT("encrypt", EncryptSystemSettingModel.class),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
SystemSettingTypeEnum(Class<? extends GenericsDataStrategy<? extends GenericsDataModel>> strategyClass) {
|
private final String prefix;
|
||||||
this.type = this.name();
|
|
||||||
this.strategyClass = strategyClass;
|
private final Class<?> modelClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析
|
||||||
|
*
|
||||||
|
* @param settings settings
|
||||||
|
* @return model
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T parseModel(Map<String, String> settings) {
|
||||||
|
return (T) JSON.parseObject(JSON.toJSONString(settings)).toJavaObject(modelClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String type;
|
|
||||||
|
|
||||||
private final Class<? extends GenericsDataStrategy<? extends GenericsDataModel>> strategyClass;
|
|
||||||
|
|
||||||
public static SystemSettingTypeEnum of(String type) {
|
public static SystemSettingTypeEnum of(String type) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (SystemSettingTypeEnum value : values()) {
|
for (SystemSettingTypeEnum value : values()) {
|
||||||
if (value.type.equals(type)) {
|
if (value.name().equals(type)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 key
|
||||||
|
*
|
||||||
|
* @param item item
|
||||||
|
* @return key
|
||||||
|
*/
|
||||||
|
public String getConfigKey(String item) {
|
||||||
|
return prefix + Const.DOT + item;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||||
|
*
|
||||||
|
* https://visor.dromara.org
|
||||||
|
* https://visor.dromara.org.cn
|
||||||
|
* https://visor.orionsec.cn
|
||||||
|
*
|
||||||
|
* Members:
|
||||||
|
* Jiahang Li - ljh1553488six@139.com - author
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.dromara.visor.module.infra.framework.service.impl;
|
||||||
|
|
||||||
|
import cn.orionsec.kit.lang.function.Functions;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.visor.framework.config.core.service.ConfigFrameworkService;
|
||||||
|
import org.dromara.visor.module.infra.dao.SystemSettingDAO;
|
||||||
|
import org.dromara.visor.module.infra.entity.domain.SystemSettingDO;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置框架服务实现
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2025/1/6 23:35
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ConfigFrameworkServiceImpl implements ConfigFrameworkService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemSettingDAO systemSettingDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getAllConfig() {
|
||||||
|
return systemSettingDAO.of()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
SystemSettingDO::getConfigKey,
|
||||||
|
SystemSettingDO::getValue,
|
||||||
|
Functions.right()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||||
|
*
|
||||||
|
* https://visor.dromara.org
|
||||||
|
* https://visor.dromara.org.cn
|
||||||
|
* https://visor.orionsec.cn
|
||||||
|
*
|
||||||
|
* Members:
|
||||||
|
* Jiahang Li - ljh1553488six@139.com - author
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.dromara.visor.module.infra.handler.setting.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密系统配置模型
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2024/10/9 11:45
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class EncryptSystemSettingModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密公钥
|
||||||
|
*/
|
||||||
|
private String publicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密私钥
|
||||||
|
*/
|
||||||
|
private String privateKey;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,7 +26,6 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.visor.common.handler.data.model.GenericsDataModel;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SFTP 系统配置模型
|
* SFTP 系统配置模型
|
||||||
@@ -39,7 +38,7 @@ import org.dromara.visor.common.handler.data.model.GenericsDataModel;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class SftpSystemSettingModel implements GenericsDataModel {
|
public class SftpSystemSettingModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览大小
|
* 预览大小
|
||||||
|
|||||||
@@ -22,11 +22,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.dromara.visor.module.infra.service;
|
package org.dromara.visor.module.infra.service;
|
||||||
|
|
||||||
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdatePartialRequest;
|
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateBatchRequest;
|
||||||
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||||
import org.dromara.visor.module.infra.entity.vo.AppInfoVO;
|
import org.dromara.visor.module.infra.entity.vo.AppInfoVO;
|
||||||
|
import org.dromara.visor.module.infra.entity.vo.SystemSettingAggregateVO;
|
||||||
import java.util.Map;
|
import org.dromara.visor.module.infra.handler.setting.model.EncryptSystemSettingModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统设置服务
|
* 系统设置服务
|
||||||
@@ -45,26 +45,40 @@ public interface SystemSettingService {
|
|||||||
AppInfoVO getAppInfo();
|
AppInfoVO getAppInfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新系统设置
|
* 获取系统聚合设置
|
||||||
*
|
*
|
||||||
* @param request request
|
* @return setting
|
||||||
* @return effect
|
|
||||||
*/
|
*/
|
||||||
Integer updateSystemSetting(SystemSettingUpdateRequest request);
|
SystemSettingAggregateVO getSystemAggregateSetting();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成密钥对
|
||||||
|
*
|
||||||
|
* @return keypair
|
||||||
|
*/
|
||||||
|
EncryptSystemSettingModel generatorKeypair();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过类型查询系统设置
|
||||||
|
*
|
||||||
|
* @param type type
|
||||||
|
* @param <T> T
|
||||||
|
* @return row
|
||||||
|
*/
|
||||||
|
<T> T getSystemSettingByType(String type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新部分系统设置
|
* 更新部分系统设置
|
||||||
*
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
*/
|
*/
|
||||||
void updatePartialSystemSetting(SystemSettingUpdatePartialRequest request);
|
void updateSystemSetting(SystemSettingUpdateRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过类型查询系统设置
|
* 更新系统设置
|
||||||
*
|
*
|
||||||
* @param type type
|
* @param request request
|
||||||
* @return row
|
|
||||||
*/
|
*/
|
||||||
Map<String, Object> getSystemSettingByType(String type);
|
void updateSystemSettingBatch(SystemSettingUpdateBatchRequest request);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,38 +23,46 @@
|
|||||||
package org.dromara.visor.module.infra.service.impl;
|
package org.dromara.visor.module.infra.service.impl;
|
||||||
|
|
||||||
import cn.orionsec.kit.ext.process.ProcessAwaitExecutor;
|
import cn.orionsec.kit.ext.process.ProcessAwaitExecutor;
|
||||||
|
import cn.orionsec.kit.lang.define.wrapper.Pair;
|
||||||
import cn.orionsec.kit.lang.function.Functions;
|
import cn.orionsec.kit.lang.function.Functions;
|
||||||
import cn.orionsec.kit.lang.support.Attempt;
|
import cn.orionsec.kit.lang.support.Attempt;
|
||||||
import cn.orionsec.kit.lang.utils.Arrays1;
|
import cn.orionsec.kit.lang.utils.Arrays1;
|
||||||
import cn.orionsec.kit.lang.utils.Refs;
|
import cn.orionsec.kit.lang.utils.Objects1;
|
||||||
import cn.orionsec.kit.lang.utils.Strings;
|
import cn.orionsec.kit.lang.utils.Strings;
|
||||||
import cn.orionsec.kit.lang.utils.collect.Maps;
|
import cn.orionsec.kit.lang.utils.crypto.Keys;
|
||||||
|
import cn.orionsec.kit.lang.utils.crypto.RSA;
|
||||||
import cn.orionsec.kit.lang.utils.crypto.Signatures;
|
import cn.orionsec.kit.lang.utils.crypto.Signatures;
|
||||||
import cn.orionsec.kit.lang.utils.io.Streams;
|
import cn.orionsec.kit.lang.utils.io.Streams;
|
||||||
|
import cn.orionsec.kit.spring.SpringHolder;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import org.dromara.visor.common.constant.AppConst;
|
import org.dromara.visor.common.constant.AppConst;
|
||||||
import org.dromara.visor.common.constant.Const;
|
import org.dromara.visor.common.constant.Const;
|
||||||
import org.dromara.visor.common.constant.ErrorMessage;
|
import org.dromara.visor.common.constant.ErrorMessage;
|
||||||
import org.dromara.visor.common.utils.Valid;
|
import org.dromara.visor.common.utils.Valid;
|
||||||
import org.dromara.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
import org.dromara.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||||
import org.dromara.visor.framework.redis.core.utils.RedisMaps;
|
import org.dromara.visor.framework.config.core.event.ConfigUpdateEvent;
|
||||||
|
import org.dromara.visor.framework.redis.core.utils.RedisStrings;
|
||||||
import org.dromara.visor.framework.redis.core.utils.RedisUtils;
|
import org.dromara.visor.framework.redis.core.utils.RedisUtils;
|
||||||
import org.dromara.visor.module.infra.dao.SystemSettingDAO;
|
import org.dromara.visor.module.infra.dao.SystemSettingDAO;
|
||||||
import org.dromara.visor.module.infra.define.cache.SystemSettingKeyDefine;
|
import org.dromara.visor.module.infra.define.cache.SystemSettingKeyDefine;
|
||||||
import org.dromara.visor.module.infra.define.operator.SystemSettingOperatorType;
|
import org.dromara.visor.module.infra.define.operator.SystemSettingOperatorType;
|
||||||
import org.dromara.visor.module.infra.entity.domain.SystemSettingDO;
|
import org.dromara.visor.module.infra.entity.domain.SystemSettingDO;
|
||||||
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdatePartialRequest;
|
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateBatchRequest;
|
||||||
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
import org.dromara.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||||
import org.dromara.visor.module.infra.entity.vo.AppInfoVO;
|
import org.dromara.visor.module.infra.entity.vo.AppInfoVO;
|
||||||
|
import org.dromara.visor.module.infra.entity.vo.SystemSettingAggregateVO;
|
||||||
import org.dromara.visor.module.infra.enums.SystemSettingTypeEnum;
|
import org.dromara.visor.module.infra.enums.SystemSettingTypeEnum;
|
||||||
|
import org.dromara.visor.module.infra.handler.setting.model.EncryptSystemSettingModel;
|
||||||
|
import org.dromara.visor.module.infra.handler.setting.model.SftpSystemSettingModel;
|
||||||
import org.dromara.visor.module.infra.service.SystemSettingService;
|
import org.dromara.visor.module.infra.service.SystemSettingService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,28 +89,103 @@ public class SystemSettingServiceImpl implements SystemSettingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer updateSystemSetting(SystemSettingUpdateRequest request) {
|
public SystemSettingAggregateVO getSystemAggregateSetting() {
|
||||||
String type = request.getType();
|
// 查询缓存
|
||||||
String item = request.getItem();
|
SystemSettingAggregateVO cache = RedisStrings.getJson(SystemSettingKeyDefine.SETTING);
|
||||||
Object value = request.getValue();
|
SystemSettingAggregateVO result = Objects1.def(cache, SystemSettingAggregateVO::new);
|
||||||
// 更新
|
if (cache == null) {
|
||||||
SystemSettingDO update = new SystemSettingDO();
|
// 查询数据库
|
||||||
update.setValue(Refs.json(value));
|
Map<String, List<SystemSettingDO>> typeGroup = systemSettingDAO.of()
|
||||||
LambdaQueryWrapper<SystemSettingDO> wrapper = systemSettingDAO.lambda()
|
.createWrapper()
|
||||||
.eq(SystemSettingDO::getType, type)
|
.select(SystemSettingDO::getType,
|
||||||
.eq(SystemSettingDO::getItem, item);
|
SystemSettingDO::getItem,
|
||||||
int effect = systemSettingDAO.update(update, wrapper);
|
SystemSettingDO::getValue)
|
||||||
// 删除缓存
|
.in(SystemSettingDO::getType,
|
||||||
RedisUtils.delete(SystemSettingKeyDefine.SETTING.format(type));
|
SystemSettingTypeEnum.SFTP.name(),
|
||||||
// 设置日志参数
|
SystemSettingTypeEnum.ENCRYPT.name())
|
||||||
OperatorLogs.add(OperatorLogs.TEXT, Strings.format(SystemSettingOperatorType.UPDATE_TEXT, type, item, value));
|
.then()
|
||||||
return effect;
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(SystemSettingDO::getType));
|
||||||
|
// 数据组合
|
||||||
|
typeGroup.forEach((k, v) -> {
|
||||||
|
// 类型数据
|
||||||
|
SystemSettingTypeEnum settingType = SystemSettingTypeEnum.of(k);
|
||||||
|
Map<String, String> typeSettings = v.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
SystemSettingDO::getItem,
|
||||||
|
SystemSettingDO::getValue,
|
||||||
|
Functions.right()));
|
||||||
|
Object setting = settingType.parseModel(typeSettings);
|
||||||
|
if (SystemSettingTypeEnum.SFTP.equals(settingType)) {
|
||||||
|
// SFTP 设置
|
||||||
|
result.setSftp((SftpSystemSettingModel) setting);
|
||||||
|
} else if (SystemSettingTypeEnum.ENCRYPT.equals(settingType)) {
|
||||||
|
// 加密设置
|
||||||
|
EncryptSystemSettingModel encryptSetting = (EncryptSystemSettingModel) setting;
|
||||||
|
encryptSetting.setPrivateKey(null);
|
||||||
|
result.setEncrypt(encryptSetting);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 设置缓存
|
||||||
|
RedisStrings.setJson(SystemSettingKeyDefine.SETTING, result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePartialSystemSetting(SystemSettingUpdatePartialRequest request) {
|
public EncryptSystemSettingModel generatorKeypair() {
|
||||||
|
// 生成密钥对
|
||||||
|
Pair<RSAPublicKey, RSAPrivateKey> pair = RSA.generatorKeys();
|
||||||
|
return EncryptSystemSettingModel.builder()
|
||||||
|
.publicKey(Keys.getPublicKey(pair.getKey()))
|
||||||
|
.privateKey(Keys.getPrivateKey(pair.getValue()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T getSystemSettingByType(String type) {
|
||||||
|
SystemSettingTypeEnum settingType = SystemSettingTypeEnum.of(type);
|
||||||
|
Valid.notNull(settingType, ErrorMessage.ERROR_TYPE);
|
||||||
|
// 查询数据库
|
||||||
|
Map<String, String> settings = systemSettingDAO.of()
|
||||||
|
.createWrapper()
|
||||||
|
.eq(SystemSettingDO::getType, type)
|
||||||
|
.then()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
SystemSettingDO::getItem,
|
||||||
|
SystemSettingDO::getValue,
|
||||||
|
Functions.right()));
|
||||||
|
// 解析
|
||||||
|
return settingType.parseModel(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSystemSetting(SystemSettingUpdateRequest request) {
|
||||||
String type = request.getType();
|
String type = request.getType();
|
||||||
Map<String, Object> settings = request.getSettings();
|
SystemSettingTypeEnum settingType = Valid.valid(SystemSettingTypeEnum::of, type);
|
||||||
|
String item = request.getItem();
|
||||||
|
String value = request.getValue();
|
||||||
|
// 更新
|
||||||
|
SystemSettingDO update = new SystemSettingDO();
|
||||||
|
update.setValue(value);
|
||||||
|
LambdaQueryWrapper<SystemSettingDO> wrapper = systemSettingDAO.lambda()
|
||||||
|
.eq(SystemSettingDO::getType, type)
|
||||||
|
.eq(SystemSettingDO::getItem, item);
|
||||||
|
systemSettingDAO.update(update, wrapper);
|
||||||
|
// 删除缓存
|
||||||
|
RedisUtils.delete(SystemSettingKeyDefine.SETTING);
|
||||||
|
// 设置日志参数
|
||||||
|
OperatorLogs.add(OperatorLogs.TEXT, Strings.format(SystemSettingOperatorType.UPDATE_TEXT, type, item, value));
|
||||||
|
// 触发修改事件
|
||||||
|
SpringHolder.publishEvent(ConfigUpdateEvent.of(settingType.getConfigKey(item), value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSystemSettingBatch(SystemSettingUpdateBatchRequest request) {
|
||||||
|
String type = request.getType();
|
||||||
|
SystemSettingTypeEnum settingType = Valid.valid(SystemSettingTypeEnum::of, type);
|
||||||
|
Map<String, String> settings = request.getSettings();
|
||||||
// 删除
|
// 删除
|
||||||
LambdaQueryWrapper<SystemSettingDO> deleteWrapper = systemSettingDAO.lambda()
|
LambdaQueryWrapper<SystemSettingDO> deleteWrapper = systemSettingDAO.lambda()
|
||||||
.eq(SystemSettingDO::getType, type)
|
.eq(SystemSettingDO::getType, type)
|
||||||
@@ -112,63 +195,25 @@ public class SystemSettingServiceImpl implements SystemSettingService {
|
|||||||
List<SystemSettingDO> rows = settings.entrySet()
|
List<SystemSettingDO> rows = settings.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.map(s -> SystemSettingDO.builder()
|
.map(s -> SystemSettingDO.builder()
|
||||||
|
.configKey(settingType.getConfigKey(s.getKey()))
|
||||||
.type(type)
|
.type(type)
|
||||||
.item(s.getKey())
|
.item(s.getKey())
|
||||||
.value(Refs.json(s.getValue()))
|
.value(s.getValue())
|
||||||
.build())
|
.build())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
// 插入
|
// 插入
|
||||||
systemSettingDAO.insertBatch(rows);
|
systemSettingDAO.insertBatch(rows);
|
||||||
// 删除缓存
|
// 删除缓存
|
||||||
RedisUtils.delete(SystemSettingKeyDefine.SETTING.format(type));
|
RedisUtils.delete(SystemSettingKeyDefine.SETTING);
|
||||||
// 设置日志参数
|
// 设置日志参数
|
||||||
OperatorLogs.add(OperatorLogs.TEXT, Strings.format(SystemSettingOperatorType.UPDATE_PARTIAL_TEXT, type));
|
OperatorLogs.add(OperatorLogs.TEXT, Strings.format(SystemSettingOperatorType.UPDATE_BATCH_TEXT, type));
|
||||||
}
|
// 触发修改事件
|
||||||
|
Map<String, String> eventConfig = rows.stream()
|
||||||
@Override
|
.collect(Collectors.toMap(
|
||||||
public Map<String, Object> getSystemSettingByType(String type) {
|
SystemSettingDO::getConfigKey,
|
||||||
SystemSettingTypeEnum settingType = SystemSettingTypeEnum.of(type);
|
SystemSettingDO::getValue,
|
||||||
Valid.notNull(settingType, ErrorMessage.ERROR_TYPE);
|
Functions.right()));
|
||||||
// 查询缓存
|
SpringHolder.publishEvent(ConfigUpdateEvent.of(eventConfig));
|
||||||
String key = SystemSettingKeyDefine.SETTING.format(type);
|
|
||||||
Map<String, String> settings = RedisMaps.entities(key);
|
|
||||||
boolean setCache = Maps.isEmpty(settings);
|
|
||||||
// 查询数据库
|
|
||||||
if (Maps.isEmpty(settings)) {
|
|
||||||
settings = systemSettingDAO.of()
|
|
||||||
.createWrapper()
|
|
||||||
.eq(SystemSettingDO::getType, type)
|
|
||||||
.then()
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toMap(
|
|
||||||
SystemSettingDO::getItem,
|
|
||||||
SystemSettingDO::getValue,
|
|
||||||
Functions.right()));
|
|
||||||
}
|
|
||||||
// 初始化
|
|
||||||
if (Maps.isEmpty(settings)) {
|
|
||||||
// 获取默认值
|
|
||||||
Map<String, Object> defaultConfig = settingType.getDefault().toMap();
|
|
||||||
settings = Maps.map(defaultConfig, Function.identity(), Refs::json);
|
|
||||||
// 插入默认值
|
|
||||||
List<SystemSettingDO> entities = settings
|
|
||||||
.entrySet()
|
|
||||||
.stream()
|
|
||||||
.map(s -> {
|
|
||||||
SystemSettingDO entity = new SystemSettingDO();
|
|
||||||
entity.setType(type);
|
|
||||||
entity.setItem(s.getKey());
|
|
||||||
entity.setValue(s.getValue());
|
|
||||||
return entity;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
systemSettingDAO.insertBatch(entities);
|
|
||||||
}
|
|
||||||
// 设置缓存
|
|
||||||
if (setCache) {
|
|
||||||
RedisMaps.putAll(key, SystemSettingKeyDefine.SETTING, settings);
|
|
||||||
}
|
|
||||||
// unRef
|
|
||||||
return Maps.map(settings, Function.identity(), Refs::unref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<!-- 通用查询映射结果 -->
|
<!-- 通用查询映射结果 -->
|
||||||
<resultMap id="BaseResultMap" type="org.dromara.visor.module.infra.entity.domain.SystemSettingDO">
|
<resultMap id="BaseResultMap" type="org.dromara.visor.module.infra.entity.domain.SystemSettingDO">
|
||||||
<id column="id" property="id"/>
|
<id column="id" property="id"/>
|
||||||
|
<result column="config_key" property="configKey"/>
|
||||||
<result column="type" property="type"/>
|
<result column="type" property="type"/>
|
||||||
<result column="item" property="item"/>
|
<result column="item" property="item"/>
|
||||||
<result column="value" property="value"/>
|
<result column="value" property="value"/>
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
|
|
||||||
<!-- 通用查询结果列 -->
|
<!-- 通用查询结果列 -->
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id, type, item, value, create_time, update_time, creator, updater, deleted
|
id, config_key, type, item, value, create_time, update_time, creator, updater, deleted
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user