br-addon 0.2.20

This is an addon
Documentation
use json::{array, JsonValue, object};
use crate::plugin::{{plugin}}::{{model_a}}::{{model}};
use br_addon::Response;
use br_addon::action::Action;
use br_excel::Head;

pub struct {{action}} {
    pub module: {{model}},
}

impl Action for {{action}} {

    fn title(&mut self) -> &'static str { "{{title}}" }
      fn params(&mut self) -> JsonValue {
            let mut params = object! {};
            params
        }
            fn interface_type(&self) -> InterfaceType {
                InterfaceType::BTN
            }
    fn index(&mut self,request: Request) -> ApiResponse {
          let temp_dir = env::temp_dir();
                match fs::create_dir_all(&temp_dir) {
                    Ok(_) => (),
                    Err(_) => return ApiResponse::fail(800007, "创建临时下载地址失败")
                }

               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 binding = temp_dir.join("商户类别模板.xlsx");
                       let filename = binding.to_str().unwrap();
                       let mut excel = br_excel::write::Write::new(filename);
                       excel.set_page(1, "商户类别", heads, array![]);
                       match excel.save() {
                           true => ApiResponse::download(filename),
                           false => ApiResponse::fail(800006, "下载失败")
                       }
        }
    }
}