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 dependent(&mut self) -> Vec<&'static str> {
vec!["file.file.get_path"]
}
fn params(&mut self) -> JsonValue {
let mut params = object! {};
params["file"] = br_fields::files::Files::new(true, "file", "文件").option(vec!["xlsx"]).field();
return params;
}
fn index(&mut self, header: JsonValue, _request: JsonValue) -> Response {
let file_path = match addon("file.file.add_runtime").get(header.clone(), object! {
files:request["file"].clone()
}) {
Ok(e) => e,
Err(e) => return self.fail(&*e.to_string())
};
if !Path::new(file_path.as_str().unwrap().clone()).is_file() {
return self.fail("获取文件失败");
}
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 data = br_excel::read::Read::export(file_url.as_str().unwrap().clone(), 0, 1, heads);
let mut data = data.members().map(|x| x.clone()).collect::<Vec<JsonValue>>();
data.retain(|item| {
if item["order_sn"].is_empty() {
false
} else {
true
}
});
/*业务处理*/
return self.success(data, "ok");
}
}