//#import excel.js
//#import $owl_download_template:services/modelService.jsx

function main() {
    var params = JSON.parse($body);

    var id = "owl_download_template_user_batch_export_by_userid";
    var jDownloadTemplate = owl_download_templateService.get(id);
    var fileUrl = "";
    if (!jDownloadTemplate) {
        var index = 0;
        var titles = [
            {"index": index++, "columnWidth": "30", "field": "userId", "title": "会员ID"}
        ];
        var recordList = [
            {
                userId: "owl_mall_u_50000"
            }
        ];

        var file_type_name = "根据会员ID导出消费信息模板";

        fileUrl = Excel.createExcelList(file_type_name, titles, recordList);

        jDownloadTemplate = {};
        jDownloadTemplate.file_type_id = "user_batch_export_by_userid";
        jDownloadTemplate.file_type_name = file_type_name;
        jDownloadTemplate.file = {url: fileUrl, name: file_type_name};
        owl_download_templateService.add(jDownloadTemplate);
    } else {
        fileUrl = jDownloadTemplate.file.url;
    }

    var ret = {
        state: 'ok',
        action: 'navigate',
        target: "_blank",
        url: fileUrl
    }
    out.print(JSON.stringify(ret));

}

main();
