refactor: 重构数据额外配置.

This commit is contained in:
lijiahangmax
2023-12-21 01:20:57 +08:00
parent a365b8a955
commit 4bae5a35d6
28 changed files with 757 additions and 137 deletions

View File

@@ -0,0 +1,56 @@
package com.orion.ops.framework.common.handler.data;
import com.alibaba.fastjson.JSON;
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
import com.orion.ops.framework.common.handler.data.strategy.MapDataStrategy;
import com.orion.spring.SpringHolder;
/**
* 标准数据定义
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/12/21 0:07
*/
public interface GenericsDataDefinition {
/**
* 获取数据模型类型
*
* @return class
*/
Class<? extends GenericsDataModel> getType();
/**
* 获取数据处理策略
*
* @return class
*/
Class<? extends MapDataStrategy<? extends GenericsDataModel>> getStrategy();
/**
* 获取数据模型策略处理器
*
* @param <Model> Model
* @param <Strategy> Strategy
* @return StrategyBean
*/
@SuppressWarnings("unchecked")
default <Model extends GenericsDataModel, Strategy extends MapDataStrategy<Model>> Strategy getStrategyBean() {
return (Strategy) SpringHolder.getBean(this.getStrategy());
}
/**
* 反序列化对象
*
* @param json json
* @param <Model> Model
* @return object
*/
@SuppressWarnings("unchecked")
default <Model extends GenericsDataModel> Model parse(String json) {
return (Model) JSON.parseObject(json, this.getType());
}
}

View File

@@ -9,43 +9,60 @@ import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
* @version 1.0.0
* @since 2023/12/20 22:09
*/
public interface GenericsDataStrategy<Config extends GenericsDataModel, View> {
public interface GenericsDataStrategy<Model extends GenericsDataModel, View> {
/**
* 获取默认值
*
* @return 默认值
*/
Config getDefault();
Model getDefault();
/**
* 更新填充
*
* @param before 修改前配置
* @param after 修改后配置
* @param beforeModel 修改前配置
* @param afterModel 修改后配置
*/
void updateFill(Config before, Config after);
void updateFill(Model beforeModel, Model afterModel);
/**
* 预校验参数
*
* @param config config
* @param model model
*/
void preValidConfig(Config config);
void preValid(Model model);
/**
* 校验参数
*
* @param config config
* @param model model
*/
void validConfig(Config config);
void valid(Model model);
/**
* 执行完整验证链
* <p>
* preValid > updateFill > preValid
*
* @param beforeModel beforeModel
* @param afterModel afterModel
*/
default void doValidChain(Model beforeModel, Model afterModel) {
// 预校验参数
this.preValid(afterModel);
// 更新填充
this.updateFill(beforeModel, afterModel);
// 校验参数
this.valid(afterModel);
}
/**
* 转为视图配置
*
* @param config config
* @param model model
* @return 视图配置
*/
View toView(String config);
View toView(String model);
}

View File

@@ -1,5 +1,6 @@
package com.orion.ops.framework.common.handler.data.strategy;
import com.alibaba.fastjson.JSONObject;
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
import java.util.Map;
@@ -11,6 +12,11 @@ import java.util.Map;
* @version 1.0.0
* @since 2023/12/20 22:11
*/
public interface MapDataStrategy<Config extends GenericsDataModel> extends GenericsDataStrategy<Config, Map<String, Object>> {
public interface MapDataStrategy<Model extends GenericsDataModel> extends GenericsDataStrategy<Model, Map<String, Object>> {
@Override
default Map<String, Object> toView(String model) {
return JSONObject.parseObject(model);
}
}