| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 | 
							
- //默认值设置
 
- defaultinput = {
 
-     server: "http://172.23.12.228:8080",
 
-     author: base64.encode("meta.admin:admin"),
 
-     istesting: true,
 
-     classname: "/cncc/action/test",
 
-     data: null,
 
-     datafiledir: "/opt/cncc/ITIL/change_main",
 
-     datafilename: "",
 
-     jsfilename: "/script/cncc/ITIL/测试.js",
 
-     clsoption: "with ttl=10 day, version=true, nickname='test'",
 
-     fieldmap: {id: "jid"},
 
-     fields: {idUnique: "string,key"},
 
-     mustfield: "id,idUnique",
 
- };
 
- inputmapping = {
 
-     "change": {
 
-         classname: "/cncc/action/change_main",
 
-         datafiledir: "/opt/cncc/ITIL/change_main",
 
-         jsfilename: "/script/cncc/ITIL/变更单.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='change_main'",
 
-     },
 
-     "event": {
 
-         classname: "/cncc/action/event",
 
-         datafiledir: "/opt/cncc/ITIL/event",
 
-         jsfilename: "/script/cncc/ITIL/事件单.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='event'",
 
-     },
 
-     "problem": {
 
-         classname: "/cncc/action/problem",
 
-         datafiledir: "/opt/cncc/ITIL/problem",
 
-         jsfilename: "/script/cncc/ITIL/问题单.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='problem'",
 
-     },
 
-     "baobei": {
 
-         classname: "/cncc/action/baobei",
 
-         datafiledir: "/opt/cncc/ITIL/baobei",
 
-         jsfilename: "/script/cncc/ITIL/报备.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='baobei'",
 
-     },
 
-     "shebeishangxiadian": {
 
-         classname: "/cncc/action/shebeishangxiadian",
 
-         datafiledir: "/opt/cncc/ITIL/shebeishangxiadian",
 
-         jsfilename: "/script/cncc/ITIL/设备上下电.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='shebeishangxiadian'",
 
-     },
 
-     "shujuhuoqu": {
 
-         classname: "/cncc/action/shujuhuoqu",
 
-         datafiledir: "/opt/cncc/ITIL/shujuhuoqu",
 
-         jsfilename: "/script/cncc/ITIL/数据获取.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='shujuhuoqu'",
 
-     },
 
-     "yanlian": {
 
-         classname: "/cncc/action/yanlian",
 
-         datafiledir: "/opt/cncc/ITIL/yanlian",
 
-         jsfilename: "/script/cncc/ITIL/应急演练.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='yanlian'",
 
-     },
 
-     "project": {
 
-         classname: "/cncc/action/project",
 
-         datafiledir: "/opt/cncc/ITIL/project",
 
-         jsfilename: "/script/cncc/ITIL/项目实施或巡检.js",
 
-         clsoption: "with ttl=10 day, version=true, nickname='project'",
 
-     }
 
- };
 
- // 输入输出参数格式化
 
- input = INPUT;
 
- output = {};
 
- try {
 
-     input = decodeURIComponent(input);
 
- } catch(e) {}
 
- try {
 
-     input = base64.decode(input);
 
- } catch(e) {}
 
- try {
 
-     input = JSON.parse(input);
 
-     input = JSON.parse(input);
 
- } catch(e) {}
 
- // 通用函数
 
- function isempty(o) {
 
-     if (o) {
 
-         for (var k in o){
 
-             return false;
 
-         }
 
-     } 
 
-     return true;
 
- }
 
- // 主执行阶段
 
- function main() {
 
-     output.info = {};
 
-     output.info.p0 = {name: "确认参数"};
 
-     p = inputmapping[input.name];
 
-     if (p) {
 
-         for (var k in p) {
 
-             defaultinput[k] = p[k];
 
-         }
 
-     }
 
-     server = input.server;
 
-     if (!server) {
 
-         server = defaultinput.server;
 
-     }
 
-     author = input.author;
 
-     if (!author) {
 
-         author = defaultinput.author;
 
-     }
 
-     istesting = input.istesting;
 
-     if (!istesting) {
 
-         istesting = defaultinput.istesting;
 
-     }
 
-     classname = input.classname;
 
-     if (!classname) {
 
-         classname = defaultinput.classname;
 
-     }
 
-     if (classname[0] != "/") {
 
-         throw ("classname必须以 / 开头");
 
-     }
 
-     if (classname.substring(0,8) == "/matrix/") {
 
-         throw ("classname不能以 /matrix/ 开头");
 
-     }
 
-     data = input.data;
 
-     if (isempty(data)) {
 
-         data = defaultinput.data;
 
-         if (isempty(data)) {
 
-             datafilename = input.datafilename;
 
-             if (!datafilename) {
 
-                 datafilename = defaultinput.datafilename;
 
-             }
 
-             if (datafilename) {
 
-                 try {
 
-                     data = dfs.read(datafilename);
 
-                     data = JSON.parse(data);
 
-                 } catch(e) {}
 
-             }
 
-         }
 
-         if (isempty(data)) {
 
-             datafiledir = input.datafiledir;
 
-             if (!datafiledir) {
 
-                 if (classname == defaultinput.classname) {
 
-                     datafiledir = defaultinput.datafiledir;
 
-                 } else {
 
-                     datafiledir = "/opt" + classname;
 
-                 }
 
-             }
 
-             // 读取所有文件,综合数据
 
-             data = {};
 
-             files = dfs.readdir(datafiledir);
 
-             for (i = 0; i < files.length; i++) { 
 
-                 try {
 
-                     adat = dfs.read(files[i].fullname);
 
-                     adat = JSON.parse(adat);
 
-                     if (typeof(adat) != "object") {
 
-                         throw("只接收JSON对象数据");
 
-                     }
 
-                     for (var k in adat) {
 
-                         if (!data[k]) {
 
-                             data[k] = adat[k];
 
-                         } else if (adat[k]) {
 
-                             if (typeof(adat[k]) == "object") {
 
-                                 if (JSON.stringify(adat[k]).length > JSON.stringify(data[k]).length) {
 
-                                     data[k] = adat[k];
 
-                                 }
 
-                             } else if (typeof(adat[k]) == "string") {
 
-                                 if (typeof(data[k]) != "string") {
 
-                                     data[k] = adat[k];
 
-                                 } else if (adat[k].length > data[k].length) {
 
-                                     data[k] = adat[k];
 
-                                 }
 
-                             } else if (typeof(adat[k]) == "number") {
 
-                                 if (typeof(data[k]) == "number") {
 
-                                     if ((""+adat[k]).indexOf(".")>=0) {
 
-                                         data[k] = adat[k];
 
-                                     }
 
-                                 }
 
-                             } else if (typeof(adat[k]) == "boolean") {
 
-                                 if (typeof(data[k]) != "boolean") {
 
-                                     data[k] = ""+adat[k];
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 } catch(e) {}
 
-             }
 
-         }
 
-     }
 
-     jsfilename = input.jsfilename;
 
-     if (!jsfilename) {
 
-         jsfilename = defaultinput.jsfilename;
 
-     }
 
-     clsoption = input.clsoption;
 
-     if (!clsoption) {
 
-         clsoption = defaultinput.clsoption;
 
-     }
 
-     fieldmap = input.fieldmap;
 
-     if (!fieldmap) {
 
-         fieldmap = defaultinput.fieldmap;
 
-     }
 
-     mustfield = input.mustfield;
 
-     if (!mustfield) {
 
-         mustfield = defaultinput.mustfield;
 
-     }
 
-     fields = input.fields;
 
-     if (!fields) {
 
-         fields = defaultinput.fields;
 
-     }
 
-     reqinput = {
 
-         istesting: istesting,
 
-         classname: classname, 
 
-         jsfilename: jsfilename,
 
-         clsoption: clsoption, 
 
-         fieldmap: fieldmap,
 
-         fields: fields,
 
-         mustfield: mustfield,
 
-         data: data,
 
-     };
 
-     reqinput = encodeURIComponent(JSON.stringify(reqinput));
 
-     output.info.p1 = {name:"生成类"};
 
-     http.do("POST", 
 
-         server+"/script/exec/js?filepath=/matrix/utils/AlterClassByJson.js",
 
-         {
 
-             "Authorization": "Basic "+author,
 
-             "Content-Type": "application/x-www-form-urlencoded",
 
-             "Data-Type": "json"
 
-         },
 
-         'input='+reqinput,
 
-         function(response){
 
-             // success func
 
-             ret = response.data;
 
-             if (ret.message) {
 
-                 output.info.p1.result = ret.message;
 
-             } else {
 
-                 output.info.p1.result = ret;
 
-             }
 
-         },
 
-         function(response){
 
-             // error func
 
-             output.error = response.data;
 
-         });
 
-     if (output.error || output.info.p1.result.error) {
 
-         return;
 
-     }
 
-     output.info.p2 = {name:"生成脚本"};
 
-     http.do("POST", 
 
-         server+"/script/exec/js?filepath=/matrix/utils/JsonImporterGen.js&input="+reqinput,
 
-         {"Authorization": "Basic "+author},
 
-         '',
 
-         function(response){
 
-             // success func
 
-             ret = response.data;
 
-             if (ret.message) {
 
-                 output.info.p2.result = ret.message;
 
-             } else {
 
-                 output.info.p2.result = ret;
 
-             }
 
-         },
 
-         function(response){
 
-             // error func
 
-             output.error = response.data;
 
-         });
 
-     if (output.error || output.info.p2.result.error) {
 
-         return;
 
-     }
 
-     output.info.p2x = {name:"激活脚本"};
 
-     calljsfp = encodeURIComponent(jsfilename.replace(/\/script/, ""));
 
-     http.do("POST", 
 
-         server+"/fs/tolocal/script"+calljsfp+"?issys=true",
 
-         {"Authorization": "Basic "+author},
 
-         '',
 
-         function(response){
 
-             // success func
 
-             ret = response.data;
 
-             if (ret.message) {
 
-                 output.info.p2x.result = ret.message;
 
-             } else {
 
-                 output.info.p2x.result = ret;
 
-             }
 
-         },
 
-         function(response){
 
-             // error func
 
-             output.error = response.data;
 
-         });
 
-     if (output.error || output.info.p2x.result.error) {
 
-         return;
 
-     }
 
-     output.info.p3 = {name:"插入数据"};
 
-     reqinput = encodeURIComponent(base64.encode(JSON.stringify(data)));
 
-     calljsfp = encodeURIComponent(jsfilename.replace(/\/script/, ""));
 
-     http.do("POST", 
 
-         server+"/script/exec/js?filepath="+calljsfp+"&input="+reqinput,
 
-         {"Authorization": "Basic "+author},
 
-         '',
 
-         function(response){
 
-             // success func
 
-             ret = response.data;
 
-             if (ret.message) {
 
-                 output.info.p3.result = ret.message;
 
-             } else {
 
-                 output.info.p3.result = ret;
 
-             }
 
-         },
 
-         function(response){
 
-             // error func
 
-             output.error = response.data;
 
-         });
 
-     if (output.error || output.info.p3.result.error) {
 
-         return;
 
-     }
 
-     output.info.p4 = {name:"完成"};
 
- }
 
- try {
 
-     main();
 
- } catch(e) {
 
-     if (typeof(e) == "object") {
 
-         output.error = e;
 
-     } else if (typeof(e) == "string") {
 
-         output.error = "错误:" + e;
 
-     } else {
 
-         output.error = JSON.stringify(e);
 
-     }
 
- }
 
- // 返回输出信息
 
- OUTPUT = output;
 
 
  |