function transform(msgPayload) {
// docType
let xmlStr = '<?xml version="1.0" encoding="utf-8"?>'
// xml 请求声明信息
xmlStr += '<ufinterface sender="001" receiver="u8" roottag="inventoryclass" docid="136739611" proc="Add" codeexchanged="N" exportneedexch="N" paginate="0" display="存货分类" family="基础档案" timestamp="0x000000000027B669">';
// 回写构建关键数据
for (let i = 0; i < msgPayload.length; i++) {
xmlStr += '<inventoryclass>'
xmlStr += '<code>' + msgPayload[i].code + '</code>' +
'<name>' + msgPayload[i].name + '</name>' +
'<rank>' + msgPayload[i].rank + '</rank>' +
'<end_rank_flag>' + msgPayload[i].end_rank_flag + '</end_rank_flag>'
xmlStr += '</inventoryclass>'
}
// 结束标签
xmlStr += '</ufinterface>'
let returnMessage = {code: 200, msg: "成功", data: []}
//导入Java支持
let BarnaclePlugin = Java.type("com.jgyun.utils.BarnaclePlugin");
//请求的EAI接口地址
let url = "http://192.168.101.185/u8eai/import.asp"
let middle = null;
try {
//请求接口,返回XML格式结果
middle = BarnaclePlugin.postXml(url, xmlStr)
//xml格式转换为JSONObject
middle = BarnaclePlugin.parseXml2Json(middle)
//分析结果并作转换
var resultMap = [];
for (let i = 0; i < middle.ufinterface.item.length; i++) {
if (middle.ufinterface.item[i].succeed != 0) {
returnMessage.code = 500
resultMap.push({
"code": 500,
"msg": middle.ufinterface.item[i].dsc,
"key": middle.ufinterface.item[i].key
})
} else {
resultMap.push({
"code": 200,
"msg": middle.ufinterface.item[i].dsc,
"key": middle.ufinterface.item[i].key
})
}
}
} catch (e) {
returnMessage.code = 500;
returnMessage.msg = e.message;
returnMessage.data = null;
}
//构造成功返回信息
returnMessage.data = resultMap;
returnMessage.msg = "插入操作";
return JSON.stringify(returnMessage);
}