Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / components / import / cm / csv2.js
index 8500e97..94d89b3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x14e1=['unlink','complete','argv','root','existsSync','file\x20doesn\x27t\x20exists','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','No\x20agent\x20available','SIGINT','uncaughtException','path','lodash','papaparse','util','moment','squel','ioredis','../../../mysqldb','../../../config/environment','../../../config/logger','import','defaults','redis','format','YYYY-MM-DD\x20HH:mm:ss','test','field','phone','from','.id\x20=\x20','\x20=\x20','where','.dialCheckDuplicateType\x20IN\x20(','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.priority','cm_contacts.UserId','insert','into','cm_hopper','fromQuery','scheduledat','ContactId','ListId','updatedAt','priority','UserId','recallme','select','fields','join','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','\x22always\x22','\x22onlyIfOpen\x22','cm_contacts.phone\x20NOT\x20IN\x20(?)','toString','cm_hopper_black','createdAt','ListId\x20=\x20?','\x20=\x20?','concat','keys','CompanyId','deletedAt\x20IS\x20NULL','id\x20IN\x20?','MIN(id)','min_id','group','info','Received\x20SIGINT','error','message','exit','errors','push','code','sequelize','query','spread','catch','main','start','binding','socket_timestamp','server/files/tmp','.csv','header','writeFileSync','parse','data','length','rows','hasOwnProperty','trim','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','includes','agent\x20not\x20exists','email','email\x20wrong\x20format','YYYY-MM-DD','firstName','\x20not\x20specified','appendFileSync','emit','contact:import:','Abort\x20parser','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','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','isNil','DROP\x20TABLE\x20','voice_queues_has_cm_lists','VoiceQueueId','voice_queues_has_cm_blacklists','voice_queues','campaigns_has_cm_lists','campaigns','CampaignId','campaigns_has_cm_blacklists','then','finish','affectedRows'];(function(_0x215525,_0x26fc83){var _0x1b98c3=function(_0x4056ab){while(--_0x4056ab){_0x215525['push'](_0x215525['shift']());}};_0x1b98c3(++_0x26fc83);}(_0x14e1,0x11d));var _0x114e=function(_0x30c94a,_0x34f294){_0x30c94a=_0x30c94a-0x0;var _0x49cf29=_0x14e1[_0x30c94a];return _0x49cf29;};'use strict';var fs=require('fs');var path=require(_0x114e('0x0'));var _=require(_0x114e('0x1'));var Papa=require(_0x114e('0x2'));var util=require(_0x114e('0x3'));var BPromise=require('bluebird');var moment=require(_0x114e('0x4'));var squel=require(_0x114e('0x5'));var Redis=require(_0x114e('0x6'));var db=require(_0x114e('0x7'))['db'];var config=require(_0x114e('0x8'));var logger=require(_0x114e('0x9'))(_0x114e('0xa'));config['redis']=_[_0x114e('0xb')](config[_0x114e('0xc')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x114e('0xc')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0x114e('0xd')](_0x114e('0xe'));function isEmail(_0x2ccaf0){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))*$/[_0x114e('0xf')](_0x2ccaf0);}function selectNotIn(_0x253b81,_0x49ae8d,_0x498ea9,_0x1b328e,_0x21959b){return squel['select']()[_0x114e('0x10')](_0x114e('0x11'))[_0x114e('0x12')](_0x1b328e)['join'](_0x49ae8d,null,_0x49ae8d+_0x114e('0x13')+_0x1b328e+'.'+_0x498ea9)['where'](_0x1b328e+'.'+_0x498ea9+_0x114e('0x14')+_0x253b81+'.'+_0x498ea9)[_0x114e('0x15')](_0x49ae8d+_0x114e('0x16')+_0x21959b['join']()+')');}function insertCmHopper(_0x53c4f4,_0x31dabf,_0x4abb32,_0x19b1f3,_0x474e35){var _0x2a4ca2=['cm_contacts.phone',_0x114e('0x17'),_0x114e('0x18'),_0x114e('0x19'),_0x31dabf+'.'+_0x19b1f3,_0x114e('0x1a'),'cm_contacts.updatedAt',_0x114e('0x1b'),_0x114e('0x1c'),'\x22'+_0x474e35+'\x22'];return squel[_0x114e('0x1d')]()[_0x114e('0x1e')](_0x114e('0x1f'))[_0x114e('0x20')]([_0x114e('0x11'),_0x114e('0x21'),_0x114e('0x22'),_0x114e('0x23'),_0x19b1f3,'createdAt',_0x114e('0x24'),_0x114e('0x25'),_0x114e('0x26'),_0x114e('0x27')],squel[_0x114e('0x28')]()[_0x114e('0x29')](_0x2a4ca2)[_0x114e('0x12')](_0x31dabf)[_0x114e('0x2a')](_0x114e('0x2b'),null,_0x114e('0x2c')+_0x31dabf+_0x114e('0x2d'))['join'](_0x4abb32,null,_0x4abb32+_0x114e('0x13')+_0x31dabf+'.'+_0x19b1f3)[_0x114e('0x15')](_0x31dabf+_0x114e('0x2e'),_0x53c4f4)['where'](_0x114e('0x2f'),NOW)[_0x114e('0x15')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',selectNotIn(_0x31dabf,_0x4abb32,_0x19b1f3,_0x114e('0x1f'),[_0x114e('0x30'),_0x114e('0x31')]))[_0x114e('0x15')](_0x114e('0x32'),selectNotIn(_0x31dabf,_0x4abb32,_0x19b1f3,_0x114e('0x1f'),[_0x114e('0x30')])))[_0x114e('0x33')]();}function insertCmHopperBlack(_0x781bf1,_0x49ed9d,_0x4dfab9,_0x4b97ea){var _0x4e8ff1=['cm_contacts.phone',_0x114e('0x18'),'cm_contacts.ListId',_0x49ed9d+'.'+_0x4b97ea,_0x114e('0x1a'),'cm_contacts.updatedAt'];return squel['insert']()[_0x114e('0x1e')](_0x114e('0x34'))[_0x114e('0x20')]([_0x114e('0x11'),_0x114e('0x22'),_0x114e('0x23'),_0x4b97ea,_0x114e('0x35'),_0x114e('0x24')],squel[_0x114e('0x28')]()[_0x114e('0x29')](_0x4e8ff1)[_0x114e('0x12')](_0x49ed9d)[_0x114e('0x2a')](_0x114e('0x2b'),null,_0x114e('0x2c')+_0x49ed9d+'.CmListId')[_0x114e('0x2a')](_0x4dfab9,null,_0x4dfab9+_0x114e('0x13')+_0x49ed9d+'.'+_0x4b97ea)[_0x114e('0x15')](_0x49ed9d+'.CmListId\x20=\x20?',_0x781bf1)[_0x114e('0x15')](_0x114e('0x2f'),NOW)[_0x114e('0x15')](_0x114e('0x32'),squel[_0x114e('0x28')]()['field'](_0x114e('0x11'))[_0x114e('0x12')](_0x114e('0x34'))[_0x114e('0x15')](_0x114e('0x36'),_0x781bf1)[_0x114e('0x15')](_0x4b97ea+_0x114e('0x37'),_0x49ed9d+'.'+_0x4b97ea)))[_0x114e('0x33')]();}function insertCmContact(_0xca01c3,_0x7b62b5,_0x5ba9b7,_0x26cc13){var _0x10fe56=_[_0x114e('0x38')](_[_0x114e('0x39')](_0x26cc13),['ListId',_0x114e('0x3a'),'createdAt',_0x114e('0x24')]);return squel[_0x114e('0x1d')]()[_0x114e('0x1e')](_0x114e('0x2b'))[_0x114e('0x20')](_0x10fe56,squel[_0x114e('0x28')]()[_0x114e('0x29')](_0x10fe56)[_0x114e('0x12')](_0x7b62b5)[_0x114e('0x15')]('('+_0x5ba9b7['join'](',')+')\x20NOT\x20IN\x20?',squel[_0x114e('0x28')]()[_0x114e('0x29')](_0x5ba9b7)[_0x114e('0x12')]('cm_contacts')[_0x114e('0x15')](_0x114e('0x36'),_0xca01c3)[_0x114e('0x15')](_0x114e('0x3b')))[_0x114e('0x15')](_0x114e('0x3c'),squel['select']()['field'](_0x114e('0x3d'),_0x114e('0x3e'))[_0x114e('0x12')](_0x7b62b5)[_0x114e('0x3f')](_0x5ba9b7[_0x114e('0x2a')](','))))[_0x114e('0x33')]();}function handleStop(){logger[_0x114e('0x40')](_0x114e('0x41'));stopped=!![];}function handleUncaughtException(_0xb7ce21){logger[_0x114e('0x42')](_0xb7ce21[_0x114e('0x43')]);process[_0x114e('0x44')](0x1);}function handleError(_0x2ae571,_0x1c34ad){stats[_0x114e('0x45')][_0x114e('0x46')]({'name':_0x1c34ad[_0x114e('0x47')],'message':_0x1c34ad['message'],'row':_0x2ae571});}function handleQuery(_0x157cc0){logger[_0x114e('0x40')](_0x157cc0);return db[_0x114e('0x48')][_0x114e('0x49')](_0x157cc0)[_0x114e('0x4a')](function(_0x47da41){results[_0x114e('0x46')](_0x47da41);})[_0x114e('0x4b')](function(_0x3321c8){logger['error'](_0x3321c8[_0x114e('0x43')]);});}function main(_0x4b5192,_0x11e961,_0x6c3dfd,_0x5bba8f){logger['info'](_0x114e('0x4c'),_0x4b5192,JSON['stringify'](_0x11e961));process['send'](_0x114e('0x4d'));var _0x436dc5=_0x11e961[_0x114e('0x4e')];var _0x1a6959=_0x11e961[_0x114e('0x4f')];var _0x2adf6b=path[_0x114e('0x2a')](config['root'],_0x114e('0x50'),_0x1a6959+_0x114e('0x51'));var _0x11f11a=_['keys'](_0x436dc5)[_0x114e('0x2a')]();logger['info'](_0x114e('0x52'),_0x11f11a);fs[_0x114e('0x53')](_0x2adf6b,_0x11f11a+'\x0a');Papa[_0x114e('0x54')](fs['createReadStream'](_0x4b5192),{'header':!![],'skipEmptyLines':!![],'step':function(_0x65a2d3,_0x10e739){try{for(var _0x16db95=0x0,_0x2c86c4=[];_0x16db95<_0x65a2d3[_0x114e('0x55')][_0x114e('0x56')];_0x16db95++){stats[_0x114e('0x57')]+=0x1;if(_0x65a2d3[_0x114e('0x45')][_0x16db95]){handleError(_0x65a2d3[_0x114e('0x55')][_0x16db95],_0x65a2d3[_0x114e('0x45')][_0x16db95]);}else{var _0x29188c=[];for(var _0xede93f in _0x436dc5){if(_0x436dc5[_0x114e('0x58')](_0xede93f)){if(_0x65a2d3['data'][_0x16db95][_0x436dc5[_0xede93f]]){var _0x35beb0=_[_0x114e('0x59')](_0x65a2d3[_0x114e('0x55')][_0x16db95][_0x436dc5[_0xede93f]]['replace'](/"/g,'\x27'));switch(_0xede93f){case _0x114e('0x21'):var _0x36bb13=moment(_0x35beb0,_0x114e('0xe'),!![]);if(_0x36bb13[_0x114e('0x5a')]()){_0x2c86c4['push']('\x22'+_0x35beb0+'\x22');}else{_0x29188c[_0x114e('0x46')](_0x114e('0x5b'));}break;case'priority':var _0x375443=parseInt(_0x35beb0);_0x35beb0=_[_0x114e('0x5c')](_0x375443)||_0x375443<0x0||_0x375443>0x4?_0x5bba8f?0x3:0x2:_0x375443;_0x2c86c4[_0x114e('0x46')]('\x22'+_0x35beb0+'\x22');break;case _0x114e('0x26'):var _0x506884=parseInt(_0x35beb0);if(_[_0x114e('0x5d')](_0x506884)&&_[_0x114e('0x5e')](_0x6c3dfd,_0x506884)){_0x2c86c4['push']('\x22'+_0x506884+'\x22');}else{_0x29188c['push'](_0x114e('0x5f'));}break;case _0x114e('0x60'):if(isEmail(_0x35beb0)){_0x2c86c4[_0x114e('0x46')]('\x22'+_0x35beb0+'\x22');}else{_0x29188c[_0x114e('0x46')](_0x114e('0x61'));}break;case'dateOfBirth':var _0x5029a2=moment(_0x35beb0,_0x114e('0x62'),!![]);if(_0x5029a2[_0x114e('0x5a')]()){_0x2c86c4[_0x114e('0x46')]('\x22'+_0x35beb0+'\x22');}else{_0x29188c[_0x114e('0x46')]('dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)');}break;default:_0x2c86c4[_0x114e('0x46')]('\x22'+_0x35beb0+'\x22');}}else{switch(_0xede93f){case _0x114e('0x63'):case _0x114e('0x11'):_0x29188c[_0x114e('0x46')](_0xede93f+_0x114e('0x64'));break;default:_0x2c86c4['push']('\x22\x22');}}}}if(_0x29188c[_0x114e('0x56')]){handleError(_0x65a2d3[_0x114e('0x55')][_0x16db95],{'code':'SystemRow','message':_0x29188c[_0x114e('0x2a')]()});}else{fs[_0x114e('0x65')](_0x2adf6b,_0x2c86c4['join']()+'\x0a');}_0x2c86c4=[];}if(!(stats['rows']%0xc8)){socket[_0x114e('0x66')](_0x114e('0x67')+_0x1a6959,stats);stats['errors']=[];}}if(stopped){logger[_0x114e('0x40')](_0x114e('0x68'));_0x10e739['abort']();}}catch(_0x357259){handleError(_0x65a2d3[_0x114e('0x55')][_0x16db95],{'code':'SystemError','message':_0x357259[_0x114e('0x43')]});logger['error'](_0x114e('0x69'),_0x357259[_0x114e('0x43')]);}},'complete':function(){try{var _0x3bdeb2=[];var _0x15155e=_0x114e('0x2b');if(_0x11e961[_0x114e('0x6a')]&&_0x11e961['duplicates'][_0x114e('0x56')]){_0x15155e=_0x114e('0x6b')+_0x1a6959;_0x3bdeb2[_0x114e('0x46')](_0x114e('0x6c')+_0x15155e+'\x20LIKE\x20cm_contacts;');}var _0x520e59=util[_0x114e('0xd')](_0x114e('0x6d'),_0x2adf6b,_0x15155e,_0x11f11a,_0x11e961['ListId'],_0x11e961[_0x114e('0x3a')]||null,NOW,NOW);if(_[_0x114e('0x6e')](_0x436dc5[_0x114e('0x21')])){_0x520e59+=',\x20scheduledAt\x20=\x20NOW()';}_0x3bdeb2['push'](_0x520e59);if(_0x11e961[_0x114e('0x6a')]&&_0x11e961[_0x114e('0x6a')][_0x114e('0x56')]){_0x3bdeb2[_0x114e('0x46')](insertCmContact(_0x11e961['ListId'],_0x15155e,_0x11e961[_0x114e('0x6a')],_0x436dc5));_0x3bdeb2[_0x114e('0x46')](_0x114e('0x6f')+_0x15155e+';');}_0x3bdeb2[_0x114e('0x46')](insertCmHopper(_0x11e961[_0x114e('0x23')],_0x114e('0x70'),'voice_queues',_0x114e('0x71'),_0x5bba8f));_0x3bdeb2[_0x114e('0x46')](insertCmHopperBlack(_0x11e961['ListId'],_0x114e('0x72'),_0x114e('0x73'),_0x114e('0x71')));_0x3bdeb2[_0x114e('0x46')](insertCmHopper(_0x11e961[_0x114e('0x23')],_0x114e('0x74'),_0x114e('0x75'),_0x114e('0x76'),_0x5bba8f));_0x3bdeb2[_0x114e('0x46')](insertCmHopperBlack(_0x11e961[_0x114e('0x23')],_0x114e('0x77'),_0x114e('0x75'),_0x114e('0x76')));BPromise['each'](_0x3bdeb2,handleQuery)[_0x114e('0x78')](function(_0x397456){stats[_0x114e('0x79')]=!![];stats[_0x114e('0x7a')]=_0x11e961[_0x114e('0x6a')]&&_0x11e961['duplicates'][_0x114e('0x56')]?results[0x2][_0x114e('0x7a')]:results[0x0][_0x114e('0x7a')];socket[_0x114e('0x66')](_0x114e('0x67')+_0x1a6959,stats);fs[_0x114e('0x7b')](_0x4b5192);fs[_0x114e('0x7b')](_0x2adf6b);process['exit'](0x0);})['catch'](function(_0x8e5c12){logger['error'](_0x8e5c12['message']);process[_0x114e('0x44')](0x1);});}catch(_0x1be787){logger[_0x114e('0x42')](_0x114e('0x7c'),_0x1be787[_0x114e('0x43')]);process[_0x114e('0x44')](0x1);}},'error':function(_0x152a8f,_0x529995,_0x5b72de,_0x1a29eb){throw new Error(_0x1a29eb);}});}function validate(){if(process[_0x114e('0x7d')]&&process[_0x114e('0x7d')][_0x114e('0x56')]<0x4){throw new Error('arguments\x20<filename>\x20<parameters>\x20<agents>');}var _0x231054=path[_0x114e('0x2a')](config[_0x114e('0x7e')],'server/files/tmp',process['argv'][0x2]);if(!fs[_0x114e('0x7f')](_0x231054)){throw new Error(_0x114e('0x80'));}var _0x4945b2={};try{_0x4945b2=JSON['parse'](process[_0x114e('0x7d')][0x3]);if(!_0x4945b2[_0x114e('0x4e')]){throw new Error('binding\x20doesn\x27t\x20exists');}if(!_0x4945b2[_0x114e('0x4e')][_0x114e('0x11')]){throw new Error('phone\x20is\x20mandatory');}if(!_0x4945b2[_0x114e('0x4e')]['firstName']){throw new Error(_0x114e('0x81'));}var _0x2eef55=0x0;if(_0x4945b2[_0x114e('0x4e')][_0x114e('0x26')]){_0x2eef55=0x1;}if(!_0x4945b2['ListId']){throw new Error(_0x114e('0x82'));}}catch(_0x195669){throw new Error(_0x114e('0x83'));}var _0x16011b=[];try{_0x16011b=_[_0x114e('0x84')](JSON[_0x114e('0x54')](process[_0x114e('0x7d')][0x4]),'id');}catch(_0x15421b){logger['info'](_0x114e('0x85'));}main(_0x231054,_0x4945b2,_0x16011b,_0x2eef55);}validate();process['on'](_0x114e('0x86'),handleStop);process['on'](_0x114e('0x87'),handleUncaughtException);
\ No newline at end of file
+var _0x33c4=['scheduledat','ListId','createdAt','priority','recallme','fields','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_contacts.phone','cm_contacts.id','cm_hopper_black','ContactId','updatedAt','select','ListId\x20=\x20?','\x20=\x20?','concat','keys',')\x20NOT\x20IN\x20?','deletedAt\x20IS\x20NULL','id\x20IN\x20?','MIN(id)','min_id','group','Received\x20SIGINT','error','message','exit','push','code','info','query','spread','catch','main','stringify','send','start','root','server/files/tmp','.csv','header','parse','createReadStream','length','rows','errors','data','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','UserId','isNumber','agent\x20not\x20exists','email\x20wrong\x20format','dateOfBirth','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','\x20not\x20specified','SystemRow','emit','Abort\x20parser','SystemError','duplicates','cm_contacts_','CREATE\x20TABLE\x20','\x20LIKE\x20cm_contacts;','CompanyId','DROP\x20TABLE\x20','voice_queues_has_cm_lists','voice_queues','voice_queues_has_cm_blacklists','VoiceQueueId','campaigns','CampaignId','campaigns_has_cm_blacklists','each','then','finish','affectedRows','contact:import:','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','existsSync','binding','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','map','No\x20agent\x20available','SIGINT','uncaughtException','path','lodash','papaparse','util','bluebird','moment','squel','ioredis','../../../config/environment','../../../config/logger','import','defaults','redis','localhost','format','YYYY-MM-DD\x20HH:mm:ss','test','field','phone','from','join','.id\x20=\x20','where','\x20=\x20','cm_contacts.scheduledat','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.updatedAt','cm_contacts.priority','insert','into','cm_hopper','fromQuery'];(function(_0x24c71d,_0x441ec3){var _0x2cdd54=function(_0x31529){while(--_0x31529){_0x24c71d['push'](_0x24c71d['shift']());}};_0x2cdd54(++_0x441ec3);}(_0x33c4,0xef));var _0x433c=function(_0xb8a63a,_0x3f90ac){_0xb8a63a=_0xb8a63a-0x0;var _0x3e8367=_0x33c4[_0xb8a63a];return _0x3e8367;};'use strict';var fs=require('fs');var path=require(_0x433c('0x0'));var _=require(_0x433c('0x1'));var Papa=require(_0x433c('0x2'));var util=require(_0x433c('0x3'));var BPromise=require(_0x433c('0x4'));var moment=require(_0x433c('0x5'));var squel=require(_0x433c('0x6'));var Redis=require(_0x433c('0x7'));var db=require('../../../mysqldb')['db'];var config=require(_0x433c('0x8'));var logger=require(_0x433c('0x9'))(_0x433c('0xa'));config['redis']=_[_0x433c('0xb')](config[_0x433c('0xc')],{'host':_0x433c('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x433c('0xc')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0x433c('0xe')](_0x433c('0xf'));function isEmail(_0x238dcf){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))*$/[_0x433c('0x10')](_0x238dcf);}function selectNotIn(_0x367f7f,_0x499c2d,_0x356b44,_0x27663e,_0x4559ff){return squel['select']()[_0x433c('0x11')](_0x433c('0x12'))[_0x433c('0x13')](_0x27663e)[_0x433c('0x14')](_0x499c2d,null,_0x499c2d+_0x433c('0x15')+_0x27663e+'.'+_0x356b44)[_0x433c('0x16')](_0x27663e+'.'+_0x356b44+_0x433c('0x17')+_0x367f7f+'.'+_0x356b44)[_0x433c('0x16')](_0x499c2d+'.dialCheckDuplicateType\x20IN\x20('+_0x4559ff[_0x433c('0x14')]()+')');}function insertCmHopper(_0x27b71c,_0x5a45d8,_0x52f8db,_0x9b2ff1,_0x41ae27){var _0x311ff5=['cm_contacts.phone',_0x433c('0x18'),'cm_contacts.id',_0x433c('0x19'),_0x5a45d8+'.'+_0x9b2ff1,_0x433c('0x1a'),_0x433c('0x1b'),_0x433c('0x1c'),'cm_contacts.UserId','\x22'+_0x41ae27+'\x22'];return squel[_0x433c('0x1d')]()[_0x433c('0x1e')](_0x433c('0x1f'))[_0x433c('0x20')]([_0x433c('0x12'),_0x433c('0x21'),'ContactId',_0x433c('0x22'),_0x9b2ff1,_0x433c('0x23'),'updatedAt',_0x433c('0x24'),'UserId',_0x433c('0x25')],squel['select']()[_0x433c('0x26')](_0x311ff5)['from'](_0x5a45d8)['join'](_0x433c('0x27'),null,_0x433c('0x28')+_0x5a45d8+_0x433c('0x29'))['join'](_0x52f8db,null,_0x52f8db+_0x433c('0x15')+_0x5a45d8+'.'+_0x9b2ff1)['where'](_0x5a45d8+_0x433c('0x2a'),_0x27b71c)[_0x433c('0x16')](_0x433c('0x2b'),NOW)[_0x433c('0x16')](_0x433c('0x2c'),selectNotIn(_0x5a45d8,_0x52f8db,_0x9b2ff1,_0x433c('0x1f'),[_0x433c('0x2d'),_0x433c('0x2e')]))[_0x433c('0x16')](_0x433c('0x2c'),selectNotIn(_0x5a45d8,_0x52f8db,_0x9b2ff1,'cm_hopper',[_0x433c('0x2d')])))[_0x433c('0x2f')]();}function insertCmHopperBlack(_0x405606,_0x24f2a4,_0x285817,_0x388562){var _0x36da0f=[_0x433c('0x30'),_0x433c('0x31'),'cm_contacts.ListId',_0x24f2a4+'.'+_0x388562,_0x433c('0x1a'),_0x433c('0x1b')];return squel[_0x433c('0x1d')]()[_0x433c('0x1e')](_0x433c('0x32'))['fromQuery']([_0x433c('0x12'),_0x433c('0x33'),_0x433c('0x22'),_0x388562,_0x433c('0x23'),_0x433c('0x34')],squel[_0x433c('0x35')]()[_0x433c('0x26')](_0x36da0f)[_0x433c('0x13')](_0x24f2a4)[_0x433c('0x14')](_0x433c('0x27'),null,_0x433c('0x28')+_0x24f2a4+_0x433c('0x29'))[_0x433c('0x14')](_0x285817,null,_0x285817+'.id\x20=\x20'+_0x24f2a4+'.'+_0x388562)[_0x433c('0x16')](_0x24f2a4+'.CmListId\x20=\x20?',_0x405606)[_0x433c('0x16')](_0x433c('0x2b'),NOW)[_0x433c('0x16')](_0x433c('0x2c'),squel['select']()['field'](_0x433c('0x12'))['from']('cm_hopper_black')[_0x433c('0x16')](_0x433c('0x36'),_0x405606)[_0x433c('0x16')](_0x388562+_0x433c('0x37'),_0x24f2a4+'.'+_0x388562)))[_0x433c('0x2f')]();}function insertCmContact(_0x26ef27,_0x403a8a,_0xc7a2b8,_0x12fa84){var _0x10c598=_[_0x433c('0x38')](_[_0x433c('0x39')](_0x12fa84),['ListId','CompanyId',_0x433c('0x23'),'updatedAt']);return squel[_0x433c('0x1d')]()[_0x433c('0x1e')](_0x433c('0x27'))[_0x433c('0x20')](_0x10c598,squel['select']()[_0x433c('0x26')](_0x10c598)[_0x433c('0x13')](_0x403a8a)['where']('('+_0xc7a2b8[_0x433c('0x14')](',')+_0x433c('0x3a'),squel[_0x433c('0x35')]()[_0x433c('0x26')](_0xc7a2b8)[_0x433c('0x13')](_0x433c('0x27'))[_0x433c('0x16')](_0x433c('0x36'),_0x26ef27)['where'](_0x433c('0x3b')))[_0x433c('0x16')](_0x433c('0x3c'),squel['select']()['field'](_0x433c('0x3d'),_0x433c('0x3e'))['from'](_0x403a8a)[_0x433c('0x3f')](_0xc7a2b8[_0x433c('0x14')](','))))['toString']();}function handleStop(){logger['info'](_0x433c('0x40'));stopped=!![];}function handleUncaughtException(_0x9cb837){logger[_0x433c('0x41')](_0x9cb837[_0x433c('0x42')]);process[_0x433c('0x43')](0x1);}function handleError(_0x48c1d9,_0x1315e7){stats['errors'][_0x433c('0x44')]({'name':_0x1315e7[_0x433c('0x45')],'message':_0x1315e7[_0x433c('0x42')],'row':_0x48c1d9});}function handleQuery(_0x5e5e16){logger[_0x433c('0x46')](_0x5e5e16);return db['sequelize'][_0x433c('0x47')](_0x5e5e16)[_0x433c('0x48')](function(_0x111434){results[_0x433c('0x44')](_0x111434);})[_0x433c('0x49')](function(_0x53020b){logger[_0x433c('0x41')](_0x53020b[_0x433c('0x42')]);});}function main(_0x586a4c,_0x4045cd,_0x2cd835,_0x519980){logger[_0x433c('0x46')](_0x433c('0x4a'),_0x586a4c,JSON[_0x433c('0x4b')](_0x4045cd));process[_0x433c('0x4c')](_0x433c('0x4d'));var _0x2aaa00=_0x4045cd['binding'];var _0x3b3081=_0x4045cd['socket_timestamp'];var _0x41d5ba=path[_0x433c('0x14')](config[_0x433c('0x4e')],_0x433c('0x4f'),_0x3b3081+_0x433c('0x50'));var _0x31fbd2=_[_0x433c('0x39')](_0x2aaa00)[_0x433c('0x14')]();logger['info'](_0x433c('0x51'),_0x31fbd2);fs['writeFileSync'](_0x41d5ba,_0x31fbd2+'\x0a');Papa[_0x433c('0x52')](fs[_0x433c('0x53')](_0x586a4c),{'header':!![],'skipEmptyLines':!![],'step':function(_0x56eb3b,_0x1ece1c){try{for(var _0x2ae241=0x0,_0x1ef56a=[];_0x2ae241<_0x56eb3b['data'][_0x433c('0x54')];_0x2ae241++){stats[_0x433c('0x55')]+=0x1;if(_0x56eb3b[_0x433c('0x56')][_0x2ae241]){handleError(_0x56eb3b[_0x433c('0x57')][_0x2ae241],_0x56eb3b[_0x433c('0x56')][_0x2ae241]);}else{var _0x1a9471=[];for(var _0x5dc935 in _0x2aaa00){if(_0x2aaa00['hasOwnProperty'](_0x5dc935)){if(_0x56eb3b[_0x433c('0x57')][_0x2ae241][_0x2aaa00[_0x5dc935]]){var _0x4e1825=_[_0x433c('0x58')](_0x56eb3b[_0x433c('0x57')][_0x2ae241][_0x2aaa00[_0x5dc935]][_0x433c('0x59')](/"/g,'\x27'));switch(_0x5dc935){case'scheduledat':var _0x219d54=moment(_0x4e1825,_0x433c('0xf'),!![]);if(_0x219d54[_0x433c('0x5a')]()){_0x1ef56a[_0x433c('0x44')]('\x22'+_0x4e1825+'\x22');}else{_0x1a9471[_0x433c('0x44')](_0x433c('0x5b'));}break;case'priority':var _0x12bb26=parseInt(_0x4e1825);_0x4e1825=_[_0x433c('0x5c')](_0x12bb26)||_0x12bb26<0x0||_0x12bb26>0x4?_0x519980?0x3:0x2:_0x12bb26;_0x1ef56a[_0x433c('0x44')]('\x22'+_0x4e1825+'\x22');break;case _0x433c('0x5d'):var _0x40b996=parseInt(_0x4e1825);if(_[_0x433c('0x5e')](_0x40b996)&&_['includes'](_0x2cd835,_0x40b996)){_0x1ef56a[_0x433c('0x44')]('\x22'+_0x40b996+'\x22');}else{_0x1a9471[_0x433c('0x44')](_0x433c('0x5f'));}break;case'email':if(isEmail(_0x4e1825)){_0x1ef56a['push']('\x22'+_0x4e1825+'\x22');}else{_0x1a9471[_0x433c('0x44')](_0x433c('0x60'));}break;case _0x433c('0x61'):var _0x2b744c=moment(_0x4e1825,'YYYY-MM-DD',!![]);if(_0x2b744c[_0x433c('0x5a')]()){_0x1ef56a[_0x433c('0x44')]('\x22'+_0x4e1825+'\x22');}else{_0x1a9471['push'](_0x433c('0x62'));}break;default:_0x1ef56a['push']('\x22'+_0x4e1825+'\x22');}}else{switch(_0x5dc935){case _0x433c('0x63'):case _0x433c('0x12'):_0x1a9471[_0x433c('0x44')](_0x5dc935+_0x433c('0x64'));break;default:_0x1ef56a[_0x433c('0x44')]('\x22\x22');}}}}if(_0x1a9471[_0x433c('0x54')]){handleError(_0x56eb3b[_0x433c('0x57')][_0x2ae241],{'code':_0x433c('0x65'),'message':_0x1a9471[_0x433c('0x14')]()});}else{fs['appendFileSync'](_0x41d5ba,_0x1ef56a[_0x433c('0x14')]()+'\x0a');}_0x1ef56a=[];}if(!(stats['rows']%0xc8)){socket[_0x433c('0x66')]('contact:import:'+_0x3b3081,stats);stats['errors']=[];}}if(stopped){logger[_0x433c('0x46')](_0x433c('0x67'));_0x1ece1c['abort']();}}catch(_0x405539){handleError(_0x56eb3b['data'][_0x2ae241],{'code':_0x433c('0x68'),'message':_0x405539[_0x433c('0x42')]});logger[_0x433c('0x41')]('step',_0x405539['message']);}},'complete':function(){try{var _0x2c47ae=[];var _0x319c5c=_0x433c('0x27');if(_0x4045cd[_0x433c('0x69')]&&_0x4045cd[_0x433c('0x69')][_0x433c('0x54')]){_0x319c5c=_0x433c('0x6a')+_0x3b3081;_0x2c47ae['push'](_0x433c('0x6b')+_0x319c5c+_0x433c('0x6c'));}var _0xc14bec=util[_0x433c('0xe')]('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',_0x41d5ba,_0x319c5c,_0x31fbd2,_0x4045cd[_0x433c('0x22')],_0x4045cd[_0x433c('0x6d')]||null,NOW,NOW);if(_['isNil'](_0x2aaa00[_0x433c('0x21')])){_0xc14bec+=',\x20scheduledAt\x20=\x20NOW()';}_0x2c47ae[_0x433c('0x44')](_0xc14bec);if(_0x4045cd[_0x433c('0x69')]&&_0x4045cd['duplicates'][_0x433c('0x54')]){_0x2c47ae['push'](insertCmContact(_0x4045cd[_0x433c('0x22')],_0x319c5c,_0x4045cd[_0x433c('0x69')],_0x2aaa00));_0x2c47ae[_0x433c('0x44')](_0x433c('0x6e')+_0x319c5c+';');}_0x2c47ae[_0x433c('0x44')](insertCmHopper(_0x4045cd['ListId'],_0x433c('0x6f'),_0x433c('0x70'),'VoiceQueueId',_0x519980));_0x2c47ae['push'](insertCmHopperBlack(_0x4045cd[_0x433c('0x22')],_0x433c('0x71'),_0x433c('0x70'),_0x433c('0x72')));_0x2c47ae[_0x433c('0x44')](insertCmHopper(_0x4045cd[_0x433c('0x22')],'campaigns_has_cm_lists',_0x433c('0x73'),_0x433c('0x74'),_0x519980));_0x2c47ae['push'](insertCmHopperBlack(_0x4045cd[_0x433c('0x22')],_0x433c('0x75'),_0x433c('0x73'),_0x433c('0x74')));BPromise[_0x433c('0x76')](_0x2c47ae,handleQuery)[_0x433c('0x77')](function(_0x5e6f77){stats[_0x433c('0x78')]=!![];stats[_0x433c('0x79')]=_0x4045cd[_0x433c('0x69')]&&_0x4045cd['duplicates'][_0x433c('0x54')]?results[0x2][_0x433c('0x79')]:results[0x0][_0x433c('0x79')];socket['emit'](_0x433c('0x7a')+_0x3b3081,stats);fs[_0x433c('0x7b')](_0x586a4c);fs[_0x433c('0x7b')](_0x41d5ba);process[_0x433c('0x43')](0x0);})[_0x433c('0x49')](function(_0x1cded0){logger[_0x433c('0x41')](_0x1cded0[_0x433c('0x42')]);process[_0x433c('0x43')](0x1);});}catch(_0x3e9f92){logger[_0x433c('0x41')](_0x433c('0x7c'),_0x3e9f92[_0x433c('0x42')]);process['exit'](0x1);}},'error':function(_0x2b3c62,_0x4f3351,_0x2ee4ff,_0x149ef8){throw new Error(_0x149ef8);}});}function validate(){if(process[_0x433c('0x7d')]&&process[_0x433c('0x7d')][_0x433c('0x54')]<0x4){throw new Error(_0x433c('0x7e'));}var _0xe07ab0=path[_0x433c('0x14')](config[_0x433c('0x4e')],'server/files/tmp',process[_0x433c('0x7d')][0x2]);if(!fs[_0x433c('0x7f')](_0xe07ab0)){throw new Error('file\x20doesn\x27t\x20exists');}var _0x31fd5d={};try{_0x31fd5d=JSON[_0x433c('0x52')](process[_0x433c('0x7d')][0x3]);if(!_0x31fd5d[_0x433c('0x80')]){throw new Error('binding\x20doesn\x27t\x20exists');}if(!_0x31fd5d['binding'][_0x433c('0x12')]){throw new Error(_0x433c('0x81'));}if(!_0x31fd5d['binding'][_0x433c('0x63')]){throw new Error(_0x433c('0x82'));}var _0x3e8873=0x0;if(_0x31fd5d[_0x433c('0x80')]['UserId']){_0x3e8873=0x1;}if(!_0x31fd5d[_0x433c('0x22')]){throw new Error(_0x433c('0x83'));}}catch(_0x2e9027){throw new Error('body\x20id\x20mandatory');}var _0x2ba1cc=[];try{_0x2ba1cc=_[_0x433c('0x84')](JSON['parse'](process['argv'][0x4]),'id');}catch(_0x4cf993){logger[_0x433c('0x46')](_0x433c('0x85'));}main(_0xe07ab0,_0x31fd5d,_0x2ba1cc,_0x3e8873);}validate();process['on'](_0x433c('0x86'),handleStop);process['on'](_0x433c('0x87'),handleUncaughtException);
\ No newline at end of file