var fs = require('fs'); var dom = require("xmldom").DOMParser; var select = require('xpath.js'); var dataDetailPath = "/home/server_data/data-detail.xml" var dataPath = "/home/server_data/data.xml" var versionPath = "/home/server_data/version.txt" //����fileId����ȡ�ļ���ŵ�λ�� function getVersionPath(fileId){ fileId = fileId.replace(/\"/g, ""); var item = "")[1].split("")[0]; if(version.value < oldBigVersion){ version.value = oldBigVersion; } } } version.value ++; return version.value; } function mkdataForPage(collecttime, realtype, realpath, realbatch, realid, realname, version){ // var resultXmlData = ""; // var realpath = "/uplaods/"; // var realtype = "01"; // var realbatch = "01_A"; // var realid = "32550_111"; // var realname = "�Ͼ���_������_��Ч����ϵͳ"; //json���Եĸ�ʽ����@ var type ="id=\""+realtype+"\""; var batch = "id=\""+realtype+"_"+realbatch+"\""; var id = realtype+"_"+realbatch+"_"+realid+"\""; var versionid = realtype+"_"+realbatch + "_"+realid + "_" + version +"\""; var name = "name=\""+realname+"\""; var path = "path=\""+realpath+"\""; var versionstrutf = fs.readFileSync(versionPath, "utf-8"); console.log(typeof versionstrutf); console.log("------------- mkdataForPage --------------"); fs.readFile(dataPath, "utf-8", function(err, data){ if(err){ console.log("��ȡ�ļ� "+dataDetailPath+" fail " + err); } else{ var dataNodes = data.split("\n"; isexist = "1"; dataNodes[i] = dataNodes[i] + nodestr; } } } if(isexist.indexOf("1") == -1){ var nodestr = ""; for(var i=0; i < sizel; i++){ if(dataNodes[i].indexOf(batch) != -1){ var items = dataNodes[i].split("\n"; nodestr = nodestr + "\n\n"; isexist = "1"; dataNodes[i] = dataNodes[i] + nodestr; break; } else{ var items = dataNodes[i].split("\n"; nodestr = nodestr + "\n\n"; isexist = "1"; nodestr = items[0] +"\n" + nodestr +"\n\n"; dataNodes[i] = nodestr; break; } } } } var resultdatastr = ""; for(var j=0; j < sizel-1; j++){ resultdatastr = resultdatastr + dataNodes[j] + "\n"; itemStr += "\t\t\t\t"+name+"\n"; itemStr += "\t\t\t\t"+collecttime+"\n"; itemStr += "\t\t\t\t\n"; itemStr += "\t\t\t\t"+province+"\n"; itemStr += "\t\t\t\t"+city+"\n"; itemStr += "\t\t\t\t"+county+"\n"; itemStr += "\t\t\t\t"+system+"\n"; itemStr += "\t\t\t\t"+version+"\n"; itemStr += "\t\t\t\t"+realpath+"\n"; itemStr += "\t\t\t\t"+areacode+"\n"; itemStr += "\t\t\t\t"+systemcode+"\n"; itemStr += "\t\t\t\t"+contacts+"\n"; itemStr += "\t\t\t\t"+phone+"\n"; itemStr += "\t\t\t\t"+type+"\n\t\t\t"+itemEnd+"\n\t\t"; // ��� �� resultStr // û�� item�� itemsize ==1 if(itemsize ==1){ var dataTimebeginstr = itemArray[0].split(dataTimeEndstr); resultStr += dataTimestr; resultStr += dataTimebeginstr[0]; resultStr += "\t" + itemStr; resultStr += dataTimeEndstr; for(var i = 1; i < dataTimebeginstr.length;i++){ resultStr += dataTimebeginstr[i]; } } // �� item�� else{ resultStr += dataTimestr; resultStr += itemArray[0]; if(version == 1){ for(var i=1; i < itemsize-1; i++){ resultStr += item; resultStr += itemArray[i]; } resultStr += itemStr + "\t"; resultStr += item; // itemArray[itemsize-1]: ������ resultStr += itemArray[itemsize-1]; } else{ var addtimes = 0; var isadd = 0; for(var i=1; i < itemsize-1; i++){ isadd++; if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } resultStr += item; resultStr += itemArray[i]; } if(isadd == 0){ if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } } // itemArray[itemsize-1]: ������ resultStr += item; resultStr += itemArray[itemsize-1]; } } } // ��1����ʱ else{ resultStr += datatype; resultStr += timesArray[0]; resultStr += dataTimestr; // item Ԫ�� var itemArray = timesArray[1].split(item); var itemsize = itemArray.length; var nowDate = new Date(); // itemԪ�� var itemStr = "\n"; itemStr += "\t\t\t\t"+name+"\n"; itemStr += "\t\t\t\t"+collecttime+"\n"; itemStr += "\t\t\t\t\n"; itemStr += "\t\t\t\t"+province+"\n"; itemStr += "\t\t\t\t"+city+"\n"; itemStr += "\t\t\t\t"+county+"\n"; itemStr += "\t\t\t\t"+system+"\n"; itemStr += "\t\t\t\t"+version+"\n"; itemStr += "\t\t\t\t"+realpath+"\n"; itemStr += "\t\t\t\t"+areacode+"\n"; itemStr += "\t\t\t\t"+systemcode+"\n"; itemStr += "\t\t\t\t"+contacts+"\n"; itemStr += "\t\t\t\t"+phone+"\n"; itemStr += "\t\t\t\t"+type+"\n\t\t\t"+itemEnd+"\n\t\t"; // ��� �� resultStr // û�� item�� itemsize ==1 if(itemsize ==1){ var dataTimebeginstr = itemArray[0].split(dataTimeEndstr); resultStr += dataTimebeginstr[0]; resultStr += "\t" + itemStr; resultStr += dataTimeEndstr; for(var i = 1; i < dataTimebeginstr.length;i++){ resultStr += dataTimebeginstr[i]; } } // �� item�� else{ resultStr += itemArray[0]; if(version == 1){ for(var i=1; i < itemsize-1; i++){ resultStr += item; resultStr += itemArray[i]; } resultStr += itemStr + "\t"; resultStr += item; // itemArray[itemsize-1]: ������ resultStr += itemArray[itemsize-1]; } else{ var addtimes = 0; var isadd = 0; for(var i=1; i < itemsize-1; i++){ isadd++; if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } resultStr += item; resultStr += itemArray[i]; } if(isadd == 0){ if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } } // itemArray[itemsize-1]: ������ resultStr += item; resultStr += itemArray[itemsize-1]; } } //Ȼ����ϵ�2���� resultStr += dataTimestr; resultStr += timesArray[2]; } } // ������籣 else{ resultStr += typeArray[0]; //�籣 ��typeArray[1] var timesArray = typeArray[1].split(dataTimestr); // �������:���ǵ�һ���εģ��ǵ�2����; {timesArray[0]:ͷ�� timesArray[1]:1���Σ� timesArray[2]:2����} if(timesArray[1].indexOf(dataTimetemstr)== -1){ resultStr += datatype; resultStr += timesArray[0]; // ���ϵ�1���� resultStr += dataTimestr; resultStr += timesArray[1]; var itemArray = timesArray[2].split(item); var itemsize = itemArray.length; var nowDate = new Date(); // itemԪ�� var itemStr = "\n"; itemStr += "\t\t\t\t"+name+"\n"; itemStr += "\t\t\t\t"+collecttime+"\n"; itemStr += "\t\t\t\t\n"; itemStr += "\t\t\t\t"+province+"\n"; itemStr += "\t\t\t\t"+city+"\n"; itemStr += "\t\t\t\t"+county+"\n"; itemStr += "\t\t\t\t"+system+"\n"; itemStr += "\t\t\t\t"+version+"\n"; itemStr += "\t\t\t\t"+realpath+"\n"; itemStr += "\t\t\t\t"+areacode+"\n"; itemStr += "\t\t\t\t"+systemcode+"\n"; itemStr += "\t\t\t\t"+contacts+"\n"; itemStr += "\t\t\t\t"+phone+"\n"; itemStr += "\t\t\t\t"+type+"\n\t\t\t"+itemEnd+"\n\t\t"; // ��� �� resultStr // û�� item�� itemsize ==1 if(itemsize ==1){ var dataTimebeginstr = itemArray[0].split(dataTimeEndstr); resultStr += dataTimestr; resultStr += dataTimebeginstr[0]; resultStr = resultStr + "\t" + itemStr; resultStr += dataTimeEndstr; for(var i = 1; i < dataTimebeginstr.length;i++){ resultStr += dataTimebeginstr[i]; } } // �� item�� else{ resultStr += dataTimestr; resultStr += itemArray[0]; if(version == 1){ for(var i=1; i < itemsize-1; i++){ resultStr += item; resultStr += itemArray[i]; } resultStr += itemStr + "\t"; resultStr += item; // itemArray[itemsize-1]: ������ resultStr += itemArray[itemsize-1]; } else{ var addtimes = 0; var isadd = 0; for(var i=1; i < itemsize-1; i++){ isadd++; if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } resultStr += item; resultStr += itemArray[i]; } if(isadd == 0){ if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } } // itemArray[itemsize-1]: ������ resultStr += item; resultStr += itemArray[itemsize-1]; } } } // ��1����ʱ else{ resultStr += datatype; resultStr += timesArray[0]; resultStr += dataTimestr; // item Ԫ�� var itemArray = timesArray[1].split(item); var itemsize = itemArray.length; var nowDate = new Date(); // itemԪ�� var itemStr = "\n"; itemStr += "\t\t\t\t"+name+"\n"; itemStr += "\t\t\t\t"+collecttime+"\n"; itemStr += "\t\t\t\t\n"; itemStr += "\t\t\t\t"+province+"\n"; itemStr += "\t\t\t\t"+city+"\n"; itemStr += "\t\t\t\t"+county+"\n"; itemStr += "\t\t\t\t"+system+"\n"; itemStr += "\t\t\t\t"+version+"\n"; itemStr += "\t\t\t\t"+realpath+"\n"; itemStr += "\t\t\t\t"+areacode+"\n"; itemStr += "\t\t\t\t"+systemcode+"\n"; itemStr += "\t\t\t\t"+contacts+"\n"; itemStr += "\t\t\t\t"+phone+"\n"; itemStr += "\t\t\t\t"+type+"\n\t\t\t"+itemEnd+"\n\t\t"; // ��� �� resultStr // û�� item�� itemsize ==1 if(itemsize ==1){ var dataTimebeginstr = itemArray[0].split(dataTimeEndstr); resultStr += dataTimebeginstr[0]; resultStr = resultStr + "\t" + itemStr; resultStr += dataTimeEndstr; for(var i = 1; i < dataTimebeginstr.length;i++){ resultStr += dataTimebeginstr[i]; } } // �� item�� else{ resultStr += itemArray[0]; if(version == 1){ for(var i=1; i < itemsize-1; i++){ resultStr += item; resultStr += itemArray[i]; } resultStr += itemStr+"\t"; resultStr += item; // itemArray[itemsize-1]: ������ resultStr += itemArray[itemsize-1]; } else{ var addtimes = 0; var isadd = 0; for(var i=1; i < itemsize-1; i++){ isadd++; if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } resultStr += item; resultStr += itemArray[i]; } if(isadd == 0){ if(addtimes == 0){ if(itemArray[i].indexOf(id)!= -1){ resultStr += itemStr + "\t"; addtimes = 1; } } } // itemArray[itemsize-1]: ������ resultStr += item; resultStr += itemArray[itemsize-1]; } } //Ȼ����ϵ�2���� resultStr += dataTimestr; resultStr += timesArray[2]; } //���ϲ����� resultStr += datatype; resultStr += typeArray[2]; } console.log("-----------------------------------------------"); console.log(resultStr); console.log(typeof resultStr); // д���ļ� fs.writeFile(dataDetailPath, resultStr, function(err){ if(err) console.log(err); else console.log('has finished'); }); } }); } exports.getVersionPath = getVersionPath; exports.mkdataForPage = mkdataForPage exports.saveByIdToXml = saveByIdToXml