refactor: 重构服务依赖注入和上下文管理
移除硬编码的服务注入,改为使用缓存机制动态获取Bean 优化上下文类结构,统一服务获取方式 添加PageContent类支持分页数据封装 实现异步数据加载功能
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.data.domain.Sort;
|
||||
import com.ecep.contract.controller.table.EditableEntityTableTabSkin;
|
||||
import com.ecep.contract.controller.table.TableTabSkin;
|
||||
import com.ecep.contract.model.IdentityEntity;
|
||||
import com.ecep.contract.service.QueryService;
|
||||
import com.ecep.contract.service.ViewModelService;
|
||||
import com.ecep.contract.util.TableViewUtils;
|
||||
import com.ecep.contract.util.UITools;
|
||||
@@ -419,17 +420,14 @@ public abstract class AbstEntityManagerSkin<T extends IdentityEntity, TV extends
|
||||
dataSet.clear();
|
||||
runAsync(() -> {
|
||||
controller.setStatus("载入中...");
|
||||
// 异步加载数据
|
||||
if (getViewModelService() instanceof QueryService<T, TV> queryService) {
|
||||
asyncLoadTableData(queryService, future);
|
||||
return;
|
||||
}
|
||||
// 同步加载方法
|
||||
List<TV> models = loadTableData();
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
updateTableDataSet(models);
|
||||
allowResize = true; // 恢复调整
|
||||
future.complete(null);
|
||||
} catch (Exception e) {
|
||||
allowResize = true; // 恢复调整
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
_updateModels(models, future);
|
||||
}).exceptionally(ex -> {
|
||||
future.completeExceptionally(ex);
|
||||
return null;
|
||||
@@ -438,6 +436,20 @@ public abstract class AbstEntityManagerSkin<T extends IdentityEntity, TV extends
|
||||
return future;
|
||||
}
|
||||
|
||||
|
||||
private void _updateModels(List<TV> models, CompletableFuture<Void> future) {
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
updateTableDataSet(models);
|
||||
allowResize = true; // 恢复调整
|
||||
future.complete(null);
|
||||
} catch (Exception e) {
|
||||
allowResize = true; // 恢复调整
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表格数据
|
||||
*
|
||||
@@ -489,6 +501,25 @@ public abstract class AbstEntityManagerSkin<T extends IdentityEntity, TV extends
|
||||
return page.map(service::from).toList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 异步加载表格数据
|
||||
*
|
||||
* @param queryService
|
||||
* @param future
|
||||
*/
|
||||
private void asyncLoadTableData(QueryService<T, TV> queryService, CompletableFuture<Void> future) {
|
||||
queryService.asyncFindAll(getSpecification(), getPageable()).whenComplete((result, ex) -> {
|
||||
if (ex != null) {
|
||||
future.completeExceptionally(ex);
|
||||
return;
|
||||
}
|
||||
updateFooter(result);
|
||||
List<TV> models = result.map(getViewModelService()::from).toList();
|
||||
_updateModels(models, future);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ViewModelService
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user