123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // ___classname___ JSON数据导入程序
- // ___datetime_now___ 由 JsonImportGen.js 自动生成,请勿手动修改
-
- // 输入输出参数格式化
- input = INPUT;
- try {
- input = decodeURIComponent(input);
- } catch(e) {}
- try {
- input = base64.decode(input);
- } catch(e) {}
- try {
- input = JSON.parse(input);
- input = JSON.parse(input);
- } catch(e) {}
- output = {};
- istesting = ___istesting___;
- function teststore() {
- // 输入JSON临时存入DFS
- dir = "/opt___classname___";
- dtm = new Date().toJSON().replace(/[\-\:\.TZ ]/mg, "");
- fn = dir + "/" + dtm;
- if (input.id) {
- fn += "." + input.id;
- } else {
- fn += "_" + _.random(0, 1000000);
- }
- fn += ".json";
- dfs.write(fn, JSON.stringify(input, " ", 4));
- output.filename = fn;
- // 刪除旧交件
- files = dfs.readdir(dir);
- dt = Date.now() - 1000 * 3600 * 24 * 10;
- for (i = 0; i < files.length; i++) {
- if (files[i].mtime < dt) {
- dfs.remove(files[i].fullname);
- }
- }
- // 留最后10个
- files.sort(function(a,b){ return a.mtime-b.mtime; });
- for (i = 0; i < files.length-10; i++) {
- dfs.remove(files[i].fullname);
- }
- }
- // 主执行阶段
- try {
- if (istesting) {
- teststore();
- }
- // 数据合法性检查
- if (___datacheck___) {}
- // mql定义
- mql = `___mql___`;
- // 执行mql
- ret = odb.mql(mql, ___values___);
- // 打印完成信息
- output.info=___datainfo___;
- log.info(output.info);
- } catch(e) {
- if (typeof(e) == "object") {
- output.error = e;
- } else if (typeof(e) == "string") {
- output.error = "插库错误:" + e;
- } else {
- output.error = JSON.stringify(e);
- }
- log.error(output.error);
- }
- // 返回输出信息
- OUTPUT = output;
|