Built motion from commit 19a84241.|2.5.34
[motion2.git] / server / components / import / cm / csv2.js
index 94d89b3..609e4ae 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-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
+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