var jsonList = request.params.ff;//成功接收数据
var i = 0;
var insertSuccess=0;
var insertFailer=0;
var updateSuccess=0;
var updateFailer = 0;
message = [];
haha = [];
query = new AV.Query('GCWLHD');
var GCWLHD = AV.Object.extend("GCWLHD")
var gcwlhd = new GCWLHD()
for (var key in jsonList) {
i++;
query.equalTo("DocCode", jsonList[key]["DocCode"]);
query.find().then(function (results) {
if (results.length == 1) {
results[0].set("DocCode", jsonList[key]["DocCode"]);
results[0].set("FormID", jsonList[key]["FormID"]);
results[0].save().then(function () {
message.push({ 'message': jsonList[key]["DocCode"] + "更新成功" });
updateSuccess++;
}, function (error) {
message.push({ 'message': jsonList[key]["DocCode"] + "更新失败" + error });
updateFailer++;
})
} else if (results.length == 0) {
gcwlhd.set("DocCode", jsonList[key]["DocCode"]);
gcwlhd.set("FormID", jsonList[key]["FormID"]);
gcwlhd.save().then(function () {
message.push({ 'message': jsonList[key]["DocCode"] + "插入成功" });
insertSuccess++;
}, function (error) {
message.push({ 'message': jsonList[key]["DocCode"] + "插入失败" + error });
insertFailer++;
})
}
})
haha.push("我浏览了" + jsonList[key]["DocCode"]);
}
return "i="+i+" "+haha+message+"成功插入:"+insertSuccess+" 成功更新:"+updateSuccess+" 插入失败:"+insertFailer+" 更新失败"+updateFailer;