🎨 优化策略定义逻辑.

This commit is contained in:
lijiahangmax
2024-12-29 13:11:09 +08:00
parent 6606d2ca76
commit 6b14c2ef9c
11 changed files with 57 additions and 32 deletions

View File

@@ -34,7 +34,7 @@ import org.dromara.visor.framework.common.handler.data.strategy.GenericsDataStra
* @since 2023/12/21 0:07
*/
@SuppressWarnings("unchecked")
public interface GenericsDataDefinition {
public interface GenericsStrategyDefinition {
/**
* 获取数据处理策略
@@ -54,12 +54,32 @@ public interface GenericsDataDefinition {
return (S) SpringHolder.getBean(this.getStrategyClass());
}
/**
* 获取默认值
*
* @param <M> model
* @return model
*/
default <M extends GenericsDataModel> M getDefault() {
return (M) this.getStrategy().getDefault();
}
/**
* 执行完整验证链
*
* @param beforeModel beforeModel
* @param afterModel afterModel
*/
default void doValid(GenericsDataModel beforeModel, GenericsDataModel afterModel) {
this.getStrategy().doValid(beforeModel, afterModel);
}
/**
* 反序列化对象
*
* @param serialModel serialModel
* @param <M> Model
* @return object
* @param <M> model
* @return model
*/
default <M extends GenericsDataModel> M parse(String serialModel) {
return (M) this.getStrategy().parse(serialModel);
@@ -69,14 +89,11 @@ public interface GenericsDataDefinition {
* 转为视图对象
*
* @param serialModel serialModel
* @param <M> Model
* @param <M> model
* @return viewModel
*/
default <M extends GenericsDataModel> M toView(String serialModel) {
GenericsDataStrategy<GenericsDataModel> strategy = this.getStrategy();
GenericsDataModel model = strategy.parse(serialModel);
strategy.toView(model);
return (M) model;
return (M) this.getStrategy().toView(serialModel);
}
}

View File

@@ -84,4 +84,13 @@ public abstract class AbstractGenericsDataStrategy<M extends GenericsDataModel>
public void toView(M model) {
}
@Override
public M toView(String serialModel) {
// 解析
M parse = this.parse(serialModel);
// 转为视图对象
this.toView(parse);
return parse;
}
}

View File

@@ -65,4 +65,12 @@ public interface GenericsDataStrategy<M extends GenericsDataModel> {
*/
void toView(M model);
/**
* 转为视图配置
*
* @param serialModel serialModel
* @return model
*/
M toView(String serialModel);
}