Built motion from commit (unavailable).|2.5.13
[motion2.git] / server / components / import / cm / csv2.js
index 400e188..8500e97 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x733f=['isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','includes','agent\x20not\x20exists','dateOfBirth','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','\x20not\x20specified','SystemRow','appendFileSync','emit','contact:import:','abort','SystemError','step','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','VoiceQueueId','CampaignId','campaigns','each','then','affectedRows','unlink','exit','catch','argv','root','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','util','bluebird','moment','../../../mysqldb','../../../config/logger','redis','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','test','select','field','phone','from','join','.id\x20=\x20','where','\x20=\x20','.dialCheckDuplicateType\x20IN\x20(','cm_contacts.phone','cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.updatedAt','cm_contacts.priority','cm_contacts.UserId','insert','into','cm_hopper','fromQuery','scheduledat','ContactId','createdAt','updatedAt','priority','UserId','recallme','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_hopper_black','ListId','fields','ListId\x20=\x20?','\x20=\x20?','concat','keys','CompanyId',')\x20NOT\x20IN\x20?','deletedAt\x20IS\x20NULL','MIN(id)','min_id','group','info','Received\x20SIGINT','error','message','errors','code','sequelize','query','push','stringify','send','start','binding','socket_timestamp','.csv','header','createReadStream','data','length','rows','trim'];(function(_0x403573,_0x3f6489){var _0x3c39e6=function(_0x172f79){while(--_0x172f79){_0x403573['push'](_0x403573['shift']());}};_0x3c39e6(++_0x3f6489);}(_0x733f,0xab));var _0xf733=function(_0x5934c4,_0x260346){_0x5934c4=_0x5934c4-0x0;var _0x23f771=_0x733f[_0x5934c4];return _0x23f771;};'use strict';var fs=require('fs');var path=require('path');var _=require('lodash');var Papa=require('papaparse');var util=require(_0xf733('0x0'));var BPromise=require(_0xf733('0x1'));var moment=require(_0xf733('0x2'));var squel=require('squel');var Redis=require('ioredis');var db=require(_0xf733('0x3'))['db'];var config=require('../../../config/environment');var logger=require(_0xf733('0x4'))('import');config['redis']=_['defaults'](config[_0xf733('0x5')],{'host':'localhost','port':0x18eb});var socket=require(_0xf733('0x6'))(new Redis(config[_0xf733('0x5')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0xf733('0x7')](_0xf733('0x8'));function isEmail(_0x19af8f){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))*$/[_0xf733('0x9')](_0x19af8f);}function selectNotIn(_0x33b596,_0x53d170,_0x4b63bd,_0x48e093,_0x231d65){return squel[_0xf733('0xa')]()[_0xf733('0xb')](_0xf733('0xc'))[_0xf733('0xd')](_0x48e093)[_0xf733('0xe')](_0x53d170,null,_0x53d170+_0xf733('0xf')+_0x48e093+'.'+_0x4b63bd)[_0xf733('0x10')](_0x48e093+'.'+_0x4b63bd+_0xf733('0x11')+_0x33b596+'.'+_0x4b63bd)[_0xf733('0x10')](_0x53d170+_0xf733('0x12')+_0x231d65[_0xf733('0xe')]()+')');}function insertCmHopper(_0x308fe9,_0x37e2a9,_0xb42bfa,_0x17c018,_0x5aa76b){var _0xd242de=[_0xf733('0x13'),'cm_contacts.scheduledat',_0xf733('0x14'),_0xf733('0x15'),_0x37e2a9+'.'+_0x17c018,_0xf733('0x16'),_0xf733('0x17'),_0xf733('0x18'),_0xf733('0x19'),'\x22'+_0x5aa76b+'\x22'];return squel[_0xf733('0x1a')]()[_0xf733('0x1b')](_0xf733('0x1c'))[_0xf733('0x1d')](['phone',_0xf733('0x1e'),_0xf733('0x1f'),'ListId',_0x17c018,_0xf733('0x20'),_0xf733('0x21'),_0xf733('0x22'),_0xf733('0x23'),_0xf733('0x24')],squel['select']()['fields'](_0xd242de)['from'](_0x37e2a9)[_0xf733('0xe')](_0xf733('0x25'),null,_0xf733('0x26')+_0x37e2a9+_0xf733('0x27'))[_0xf733('0xe')](_0xb42bfa,null,_0xb42bfa+_0xf733('0xf')+_0x37e2a9+'.'+_0x17c018)[_0xf733('0x10')](_0x37e2a9+'.CmListId\x20=\x20?',_0x308fe9)[_0xf733('0x10')](_0xf733('0x28'),NOW)['where'](_0xf733('0x29'),selectNotIn(_0x37e2a9,_0xb42bfa,_0x17c018,_0xf733('0x1c'),[_0xf733('0x2a'),_0xf733('0x2b')]))[_0xf733('0x10')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',selectNotIn(_0x37e2a9,_0xb42bfa,_0x17c018,_0xf733('0x1c'),[_0xf733('0x2a')])))[_0xf733('0x2c')]();}function insertCmHopperBlack(_0x4e163e,_0xdc0203,_0x104ba0,_0x1587bf){var _0x1526f0=[_0xf733('0x13'),_0xf733('0x14'),_0xf733('0x15'),_0xdc0203+'.'+_0x1587bf,_0xf733('0x16'),_0xf733('0x17')];return squel['insert']()['into'](_0xf733('0x2d'))[_0xf733('0x1d')]([_0xf733('0xc'),_0xf733('0x1f'),_0xf733('0x2e'),_0x1587bf,_0xf733('0x20'),_0xf733('0x21')],squel[_0xf733('0xa')]()[_0xf733('0x2f')](_0x1526f0)['from'](_0xdc0203)[_0xf733('0xe')](_0xf733('0x25'),null,'cm_contacts.ListId\x20=\x20'+_0xdc0203+_0xf733('0x27'))[_0xf733('0xe')](_0x104ba0,null,_0x104ba0+'.id\x20=\x20'+_0xdc0203+'.'+_0x1587bf)[_0xf733('0x10')](_0xdc0203+'.CmListId\x20=\x20?',_0x4e163e)['where']('cm_contacts.createdAt\x20=\x20?',NOW)[_0xf733('0x10')](_0xf733('0x29'),squel[_0xf733('0xa')]()[_0xf733('0xb')](_0xf733('0xc'))[_0xf733('0xd')](_0xf733('0x2d'))['where'](_0xf733('0x30'),_0x4e163e)['where'](_0x1587bf+_0xf733('0x31'),_0xdc0203+'.'+_0x1587bf)))['toString']();}function insertCmContact(_0x2af3aa,_0xa2f5fa,_0x504367,_0x221344){var _0x3fc665=_[_0xf733('0x32')](_[_0xf733('0x33')](_0x221344),[_0xf733('0x2e'),_0xf733('0x34'),_0xf733('0x20'),_0xf733('0x21')]);return squel[_0xf733('0x1a')]()['into'](_0xf733('0x25'))[_0xf733('0x1d')](_0x3fc665,squel['select']()[_0xf733('0x2f')](_0x3fc665)[_0xf733('0xd')](_0xa2f5fa)[_0xf733('0x10')]('('+_0x504367[_0xf733('0xe')](',')+_0xf733('0x35'),squel[_0xf733('0xa')]()[_0xf733('0x2f')](_0x504367)['from'](_0xf733('0x25'))[_0xf733('0x10')](_0xf733('0x30'),_0x2af3aa)[_0xf733('0x10')](_0xf733('0x36')))[_0xf733('0x10')]('id\x20IN\x20?',squel['select']()[_0xf733('0xb')](_0xf733('0x37'),_0xf733('0x38'))['from'](_0xa2f5fa)[_0xf733('0x39')](_0x504367[_0xf733('0xe')](','))))['toString']();}function handleStop(){logger[_0xf733('0x3a')](_0xf733('0x3b'));stopped=!![];}function handleUncaughtException(_0x974d52){logger[_0xf733('0x3c')](_0x974d52[_0xf733('0x3d')]);process['exit'](0x1);}function handleError(_0x1c56e8,_0x4f708d){stats[_0xf733('0x3e')]['push']({'name':_0x4f708d[_0xf733('0x3f')],'message':_0x4f708d[_0xf733('0x3d')],'row':_0x1c56e8});}function handleQuery(_0x153e9f){logger[_0xf733('0x3a')](_0x153e9f);return db[_0xf733('0x40')][_0xf733('0x41')](_0x153e9f)['spread'](function(_0x4fb9ea){results[_0xf733('0x42')](_0x4fb9ea);})['catch'](function(_0x2bcbaa){logger[_0xf733('0x3c')](_0x2bcbaa[_0xf733('0x3d')]);});}function main(_0xec0b3f,_0x4a55d0,_0x586d9a,_0x5d0e49){logger[_0xf733('0x3a')]('main',_0xec0b3f,JSON[_0xf733('0x43')](_0x4a55d0));process[_0xf733('0x44')](_0xf733('0x45'));var _0x517e28=_0x4a55d0[_0xf733('0x46')];var _0x3f83f9=_0x4a55d0[_0xf733('0x47')];var _0x1442b5=path['join'](config['root'],'server/files/tmp',_0x3f83f9+_0xf733('0x48'));var _0x5d9deb=_[_0xf733('0x33')](_0x517e28)[_0xf733('0xe')]();logger[_0xf733('0x3a')](_0xf733('0x49'),_0x5d9deb);fs['writeFileSync'](_0x1442b5,_0x5d9deb+'\x0a');Papa['parse'](fs[_0xf733('0x4a')](_0xec0b3f),{'header':!![],'skipEmptyLines':!![],'step':function(_0x5974ad,_0x208ba7){try{for(var _0x2da503=0x0,_0x234670=[];_0x2da503<_0x5974ad[_0xf733('0x4b')][_0xf733('0x4c')];_0x2da503++){stats[_0xf733('0x4d')]+=0x1;if(_0x5974ad['errors'][_0x2da503]){handleError(_0x5974ad[_0xf733('0x4b')][_0x2da503],_0x5974ad[_0xf733('0x3e')][_0x2da503]);}else{var _0x57e5ef=[];for(var _0x478cfb in _0x517e28){if(_0x517e28['hasOwnProperty'](_0x478cfb)){if(_0x5974ad[_0xf733('0x4b')][_0x2da503][_0x517e28[_0x478cfb]]){var _0x5584c1=_[_0xf733('0x4e')](_0x5974ad[_0xf733('0x4b')][_0x2da503][_0x517e28[_0x478cfb]]['replace'](/"/g,'\x27'));switch(_0x478cfb){case'scheduledat':var _0x569573=moment(_0x5584c1,_0xf733('0x8'),!![]);if(_0x569573[_0xf733('0x4f')]()){_0x234670['push']('\x22'+_0x5584c1+'\x22');}else{_0x57e5ef[_0xf733('0x42')](_0xf733('0x50'));}break;case _0xf733('0x22'):var _0x595421=parseInt(_0x5584c1);_0x5584c1=_[_0xf733('0x51')](_0x595421)||_0x595421<0x0||_0x595421>0x4?_0x5d0e49?0x3:0x2:_0x595421;_0x234670[_0xf733('0x42')]('\x22'+_0x5584c1+'\x22');break;case _0xf733('0x23'):var _0x36dd42=parseInt(_0x5584c1);if(_[_0xf733('0x52')](_0x36dd42)&&_[_0xf733('0x53')](_0x586d9a,_0x36dd42)){_0x234670[_0xf733('0x42')]('\x22'+_0x36dd42+'\x22');}else{_0x57e5ef[_0xf733('0x42')](_0xf733('0x54'));}break;case'email':if(isEmail(_0x5584c1)){_0x234670[_0xf733('0x42')]('\x22'+_0x5584c1+'\x22');}else{_0x57e5ef[_0xf733('0x42')]('email\x20wrong\x20format');}break;case _0xf733('0x55'):var _0x448773=moment(_0x5584c1,_0xf733('0x56'),!![]);if(_0x448773[_0xf733('0x4f')]()){_0x234670[_0xf733('0x42')]('\x22'+_0x5584c1+'\x22');}else{_0x57e5ef[_0xf733('0x42')](_0xf733('0x57'));}break;default:_0x234670[_0xf733('0x42')]('\x22'+_0x5584c1+'\x22');}}else{switch(_0x478cfb){case'firstName':case _0xf733('0xc'):_0x57e5ef[_0xf733('0x42')](_0x478cfb+_0xf733('0x58'));break;default:_0x234670['push']('\x22\x22');}}}}if(_0x57e5ef[_0xf733('0x4c')]){handleError(_0x5974ad[_0xf733('0x4b')][_0x2da503],{'code':_0xf733('0x59'),'message':_0x57e5ef[_0xf733('0xe')]()});}else{fs[_0xf733('0x5a')](_0x1442b5,_0x234670[_0xf733('0xe')]()+'\x0a');}_0x234670=[];}if(!(stats[_0xf733('0x4d')]%0xc8)){socket[_0xf733('0x5b')](_0xf733('0x5c')+_0x3f83f9,stats);stats[_0xf733('0x3e')]=[];}}if(stopped){logger[_0xf733('0x3a')]('Abort\x20parser');_0x208ba7[_0xf733('0x5d')]();}}catch(_0x199d2f){handleError(_0x5974ad[_0xf733('0x4b')][_0x2da503],{'code':_0xf733('0x5e'),'message':_0x199d2f['message']});logger[_0xf733('0x3c')](_0xf733('0x5f'),_0x199d2f[_0xf733('0x3d')]);}},'complete':function(){try{var _0x5cc11f=[];var _0x26aa16=_0xf733('0x25');if(_0x4a55d0[_0xf733('0x60')]&&_0x4a55d0[_0xf733('0x60')][_0xf733('0x4c')]){_0x26aa16=_0xf733('0x61')+_0x3f83f9;_0x5cc11f['push'](_0xf733('0x62')+_0x26aa16+_0xf733('0x63'));}var _0x18872e=util[_0xf733('0x7')](_0xf733('0x64'),_0x1442b5,_0x26aa16,_0x5d9deb,_0x4a55d0['ListId'],_0x4a55d0[_0xf733('0x34')]||null,NOW,NOW);if(_['isNil'](_0x517e28[_0xf733('0x1e')])){_0x18872e+=_0xf733('0x65');}_0x5cc11f[_0xf733('0x42')](_0x18872e);if(_0x4a55d0[_0xf733('0x60')]&&_0x4a55d0[_0xf733('0x60')][_0xf733('0x4c')]){_0x5cc11f[_0xf733('0x42')](insertCmContact(_0x4a55d0[_0xf733('0x2e')],_0x26aa16,_0x4a55d0[_0xf733('0x60')],_0x517e28));_0x5cc11f[_0xf733('0x42')](_0xf733('0x66')+_0x26aa16+';');}_0x5cc11f[_0xf733('0x42')](insertCmHopper(_0x4a55d0[_0xf733('0x2e')],'voice_queues_has_cm_lists',_0xf733('0x67'),'VoiceQueueId',_0x5d0e49));_0x5cc11f[_0xf733('0x42')](insertCmHopperBlack(_0x4a55d0['ListId'],'voice_queues_has_cm_blacklists',_0xf733('0x67'),_0xf733('0x68')));_0x5cc11f['push'](insertCmHopper(_0x4a55d0['ListId'],'campaigns_has_cm_lists','campaigns',_0xf733('0x69'),_0x5d0e49));_0x5cc11f[_0xf733('0x42')](insertCmHopperBlack(_0x4a55d0[_0xf733('0x2e')],'campaigns_has_cm_blacklists',_0xf733('0x6a'),_0xf733('0x69')));BPromise[_0xf733('0x6b')](_0x5cc11f,handleQuery)[_0xf733('0x6c')](function(_0x449782){stats['finish']=!![];stats[_0xf733('0x6d')]=_0x4a55d0[_0xf733('0x60')]&&_0x4a55d0[_0xf733('0x60')][_0xf733('0x4c')]?results[0x2][_0xf733('0x6d')]:results[0x0][_0xf733('0x6d')];socket['emit'](_0xf733('0x5c')+_0x3f83f9,stats);fs[_0xf733('0x6e')](_0xec0b3f);fs[_0xf733('0x6e')](_0x1442b5);process[_0xf733('0x6f')](0x0);})[_0xf733('0x70')](function(_0x415b2c){logger[_0xf733('0x3c')](_0x415b2c[_0xf733('0x3d')]);process['exit'](0x1);});}catch(_0x1d234d){logger[_0xf733('0x3c')]('complete',_0x1d234d['message']);process['exit'](0x1);}},'error':function(_0x3ba4a3,_0x592975,_0x159d99,_0x25213e){throw new Error(_0x25213e);}});}function validate(){if(process[_0xf733('0x71')]&&process[_0xf733('0x71')][_0xf733('0x4c')]<0x4){throw new Error('arguments\x20<filename>\x20<parameters>\x20<agents>');}var _0x34c317=path['join'](config[_0xf733('0x72')],_0xf733('0x73'),process[_0xf733('0x71')][0x2]);if(!fs[_0xf733('0x74')](_0x34c317)){throw new Error(_0xf733('0x75'));}var _0x50a69b={};try{_0x50a69b=JSON[_0xf733('0x76')](process[_0xf733('0x71')][0x3]);if(!_0x50a69b[_0xf733('0x46')]){throw new Error('binding\x20doesn\x27t\x20exists');}if(!_0x50a69b[_0xf733('0x46')][_0xf733('0xc')]){throw new Error(_0xf733('0x77'));}if(!_0x50a69b[_0xf733('0x46')]['firstName']){throw new Error(_0xf733('0x78'));}var _0x2b603d=0x0;if(_0x50a69b[_0xf733('0x46')][_0xf733('0x23')]){_0x2b603d=0x1;}if(!_0x50a69b['ListId']){throw new Error(_0xf733('0x79'));}}catch(_0x1a448b){throw new Error(_0xf733('0x7a'));}var _0x3ee1b9=[];try{_0x3ee1b9=_[_0xf733('0x7b')](JSON[_0xf733('0x76')](process[_0xf733('0x71')][0x4]),'id');}catch(_0x37255b){logger['info'](_0xf733('0x7c'));}main(_0x34c317,_0x50a69b,_0x3ee1b9,_0x2b603d);}validate();process['on']('SIGINT',handleStop);process['on']('uncaughtException',handleUncaughtException);
\ No newline at end of file
+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