Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / components / import / cm / csv2.js
index 609e4ae..11e6722 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xeac6=['papaparse','bluebird','squel','ioredis','../../../mysqldb','../../../config/environment','../../../config/logger','import','localhost','socket.io-emitter','redis','format','YYYY-MM-DD\x20HH:mm:ss','test','select','phone','from','where','.dialCheckDuplicateType\x20IN\x20(','join','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.priority','cm_contacts.UserId','insert','into','cm_hopper','scheduledat','ContactId','ListId','createdAt','priority','UserId','recallme','fields','cm_contacts','cm_contacts.ListId\x20=\x20','.id\x20=\x20','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_contacts.id','cm_contacts.updatedAt','cm_hopper_black','updatedAt','field','\x20=\x20?','concat','keys','fromQuery',')\x20NOT\x20IN\x20?','ListId\x20=\x20?','deletedAt\x20IS\x20NULL','id\x20IN\x20?','MIN(id)','min_id','group','info','Received\x20SIGINT','error','message','exit','errors','push','sequelize','spread','catch','main','stringify','send','binding','server/files/tmp','writeFileSync','parse','createReadStream','data','length','rows','hasOwnProperty','trim','replace','isValid','isNumber','agent\x20not\x20exists','email','email\x20wrong\x20format','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','\x20not\x20specified','emit','contact:import:','Abort\x20parser','abort','SystemError','step','duplicates','\x20LIKE\x20cm_contacts;','LOAD\x20DATA\x20LOCAL\x20INFILE\x20\x27%s\x27\x20INTO\x20TABLE\x20%s\x20CHARACTER\x20SET\x20UTF8\x20FIELDS\x20TERMINATED\x20BY\x20\x27,\x27\x20ENCLOSED\x20BY\x20\x27\x22\x27\x20LINES\x20TERMINATED\x20BY\x20\x27\x0a\x27\x20IGNORE\x201\x20ROWS\x20(%s)\x20SET\x20id\x20=\x20NULL,\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27','CompanyId','isNil','voice_queues_has_cm_lists','VoiceQueueId','voice_queues_has_cm_blacklists','campaigns_has_cm_lists','campaigns','CampaignId','each','finish','unlink','complete','argv','root','existsSync','file\x20doesn\x27t\x20exists','binding\x20doesn\x27t\x20exists','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','SIGINT','uncaughtException','lodash'];(function(_0x44c9f8,_0x130004){var _0x1ff0d5=function(_0x2f8d9c){while(--_0x2f8d9c){_0x44c9f8['push'](_0x44c9f8['shift']());}};_0x1ff0d5(++_0x130004);}(_0xeac6,0x7f));var _0x6eac=function(_0x4ccfd6,_0x43fecf){_0x4ccfd6=_0x4ccfd6-0x0;var _0x80beb6=_0xeac6[_0x4ccfd6];return _0x80beb6;};'use strict';var fs=require('fs');var path=require('path');var _=require(_0x6eac('0x0'));var Papa=require(_0x6eac('0x1'));var util=require('util');var BPromise=require(_0x6eac('0x2'));var moment=require('moment');var squel=require(_0x6eac('0x3'));var Redis=require(_0x6eac('0x4'));var db=require(_0x6eac('0x5'))['db'];var config=require(_0x6eac('0x6'));var logger=require(_0x6eac('0x7'))(_0x6eac('0x8'));config['redis']=_['defaults'](config['redis'],{'host':_0x6eac('0x9'),'port':0x18eb});var socket=require(_0x6eac('0xa'))(new Redis(config[_0x6eac('0xb')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0x6eac('0xc')](_0x6eac('0xd'));function isEmail(_0x189e32){return/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/[_0x6eac('0xe')](_0x189e32);}function selectNotIn(_0x198c05,_0x3c857f,_0x508e6c,_0x4bf461,_0x96c574){return squel[_0x6eac('0xf')]()['field'](_0x6eac('0x10'))[_0x6eac('0x11')](_0x4bf461)['join'](_0x3c857f,null,_0x3c857f+'.id\x20=\x20'+_0x4bf461+'.'+_0x508e6c)['where'](_0x4bf461+'.'+_0x508e6c+'\x20=\x20'+_0x198c05+'.'+_0x508e6c)[_0x6eac('0x12')](_0x3c857f+_0x6eac('0x13')+_0x96c574[_0x6eac('0x14')]()+')');}function insertCmHopper(_0x48a6fa,_0xafaa39,_0x450528,_0x566e81,_0x4f6f11){var _0x558fd0=[_0x6eac('0x15'),_0x6eac('0x16'),'cm_contacts.id',_0x6eac('0x17'),_0xafaa39+'.'+_0x566e81,_0x6eac('0x18'),'cm_contacts.updatedAt',_0x6eac('0x19'),_0x6eac('0x1a'),'\x22'+_0x4f6f11+'\x22'];return squel[_0x6eac('0x1b')]()[_0x6eac('0x1c')](_0x6eac('0x1d'))['fromQuery']([_0x6eac('0x10'),_0x6eac('0x1e'),_0x6eac('0x1f'),_0x6eac('0x20'),_0x566e81,_0x6eac('0x21'),'updatedAt',_0x6eac('0x22'),_0x6eac('0x23'),_0x6eac('0x24')],squel[_0x6eac('0xf')]()[_0x6eac('0x25')](_0x558fd0)['from'](_0xafaa39)[_0x6eac('0x14')](_0x6eac('0x26'),null,_0x6eac('0x27')+_0xafaa39+'.CmListId')[_0x6eac('0x14')](_0x450528,null,_0x450528+_0x6eac('0x28')+_0xafaa39+'.'+_0x566e81)[_0x6eac('0x12')](_0xafaa39+_0x6eac('0x29'),_0x48a6fa)[_0x6eac('0x12')](_0x6eac('0x2a'),NOW)['where'](_0x6eac('0x2b'),selectNotIn(_0xafaa39,_0x450528,_0x566e81,_0x6eac('0x1d'),[_0x6eac('0x2c'),_0x6eac('0x2d')]))[_0x6eac('0x12')](_0x6eac('0x2b'),selectNotIn(_0xafaa39,_0x450528,_0x566e81,'cm_hopper',[_0x6eac('0x2c')])))[_0x6eac('0x2e')]();}function insertCmHopperBlack(_0x1fafb3,_0x1849b2,_0x56f994,_0x2a7e54){var _0x123f8d=[_0x6eac('0x15'),_0x6eac('0x2f'),_0x6eac('0x17'),_0x1849b2+'.'+_0x2a7e54,'cm_contacts.createdAt',_0x6eac('0x30')];return squel[_0x6eac('0x1b')]()['into'](_0x6eac('0x31'))['fromQuery'](['phone',_0x6eac('0x1f'),_0x6eac('0x20'),_0x2a7e54,_0x6eac('0x21'),_0x6eac('0x32')],squel[_0x6eac('0xf')]()[_0x6eac('0x25')](_0x123f8d)[_0x6eac('0x11')](_0x1849b2)[_0x6eac('0x14')]('cm_contacts',null,_0x6eac('0x27')+_0x1849b2+'.CmListId')[_0x6eac('0x14')](_0x56f994,null,_0x56f994+_0x6eac('0x28')+_0x1849b2+'.'+_0x2a7e54)[_0x6eac('0x12')](_0x1849b2+_0x6eac('0x29'),_0x1fafb3)[_0x6eac('0x12')](_0x6eac('0x2a'),NOW)[_0x6eac('0x12')](_0x6eac('0x2b'),squel[_0x6eac('0xf')]()[_0x6eac('0x33')](_0x6eac('0x10'))[_0x6eac('0x11')](_0x6eac('0x31'))[_0x6eac('0x12')]('ListId\x20=\x20?',_0x1fafb3)['where'](_0x2a7e54+_0x6eac('0x34'),_0x1849b2+'.'+_0x2a7e54)))['toString']();}function insertCmContact(_0x4bdf4a,_0x340753,_0x1380c6,_0x322931){var _0x5f319c=_[_0x6eac('0x35')](_[_0x6eac('0x36')](_0x322931),['ListId','CompanyId',_0x6eac('0x21'),_0x6eac('0x32')]);return squel['insert']()[_0x6eac('0x1c')](_0x6eac('0x26'))[_0x6eac('0x37')](_0x5f319c,squel[_0x6eac('0xf')]()['fields'](_0x5f319c)[_0x6eac('0x11')](_0x340753)['where']('('+_0x1380c6[_0x6eac('0x14')](',')+_0x6eac('0x38'),squel[_0x6eac('0xf')]()['fields'](_0x1380c6)[_0x6eac('0x11')](_0x6eac('0x26'))[_0x6eac('0x12')](_0x6eac('0x39'),_0x4bdf4a)[_0x6eac('0x12')](_0x6eac('0x3a')))[_0x6eac('0x12')](_0x6eac('0x3b'),squel[_0x6eac('0xf')]()[_0x6eac('0x33')](_0x6eac('0x3c'),_0x6eac('0x3d'))[_0x6eac('0x11')](_0x340753)[_0x6eac('0x3e')](_0x1380c6[_0x6eac('0x14')](','))))[_0x6eac('0x2e')]();}function handleStop(){logger[_0x6eac('0x3f')](_0x6eac('0x40'));stopped=!![];}function handleUncaughtException(_0x2ef38f){logger[_0x6eac('0x41')](_0x2ef38f[_0x6eac('0x42')]);process[_0x6eac('0x43')](0x1);}function handleError(_0x175f37,_0x396845){stats[_0x6eac('0x44')][_0x6eac('0x45')]({'name':_0x396845['code'],'message':_0x396845[_0x6eac('0x42')],'row':_0x175f37});}function handleQuery(_0x4b734b){logger[_0x6eac('0x3f')](_0x4b734b);return db[_0x6eac('0x46')]['query'](_0x4b734b)[_0x6eac('0x47')](function(_0x3d7012){results['push'](_0x3d7012);})[_0x6eac('0x48')](function(_0x6db618){logger[_0x6eac('0x41')](_0x6db618['message']);});}function main(_0x43d9b1,_0x4c34b2,_0x5e808a,_0xdb2feb){logger['info'](_0x6eac('0x49'),_0x43d9b1,JSON[_0x6eac('0x4a')](_0x4c34b2));process[_0x6eac('0x4b')]('start');var _0x533f48=_0x4c34b2[_0x6eac('0x4c')];var _0x3ace76=_0x4c34b2['socket_timestamp'];var _0x1a6cdd=path[_0x6eac('0x14')](config['root'],_0x6eac('0x4d'),_0x3ace76+'.csv');var _0x43009c=_[_0x6eac('0x36')](_0x533f48)[_0x6eac('0x14')]();logger[_0x6eac('0x3f')]('header',_0x43009c);fs[_0x6eac('0x4e')](_0x1a6cdd,_0x43009c+'\x0a');Papa[_0x6eac('0x4f')](fs[_0x6eac('0x50')](_0x43d9b1),{'header':!![],'skipEmptyLines':!![],'step':function(_0xec87bb,_0x418f0b){try{for(var _0x53c210=0x0,_0x542625=[];_0x53c210<_0xec87bb[_0x6eac('0x51')][_0x6eac('0x52')];_0x53c210++){stats[_0x6eac('0x53')]+=0x1;if(_0xec87bb[_0x6eac('0x44')][_0x53c210]){handleError(_0xec87bb[_0x6eac('0x51')][_0x53c210],_0xec87bb[_0x6eac('0x44')][_0x53c210]);}else{var _0x60aa7b=[];for(var _0x48a3e6 in _0x533f48){if(_0x533f48[_0x6eac('0x54')](_0x48a3e6)){if(_0xec87bb[_0x6eac('0x51')][_0x53c210][_0x533f48[_0x48a3e6]]){var _0x49c964=_[_0x6eac('0x55')](_0xec87bb[_0x6eac('0x51')][_0x53c210][_0x533f48[_0x48a3e6]][_0x6eac('0x56')](/"/g,'\x27'));switch(_0x48a3e6){case _0x6eac('0x1e'):var _0x5e5203=moment(_0x49c964,_0x6eac('0xd'),!![]);if(_0x5e5203[_0x6eac('0x57')]()){_0x542625[_0x6eac('0x45')]('\x22'+_0x49c964+'\x22');}else{_0x60aa7b[_0x6eac('0x45')]('scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)');}break;case'priority':var _0x2c55bb=parseInt(_0x49c964);_0x49c964=_['isNaN'](_0x2c55bb)||_0x2c55bb<0x0||_0x2c55bb>0x4?_0xdb2feb?0x3:0x2:_0x2c55bb;_0x542625['push']('\x22'+_0x49c964+'\x22');break;case'UserId':var _0x5782d7=parseInt(_0x49c964);if(_[_0x6eac('0x58')](_0x5782d7)&&_['includes'](_0x5e808a,_0x5782d7)){_0x542625['push']('\x22'+_0x5782d7+'\x22');}else{_0x60aa7b[_0x6eac('0x45')](_0x6eac('0x59'));}break;case _0x6eac('0x5a'):if(isEmail(_0x49c964)){_0x542625[_0x6eac('0x45')]('\x22'+_0x49c964+'\x22');}else{_0x60aa7b[_0x6eac('0x45')](_0x6eac('0x5b'));}break;case'dateOfBirth':var _0x3f8295=moment(_0x49c964,_0x6eac('0x5c'),!![]);if(_0x3f8295[_0x6eac('0x57')]()){_0x542625['push']('\x22'+_0x49c964+'\x22');}else{_0x60aa7b['push'](_0x6eac('0x5d'));}break;default:_0x542625[_0x6eac('0x45')]('\x22'+_0x49c964+'\x22');}}else{switch(_0x48a3e6){case _0x6eac('0x5e'):case _0x6eac('0x10'):_0x60aa7b[_0x6eac('0x45')](_0x48a3e6+_0x6eac('0x5f'));break;default:_0x542625[_0x6eac('0x45')]('\x22\x22');}}}}if(_0x60aa7b['length']){handleError(_0xec87bb[_0x6eac('0x51')][_0x53c210],{'code':'SystemRow','message':_0x60aa7b['join']()});}else{fs['appendFileSync'](_0x1a6cdd,_0x542625[_0x6eac('0x14')]()+'\x0a');}_0x542625=[];}if(!(stats[_0x6eac('0x53')]%0xc8)){socket[_0x6eac('0x60')](_0x6eac('0x61')+_0x3ace76,stats);stats[_0x6eac('0x44')]=[];}}if(stopped){logger[_0x6eac('0x3f')](_0x6eac('0x62'));_0x418f0b[_0x6eac('0x63')]();}}catch(_0x294cc6){handleError(_0xec87bb[_0x6eac('0x51')][_0x53c210],{'code':_0x6eac('0x64'),'message':_0x294cc6[_0x6eac('0x42')]});logger[_0x6eac('0x41')](_0x6eac('0x65'),_0x294cc6[_0x6eac('0x42')]);}},'complete':function(){try{var _0x4a1a5a=[];var _0x3fde3a='cm_contacts';if(_0x4c34b2[_0x6eac('0x66')]&&_0x4c34b2[_0x6eac('0x66')][_0x6eac('0x52')]){_0x3fde3a='cm_contacts_'+_0x3ace76;_0x4a1a5a[_0x6eac('0x45')]('CREATE\x20TABLE\x20'+_0x3fde3a+_0x6eac('0x67'));}var _0x2634f5=util[_0x6eac('0xc')](_0x6eac('0x68'),_0x1a6cdd,_0x3fde3a,_0x43009c,_0x4c34b2[_0x6eac('0x20')],_0x4c34b2[_0x6eac('0x69')]||null,NOW,NOW);if(_[_0x6eac('0x6a')](_0x533f48[_0x6eac('0x1e')])){_0x2634f5+=',\x20scheduledAt\x20=\x20NOW()';}_0x4a1a5a['push'](_0x2634f5);if(_0x4c34b2['duplicates']&&_0x4c34b2[_0x6eac('0x66')][_0x6eac('0x52')]){_0x4a1a5a[_0x6eac('0x45')](insertCmContact(_0x4c34b2[_0x6eac('0x20')],_0x3fde3a,_0x4c34b2[_0x6eac('0x66')],_0x533f48));_0x4a1a5a[_0x6eac('0x45')]('DROP\x20TABLE\x20'+_0x3fde3a+';');}_0x4a1a5a[_0x6eac('0x45')](insertCmHopper(_0x4c34b2[_0x6eac('0x20')],_0x6eac('0x6b'),'voice_queues',_0x6eac('0x6c'),_0xdb2feb));_0x4a1a5a[_0x6eac('0x45')](insertCmHopperBlack(_0x4c34b2[_0x6eac('0x20')],_0x6eac('0x6d'),'voice_queues',_0x6eac('0x6c')));_0x4a1a5a[_0x6eac('0x45')](insertCmHopper(_0x4c34b2['ListId'],_0x6eac('0x6e'),_0x6eac('0x6f'),_0x6eac('0x70'),_0xdb2feb));_0x4a1a5a[_0x6eac('0x45')](insertCmHopperBlack(_0x4c34b2[_0x6eac('0x20')],'campaigns_has_cm_blacklists',_0x6eac('0x6f'),_0x6eac('0x70')));BPromise[_0x6eac('0x71')](_0x4a1a5a,handleQuery)['then'](function(_0x56f801){stats[_0x6eac('0x72')]=!![];stats['affectedRows']=_0x4c34b2[_0x6eac('0x66')]&&_0x4c34b2[_0x6eac('0x66')][_0x6eac('0x52')]?results[0x2]['affectedRows']:results[0x0]['affectedRows'];socket['emit']('contact:import:'+_0x3ace76,stats);fs[_0x6eac('0x73')](_0x43d9b1);fs[_0x6eac('0x73')](_0x1a6cdd);process[_0x6eac('0x43')](0x0);})[_0x6eac('0x48')](function(_0xbe9076){logger[_0x6eac('0x41')](_0xbe9076[_0x6eac('0x42')]);process[_0x6eac('0x43')](0x1);});}catch(_0x2d8eca){logger[_0x6eac('0x41')](_0x6eac('0x74'),_0x2d8eca[_0x6eac('0x42')]);process[_0x6eac('0x43')](0x1);}},'error':function(_0x226928,_0x51135c,_0x42f294,_0xac9b2e){throw new Error(_0xac9b2e);}});}function validate(){if(process[_0x6eac('0x75')]&&process[_0x6eac('0x75')][_0x6eac('0x52')]<0x4){throw new Error('arguments\x20<filename>\x20<parameters>\x20<agents>');}var _0x4598dd=path[_0x6eac('0x14')](config[_0x6eac('0x76')],_0x6eac('0x4d'),process[_0x6eac('0x75')][0x2]);if(!fs[_0x6eac('0x77')](_0x4598dd)){throw new Error(_0x6eac('0x78'));}var _0x3a4a6d={};try{_0x3a4a6d=JSON[_0x6eac('0x4f')](process[_0x6eac('0x75')][0x3]);if(!_0x3a4a6d[_0x6eac('0x4c')]){throw new Error(_0x6eac('0x79'));}if(!_0x3a4a6d[_0x6eac('0x4c')]['phone']){throw new Error('phone\x20is\x20mandatory');}if(!_0x3a4a6d[_0x6eac('0x4c')][_0x6eac('0x5e')]){throw new Error(_0x6eac('0x7a'));}var _0x4f9fb7=0x0;if(_0x3a4a6d[_0x6eac('0x4c')][_0x6eac('0x23')]){_0x4f9fb7=0x1;}if(!_0x3a4a6d[_0x6eac('0x20')]){throw new Error(_0x6eac('0x7b'));}}catch(_0x137fb1){throw new Error(_0x6eac('0x7c'));}var _0x10e087=[];try{_0x10e087=_[_0x6eac('0x7d')](JSON['parse'](process['argv'][0x4]),'id');}catch(_0x397c5d){logger[_0x6eac('0x3f')]('No\x20agent\x20available');}main(_0x4598dd,_0x3a4a6d,_0x10e087,_0x4f9fb7);}validate();process['on'](_0x6eac('0x7e'),handleStop);process['on'](_0x6eac('0x7f'),handleUncaughtException);
\ No newline at end of file
+var _0x99f7=['firstName','itemTypeId','description','SystemRow','appendFileSync','Abort\x20parser','SystemError','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','campaigns_','voice_queues_','(id\x20int,dialTimezone\x20varchar(255),offset\x20int);','each','dialTimezone,utcOffset','CompanyId',',\x20scheduledAt\x20=\x20NOW()','orderBy','voice_queues_has_cm_lists','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','CampaignId','campaigns_has_cm_blacklists','DROP\x20TABLE\x20','finish','affectedRows','emit','contact:import:','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','server/files/tmp','existsSync','file\x20doesn\x27t\x20exists','parse','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','map','No\x20agent\x20available','SIGINT','lodash','moment','squel','ioredis','../../../config/environment','../../../config/environment/shared','../../../config/logger','import','redis','defaults','localhost','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','select','field','phone','from','where','.dialCheckDuplicateType\x20IN\x20(','CmContact','findAll','AdditionalPhones','then','length','push','all','split','CmContactHasItem','findOne','update','updated','create','PHONE','inserted','cm_contacts.phone','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.priority','insert','into','cm_hopper','ContactId','ListId','createdAt','updatedAt','priority','UserId','recallme','cm_contacts','.CmListId','join','.id\x20=\x20','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_contacts.updatedAt','cm_hopper_black','fields','cm_contacts.ListId\x20=\x20','\x20=\x20','.offset-cm_contacts.utcOffset\x20minute)','cm_contacts.UserId','fromQuery','scheduledat','cm_hopper.id','cm_contact_has_items.item','cm_contact_has_items.createdAt','cm_hopper_additional_phones','CmHopperId','OrderBy','cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId','cm_hopper.ListId\x20=\x20?','concat','keys','scheduledAt','ListId\x20=\x20?','id\x20IN\x20?','min_id','info','Received\x20SIGINT','exit','errors','sequelize','spread','catch','message','campaigns.id','campaigns.dialTimezone','campaigns','campaigns_has_cm_lists','campaigns.id\x20=\x20campaigns_has_cm_lists.CampaignId','error','voice_queues.id','voice_queues.id\x20=\x20voice_queues_has_cm_lists.VoiceQueueId','query','timezones','dialTimezone','utcOffset','set','offset','main','send','start','binding','clone','socket_timestamp','root','.csv','header','ContactItemType','name','_description','writeFileSync','createReadStream','rows','data','find','isNil','hasOwnProperty','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNumber','includes','agent\x20not\x20exists','email','email\x20wrong\x20format','YYYY-MM-DD'];(function(_0x2e08fe,_0x4f4b67){var _0xe83039=function(_0x3be780){while(--_0x3be780){_0x2e08fe['push'](_0x2e08fe['shift']());}};_0xe83039(++_0x4f4b67);}(_0x99f7,0xe1));var _0x799f=function(_0x186e1a,_0x59d2b8){_0x186e1a=_0x186e1a-0x0;var _0x1c2d5b=_0x99f7[_0x186e1a];return _0x1c2d5b;};'use strict';var fs=require('fs');var path=require('path');var _=require(_0x799f('0x0'));var Papa=require('papaparse');var util=require('util');var BPromise=require('bluebird');var moment=require(_0x799f('0x1'));var squel=require(_0x799f('0x2'));var Redis=require(_0x799f('0x3'));var db=require('../../../mysqldb')['db'];var config=require(_0x799f('0x4'));var shared=require(_0x799f('0x5'));var logger=require(_0x799f('0x6'))(_0x799f('0x7'));config[_0x799f('0x8')]=_[_0x799f('0x9')](config[_0x799f('0x8')],{'host':_0x799f('0xa'),'port':0x18eb});var socket=require(_0x799f('0xb'))(new Redis(config[_0x799f('0x8')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var orderBy=0x0;var stopped=![];var NOW=moment()[_0x799f('0xc')](_0x799f('0xd'));var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];var tmp_voice_queues;var tmp_campaigns;var tzOffset=0x0;var hasTZ;var NOW=moment()[_0x799f('0xc')](_0x799f('0xd'));function isEmail(_0x1068e9){return/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/['test'](_0x1068e9);}function selectNotIn(_0x527787,_0x1ba2ce,_0x322b30,_0x2159ef,_0x52e2d4){return squel[_0x799f('0xe')]()[_0x799f('0xf')](_0x799f('0x10'))[_0x799f('0x11')](_0x2159ef)['join'](_0x1ba2ce,null,_0x1ba2ce+'.id\x20=\x20'+_0x2159ef+'.'+_0x322b30)[_0x799f('0x12')](_0x2159ef+'.'+_0x322b30+'\x20=\x20'+_0x527787+'.'+_0x322b30)['where'](_0x1ba2ce+_0x799f('0x13')+_0x52e2d4['join']()+')');}function handleAdditionalPhones(){return new Promise(function(_0x2096ac,_0x39e0fc){promisesAdditionalPhones=[];return db[_0x799f('0x14')][_0x799f('0x15')]({'raw':!![],'attributes':['id',_0x799f('0x16')],'where':{'createdAt':NOW,'AdditionalPhones':{'$ne':null}}})[_0x799f('0x17')](function(_0x44efb7){if(_0x44efb7!==null){var _0x2df48c=[];for(var _0x146387=0x0;_0x146387<_0x44efb7[_0x799f('0x18')];_0x146387++){var _0x4ea6a7=_0x44efb7[_0x146387];_0x2df48c[_0x799f('0x19')](insertAdditionalPhones(_0x4ea6a7));}}Promise[_0x799f('0x1a')](_0x2df48c)[_0x799f('0x17')](function(){_0x2096ac({'val':0x1});});});});}function insertAdditionalPhones(_0x122697){return new Promise(function(_0x527659,_0x49c4de){var _0x5f2f01=_0x122697[_0x799f('0x16')];var _0x12308b=_0x5f2f01[_0x799f('0x1b')](';');var _0x2f3478=[];orderBy=0x0;for(var _0x3a8eda=0x0;_0x3a8eda<_0x12308b[_0x799f('0x18')];_0x3a8eda++){_0x2f3478[_0x799f('0x19')](splitAdditionalPhone(_0x122697['id'],_0x12308b[_0x3a8eda]));}Promise[_0x799f('0x1a')](_0x2f3478)[_0x799f('0x17')](function(){_0x527659({'val':_0x12308b[_0x799f('0x18')]});});});}function splitAdditionalPhone(_0x418968,_0x79115c){return new Promise(function(_0x4073aa,_0xb86804){var _0x5066ce=_0x79115c[_0x799f('0x1b')](':');var _0x4cf246=_0x5066ce[0x0];var _0x96fb1d=_0x5066ce[0x1];if(!_['isNil'](_0x96fb1d)){var _0x41a3ea=_0x96fb1d[_0x799f('0x1b')]('|');var _0x3e2e7a=[];for(var _0x4e9b1b=0x0;_0x4e9b1b<_0x41a3ea[_0x799f('0x18')];_0x4e9b1b++){if(_0x41a3ea[_0x4e9b1b]!==''){var _0x522772=_['filter'](promisesAdditionalPhones,{'contactId':_0x418968,'phone':_0x41a3ea[_0x4e9b1b]});if(_0x522772['length']==0x0){orderBy++;promisesAdditionalPhones[_0x799f('0x19')]({'contactId':_0x418968,'contactTypeId':_0x4cf246,'phone':_0x41a3ea[_0x4e9b1b],'orderBy':orderBy});}}}_0x4073aa({'ok':0x1});}else _0x4073aa({'res':0x0});});}function createAdditionalPhone(_0x36983a,_0x4d5629,_0x296e85,_0x3361dc){var _0x5ccbcf='';var _0x3b04ed='';var _0x1638e9=_0x296e85[_0x799f('0x1b')]('§');_0x5ccbcf=_0x1638e9[0x0];if(_0x1638e9[_0x799f('0x18')]==0x2)_0x3b04ed=_0x1638e9[0x1];return new Promise(function(_0x1df4e5,_0x5c956f){return db[_0x799f('0x1c')][_0x799f('0x1d')]({'where':{'CmContactId':_0x36983a,'item':_0x5ccbcf}})['then'](function(_0x467a52){if(_0x467a52){return db[_0x799f('0x1c')][_0x799f('0x1e')]({'ItemTypeId':_0x4d5629,'description':_0x3b04ed,'OrderBy':_0x3361dc},{'where':{'CmContactId':_0x36983a,'item':_0x5ccbcf}})[_0x799f('0x17')](function(_0x431d91){_0x1df4e5({'res':_0x799f('0x1f')});});}else{return db[_0x799f('0x1c')][_0x799f('0x20')]({'CmContactId':_0x36983a,'item':_0x5ccbcf,'description':_0x3b04ed,'ItemTypeId':_0x4d5629,'OrderBy':_0x3361dc,'ItemClass':_0x799f('0x21')})[_0x799f('0x17')](function(_0x205e1c){_0x1df4e5({'res':_0x799f('0x22')});});}});});}function insertCmHopper(_0x40ea8b,_0x57b18b,_0x3f7ebd,_0x597de8,_0x297b04){var _0x39480e=[_0x799f('0x23'),_0x799f('0x24'),_0x799f('0x25'),_0x799f('0x26'),_0x57b18b+'.'+_0x597de8,_0x799f('0x27'),'cm_contacts.updatedAt',_0x799f('0x28'),'cm_contacts.UserId','\x22'+_0x297b04+'\x22'];return squel[_0x799f('0x29')]()[_0x799f('0x2a')](_0x799f('0x2b'))['fromQuery']([_0x799f('0x10'),'scheduledat',_0x799f('0x2c'),_0x799f('0x2d'),_0x597de8,_0x799f('0x2e'),_0x799f('0x2f'),_0x799f('0x30'),_0x799f('0x31'),_0x799f('0x32')],squel[_0x799f('0xe')]()['fields'](_0x39480e)[_0x799f('0x11')](_0x57b18b)['join'](_0x799f('0x33'),null,'cm_contacts.ListId\x20=\x20'+_0x57b18b+_0x799f('0x34'))[_0x799f('0x35')](_0x3f7ebd,null,_0x3f7ebd+_0x799f('0x36')+_0x57b18b+'.'+_0x597de8)['where'](_0x57b18b+_0x799f('0x37'),_0x40ea8b)[_0x799f('0x12')](_0x799f('0x38'),NOW)[_0x799f('0x12')](_0x799f('0x39'),selectNotIn(_0x57b18b,_0x3f7ebd,_0x597de8,_0x799f('0x2b'),[_0x799f('0x3a'),_0x799f('0x3b')]))[_0x799f('0x12')](_0x799f('0x39'),selectNotIn(_0x57b18b,_0x3f7ebd,_0x597de8,'cm_hopper',['\x22always\x22'])))[_0x799f('0x3c')]();}function insertCmHopperBlack(_0x552980,_0x52eaeb,_0x464230,_0x57c4b4){var _0x42ce7a=[_0x799f('0x23'),_0x799f('0x25'),_0x799f('0x26'),_0x52eaeb+'.'+_0x57c4b4,_0x799f('0x27'),_0x799f('0x3d')];return squel['insert']()[_0x799f('0x2a')](_0x799f('0x3e'))['fromQuery']([_0x799f('0x10'),_0x799f('0x2c'),_0x799f('0x2d'),_0x57c4b4,_0x799f('0x2e'),_0x799f('0x2f')],squel[_0x799f('0xe')]()[_0x799f('0x3f')](_0x42ce7a)[_0x799f('0x11')](_0x52eaeb)[_0x799f('0x35')]('cm_contacts',null,_0x799f('0x40')+_0x52eaeb+_0x799f('0x34'))[_0x799f('0x35')](_0x464230,null,_0x464230+'.id\x20=\x20'+_0x52eaeb+'.'+_0x57c4b4)[_0x799f('0x12')](_0x52eaeb+_0x799f('0x37'),_0x552980)[_0x799f('0x12')](_0x799f('0x38'),NOW)[_0x799f('0x12')](_0x799f('0x39'),squel[_0x799f('0xe')]()['field'](_0x799f('0x10'))[_0x799f('0x11')]('cm_hopper_black')[_0x799f('0x12')]('ListId\x20=\x20?',_0x552980)[_0x799f('0x12')](_0x57c4b4+_0x799f('0x41')+_0x52eaeb+'.'+_0x57c4b4)))[_0x799f('0x3c')]();}function insertTzCmHopper(_0x20320c,_0x1aa409,_0x3abf60,_0x19b34c,_0x253d50,_0x2acb18){var _0x437341=[_0x799f('0x23'),'date_add(cm_contacts.scheduledat,interval\x20'+_0x2acb18+_0x799f('0x42'),'cm_contacts.id','cm_contacts.ListId',_0x1aa409+'.'+_0x19b34c,_0x799f('0x27'),_0x799f('0x3d'),_0x799f('0x28'),_0x799f('0x43'),'\x22'+_0x253d50+'\x22'];var _0x11ddf0=squel['insert']()[_0x799f('0x2a')](_0x799f('0x2b'))[_0x799f('0x44')]([_0x799f('0x10'),_0x799f('0x45'),'ContactId',_0x799f('0x2d'),_0x19b34c,_0x799f('0x2e'),_0x799f('0x2f'),_0x799f('0x30'),_0x799f('0x31'),_0x799f('0x32')],squel[_0x799f('0xe')]()['fields'](_0x437341)[_0x799f('0x11')](_0x1aa409)[_0x799f('0x35')]('cm_contacts',null,_0x799f('0x40')+_0x1aa409+_0x799f('0x34'))[_0x799f('0x35')](_0x3abf60,null,_0x3abf60+_0x799f('0x36')+_0x1aa409+'.'+_0x19b34c)[_0x799f('0x35')](_0x2acb18,null,_0x2acb18+_0x799f('0x36')+_0x1aa409+'.'+_0x19b34c)[_0x799f('0x12')](_0x1aa409+_0x799f('0x37'),_0x20320c)[_0x799f('0x12')](_0x799f('0x38'),NOW)['where'](_0x799f('0x39'),selectNotIn(_0x1aa409,_0x3abf60,_0x19b34c,_0x799f('0x2b'),[_0x799f('0x3a'),_0x799f('0x3b')]))[_0x799f('0x12')](_0x799f('0x39'),selectNotIn(_0x1aa409,_0x3abf60,_0x19b34c,_0x799f('0x2b'),[_0x799f('0x3a')])))[_0x799f('0x3c')]();return _0x11ddf0;}function insertTzCmHopperBlack(_0x65b997,_0x2dbf66,_0x460fa6,_0x31e127){var _0x1938c5=[_0x799f('0x23'),_0x799f('0x25'),_0x799f('0x26'),_0x2dbf66+'.'+_0x31e127,_0x799f('0x27'),'cm_contacts.updatedAt'];return squel['insert']()['into'](_0x799f('0x3e'))[_0x799f('0x44')]([_0x799f('0x10'),_0x799f('0x2c'),'ListId',_0x31e127,_0x799f('0x2e'),_0x799f('0x2f')],squel['select']()[_0x799f('0x3f')](_0x1938c5)['from'](_0x2dbf66)['join']('cm_contacts',null,_0x799f('0x40')+_0x2dbf66+_0x799f('0x34'))[_0x799f('0x35')](_0x460fa6,null,_0x460fa6+_0x799f('0x36')+_0x2dbf66+'.'+_0x31e127)[_0x799f('0x12')](_0x2dbf66+_0x799f('0x37'),_0x65b997)[_0x799f('0x12')](_0x799f('0x38'),NOW)[_0x799f('0x12')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel[_0x799f('0xe')]()[_0x799f('0xf')]('phone')[_0x799f('0x11')](_0x799f('0x3e'))['where']('ListId\x20=\x20?',_0x65b997)['where'](_0x31e127+_0x799f('0x41')+_0x2dbf66+'.'+_0x31e127)))['toString']();}function insertCmHopperAdditionalPhones(_0x36fb4e){var _0x474356=[_0x799f('0x46'),_0x799f('0x47'),'cm_contact_has_items.OrderBy',_0x799f('0x48'),'cm_contact_has_items.updatedAt'];return squel[_0x799f('0x29')]()['into'](_0x799f('0x49'))[_0x799f('0x44')]([_0x799f('0x4a'),'phone',_0x799f('0x4b'),'createdAt','updatedAt'],squel[_0x799f('0xe')]()[_0x799f('0x3f')](_0x474356)['from'](_0x799f('0x2b'))['join'](_0x799f('0x33'),null,'cm_contacts.id\x20=\x20cm_hopper.ContactId')[_0x799f('0x35')]('cm_contact_has_items',null,_0x799f('0x4c'))[_0x799f('0x12')](_0x799f('0x4d'),_0x36fb4e)[_0x799f('0x12')](_0x799f('0x38'),NOW))[_0x799f('0x3c')]();}function insertCmContact(_0x3ca082,_0x3a11cf,_0x56f33b,_0x13b1fd){var _0x3e7576=_[_0x799f('0x4e')](_[_0x799f('0x4f')](_0x13b1fd),[_0x799f('0x2d'),'CompanyId','createdAt',_0x799f('0x2f'),_0x799f('0x50')]);return squel['insert']()['into']('cm_contacts')[_0x799f('0x44')](_0x3e7576,squel[_0x799f('0xe')]()[_0x799f('0x3f')](_0x3e7576)['from'](_0x3a11cf)[_0x799f('0x12')]('('+_0x56f33b['join'](',')+')\x20NOT\x20IN\x20?',squel['select']()[_0x799f('0x3f')](_0x56f33b)['from'](_0x799f('0x33'))[_0x799f('0x12')](_0x799f('0x51'),_0x3ca082)[_0x799f('0x12')]('deletedAt\x20IS\x20NULL'))['where'](_0x799f('0x52'),squel['select']()['field']('MIN(id)',_0x799f('0x53'))[_0x799f('0x11')](_0x3a11cf)['group'](_0x56f33b[_0x799f('0x35')](','))))[_0x799f('0x3c')]();}function handleStop(){logger[_0x799f('0x54')](_0x799f('0x55'));stopped=!![];}function handleUncaughtException(_0x23943d){logger['error'](_0x23943d['message']);process[_0x799f('0x56')](0x1);}function handleError(_0x59d330,_0x58e8ad){stats[_0x799f('0x57')][_0x799f('0x19')]({'name':_0x58e8ad['code'],'message':_0x58e8ad['message'],'row':_0x59d330});}function handleQuery(_0x4a1a9c){logger['info'](_0x4a1a9c);return db[_0x799f('0x58')]['query'](_0x4a1a9c)[_0x799f('0x59')](function(_0x32291c){results[_0x799f('0x19')](_0x32291c);})[_0x799f('0x5a')](function(_0x1ba40b){logger['error'](_0x1ba40b[_0x799f('0x5b')]);});}function updateTzCampaigns(_0x151332){return new Promise(function(_0x319bfe,_0x2e40c6){var _0x44c63c=squel[_0x799f('0xe')]()[_0x799f('0x3f')]([_0x799f('0x5c'),_0x799f('0x5d')])[_0x799f('0x11')](_0x799f('0x5e'))[_0x799f('0x35')](_0x799f('0x5f'),null,_0x799f('0x60'))[_0x799f('0x12')]('campaigns_has_cm_lists.CmListId='+_0x151332);db[_0x799f('0x58')]['query'](_0x44c63c[_0x799f('0x3c')]())[_0x799f('0x59')](function(_0x4600b9){var _0x2ad685=[];for(var _0xd577a0=0x0;_0xd577a0<_0x4600b9['length'];_0xd577a0++){_0x2ad685['push'](getTimezoneData(_0x4600b9[_0xd577a0],tmp_campaigns));}BPromise[_0x799f('0x1a')](_0x2ad685)[_0x799f('0x17')](function(){_0x319bfe({'val':0x1});});})[_0x799f('0x5a')](function(_0x4adae8){logger[_0x799f('0x61')](_0x4adae8['message']);_0x319bfe({'val':0x0});});});}function updateTzVoiceQueues(_0x10bf22){return new Promise(function(_0x4b0563,_0x3f41d9){var _0x55579a=squel[_0x799f('0xe')]()[_0x799f('0x3f')]([_0x799f('0x62'),'voice_queues.dialTimezone'])[_0x799f('0x11')]('voice_queues')[_0x799f('0x35')]('voice_queues_has_cm_lists',null,_0x799f('0x63'))[_0x799f('0x12')]('voice_queues_has_cm_lists.CmListId='+_0x10bf22);db[_0x799f('0x58')][_0x799f('0x64')](_0x55579a[_0x799f('0x3c')]())['spread'](function(_0x2a7fbb){var _0xf2a5a4=[];for(var _0x517a70=0x0;_0x517a70<_0x2a7fbb[_0x799f('0x18')];_0x517a70++){_0xf2a5a4[_0x799f('0x19')](getTimezoneData(_0x2a7fbb[_0x517a70],tmp_voice_queues));}BPromise[_0x799f('0x1a')](_0xf2a5a4)['then'](function(){_0x4b0563({'val':0x1});});})['catch'](function(_0x5dbaae){logger['error'](_0x5dbaae[_0x799f('0x5b')]);_0x4b0563({'val':0x0});});});}function getTimezoneData(_0x418b31,_0x5bd62c){return new Promise(function(_0x4d54aa,_0x2a88dc){var _0x391544=shared[_0x799f('0x65')];var _0xb93c7d=_0x391544[_0x418b31[_0x799f('0x66')]];if(_['isNil'](_0xb93c7d)){_0x4d54aa({'ret':0x1});}else{var _0x487162=_0xb93c7d[_0x799f('0x67')];var _0x539ce8=squel[_0x799f('0x29')]()[_0x799f('0x2a')](_0x5bd62c)[_0x799f('0x68')]('id',_0x418b31['id'])[_0x799f('0x68')](_0x799f('0x69'),_0x487162)['set'](_0x799f('0x66'),_0x418b31[_0x799f('0x66')])[_0x799f('0x3c')]();return db[_0x799f('0x58')]['query'](_0x539ce8)[_0x799f('0x59')](function(_0x4a7981){_0x4d54aa({'ret':0x1});})[_0x799f('0x5a')](function(_0x2acef4){logger[_0x799f('0x61')](_0x2acef4[_0x799f('0x5b')]);_0x2a88dc({'ret':0x1});});}});}function handleTZQuery(_0x486e01){logger[_0x799f('0x54')](_0x486e01);return db[_0x799f('0x58')]['query'](_0x486e01)['spread'](function(_0x43752e){})[_0x799f('0x5a')](function(_0x246c7e){logger[_0x799f('0x61')](_0x246c7e[_0x799f('0x5b')]);});}function main(_0x59d87c,_0x1505dc,_0x465057,_0x21f8ce){logger['info'](_0x799f('0x6a'),_0x59d87c,JSON['stringify'](_0x1505dc));process[_0x799f('0x6b')](_0x799f('0x6c'));var _0x40e1bd=_0x1505dc[_0x799f('0x6d')];var _0x2ac3ab=_[_0x799f('0x6e')](_0x40e1bd);var _0x1ff895=_0x1505dc[_0x799f('0x6f')];var _0x540a49=path['join'](config[_0x799f('0x70')],'server/files/tmp',_0x1ff895+_0x799f('0x71'));hasTZ=_[_0x799f('0x4f')](_0x40e1bd)['includes'](_0x799f('0x66'));var _0xb5a1b1=_[_0x799f('0x4f')](_0x40e1bd)[_0x799f('0x35')]();logger[_0x799f('0x54')](_0x799f('0x72'),_0xb5a1b1);db[_0x799f('0x73')]['findAll']({'raw':!![],'attributes':['id',_0x799f('0x74')]})[_0x799f('0x17')](function(_0x23ab5c){for(var _0x398ad4=0x0;_0x398ad4<_0x23ab5c['length'];_0x398ad4++){if(_0x23ab5c[_0x398ad4][_0x799f('0x74')]in _0x40e1bd){contactItemTypes[_0x799f('0x19')](_0x23ab5c[_0x398ad4]);delete _0x2ac3ab[_0x23ab5c[_0x398ad4][_0x799f('0x74')]];hasAdditionalPhones=!![];}for(var _0x5b50c6 in _0x40e1bd){if(_0x23ab5c[_0x398ad4][_0x799f('0x74')]+_0x799f('0x75')===_0x5b50c6){phoneDescriptions[_0x799f('0x19')]({'itemTypeId':_0x23ab5c[_0x398ad4]['id'],'description':_0x5b50c6});delete _0x2ac3ab[_0x5b50c6];}}}if(hasAdditionalPhones)_0x2ac3ab[_0x799f('0x16')]='';var _0x37ffd3=_[_0x799f('0x4f')](_0x2ac3ab)[_0x799f('0x35')]();logger[_0x799f('0x54')](_0x799f('0x72'),_0x37ffd3);fs[_0x799f('0x76')](_0x540a49,_0x37ffd3+'\x0a');Papa['parse'](fs[_0x799f('0x77')](_0x59d87c),{'header':!![],'skipEmptyLines':!![],'step':function(_0x160519,_0x3f121a){try{for(var _0x4688d3=0x0,_0x381113=[];_0x4688d3<_0x160519['data'][_0x799f('0x18')];_0x4688d3++){stats[_0x799f('0x78')]+=0x1;if(_0x160519[_0x799f('0x57')][_0x4688d3]){handleError(_0x160519[_0x799f('0x79')][_0x4688d3],_0x160519[_0x799f('0x57')][_0x4688d3]);}else{var _0xe8036b=[];var _0x85f3e8=[];var _0x8cc6cd={};for(var _0x19df7a in _0x40e1bd){let _0x3cbca6=contactItemTypes[_0x799f('0x7a')](_0x390cf2=>_0x390cf2[_0x799f('0x74')]===_0x19df7a);let _0x17a231=contactItemTypes[_0x799f('0x7a')](_0x2d3c3a=>_0x2d3c3a[_0x799f('0x74')]+_0x799f('0x75')===_0x19df7a);if(_[_0x799f('0x7b')](_0x3cbca6)&&_['isNil'](_0x17a231)){if(_0x40e1bd[_0x799f('0x7c')](_0x19df7a)){if(_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x19df7a]]){var _0x585996=_[_0x799f('0x7d')](_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x19df7a]][_0x799f('0x7e')](/"/g,'\x27'));switch(_0x19df7a){case _0x799f('0x45'):var _0x48a2b4=moment(_0x585996,_0x799f('0xd'),!![]);if(_0x48a2b4[_0x799f('0x7f')]()){_0x381113['push']('\x22'+_0x585996+'\x22');}else{_0xe8036b[_0x799f('0x19')](_0x799f('0x80'));}break;case _0x799f('0x30'):var _0x242137=parseInt(_0x585996);_0x585996=_['isNaN'](_0x242137)||_0x242137<0x0||_0x242137>0x4?_0x21f8ce?0x3:0x2:_0x242137;_0x381113[_0x799f('0x19')]('\x22'+_0x585996+'\x22');break;case _0x799f('0x31'):var _0x45c994=parseInt(_0x585996);if(_[_0x799f('0x81')](_0x45c994)&&_[_0x799f('0x82')](_0x465057,_0x45c994)){_0x381113['push']('\x22'+_0x45c994+'\x22');}else{_0xe8036b[_0x799f('0x19')](_0x799f('0x83'));}break;case _0x799f('0x84'):if(isEmail(_0x585996)){_0x381113[_0x799f('0x19')]('\x22'+_0x585996+'\x22');}else{_0xe8036b[_0x799f('0x19')](_0x799f('0x85'));}break;case'dateOfBirth':var _0x25b42d=moment(_0x585996,_0x799f('0x86'),!![]);if(_0x25b42d[_0x799f('0x7f')]()){_0x381113['push']('\x22'+_0x585996+'\x22');}else{_0xe8036b['push']('dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)');}break;case'dialTimezone':var _0x4bd71c=shared['timezones'];var _0x5dafbb=_0x4bd71c[_0x585996];if(!_[_0x799f('0x7b')](_0x5dafbb)){var _0x5b0545=_0x5dafbb[_0x799f('0x67')];_0x381113['push']('\x22'+_0x585996+'\x22');_0x381113['push']('\x22'+_0x5b0545+'\x22');}break;default:_0x381113[_0x799f('0x19')]('\x22'+_0x585996+'\x22');}}else{switch(_0x19df7a){case _0x799f('0x87'):case'phone':_0xe8036b['push'](_0x19df7a+'\x20not\x20specified');break;default:_0x381113[_0x799f('0x19')]('\x22\x22');}}}}else{var _0x51257e='';if(!_[_0x799f('0x7b')](_0x3cbca6)){if(!_0x8cc6cd['hasOwnProperty'](_0x3cbca6['id'])){if(!_[_0x799f('0x7b')](_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x19df7a]])){var _0x585996=_[_0x799f('0x7d')](_0x160519['data'][_0x4688d3][_0x40e1bd[_0x19df7a]][_0x799f('0x7e')](/"/g,'\x27'));var _0x4a5be1=phoneDescriptions['find'](_0x275da4=>_0x275da4[_0x799f('0x88')]===_0x3cbca6['id']);if(!_[_0x799f('0x7b')](_0x4a5be1)){var _0x116889=_[_0x799f('0x7d')](_0x160519[_0x799f('0x79')][_0x4688d3][_0x40e1bd[_0x4a5be1[_0x799f('0x89')]]][_0x799f('0x7e')](/"/g,'\x27'));if(!_['isNil'](_0x116889))_0x585996=_0x585996+'§'+_0x116889;}if(_0x51257e=='')_0x51257e=_0x585996;else _0x51257e+='|'+_0x585996;}_0x85f3e8[_0x799f('0x19')](_0x3cbca6['id']+':'+_0x51257e);_0x8cc6cd[_0x3cbca6['id']]=0x1;}}}}if(hasAdditionalPhones){_0x381113[_0x799f('0x19')]('\x22'+_0x85f3e8[_0x799f('0x35')](';')+'\x22');}if(_0xe8036b[_0x799f('0x18')]){handleError(_0x160519[_0x799f('0x79')][_0x4688d3],{'code':_0x799f('0x8a'),'message':_0xe8036b['join']()});}else{fs[_0x799f('0x8b')](_0x540a49,_0x381113[_0x799f('0x35')]()+'\x0a');}_0x381113=[];}if(!(stats['rows']%0xc8)){socket['emit']('contact:import:'+_0x1ff895,stats);stats[_0x799f('0x57')]=[];}}if(stopped){logger[_0x799f('0x54')](_0x799f('0x8c'));_0x3f121a['abort']();}}catch(_0x407ff9){handleError(_0x160519[_0x799f('0x79')][_0x4688d3],{'code':_0x799f('0x8d'),'message':_0x407ff9[_0x799f('0x5b')]});logger['error'](_0x799f('0x8e'),_0x407ff9[_0x799f('0x5b')]);}},'complete':function(){try{var _0x487367=[];var _0x4290c7=[];var _0x5e889d=_0x799f('0x33');if(_0x1505dc[_0x799f('0x8f')]&&_0x1505dc[_0x799f('0x8f')][_0x799f('0x18')]){_0x5e889d=_0x799f('0x90')+_0x1ff895;_0x487367[_0x799f('0x19')](_0x799f('0x91')+_0x5e889d+'\x20LIKE\x20cm_contacts;');}tmp_campaigns=_0x799f('0x92')+_0x1ff895;tmp_voice_queues=_0x799f('0x93')+_0x1ff895;_0x4290c7['push']('CREATE\x20TABLE\x20'+tmp_campaigns+'(id\x20int,dialTimezone\x20varchar(255),offset\x20int);');_0x4290c7['push'](_0x799f('0x91')+tmp_voice_queues+_0x799f('0x94'));BPromise[_0x799f('0x95')](_0x4290c7,handleTZQuery)['then'](function(_0x4355c4){updateTzCampaigns(_0x1505dc[_0x799f('0x2d')])[_0x799f('0x17')](function(_0x426f0d){updateTzVoiceQueues(_0x1505dc[_0x799f('0x2d')])[_0x799f('0x17')](function(_0x3cbd90){if(hasTZ)_0x37ffd3=_0x37ffd3[_0x799f('0x7e')](_0x799f('0x66'),_0x799f('0x96'));var _0x5f0d4e=util[_0x799f('0xc')]('LOAD\x20DATA\x20LOCAL\x20INFILE\x20\x27%s\x27\x20INTO\x20TABLE\x20%s\x20CHARACTER\x20SET\x20UTF8\x20FIELDS\x20TERMINATED\x20BY\x20\x27,\x27\x20ENCLOSED\x20BY\x20\x27\x22\x27\x20LINES\x20TERMINATED\x20BY\x20\x27\x0a\x27\x20IGNORE\x201\x20ROWS\x20(%s)\x20SET\x20id\x20=\x20NULL,\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27',_0x540a49,_0x5e889d,_0x37ffd3,_0x1505dc[_0x799f('0x2d')],_0x1505dc[_0x799f('0x97')]||null,NOW,NOW);if(_[_0x799f('0x7b')](_0x40e1bd['scheduledat'])){_0x5f0d4e+=_0x799f('0x98');}_0x487367['push'](_0x5f0d4e);if(_0x1505dc[_0x799f('0x8f')]&&_0x1505dc['duplicates'][_0x799f('0x18')]){_0x487367[_0x799f('0x19')](insertCmContact(_0x1505dc['ListId'],_0x5e889d,_0x1505dc['duplicates'],_0x40e1bd));_0x487367[_0x799f('0x19')]('DROP\x20TABLE\x20'+_0x5e889d+';');}BPromise['each'](_0x487367,handleQuery)[_0x799f('0x17')](function(_0x120ccf){BPromise[_0x799f('0x1a')]([handleAdditionalPhones()])[_0x799f('0x17')](function(){_0x487367=[];for(var _0x437b17=0x0;_0x437b17<promisesAdditionalPhones[_0x799f('0x18')];_0x437b17++){if(promisesAdditionalPhones[_0x437b17][_0x799f('0x10')]!='§'){_0x487367['push'](createAdditionalPhone(promisesAdditionalPhones[_0x437b17]['contactId'],promisesAdditionalPhones[_0x437b17]['contactTypeId'],promisesAdditionalPhones[_0x437b17][_0x799f('0x10')],promisesAdditionalPhones[_0x437b17][_0x799f('0x99')]));}}BPromise[_0x799f('0x1a')](_0x487367)[_0x799f('0x17')](function(){_0x487367=[];if(hasTZ){_0x487367['push'](insertTzCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9a'),_0x799f('0x9b'),_0x799f('0x9c'),_0x21f8ce,tmp_voice_queues));_0x487367[_0x799f('0x19')](insertTzCmHopperBlack(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9d'),'voice_queues',_0x799f('0x9c')));_0x487367[_0x799f('0x19')](insertTzCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x5f'),_0x799f('0x5e'),_0x799f('0x9e'),_0x21f8ce,tmp_campaigns));_0x487367['push'](insertTzCmHopperBlack(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9f'),_0x799f('0x5e'),'CampaignId'));_0x487367[_0x799f('0x19')](insertCmHopperAdditionalPhones(_0x1505dc[_0x799f('0x2d')]));}else{_0x487367[_0x799f('0x19')](insertCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x9a'),_0x799f('0x9b'),_0x799f('0x9c'),_0x21f8ce));_0x487367[_0x799f('0x19')](insertCmHopperBlack(_0x1505dc[_0x799f('0x2d')],'voice_queues_has_cm_blacklists',_0x799f('0x9b'),'VoiceQueueId'));_0x487367[_0x799f('0x19')](insertCmHopper(_0x1505dc[_0x799f('0x2d')],_0x799f('0x5f'),_0x799f('0x5e'),'CampaignId',_0x21f8ce));_0x487367['push'](insertCmHopperBlack(_0x1505dc['ListId'],_0x799f('0x9f'),_0x799f('0x5e'),'CampaignId'));_0x487367[_0x799f('0x19')](insertCmHopperAdditionalPhones(_0x1505dc[_0x799f('0x2d')]));}_0x487367[_0x799f('0x19')](_0x799f('0xa0')+tmp_campaigns+';');_0x487367[_0x799f('0x19')]('DROP\x20TABLE\x20'+tmp_voice_queues+';');BPromise[_0x799f('0x95')](_0x487367,handleQuery)[_0x799f('0x17')](function(_0x5bb18a){stats[_0x799f('0xa1')]=!![];stats['affectedRows']=_0x1505dc[_0x799f('0x8f')]&&_0x1505dc['duplicates'][_0x799f('0x18')]?results[0x2][_0x799f('0xa2')]:results[0x0][_0x799f('0xa2')];socket[_0x799f('0xa3')](_0x799f('0xa4')+_0x1ff895,stats);fs[_0x799f('0xa5')](_0x59d87c);fs[_0x799f('0xa5')](_0x540a49);process['exit'](0x0);})[_0x799f('0x5a')](function(_0xbd2b5){logger['error'](_0xbd2b5[_0x799f('0x5b')]);process[_0x799f('0x56')](0x1);});});});})['catch'](function(_0x498be6){logger[_0x799f('0x61')](_0x498be6['message']);process[_0x799f('0x56')](0x1);});});});});}catch(_0xc2145e){logger[_0x799f('0x61')](_0x799f('0xa6'),_0xc2145e[_0x799f('0x5b')]);process[_0x799f('0x56')](0x1);}},'error':function(_0x2e3695,_0x297f62,_0x391537,_0x54aee2){throw new Error(_0x54aee2);}});});}function validate(){if(process[_0x799f('0xa7')]&&process[_0x799f('0xa7')][_0x799f('0x18')]<0x4){throw new Error(_0x799f('0xa8'));}var _0x120c41=path[_0x799f('0x35')](config[_0x799f('0x70')],_0x799f('0xa9'),process[_0x799f('0xa7')][0x2]);if(!fs[_0x799f('0xaa')](_0x120c41)){throw new Error(_0x799f('0xab'));}var _0x1709f2={};try{_0x1709f2=JSON[_0x799f('0xac')](process[_0x799f('0xa7')][0x3]);if(!_0x1709f2[_0x799f('0x6d')]){throw new Error(_0x799f('0xad'));}if(!_0x1709f2[_0x799f('0x6d')][_0x799f('0x10')]){throw new Error(_0x799f('0xae'));}if(!_0x1709f2['binding'][_0x799f('0x87')]){throw new Error(_0x799f('0xaf'));}var _0x3f2b00=0x0;if(_0x1709f2[_0x799f('0x6d')]['UserId']){_0x3f2b00=0x1;}if(!_0x1709f2[_0x799f('0x2d')]){throw new Error(_0x799f('0xb0'));}}catch(_0x211b66){throw new Error('body\x20id\x20mandatory');}var _0x51e10a=[];try{_0x51e10a=_[_0x799f('0xb1')](JSON[_0x799f('0xac')](process['argv'][0x4]),'id');}catch(_0x259b9f){logger[_0x799f('0x54')](_0x799f('0xb2'));}main(_0x120c41,_0x1709f2,_0x51e10a,_0x3f2b00);}validate();process['on'](_0x799f('0xb3'),handleStop);process['on']('uncaughtException',handleUncaughtException);
\ No newline at end of file