"use strict";(function(){"use strict";global.Promise=require("bluebird");var e=require("co");var t=require("./maccRequest");var r=require("./jsUtil");var n=require("path");var s=require("fs");var i=require("util");var o=[1,6,11];var a=[149,154,159,164];exports.setConfig=function(e,r,n){t.setConfig(e,r,n)};exports.import=function(o,a,c){console.log("城家公寓参数： ",o);var u={totalNum:o.groupNameList.length,successNum:0,failNum:0};var l=[];var p=[];return e(regeneratorRuntime.mark(function f(){var e,c,g,d,m,b,y,v,k,x,h,L,w,N,I,_;return regeneratorRuntime.wrap(function q(f){while(1){switch(f.prev=f.next){case 0:f.next=2;return t.post("/service/api/group?access_token=",{pGroupId:o.pGroupId,name:o.locationName,type:o.groupType},o.info);case 2:e=f.sent;console.log("城家公寓创建Location： ",e);if(!(e.group==undefined&&e.groupId==undefined)){f.next=6;break}return f.abrupt("return",Promise.reject("cannot build network, "+e.msg+" code:"+e.code,{count:u}));case 6:c=e.group?e.group.groupId:e.groupId;g=0;case 8:if(!(g<o.groupNameList.length)){f.next=65;break}f.next=11;return t.post("/service/api/conf/quickstart?access_token=",{type:o.netType,pGroupId:c,groupName:o.groupNameList[g],ssidList:[{ssidName:o.ssidList[g],password:"88888888",encryptionMode:"wpa2-psk",fowardType:"nat"}]},o.info);case 11:d=f.sent;console.log("城家公寓创建网点： ",d);if(!(d.groupId!=undefined)){f.next=59;break}u.successNum++;f.next=17;return t.get("/service/api/conf/group/"+d.groupId+"/templates?access_token=",o.info);case 17:m=f.sent;console.log("城家公寓获取模板： ",m);if(!(m.code!=0||!m.tempList||m.tempList.length==0)){f.next=23;break}p.push(o.ssidList[g]);if(typeof a==="function"){a(u)}return f.abrupt("continue",62);case 23:b=m.tempList[0].id;f.next=26;return t.get("/service/api/conf/gaotie/template/"+b+"/gaotie_cli_list?access_token=",o.info);case 26:y=f.sent;console.log("城家公寓获取模板cli命令列表： ",y);if(!(y.code!=0)){f.next=32;break}p.push(o.ssidList[g]);if(typeof a==="function"){a(u)}return f.abrupt("continue",62);case 32:v=null;k=null;if(y.cliList&&y.cliList.length>0){v=true;k=y.cliList[0].id}else{v=false}x="#以下命令均由机器自动生成,请勿手工修改,否则有可能引起设备无法上线!\n";h="ALL";try{if(r.getPkgInfo().uplus==true){if(o.disableEWeb==true){x+=i.format("no enable service web\n")}if(typeof o.telnetUser==="string"&&o.telnetUser.length>0&&typeof o.telnetPassword==="string"&&o.telnetPassword.length>0){x+=i.format("username %s pri 15 password %s\n",o.telnetUser,o.telnetPassword);x+="line vty 0 4\n";x+="privilege level 14\n";x+="no password\n";x+="login local\n";x+="exit\n"}L=s.readFileSync(n.join(r.getRootPath(),"/db/uplus.txt"),"utf-8");console.log("result",L);w=o.gatewayHost!=undefined?o.gatewayHost:"BVI 1";L=L.replace(/\$\{gateway\}/gi,w.trim());N=L.split(/\r?\n/gi);N.forEach(function(e){if(e.trim()!=""){x+=e+"\n"}});console.log("cli:",x);h="AP130(W2)"}}catch(q){console.error(q)}if(v){f.next=49;break}f.next=41;return t.post("/service/api/conf/gaotie/template/"+b+"/gaotie_cli?access_token=",{typeList:[h],cli:x,desc:"高级配置"},o.info);case 41:I=f.sent;console.log("城家公寓新增错开信道的cli命令： ",I);if(!(I.code!=0)){f.next=47;break}p.push(o.ssidList[g]);if(typeof a==="function"){a(u)}return f.abrupt("continue",62);case 47:f.next=57;break;case 49:f.next=51;return t.put("/service/api/conf/gaotie/template/"+b+"/gaotie_cli/"+k+"?access_token=",{typeList:[h],cli:x,desc:"高级配置"},o.info);case 51:_=f.sent;console.log("城家公寓修改错开信道的cli命令： ",_);if(!(_.code!=0)){f.next=57;break}p.push(o.ssidList[g]);if(typeof a==="function"){a(u)}return f.abrupt("continue",62);case 57:f.next=61;break;case 59:u.failNum++;l.push(o.ssidList[g]);case 61:if(typeof a==="function"){a(u)}case 62:g++;f.next=8;break;case 65:L={};L.count=u;L.failArray=l;L.failChannelArray=p;return f.abrupt("return",L);case 70:case"end":return f.stop()}}},f,this)})).catch(function(e){console.error("e:",e.toString());var t={};t.count=u;t.failArray=l;t.failChannelArray=p;return Promise.reject(e,t)}).asCallback(c)}})();