⚡ 优化标准数据模型.
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
package com.orion.visor.module.infra.handler.preference.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 偏好
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/8 13:54
|
||||
*/
|
||||
public interface PreferenceModel {
|
||||
|
||||
/**
|
||||
* 转为 map
|
||||
*
|
||||
* @return map
|
||||
*/
|
||||
default Map<String, String> toMap() {
|
||||
JSONObject map = JSON.parseObject(JSON.toJSONString(this));
|
||||
return Maps.map(map, Function.identity(), Refs::json);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.orion.visor.module.infra.handler.preference.strategy;
|
||||
|
||||
import com.orion.visor.module.infra.handler.preference.model.PreferenceModel;
|
||||
|
||||
/**
|
||||
* 偏好处理策略
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/8 13:49
|
||||
*/
|
||||
public interface IPreferenceStrategy<Model extends PreferenceModel> {
|
||||
|
||||
/**
|
||||
* 获取默认值
|
||||
*
|
||||
* @return 默认值
|
||||
*/
|
||||
Model getDefault();
|
||||
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.orion.visor.module.infra.enums;
|
||||
|
||||
import com.orion.spring.SpringHolder;
|
||||
import com.orion.visor.module.infra.handler.preference.model.PreferenceModel;
|
||||
import com.orion.visor.module.infra.handler.preference.strategy.IPreferenceStrategy;
|
||||
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.preference.strategy.SystemPreferenceStrategy;
|
||||
import com.orion.visor.module.infra.handler.preference.strategy.TerminalPreferenceStrategy;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
@@ -13,32 +15,28 @@ import lombok.Getter;
|
||||
* @since 2023/10/8 11:31
|
||||
*/
|
||||
@Getter
|
||||
public enum PreferenceTypeEnum {
|
||||
public enum PreferenceTypeEnum implements GenericsDataDefinition {
|
||||
|
||||
/**
|
||||
* 系统偏好
|
||||
*/
|
||||
SYSTEM("systemPreferenceStrategy"),
|
||||
SYSTEM(SystemPreferenceStrategy.class),
|
||||
|
||||
/**
|
||||
* 终端偏好
|
||||
*/
|
||||
TERMINAL("terminalPreferenceStrategy"),
|
||||
TERMINAL(TerminalPreferenceStrategy.class),
|
||||
|
||||
;
|
||||
|
||||
PreferenceTypeEnum(String beanName) {
|
||||
PreferenceTypeEnum(Class<? extends GenericsDataStrategy<? extends GenericsDataModel>> strategyClass) {
|
||||
this.type = this.name();
|
||||
this.beanName = beanName;
|
||||
this.strategyClass = strategyClass;
|
||||
}
|
||||
|
||||
private final String type;
|
||||
|
||||
/**
|
||||
* 策越 bean 名称
|
||||
* 可能跨模块所以不用 class
|
||||
*/
|
||||
private final String beanName;
|
||||
private final Class<? extends GenericsDataStrategy<? extends GenericsDataModel>> strategyClass;
|
||||
|
||||
public static PreferenceTypeEnum of(String type) {
|
||||
if (type == null) {
|
||||
@@ -52,15 +50,4 @@ public enum PreferenceTypeEnum {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取策略
|
||||
*
|
||||
* @param <M> model
|
||||
* @param <T> type
|
||||
* @return IPreferenceStrategy
|
||||
*/
|
||||
public <M extends PreferenceModel, T extends IPreferenceStrategy<M>> T getStrategy() {
|
||||
return SpringHolder.getBean(beanName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.visor.module.infra.handler.preference.model;
|
||||
|
||||
import com.orion.visor.framework.common.handler.data.model.GenericsDataModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -16,7 +17,7 @@ import lombok.NoArgsConstructor;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SystemPreferenceModel implements PreferenceModel {
|
||||
public class SystemPreferenceModel implements GenericsDataModel {
|
||||
|
||||
/**
|
||||
* 是否使用侧边菜单
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.orion.visor.module.infra.handler.preference.model;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orion.lang.able.IJsonObject;
|
||||
import com.orion.visor.framework.common.handler.data.model.GenericsDataModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -20,7 +21,7 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TerminalPreferenceModel implements PreferenceModel {
|
||||
public class TerminalPreferenceModel implements GenericsDataModel {
|
||||
|
||||
/**
|
||||
* 新建连接类型
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.visor.module.infra.handler.preference.strategy;
|
||||
|
||||
import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.visor.framework.common.handler.data.strategy.AbstractGenericsDataStrategy;
|
||||
import com.orion.visor.module.infra.handler.preference.model.SystemPreferenceModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -10,8 +12,12 @@ import org.springframework.stereotype.Component;
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/8 13:48
|
||||
*/
|
||||
@Component("systemPreferenceStrategy")
|
||||
public class SystemPreferenceStrategy implements IPreferenceStrategy<SystemPreferenceModel> {
|
||||
@Component
|
||||
public class SystemPreferenceStrategy extends AbstractGenericsDataStrategy<SystemPreferenceModel> {
|
||||
|
||||
public SystemPreferenceStrategy() {
|
||||
super(SystemPreferenceModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemPreferenceModel getDefault() {
|
||||
@@ -28,4 +34,9 @@ public class SystemPreferenceStrategy implements IPreferenceStrategy<SystemPrefe
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemPreferenceModel parse(String serialModel) {
|
||||
throw Exceptions.unsupported();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.orion.visor.module.infra.handler.preference.strategy;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.net.host.ssh.TerminalType;
|
||||
import com.orion.visor.framework.common.handler.data.strategy.AbstractGenericsDataStrategy;
|
||||
import com.orion.visor.module.infra.handler.preference.model.TerminalPreferenceModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -13,8 +15,12 @@ import org.springframework.stereotype.Component;
|
||||
* @version 1.0.0
|
||||
* @since 2023/12/8 14:46
|
||||
*/
|
||||
@Component("terminalPreferenceStrategy")
|
||||
public class TerminalPreferenceStrategy implements IPreferenceStrategy<TerminalPreferenceModel> {
|
||||
@Component
|
||||
public class TerminalPreferenceStrategy extends AbstractGenericsDataStrategy<TerminalPreferenceModel> {
|
||||
|
||||
public TerminalPreferenceStrategy() {
|
||||
super(TerminalPreferenceModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalPreferenceModel getDefault() {
|
||||
@@ -24,7 +30,7 @@ public class TerminalPreferenceStrategy implements IPreferenceStrategy<TerminalP
|
||||
.fontFamily("_")
|
||||
.fontSize(13)
|
||||
.lineHeight(1.12)
|
||||
.letterSpacing(1)
|
||||
.letterSpacing(0)
|
||||
.fontWeight("normal")
|
||||
.fontWeightBold("bold")
|
||||
.cursorStyle("bar")
|
||||
@@ -100,7 +106,7 @@ public class TerminalPreferenceStrategy implements IPreferenceStrategy<TerminalP
|
||||
.selectAll(false)
|
||||
.search(true)
|
||||
.copy(true)
|
||||
.paste(false)
|
||||
.paste(true)
|
||||
.interrupt(false)
|
||||
.enter(false)
|
||||
.fontSizePlus(false)
|
||||
@@ -118,7 +124,7 @@ public class TerminalPreferenceStrategy implements IPreferenceStrategy<TerminalP
|
||||
.theme(new JSONObject())
|
||||
.displaySetting(JSONObject.parseObject(defaultDisplaySetting))
|
||||
.actionBarSetting(JSONObject.parseObject(actionBarSetting))
|
||||
.rightMenuSetting(Lists.of("selectAll", "copy", "fontSizePlus", "fontSizeSubtract", "search", "clear"))
|
||||
.rightMenuSetting(Lists.of("selectAll", "copy", "paste", "fontSizePlus", "fontSizeSubtract", "search", "clear"))
|
||||
.interactSetting(JSONObject.parseObject(defaultInteractSetting))
|
||||
.pluginsSetting(JSONObject.parseObject(defaultPluginsSetting))
|
||||
.sessionSetting(JSONObject.parseObject(defaultSessionSetting))
|
||||
@@ -126,4 +132,9 @@ public class TerminalPreferenceStrategy implements IPreferenceStrategy<TerminalP
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalPreferenceModel parse(String serialModel) {
|
||||
throw Exceptions.unsupported();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -142,14 +142,14 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
public Map<String, Object> getDefaultPreferenceByType(String type, List<String> items) {
|
||||
PreferenceTypeEnum preferenceType = Valid.valid(PreferenceTypeEnum::of, type);
|
||||
// 获取默认值
|
||||
Map<String, String> defaultModel = preferenceType.getStrategy()
|
||||
Map<String, Object> defaultModel = preferenceType.getStrategy()
|
||||
.getDefault()
|
||||
.toMap();
|
||||
Map<String, Object> result = Maps.newMap();
|
||||
if (Lists.isEmpty(items)) {
|
||||
defaultModel.forEach((k, v) -> result.put(k, Refs.unref(defaultModel.get(k))));
|
||||
defaultModel.forEach((k, v) -> result.put(k, defaultModel.get(k)));
|
||||
} else {
|
||||
items.forEach(s -> result.put(s, Refs.unref(defaultModel.get(s))));
|
||||
items.forEach(s -> result.put(s, defaultModel.get(s)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -218,9 +218,10 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
// 初始化
|
||||
if (Maps.isEmpty(config)) {
|
||||
// 获取默认值
|
||||
config = type.getStrategy()
|
||||
Map<String, Object> defaultConfig = type.getStrategy()
|
||||
.getDefault()
|
||||
.toMap();
|
||||
config = Maps.map(defaultConfig, Function.identity(), Refs::json);
|
||||
// 插入默认值
|
||||
List<PreferenceDO> entities = config
|
||||
.entrySet()
|
||||
|
||||
Reference in New Issue
Block a user