查询单位 function textToJson(text){ return JSON.parse(text.replace(/([0-9a-zA-Z_]+)[ ]*:/g,`"$1":`).replace(/'/g,`"`));}async function post(url,str){return fetch(url,{method:"post",headers:{"Content-Type":"multipart/form-data"},body:str
function textToJson(text){
return JSON.parse(text.replace(/([0-9a-zA-Z_]+)[ ]*:/g,`"$1":`).replace(/'/g,`"`));
}
async function post(url,str){
return fetch(url,{
method:"post",
headers:{"Content-Type":"multipart/form-data"},
body:str,
credentials:"include"
})
}
async function postQuery(str){
return post("http://10.176.59.59/ynkzx/ria_grid.do?method=query",str);
}
async function postQueryJson(str){
let response=await postQuery(str);
let text=await response.text();
return textToJson(text);
}
response= await postQuery(`{header:{"code": -100, "message": {"title": "", "detail": ""}},body:{dataStores:{cc_ac01_az20:{rowSet:{"primary":[],"filter":[],"delete":[]},name:"cc_ac01_az20",pageNumber:1,pageSize:15000,recordCount:0,context:{"BUSINESS_ID": "", "BUSINESS_REQUEST_ID": "", "CUSTOMVPDPARA": ""},statementName:"si.cardcenter.az20_az30_5",attributes:{"baz802": ["53290101", "12"], "baz888": ["5", "12"]}}},parameters:{"BUSINESS_ID": "", "BUSINESS_REQUEST_ID": "", "CUSTOMVPDPARA": "", "PAGE_ID": "1472552252300"}}}`);
text=await response.text();
data=textToJson(text);
unitsObj=data.body.dataStores.cc_ac01_az20.rowSet.primary;
units=unitsObj.map((m)=>m.V_AC01_AZ20_AAB001);
提交单位
async function getInfo(unitID){
data=await postQueryJson(`{header:{"code": -100, "message": {"title": "", "detail": ""}},body:{dataStores:{az30Ds:{rowSet:{"primary":[],"filter":[],"delete":[]},name:"az30Ds",pageNumber:1,pageSize:10,recordCount:0,context:{"BUSINESS_ID": "UCQ023", "BUSINESS_REQUEST_ID": "REQ-ZZ-M-055-00", "CUSTOMVPDPARA": ""},statementName:"si.cardcenter.az30_unitGetCard",attributes:{"baz853": ["0", "12"], "aab001": ["${unitID}", "12"]}}},parameters:{"BUSINESS_ID": "UCQ023", "BUSINESS_REQUEST_ID": "REQ-ZZ-M-055-00", "CUSTOMVPDPARA": "", "PAGE_ID": "1328083176526"}}}`);
let result={};
result.unitID=data.body.dataStores.az30Ds.rowSet.primary[0].AZ30_AAB001;
result.unitName=data.body.dataStores.az30Ds.rowSet.primary[0].AZ30_AAB004;
data=await postQueryJson(`{header:{"code": -100, "message": {"title": "", "detail": ""}},body:{dataStores:{az30kcDs:{rowSet:{"primary":[],"filter":[],"delete":[]},name:"az30kcDs",pageNumber:1,pageSize:10,recordCount:0,context:{"BUSINESS_ID": "UCQ023", "BUSINESS_REQUEST_ID": "REQ-ZZ-M-055-00", "CUSTOMVPDPARA": ""},statementName:"si.cardcenter.untGetCard_query",attributes:{"baz853": ["0", "12"], "aab001": [${unitID}, "12"]}}},parameters:{"BUSINESS_ID": "UCQ023", "BUSINESS_REQUEST_ID": "REQ-ZZ-M-055-00", "CUSTOMVPDPARA": "", "PAGE_ID": "1328083176526"}}}`);
result.count= +data.body.dataStores.az30kcDs.rowSet.primary[0].AZ30_COUNT;
return result;
}
async function postUnitCard(unitInfo){
let response=await post("http://10.176.59.59/ynkzx/SiBusinessDelegateAction.do?method=execute&BUSINESS_REQUEST_ID=REQ-ZZ-M-055-00&MENUID=1328083176526&BUSINESS_ID=",`{header:{"code": -100, "message": {"title": "", "detail": ""}},body:{dataStores:{},parameters:{"BUSINESS_ID": "UCQ023", "aac001s": "", "baz846": "53290101", "baz864": "${unitInfo.count}", "aab001": "${unitInfo.unitID}", "aab004": "${unitInfo.unitName}", "baz834": "王建荣", "baz835": "532901197802143410", "baz842": "", "baz843": "", "baz844": "", "aab201": "532900", "baz032": ""}}}`)
let text=await response.text();
data=textToJson(text);
return data.body.parameters.$ARCHIVEFLAG$==="TRUE"
}
errorUnits=[];
warnUnits=[];
success={
count:0,
units:[]
};
//真的提交
let postUnitsCards=units.map(async (u)=>{
let info=null;
try{
info=await getInfo(u);
}catch(ex){
console.log(u+":该单位信息无法获取");
errorUnits.push(u);
return;
}
if(!info) {
console.log(u+":该单位信息无法获取");
errorUnits.push(u);
return;
}
try{
if(await postUnitCard(info)){
success.count++;
success.units.push(info);
console.log(info);
console.log("该单位传输成功\r\n,已传输成功:"+success.count+"\r\n,剩余:"+(units.length-success.count));
console.log("*********************************\r\n");
}else{
console.warn(info);
warnUnits.push(info);
console.warn("该单位已传输,并且服务器已返回值,但和成功的返回值不一样");
console.log("剩余:"+(units.length-success.count));
}
}catch(ex){
console.log(u+":该单位提交失败");
errorUnits.push(u);
}
});
for(let postUnit of postUnitsCards){
await postUnit;
}
console.log("\r\n*****************************************")
console.log("该次传输完成");
console.log("传输总记录:"+units.length);
console.log("已传输成功:"+success.count);
console.log("传输成功内容( success.units )");
console.table(success.units);
if(errorUnits.length>0){
console.log("传输失败记录(errorUnits):"+errorUnits.length);
console.log("传输失败内容(errorUnits)");
console.table(errorUnits);
}
if(warnUnits.length>0){
console.log("传输异常记录:"+warnUnits.length);
console.log("传输失败内容(warnUnits)");
console.table(warnUnits);
}
