pub struct Executor<T> { /* private fields */ }Expand description
一个行模型的通用执行器:预览 / 导入 / 导出 / 模板的统一入口
所有方法都基于模型自带的列定义与表名自动构造 runner,
需要微调时再通过 Executor::import_runner / Executor::export_runner 拿到
可配置的 runner(默认值已经可用,一般不需要)。
Implementations§
Source§impl<T: ExcelRow> Executor<T>
impl<T: ExcelRow> Executor<T>
Sourcepub fn new(name: &'static str, sheet: Option<&'static str>) -> Self
pub fn new(name: &'static str, sheet: Option<&'static str>) -> Self
手动构造(未注册模型也能用;注册模型请用 executor_for)
pub fn name(&self) -> &'static str
pub fn type_name(&self) -> &'static str
pub fn sheet_name(&self) -> Option<&'static str>
pub fn columns(&self) -> &[ColumnDef]
Sourcepub fn import_runner(&self) -> ImportRunner
pub fn import_runner(&self) -> ImportRunner
导入 runner(默认 sheets:单模型 = 按 sheet 名,多模型 = All)
会自动套用 executor_config! 注册的模型级配置(合并 / 计算列 / 批大小…)。
Sourcepub fn export_runner(&self) -> ExportRunner
pub fn export_runner(&self) -> ExportRunner
导出 runner(列宽 / 格式 / 图片行高来自列定义;并套用模型级导出配置)
Sourcepub fn export_runner_for(&self, sheet_name: impl Into<String>) -> ExportRunner
pub fn export_runner_for(&self, sheet_name: impl Into<String>) -> ExportRunner
导出 runner(显式指定工作表名)
Sourcepub fn template(&self) -> TemplateSpec
pub fn template(&self) -> TemplateSpec
导入模板(填入示例行 / 引用列表后交给 build_template)
Source§impl<T: ExcelRow> Executor<T>
impl<T: ExcelRow> Executor<T>
Sourcepub fn preview(
&self,
source: ZipSource,
limit: usize,
) -> Result<ImportPreview<T>>where
T: Serialize,
pub fn preview(
&self,
source: ZipSource,
limit: usize,
) -> Result<ImportPreview<T>>where
T: Serialize,
校验预览(不落库,只读前 limit 行)
Sourcepub fn preview_json(&self, source: ZipSource, limit: usize) -> Result<Value>where
T: Serialize,
pub fn preview_json(&self, source: ZipSource, limit: usize) -> Result<Value>where
T: Serialize,
预览转 JSON(按名调度 / HTTP 响应直接返回用)
Sourcepub async fn commit<S>(
&self,
source: ZipSource,
sink: Arc<S>,
) -> Result<ImportReport>
pub async fn commit<S>( &self, source: ZipSource, sink: Arc<S>, ) -> Result<ImportReport>
正式导入:流式解析 + 分批落库(解析在阻塞线程,落库走异步任务)
Sourcepub fn for_each_row<F>(
&self,
source: ZipSource,
on_row: F,
) -> Result<ImportReport>
pub fn for_each_row<F>( &self, source: ZipSource, on_row: F, ) -> Result<ImportReport>
只解析 + 自定义逐行处理(同步处理,不落库、不攒批)
Sourcepub fn export_sheets<P: AsRef<Path>>(
&self,
path: P,
named_rows: Vec<(String, Vec<T>)>,
) -> Result<ExportStats>
pub fn export_sheets<P: AsRef<Path>>( &self, path: P, named_rows: Vec<(String, Vec<T>)>, ) -> Result<ExportStats>
小数据量:一个文件多张工作表(每张独立数据)
Sourcepub async fn export_xlsx<P, F, Fut>(
&self,
path: P,
fetch: F,
) -> Result<ExportStats>
pub async fn export_xlsx<P, F, Fut>( &self, path: P, fetch: F, ) -> Result<ExportStats>
游标分批拉取 + 流式写文件(百万行导出推荐)
Trait Implementations§
Source§impl<T> ErasedExecutor for Executor<T>
impl<T> ErasedExecutor for Executor<T>
fn name(&self) -> &'static str
fn type_name(&self) -> &'static str
Source§fn commit_json<'life0, 'async_trait>(
&'life0 self,
source: ZipSource,
sink: Arc<dyn JsonBatchSink>,
) -> Pin<Box<dyn Future<Output = Result<ImportReport>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn commit_json<'life0, 'async_trait>(
&'life0 self,
source: ZipSource,
sink: Arc<dyn JsonBatchSink>,
) -> Pin<Box<dyn Future<Output = Result<ImportReport>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
按名导入:解析 source,把每批模型转成 JSON 交给
sinkSource§fn template(&self) -> TemplateSpec
fn template(&self) -> TemplateSpec
按名生成导入模板
Auto Trait Implementations§
impl<T> Freeze for Executor<T>
impl<T> RefUnwindSafe for Executor<T>
impl<T> Send for Executor<T>
impl<T> Sync for Executor<T>
impl<T> Unpin for Executor<T>
impl<T> UnsafeUnpin for Executor<T>
impl<T> UnwindSafe for Executor<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more