| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- // ___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 = {};
- testcfg = {};
- try {
- testcfg = JSON.parse(etcd.get("/api/test.json"));
- } catch(e) {}
- function teststoredfs() {
- // 输入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 (testcfg.stoedfs) {
- teststoredfs();
- }
- if (testcfg.checkfields) {
- eval(dfg.read("/script/matrix/utils/ajs/checkfields.js"));
- checkfields();
- }
- // 数据合法性检查
- 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;
|