|
@@ -5,60 +5,60 @@ defaultinput = {
|
|
|
clsoption: "with ttl=10 day, version=true, nickname='test'",
|
|
|
data: null,
|
|
|
datafilename: "",
|
|
|
- datafiledir: "/opt/cncc/ITIL/change_main",
|
|
|
- jsfilename: "/script/cncc/ITIL/测试.js",
|
|
|
- fieldmap: {id: "jid"},
|
|
|
- fields: {idUnique: "string,key"},
|
|
|
+ datafiledir: "/opt/cncc/data/test",
|
|
|
+ jsfilename: "/script/cncc/api/测试.js",
|
|
|
+ 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'",
|
|
|
+ classname: "/cncc/action/v2_change_main",
|
|
|
+ datafiledir: "/opt/cncc/action/change_main",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_变更单.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_change_main'",
|
|
|
},
|
|
|
"event": {
|
|
|
- classname: "/cncc/action/event",
|
|
|
+ classname: "/cncc/action/v2_event",
|
|
|
datafiledir: "/opt/cncc/ITIL/event",
|
|
|
- jsfilename: "/script/cncc/ITIL/事件单.js",
|
|
|
- clsoption: "with ttl=10 day, version=true, nickname='event'",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_事件单.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_event'",
|
|
|
},
|
|
|
"problem": {
|
|
|
- classname: "/cncc/action/problem",
|
|
|
+ classname: "/cncc/action/v2_problem",
|
|
|
datafiledir: "/opt/cncc/ITIL/problem",
|
|
|
- jsfilename: "/script/cncc/ITIL/问题单.js",
|
|
|
- clsoption: "with ttl=10 day, version=true, nickname='problem'",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_问题单.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_problem'",
|
|
|
},
|
|
|
"report": {
|
|
|
- classname: "/cncc/action/report",
|
|
|
+ classname: "/cncc/action/v2_report",
|
|
|
datafiledir: "/opt/cncc/ITIL/report",
|
|
|
- jsfilename: "/script/cncc/ITIL/报备.js",
|
|
|
- clsoption: "with ttl=10 day, version=true, nickname='report'",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_报备.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_report'",
|
|
|
},
|
|
|
"device_power_on_off": {
|
|
|
- classname: "/cncc/action/device_power_on_off",
|
|
|
+ classname: "/cncc/action/v2_device_power_on_off",
|
|
|
datafiledir: "/opt/cncc/ITIL/device_power_on_off",
|
|
|
- jsfilename: "/script/cncc/ITIL/设备上下电.js",
|
|
|
- clsoption: "with ttl=10 day, version=true, nickname='device_power_on_off'",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_设备上下电.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_device_power_on_off'",
|
|
|
},
|
|
|
"data_collect": {
|
|
|
- classname: "/cncc/action/data_collect",
|
|
|
+ classname: "/cncc/action/v2_data_collect",
|
|
|
datafiledir: "/opt/cncc/ITIL/data_collect",
|
|
|
- jsfilename: "/script/cncc/ITIL/数据获取.js",
|
|
|
- clsoption: "with ttl=10 day, version=true, nickname='data_collect'",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_数据获取.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_data_collect'",
|
|
|
},
|
|
|
"drill": {
|
|
|
- classname: "/cncc/action/drill",
|
|
|
+ classname: "/cncc/action/v2_drill",
|
|
|
datafiledir: "/opt/cncc/ITIL/drill",
|
|
|
- jsfilename: "/script/cncc/ITIL/应急演练.js",
|
|
|
- clsoption: "with ttl=10 day, version=true, nickname='drill'",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_应急演练.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_drill'",
|
|
|
},
|
|
|
"implement": {
|
|
|
- classname: "/cncc/action/implement",
|
|
|
+ classname: "/cncc/action/v2_implement",
|
|
|
datafiledir: "/opt/cncc/ITIL/implement",
|
|
|
- jsfilename: "/script/cncc/ITIL/项目实施或巡检.js",
|
|
|
- clsoption: "with ttl=10 day, version=true, nickname='implement'",
|
|
|
+ jsfilename: "/script/cncc/ITIL/v2_项目实施或巡检.js",
|
|
|
+ clsoption: "with ttl=10 day, version=true, nickname='v2_implement'",
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -67,29 +67,32 @@ input = INPUT;
|
|
|
output = {};
|
|
|
try {
|
|
|
input = decodeURIComponent(input);
|
|
|
-} catch(e) {}
|
|
|
+} catch (e) { }
|
|
|
try {
|
|
|
input = base64.decode(input);
|
|
|
-} catch(e) {}
|
|
|
+} catch (e) { }
|
|
|
try {
|
|
|
input = JSON.parse(input);
|
|
|
input = JSON.parse(input);
|
|
|
-} catch(e) {}
|
|
|
+} catch (e) { }
|
|
|
|
|
|
// 通用函数
|
|
|
function isempty(o) {
|
|
|
if (o) {
|
|
|
- for (var k in o){
|
|
|
+ for (var k in o) {
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-// 主执行阶段
|
|
|
+// 引用函数库
|
|
|
+eval(dfs.read("/script/matrix/utils/ajs/JsonImporterFuncs.js"));
|
|
|
+
|
|
|
+// 定义主程序
|
|
|
function main() {
|
|
|
output.info = {};
|
|
|
- output.info.p0 = {name: "确认参数"};
|
|
|
+ output.info.p0 = { name: "确认参数" };
|
|
|
p = inputmapping[input.name];
|
|
|
if (p) {
|
|
|
for (var k in p) {
|
|
@@ -111,7 +114,7 @@ function main() {
|
|
|
if (classname[0] != "/") {
|
|
|
throw ("classname必须以 / 开头");
|
|
|
}
|
|
|
- if (classname.substring(0,8) == "/matrix/") {
|
|
|
+ if (classname.substring(0, 8) == "/matrix/") {
|
|
|
throw ("classname不能以 /matrix/ 开头");
|
|
|
}
|
|
|
data = input.data;
|
|
@@ -126,7 +129,7 @@ function main() {
|
|
|
try {
|
|
|
data = dfs.read(datafilename);
|
|
|
data = JSON.parse(data);
|
|
|
- } catch(e) {}
|
|
|
+ } catch (e) { }
|
|
|
}
|
|
|
}
|
|
|
if (isempty(data)) {
|
|
@@ -141,41 +144,41 @@ function main() {
|
|
|
// 读取所有文件,综合数据
|
|
|
data = {};
|
|
|
files = dfs.readdir(datafiledir);
|
|
|
- for (i = 0; i < files.length; i++) {
|
|
|
+ for (i = 0; i < files.length; i++) {
|
|
|
try {
|
|
|
adat = dfs.read(files[i].fullname);
|
|
|
adat = JSON.parse(adat);
|
|
|
- if (typeof(adat) != "object") {
|
|
|
- throw("只接收JSON对象数据");
|
|
|
+ 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 (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") {
|
|
|
+ } 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) {
|
|
|
+ } 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];
|
|
|
+ } else if (typeof (adat[k]) == "boolean") {
|
|
|
+ if (typeof (data[k]) != "boolean") {
|
|
|
+ data[k] = "" + adat[k];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } catch(e) {}
|
|
|
+ } catch (e) { }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -200,42 +203,43 @@ function main() {
|
|
|
fields = defaultinput.fields;
|
|
|
}
|
|
|
reqinput = {
|
|
|
- classname: classname,
|
|
|
+ classname: classname,
|
|
|
jsfilename: jsfilename,
|
|
|
- clsoption: clsoption,
|
|
|
+ clsoption: clsoption,
|
|
|
fieldmap: fieldmap,
|
|
|
fields: fields,
|
|
|
mustfield: mustfield,
|
|
|
data: data,
|
|
|
};
|
|
|
- output.info.p1 = {name:"生成类"};
|
|
|
- output.info.p1.result = alterClass(reqinput)
|
|
|
+ output.info.p1 = { name: "生成类" };
|
|
|
+ output.info.p1.result = alterClass(reqinput);
|
|
|
if (output.info.p1.result.error) {
|
|
|
return;
|
|
|
}
|
|
|
- output.info.p2 = {name:"生成脚本"};
|
|
|
- output.info.p2.result = generateJsonImporterJS(reqinput)
|
|
|
+ output.info.p2 = { name: "生成脚本" };
|
|
|
+ output.info.p2.result = generateJsonImporterJS(reqinput);
|
|
|
if (output.info.p2.result.error) {
|
|
|
return;
|
|
|
}
|
|
|
- output.info.p3 = {name:"激活脚本"};
|
|
|
- output.info.p3.result = activeServerJS(jsfilename)
|
|
|
+ output.info.p3 = { name: "激活脚本" };
|
|
|
+ output.info.p3.result = activeServerJS(jsfilename);
|
|
|
if (output.info.p3.result.error) {
|
|
|
return;
|
|
|
}
|
|
|
- output.info.p4 = {name:"验证测试"};
|
|
|
- output.info.p4.result = runServerJS(jsfilename, data)
|
|
|
+ output.info.p4 = { name: "验证测试" };
|
|
|
+ output.info.p4.result = runServerJS(jsfilename, data);
|
|
|
if (output.info.p4.result.error) {
|
|
|
return;
|
|
|
}
|
|
|
- output.info.p5 = {name:"完成"};
|
|
|
+ output.info.p5 = { name: "完成" };
|
|
|
}
|
|
|
+// 执行主程序
|
|
|
try {
|
|
|
main();
|
|
|
-} catch(e) {
|
|
|
- if (typeof(e) == "object") {
|
|
|
+} catch (e) {
|
|
|
+ if (typeof (e) == "object") {
|
|
|
output.error = e;
|
|
|
- } else if (typeof(e) == "string") {
|
|
|
+ } else if (typeof (e) == "string") {
|
|
|
output.error = "错误:" + e;
|
|
|
} else {
|
|
|
output.error = JSON.stringify(e);
|