Built motion from commit 19a84241.|2.5.34
[motion2.git] / server / components / import / cm / csv2.js
index 03adc7f..609e4ae 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8f5a=['cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.updatedAt','cm_contacts.priority','cm_contacts.UserId','insert','into','cm_hopper','fromQuery','ContactId','ListId','createdAt','priority','UserId','recallme','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','.id\x20=\x20','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22onlyIfOpen\x22','\x22always\x22','toString','cm_hopper_black','updatedAt','fields','ListId\x20=\x20?','concat','keys','CompanyId',')\x20NOT\x20IN\x20?','deletedAt\x20IS\x20NULL','id\x20IN\x20?','MIN(id)','min_id','group','info','Received\x20SIGINT','message','exit','errors','push','sequelize','query','spread','catch','error','main','stringify','send','start','binding','root','header','writeFileSync','createReadStream','length','rows','data','trim','replace','scheduledat','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','includes','email','email\x20wrong\x20format','dateOfBirth','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','SystemRow','emit','contact:import:','abort','SystemError','duplicates','cm_contacts_','CREATE\x20TABLE\x20','\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',',\x20scheduledAt\x20=\x20NOW()','DROP\x20TABLE\x20','voice_queues_has_cm_lists','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','campaigns_has_cm_lists','campaigns','CampaignId','each','finish','affectedRows','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','server/files/tmp','existsSync','file\x20doesn\x27t\x20exists','parse','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','No\x20agent\x20available','path','papaparse','util','bluebird','moment','squel','ioredis','../../../mysqldb','../../../config/environment','import','redis','defaults','format','YYYY-MM-DD\x20HH:mm:ss','test','select','field','phone','from','join','\x20=\x20','where','.dialCheckDuplicateType\x20IN\x20(','cm_contacts.phone','cm_contacts.scheduledat'];(function(_0x116e10,_0x317c9f){var _0x34d808=function(_0x3d3af0){while(--_0x3d3af0){_0x116e10['push'](_0x116e10['shift']());}};_0x34d808(++_0x317c9f);}(_0x8f5a,0x6f));var _0xa8f5=function(_0xf95a7a,_0x30114d){_0xf95a7a=_0xf95a7a-0x0;var _0x2b07fe=_0x8f5a[_0xf95a7a];return _0x2b07fe;};'use strict';var fs=require('fs');var path=require(_0xa8f5('0x0'));var _=require('lodash');var Papa=require(_0xa8f5('0x1'));var util=require(_0xa8f5('0x2'));var BPromise=require(_0xa8f5('0x3'));var moment=require(_0xa8f5('0x4'));var squel=require(_0xa8f5('0x5'));var Redis=require(_0xa8f5('0x6'));var db=require(_0xa8f5('0x7'))['db'];var config=require(_0xa8f5('0x8'));var logger=require('../../../config/logger')(_0xa8f5('0x9'));config[_0xa8f5('0xa')]=_[_0xa8f5('0xb')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xa8f5('0xa')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0xa8f5('0xc')](_0xa8f5('0xd'));function isEmail(_0x133e48){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))*$/[_0xa8f5('0xe')](_0x133e48);}function selectNotIn(_0x33255c,_0x2267d3,_0x9fb19f,_0x160f51,_0x24368a){return squel[_0xa8f5('0xf')]()[_0xa8f5('0x10')](_0xa8f5('0x11'))[_0xa8f5('0x12')](_0x160f51)[_0xa8f5('0x13')](_0x2267d3,null,_0x2267d3+'.id\x20=\x20'+_0x160f51+'.'+_0x9fb19f)['where'](_0x160f51+'.'+_0x9fb19f+_0xa8f5('0x14')+_0x33255c+'.'+_0x9fb19f)[_0xa8f5('0x15')](_0x2267d3+_0xa8f5('0x16')+_0x24368a[_0xa8f5('0x13')]()+')');}function insertCmHopper(_0x465988,_0x3d3239,_0x129002,_0x3d838a,_0x557cd5){var _0x40341b=[_0xa8f5('0x17'),_0xa8f5('0x18'),_0xa8f5('0x19'),_0xa8f5('0x1a'),_0x3d3239+'.'+_0x3d838a,_0xa8f5('0x1b'),_0xa8f5('0x1c'),_0xa8f5('0x1d'),_0xa8f5('0x1e'),'\x22'+_0x557cd5+'\x22'];return squel[_0xa8f5('0x1f')]()[_0xa8f5('0x20')](_0xa8f5('0x21'))[_0xa8f5('0x22')]([_0xa8f5('0x11'),'scheduledat',_0xa8f5('0x23'),_0xa8f5('0x24'),_0x3d838a,_0xa8f5('0x25'),'updatedAt',_0xa8f5('0x26'),_0xa8f5('0x27'),_0xa8f5('0x28')],squel['select']()['fields'](_0x40341b)[_0xa8f5('0x12')](_0x3d3239)[_0xa8f5('0x13')](_0xa8f5('0x29'),null,_0xa8f5('0x2a')+_0x3d3239+_0xa8f5('0x2b'))[_0xa8f5('0x13')](_0x129002,null,_0x129002+_0xa8f5('0x2c')+_0x3d3239+'.'+_0x3d838a)[_0xa8f5('0x15')](_0x3d3239+_0xa8f5('0x2d'),_0x465988)[_0xa8f5('0x15')](_0xa8f5('0x2e'),NOW)[_0xa8f5('0x15')](_0xa8f5('0x2f'),selectNotIn(_0x3d3239,_0x129002,_0x3d838a,_0xa8f5('0x21'),['\x22always\x22',_0xa8f5('0x30')]))[_0xa8f5('0x15')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',selectNotIn(_0x3d3239,_0x129002,_0x3d838a,_0xa8f5('0x21'),[_0xa8f5('0x31')])))[_0xa8f5('0x32')]();}function insertCmHopperBlack(_0x3fe14d,_0x503096,_0x11a812,_0xbf7d9b){var _0x564c1e=[_0xa8f5('0x17'),_0xa8f5('0x19'),_0xa8f5('0x1a'),_0x503096+'.'+_0xbf7d9b,_0xa8f5('0x1b'),'cm_contacts.updatedAt'];return squel[_0xa8f5('0x1f')]()[_0xa8f5('0x20')](_0xa8f5('0x33'))[_0xa8f5('0x22')]([_0xa8f5('0x11'),_0xa8f5('0x23'),'ListId',_0xbf7d9b,_0xa8f5('0x25'),_0xa8f5('0x34')],squel[_0xa8f5('0xf')]()[_0xa8f5('0x35')](_0x564c1e)[_0xa8f5('0x12')](_0x503096)[_0xa8f5('0x13')]('cm_contacts',null,_0xa8f5('0x2a')+_0x503096+_0xa8f5('0x2b'))[_0xa8f5('0x13')](_0x11a812,null,_0x11a812+'.id\x20=\x20'+_0x503096+'.'+_0xbf7d9b)[_0xa8f5('0x15')](_0x503096+_0xa8f5('0x2d'),_0x3fe14d)[_0xa8f5('0x15')](_0xa8f5('0x2e'),NOW)[_0xa8f5('0x15')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel[_0xa8f5('0xf')]()[_0xa8f5('0x10')]('phone')[_0xa8f5('0x12')](_0xa8f5('0x33'))[_0xa8f5('0x15')](_0xa8f5('0x36'),_0x3fe14d)['where'](_0xbf7d9b+'\x20=\x20?',_0x503096+'.'+_0xbf7d9b)))[_0xa8f5('0x32')]();}function insertCmContact(_0x20ccdf,_0x3c4dc1,_0x51914d,_0x307aa6){var _0x42344a=_[_0xa8f5('0x37')](_[_0xa8f5('0x38')](_0x307aa6),[_0xa8f5('0x24'),_0xa8f5('0x39'),_0xa8f5('0x25'),_0xa8f5('0x34')]);return squel['insert']()['into'](_0xa8f5('0x29'))[_0xa8f5('0x22')](_0x42344a,squel['select']()[_0xa8f5('0x35')](_0x42344a)[_0xa8f5('0x12')](_0x3c4dc1)['where']('('+_0x51914d[_0xa8f5('0x13')](',')+_0xa8f5('0x3a'),squel[_0xa8f5('0xf')]()['fields'](_0x51914d)[_0xa8f5('0x12')]('cm_contacts')[_0xa8f5('0x15')](_0xa8f5('0x36'),_0x20ccdf)[_0xa8f5('0x15')](_0xa8f5('0x3b')))['where'](_0xa8f5('0x3c'),squel[_0xa8f5('0xf')]()[_0xa8f5('0x10')](_0xa8f5('0x3d'),_0xa8f5('0x3e'))[_0xa8f5('0x12')](_0x3c4dc1)[_0xa8f5('0x3f')](_0x51914d[_0xa8f5('0x13')](','))))['toString']();}function handleStop(){logger[_0xa8f5('0x40')](_0xa8f5('0x41'));stopped=!![];}function handleUncaughtException(_0x3a5370){logger['error'](_0x3a5370[_0xa8f5('0x42')]);process[_0xa8f5('0x43')](0x1);}function handleError(_0x2703fb,_0x3b4b9f){stats[_0xa8f5('0x44')][_0xa8f5('0x45')]({'name':_0x3b4b9f['code'],'message':_0x3b4b9f['message'],'row':_0x2703fb});}function handleQuery(_0x4f90d7){logger[_0xa8f5('0x40')](_0x4f90d7);return db[_0xa8f5('0x46')][_0xa8f5('0x47')](_0x4f90d7)[_0xa8f5('0x48')](function(_0x57119a){results[_0xa8f5('0x45')](_0x57119a);})[_0xa8f5('0x49')](function(_0x590061){logger[_0xa8f5('0x4a')](_0x590061[_0xa8f5('0x42')]);});}function main(_0x1e29f1,_0x2684e4,_0x3f1e72,_0x41ba86){logger[_0xa8f5('0x40')](_0xa8f5('0x4b'),_0x1e29f1,JSON[_0xa8f5('0x4c')](_0x2684e4));process[_0xa8f5('0x4d')](_0xa8f5('0x4e'));var _0x3b5b9d=_0x2684e4[_0xa8f5('0x4f')];var _0x4c7655=_0x2684e4['socket_timestamp'];var _0x4cd5=path['join'](config[_0xa8f5('0x50')],'server/files/tmp',_0x4c7655+'.csv');var _0x3c6b61=_[_0xa8f5('0x38')](_0x3b5b9d)[_0xa8f5('0x13')]();logger[_0xa8f5('0x40')](_0xa8f5('0x51'),_0x3c6b61);fs[_0xa8f5('0x52')](_0x4cd5,_0x3c6b61+'\x0a');Papa['parse'](fs[_0xa8f5('0x53')](_0x1e29f1),{'header':!![],'skipEmptyLines':!![],'step':function(_0x48b4d3,_0xb8bc73){try{for(var _0x5bc81f=0x0,_0x6f5734=[];_0x5bc81f<_0x48b4d3['data'][_0xa8f5('0x54')];_0x5bc81f++){stats[_0xa8f5('0x55')]+=0x1;if(_0x48b4d3[_0xa8f5('0x44')][_0x5bc81f]){handleError(_0x48b4d3['data'][_0x5bc81f],_0x48b4d3[_0xa8f5('0x44')][_0x5bc81f]);}else{var _0x3e2473=[];for(var _0x280406 in _0x3b5b9d){if(_0x3b5b9d['hasOwnProperty'](_0x280406)){if(_0x48b4d3[_0xa8f5('0x56')][_0x5bc81f][_0x3b5b9d[_0x280406]]){var _0x69f85b=_[_0xa8f5('0x57')](_0x48b4d3['data'][_0x5bc81f][_0x3b5b9d[_0x280406]][_0xa8f5('0x58')](/"/g,'\x27'));switch(_0x280406){case _0xa8f5('0x59'):var _0x39be51=moment(_0x69f85b,'YYYY-MM-DD\x20HH:mm:ss',!![]);if(_0x39be51[_0xa8f5('0x5a')]()){_0x6f5734[_0xa8f5('0x45')]('\x22'+_0x69f85b+'\x22');}else{_0x3e2473[_0xa8f5('0x45')](_0xa8f5('0x5b'));}break;case _0xa8f5('0x26'):var _0x143213=parseInt(_0x69f85b);_0x69f85b=_[_0xa8f5('0x5c')](_0x143213)||_0x143213<0x0||_0x143213>0x4?_0x41ba86?0x3:0x2:_0x143213;_0x6f5734[_0xa8f5('0x45')]('\x22'+_0x69f85b+'\x22');break;case _0xa8f5('0x27'):var _0x35664b=parseInt(_0x69f85b);if(_[_0xa8f5('0x5d')](_0x35664b)&&_[_0xa8f5('0x5e')](_0x3f1e72,_0x35664b)){_0x6f5734[_0xa8f5('0x45')]('\x22'+_0x35664b+'\x22');}else{_0x3e2473[_0xa8f5('0x45')]('agent\x20not\x20exists');}break;case _0xa8f5('0x5f'):if(isEmail(_0x69f85b)){_0x6f5734[_0xa8f5('0x45')]('\x22'+_0x69f85b+'\x22');}else{_0x3e2473['push'](_0xa8f5('0x60'));}break;case _0xa8f5('0x61'):var _0x546c59=moment(_0x69f85b,'YYYY-MM-DD',!![]);if(_0x546c59[_0xa8f5('0x5a')]()){_0x6f5734['push']('\x22'+_0x69f85b+'\x22');}else{_0x3e2473[_0xa8f5('0x45')](_0xa8f5('0x62'));}break;default:_0x6f5734[_0xa8f5('0x45')]('\x22'+_0x69f85b+'\x22');}}else{switch(_0x280406){case _0xa8f5('0x63'):case _0xa8f5('0x11'):_0x3e2473[_0xa8f5('0x45')](_0x280406+'\x20not\x20specified');break;default:_0x6f5734[_0xa8f5('0x45')]('\x22\x22');}}}}if(_0x3e2473[_0xa8f5('0x54')]){handleError(_0x48b4d3['data'][_0x5bc81f],{'code':_0xa8f5('0x64'),'message':_0x3e2473['join']()});}else{fs['appendFileSync'](_0x4cd5,_0x6f5734[_0xa8f5('0x13')]()+'\x0a');}_0x6f5734=[];}if(!(stats[_0xa8f5('0x55')]%0xc8)){socket[_0xa8f5('0x65')](_0xa8f5('0x66')+_0x4c7655,stats);stats[_0xa8f5('0x44')]=[];}}if(stopped){logger['info']('Abort\x20parser');_0xb8bc73[_0xa8f5('0x67')]();}}catch(_0x5095fb){handleError(_0x48b4d3['data'][_0x5bc81f],{'code':_0xa8f5('0x68'),'message':_0x5095fb[_0xa8f5('0x42')]});logger[_0xa8f5('0x4a')]('step',_0x5095fb[_0xa8f5('0x42')]);}},'complete':function(){try{var _0x55b612=[];var _0x3a161f=_0xa8f5('0x29');if(_0x2684e4[_0xa8f5('0x69')]&&_0x2684e4[_0xa8f5('0x69')][_0xa8f5('0x54')]){_0x3a161f=_0xa8f5('0x6a')+_0x4c7655;_0x55b612[_0xa8f5('0x45')](_0xa8f5('0x6b')+_0x3a161f+_0xa8f5('0x6c'));}var _0x31dffd=util[_0xa8f5('0xc')](_0xa8f5('0x6d'),_0x4cd5,_0x3a161f,_0x3c6b61,_0x2684e4[_0xa8f5('0x24')],_0x2684e4[_0xa8f5('0x39')]||null,NOW,NOW);if(_['isNil'](_0x3b5b9d[_0xa8f5('0x59')])){_0x31dffd+=_0xa8f5('0x6e');}_0x55b612[_0xa8f5('0x45')](_0x31dffd);if(_0x2684e4['duplicates']&&_0x2684e4['duplicates']['length']){_0x55b612['push'](insertCmContact(_0x2684e4[_0xa8f5('0x24')],_0x3a161f,_0x2684e4[_0xa8f5('0x69')],_0x3b5b9d));_0x55b612[_0xa8f5('0x45')](_0xa8f5('0x6f')+_0x3a161f+';');}_0x55b612['push'](insertCmHopper(_0x2684e4['ListId'],_0xa8f5('0x70'),_0xa8f5('0x71'),_0xa8f5('0x72'),_0x41ba86));_0x55b612[_0xa8f5('0x45')](insertCmHopperBlack(_0x2684e4[_0xa8f5('0x24')],_0xa8f5('0x73'),_0xa8f5('0x71'),_0xa8f5('0x72')));_0x55b612[_0xa8f5('0x45')](insertCmHopper(_0x2684e4[_0xa8f5('0x24')],_0xa8f5('0x74'),_0xa8f5('0x75'),_0xa8f5('0x76'),_0x41ba86));_0x55b612[_0xa8f5('0x45')](insertCmHopperBlack(_0x2684e4[_0xa8f5('0x24')],'campaigns_has_cm_blacklists',_0xa8f5('0x75'),_0xa8f5('0x76')));BPromise[_0xa8f5('0x77')](_0x55b612,handleQuery)['then'](function(_0x5b5a42){stats[_0xa8f5('0x78')]=!![];stats[_0xa8f5('0x79')]=_0x2684e4['duplicates']&&_0x2684e4[_0xa8f5('0x69')][_0xa8f5('0x54')]?results[0x2]['affectedRows']:results[0x0][_0xa8f5('0x79')];socket[_0xa8f5('0x65')](_0xa8f5('0x66')+_0x4c7655,stats);fs['unlink'](_0x1e29f1);fs[_0xa8f5('0x7a')](_0x4cd5);process[_0xa8f5('0x43')](0x0);})['catch'](function(_0x5990c6){logger[_0xa8f5('0x4a')](_0x5990c6[_0xa8f5('0x42')]);process[_0xa8f5('0x43')](0x1);});}catch(_0x68bfd9){logger[_0xa8f5('0x4a')](_0xa8f5('0x7b'),_0x68bfd9[_0xa8f5('0x42')]);process[_0xa8f5('0x43')](0x1);}},'error':function(_0xb41e82,_0x289937,_0x57a091,_0x191220){throw new Error(_0x191220);}});}function validate(){if(process[_0xa8f5('0x7c')]&&process['argv'][_0xa8f5('0x54')]<0x4){throw new Error(_0xa8f5('0x7d'));}var _0x4f4a0c=path[_0xa8f5('0x13')](config[_0xa8f5('0x50')],_0xa8f5('0x7e'),process[_0xa8f5('0x7c')][0x2]);if(!fs[_0xa8f5('0x7f')](_0x4f4a0c)){throw new Error(_0xa8f5('0x80'));}var _0x49edf3={};try{_0x49edf3=JSON[_0xa8f5('0x81')](process[_0xa8f5('0x7c')][0x3]);if(!_0x49edf3[_0xa8f5('0x4f')]){throw new Error('binding\x20doesn\x27t\x20exists');}if(!_0x49edf3[_0xa8f5('0x4f')][_0xa8f5('0x11')]){throw new Error(_0xa8f5('0x82'));}if(!_0x49edf3[_0xa8f5('0x4f')]['firstName']){throw new Error(_0xa8f5('0x83'));}var _0x4fdea4=0x0;if(_0x49edf3['binding'][_0xa8f5('0x27')]){_0x4fdea4=0x1;}if(!_0x49edf3[_0xa8f5('0x24')]){throw new Error(_0xa8f5('0x84'));}}catch(_0x2f09b6){throw new Error(_0xa8f5('0x85'));}var _0xc584ec=[];try{_0xc584ec=_[_0xa8f5('0x86')](JSON[_0xa8f5('0x81')](process[_0xa8f5('0x7c')][0x4]),'id');}catch(_0x3da198){logger[_0xa8f5('0x40')](_0xa8f5('0x87'));}main(_0x4f4a0c,_0x49edf3,_0xc584ec,_0x4fdea4);}validate();process['on']('SIGINT',handleStop);process['on']('uncaughtException',handleUncaughtException);
\ No newline at end of file
+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