use json::{array, JsonValue, object};
use crate::plugin::{{plugin}}::{{model_a}}::{{model}};
use br_plugin::Response;
use br_plugin::action::Action;
use br_excel::Head;
pub struct {{action}} {
pub model: {{model}},
}
impl Action for {{action}} {
fn author(&mut self) -> &'static str {""}
fn title(&mut self) -> &'static str { "{{title}}" }
fn api(&mut self) -> &'static str { "{{api}}" }
fn index(&mut self, header: JsonValue, _request: JsonValue) -> Response {
let temp_dir = format!("{}/temp", header["runtime"]);
br_file::create_dir(temp_dir.as_str());
let heads = vec![
Head::new("sn", "入库单号", "", 0),
Head::new("order_sn", "业务单号", "", 0),
Head::new("name", "名称", "", 0),
Head::new("barcode", "条码", "", 0),
Head::new("code", "货号", "", 0),
Head::new("number", "数量", "", 0),
];
let filename = format!("{}/{}", temp_dir, "{{api}}.xlsx");
let mut excel = br_excel::write::Write::new(&*filename);
excel.set_page(1, "表", heads, array![]);
match excel.save() {
true => {
return self.download(&*filename);
}
false => {
return self.fail("下载失败");
}
}
}
}