✨ 系统动态设置.
This commit is contained in:
@@ -1,28 +1,34 @@
|
||||
package com.orion.visor.module.infra.controller;
|
||||
|
||||
import com.orion.visor.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.visor.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.visor.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.visor.framework.web.core.annotation.DemoDisableApi;
|
||||
import com.orion.visor.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.visor.module.infra.define.operator.SystemSettingOperatorType;
|
||||
import com.orion.visor.module.infra.entity.request.system.SystemSettingUpdatePartialRequest;
|
||||
import com.orion.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||
import com.orion.visor.module.infra.entity.vo.AppInfoVO;
|
||||
import com.orion.visor.module.infra.service.SystemSettingService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统服务
|
||||
* 系统设置服务
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-7-17 11:39
|
||||
*/
|
||||
@Tag(name = "infra - 系统服务")
|
||||
@Tag(name = "infra - 系统设置服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@@ -40,5 +46,32 @@ public class SystemSettingController {
|
||||
return systemSettingService.getAppInfo();
|
||||
}
|
||||
|
||||
}
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/setting")
|
||||
@Operation(summary = "查询系统设置")
|
||||
@Parameter(name = "type", description = "type", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-setting:query')")
|
||||
public Map<String, Object> getSystemSettingByType(@RequestParam("type") String type) {
|
||||
return systemSettingService.getSystemSettingByType(type);
|
||||
}
|
||||
|
||||
@DemoDisableApi
|
||||
@OperatorLog(SystemSettingOperatorType.UPDATE)
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新系统设置")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
||||
public Integer updateSystemSetting(@Validated @RequestBody SystemSettingUpdateRequest request) {
|
||||
return systemSettingService.updateSystemSetting(request);
|
||||
}
|
||||
|
||||
@DemoDisableApi
|
||||
@OperatorLog(SystemSettingOperatorType.UPDATE)
|
||||
@PutMapping("/update-partial")
|
||||
@Operation(summary = "更新部分系统设置")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-setting:update')")
|
||||
public Boolean updatePartialSystemSetting(@Validated @RequestBody SystemSettingUpdatePartialRequest request) {
|
||||
systemSettingService.updatePartialSystemSetting(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.List;
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/infra/user-permission")
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class UserPermissionController {
|
||||
|
||||
@Resource
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orion.visor.module.infra.convert;
|
||||
|
||||
import com.orion.visor.module.infra.entity.domain.SystemSettingDO;
|
||||
import com.orion.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 系统设置 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 3.0.0
|
||||
* @since 2024-9-27 18:52
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemSettingConvert {
|
||||
|
||||
SystemSettingConvert MAPPER = Mappers.getMapper(SystemSettingConvert.class);
|
||||
|
||||
@Mapping(target = "value", ignore = true)
|
||||
SystemSettingDO to(SystemSettingUpdateRequest request);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.orion.visor.module.infra.dao;
|
||||
|
||||
import com.orion.visor.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.visor.module.infra.entity.domain.SystemSettingDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统设置 Mapper 接口
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 3.0.0
|
||||
* @since 2024-9-27 18:52
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemSettingDAO extends IMapper<SystemSettingDO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.orion.visor.module.infra.define.cache;
|
||||
|
||||
import com.orion.lang.define.cache.key.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.key.CacheKeyDefine;
|
||||
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
|
||||
import com.orion.lang.define.wrapper.Ref;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 系统配置缓存 key
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-27 18:37
|
||||
*/
|
||||
public interface SystemSettingKeyDefine {
|
||||
|
||||
CacheKeyDefine SETTING = new CacheKeyBuilder()
|
||||
.key("system:setting:{}")
|
||||
.desc("系统设置 ${type}")
|
||||
.type(Ref.class)
|
||||
.struct(RedisCacheStruct.HASH)
|
||||
.timeout(8, TimeUnit.HOURS)
|
||||
.build();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.orion.visor.module.infra.define.operator;
|
||||
|
||||
import com.orion.visor.framework.biz.operator.log.core.annotation.Module;
|
||||
import com.orion.visor.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
|
||||
import com.orion.visor.framework.biz.operator.log.core.model.OperatorType;
|
||||
|
||||
import static com.orion.visor.framework.biz.operator.log.core.enums.OperatorRiskLevel.M;
|
||||
|
||||
/**
|
||||
* 系统设置 操作日志类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 3.0.0
|
||||
* @since 2024-9-27 18:52
|
||||
*/
|
||||
@Module("infra:system-setting")
|
||||
public class SystemSettingOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
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 = "system-setting:update";
|
||||
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(M, UPDATE, "更新系统设置 ${text}"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.orion.visor.module.infra.entity.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.orion.visor.framework.mybatis.core.domain.BaseDO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 系统设置 实体对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 3.0.0
|
||||
* @since 2024-9-27 18:52
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "system_setting", autoResultMap = true)
|
||||
@Schema(name = "SystemSettingDO", description = "系统设置 实体对象")
|
||||
public class SystemSettingDO extends BaseDO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "配置类型")
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "配置项")
|
||||
@TableField("item")
|
||||
private String item;
|
||||
|
||||
@Schema(description = "配置值")
|
||||
@TableField("value")
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.orion.visor.module.infra.entity.request.system;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统设置部分 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 3.0.0
|
||||
* @since 2024-9-27 18:52
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "SystemSettingUpdatePartialRequest", description = "系统设置部分 更新请求对象")
|
||||
public class SystemSettingUpdatePartialRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 16)
|
||||
@Schema(description = "配置类型")
|
||||
private String type;
|
||||
|
||||
@NotEmpty
|
||||
@Schema(description = "配置")
|
||||
private Map<String, Object> settings;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.orion.visor.module.infra.entity.request.system;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 系统设置 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 3.0.0
|
||||
* @since 2024-9-27 18:52
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "SystemSettingUpdateRequest", description = "系统设置 更新请求对象")
|
||||
public class SystemSettingUpdateRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 16)
|
||||
@Schema(description = "配置类型")
|
||||
private String type;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "配置项")
|
||||
private String item;
|
||||
|
||||
@Schema(description = "配置值")
|
||||
private Object value;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.orion.visor.module.infra.enums;
|
||||
|
||||
import com.orion.visor.framework.common.handler.data.GenericsDataDefinition;
|
||||
import com.orion.visor.framework.common.handler.data.model.GenericsDataModel;
|
||||
import com.orion.visor.framework.common.handler.data.strategy.GenericsDataStrategy;
|
||||
import com.orion.visor.module.infra.handler.setting.strategy.SftpSystemSettingStrategy;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 系统配置类型枚举
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/9/27 19:07
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SystemSettingTypeEnum implements GenericsDataDefinition {
|
||||
|
||||
/**
|
||||
* SFTP 配置
|
||||
*/
|
||||
SFTP(SftpSystemSettingStrategy.class),
|
||||
|
||||
;
|
||||
|
||||
SystemSettingTypeEnum(Class<? extends GenericsDataStrategy<? extends GenericsDataModel>> strategyClass) {
|
||||
this.type = this.name();
|
||||
this.strategyClass = strategyClass;
|
||||
}
|
||||
|
||||
private final String type;
|
||||
|
||||
private final Class<? extends GenericsDataStrategy<? extends GenericsDataModel>> strategyClass;
|
||||
|
||||
public static SystemSettingTypeEnum of(String type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
for (SystemSettingTypeEnum value : values()) {
|
||||
if (value.type.equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.orion.visor.module.infra.handler.setting.model;
|
||||
|
||||
import com.orion.visor.framework.common.handler.data.model.GenericsDataModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* SFTP 系统配置模型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/10/9 11:45
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SftpSystemSettingModel implements GenericsDataModel {
|
||||
|
||||
/**
|
||||
* 预览大小
|
||||
*/
|
||||
private Integer previewSize;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.orion.visor.module.infra.handler.setting.strategy;
|
||||
|
||||
import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.visor.framework.common.handler.data.strategy.AbstractGenericsDataStrategy;
|
||||
import com.orion.visor.module.infra.handler.setting.model.SftpSystemSettingModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* SFTP 系统配置策略
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/10/9 11:44
|
||||
*/
|
||||
@Component
|
||||
public class SftpSystemSettingStrategy extends AbstractGenericsDataStrategy<SftpSystemSettingModel> {
|
||||
|
||||
public SftpSystemSettingStrategy() {
|
||||
super(SftpSystemSettingModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SftpSystemSettingModel getDefault() {
|
||||
return SftpSystemSettingModel.builder()
|
||||
.previewSize(2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SftpSystemSettingModel parse(String serialModel) {
|
||||
throw Exceptions.unsupported();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.orion.visor.module.infra.service;
|
||||
|
||||
import com.orion.visor.module.infra.entity.request.system.SystemSettingUpdatePartialRequest;
|
||||
import com.orion.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||
import com.orion.visor.module.infra.entity.vo.AppInfoVO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统服务
|
||||
* 系统设置服务
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/6/17 18:10
|
||||
* @since 2024/6/16 0:18
|
||||
*/
|
||||
public interface SystemSettingService {
|
||||
|
||||
@@ -18,4 +22,27 @@ public interface SystemSettingService {
|
||||
*/
|
||||
AppInfoVO getAppInfo();
|
||||
|
||||
/**
|
||||
* 更新系统设置
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateSystemSetting(SystemSettingUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 更新部分系统设置
|
||||
*
|
||||
* @param request request
|
||||
*/
|
||||
void updatePartialSystemSetting(SystemSettingUpdatePartialRequest request);
|
||||
|
||||
/**
|
||||
* 通过类型查询系统设置
|
||||
*
|
||||
* @param type type
|
||||
* @return row
|
||||
*/
|
||||
Map<String, Object> getSystemSettingByType(String type);
|
||||
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
if (setCache) {
|
||||
RedisMaps.putAll(key, PreferenceCacheKeyDefine.PREFERENCE, config);
|
||||
}
|
||||
// unref
|
||||
// unRef
|
||||
return Maps.map(config, Function.identity(), Refs::unref);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,39 @@
|
||||
package com.orion.visor.module.infra.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.ext.process.ProcessAwaitExecutor;
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.support.Attempt;
|
||||
import com.orion.lang.utils.Arrays1;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.lang.utils.crypto.Signatures;
|
||||
import com.orion.lang.utils.io.Streams;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.visor.framework.common.constant.AppConst;
|
||||
import com.orion.visor.framework.common.constant.Const;
|
||||
import com.orion.visor.framework.common.constant.ErrorMessage;
|
||||
import com.orion.visor.framework.common.utils.Valid;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisUtils;
|
||||
import com.orion.visor.module.infra.dao.SystemSettingDAO;
|
||||
import com.orion.visor.module.infra.define.cache.SystemSettingKeyDefine;
|
||||
import com.orion.visor.module.infra.define.operator.SystemSettingOperatorType;
|
||||
import com.orion.visor.module.infra.entity.domain.SystemSettingDO;
|
||||
import com.orion.visor.module.infra.entity.request.system.SystemSettingUpdatePartialRequest;
|
||||
import com.orion.visor.module.infra.entity.request.system.SystemSettingUpdateRequest;
|
||||
import com.orion.visor.module.infra.entity.vo.AppInfoVO;
|
||||
import com.orion.visor.module.infra.enums.SystemSettingTypeEnum;
|
||||
import com.orion.visor.module.infra.service.SystemSettingService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统服务 实现类
|
||||
@@ -26,6 +47,9 @@ public class SystemSettingServiceImpl implements SystemSettingService {
|
||||
|
||||
private String uuid;
|
||||
|
||||
@Resource
|
||||
private SystemSettingDAO systemSettingDAO;
|
||||
|
||||
@Override
|
||||
public AppInfoVO getAppInfo() {
|
||||
return AppInfoVO.builder()
|
||||
@@ -34,6 +58,99 @@ public class SystemSettingServiceImpl implements SystemSettingService {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateSystemSetting(SystemSettingUpdateRequest request) {
|
||||
String type = request.getType();
|
||||
String item = request.getItem();
|
||||
Object value = request.getValue();
|
||||
// 更新
|
||||
SystemSettingDO update = new SystemSettingDO();
|
||||
update.setValue(Refs.json(value));
|
||||
LambdaQueryWrapper<SystemSettingDO> wrapper = systemSettingDAO.lambda()
|
||||
.eq(SystemSettingDO::getType, type)
|
||||
.eq(SystemSettingDO::getItem, item);
|
||||
int effect = systemSettingDAO.update(update, wrapper);
|
||||
// 删除缓存
|
||||
RedisUtils.delete(SystemSettingKeyDefine.SETTING.format(type));
|
||||
// 设置日志参数
|
||||
OperatorLogs.add(OperatorLogs.TEXT, Strings.format(SystemSettingOperatorType.UPDATE_TEXT, type, item, value));
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePartialSystemSetting(SystemSettingUpdatePartialRequest request) {
|
||||
String type = request.getType();
|
||||
Map<String, Object> settings = request.getSettings();
|
||||
// 删除
|
||||
LambdaQueryWrapper<SystemSettingDO> deleteWrapper = systemSettingDAO.lambda()
|
||||
.eq(SystemSettingDO::getType, type)
|
||||
.in(SystemSettingDO::getItem, settings.keySet());
|
||||
systemSettingDAO.delete(deleteWrapper);
|
||||
// 插入
|
||||
List<SystemSettingDO> rows = settings.entrySet()
|
||||
.stream()
|
||||
.map(s -> SystemSettingDO.builder()
|
||||
.type(type)
|
||||
.item(s.getKey())
|
||||
.value(Refs.json(s.getValue()))
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
// 插入
|
||||
systemSettingDAO.insertBatch(rows);
|
||||
// 删除缓存
|
||||
RedisUtils.delete(SystemSettingKeyDefine.SETTING.format(type));
|
||||
// 设置日志参数
|
||||
OperatorLogs.add(OperatorLogs.TEXT, Strings.format(SystemSettingOperatorType.UPDATE_PARTIAL_TEXT, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getSystemSettingByType(String type) {
|
||||
SystemSettingTypeEnum settingType = SystemSettingTypeEnum.of(type);
|
||||
Valid.notNull(settingType, ErrorMessage.ERROR_TYPE);
|
||||
// 查询缓存
|
||||
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.getStrategy()
|
||||
.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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统 uuid
|
||||
*
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.orion.visor.module.infra.dao.SystemSettingDAO">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.orion.visor.module.infra.entity.domain.SystemSettingDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="item" property="item"/>
|
||||
<result column="value" property="value"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="creator" property="creator"/>
|
||||
<result column="updater" property="updater"/>
|
||||
<result column="deleted" property="deleted"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, type, item, value, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user