c2fea89fc810e2dfae193a2266909883c2d6f62f
[motion2.git] / server / api / cmHopperHistory / cmHopperHistory.rpc.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xdbce=['outboundOriginateFailureCallsDay','`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','`state`\x20=\x2016,\x201,\x20null','`state`\x20=\x2020,\x201,\x20null','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','outboundReCallsDay','name','ivrTotalCallsDays','ivrAnswerCallsDay','GetCampaignHopperHistory','lodash','moment','bluebird','randomstring','../../mysqldb','../../config/logger','rpc','client','http','request','then','info','debug','stringify','error','code','CmHopperHistory,\x20%s,\x20%s','message','catch','CreateCmHopperHistory','CmHopperHistory','findAll','options','raw','sequelize','COUNT','col','predictiveIntervalTotalCalls','literal','`state`\x20=\x204,\x201,\x20null','`state`\x20=\x2010,\x201,\x20null','predictiveIntervalDroppedCallsTimeout','`state`\x20=\x2011,\x201,\x20null','predictiveIntervalDroppedCallsCallersExit','`state`\x20=\x204,\x20`holdtime`,\x20null','predictiveIntervalAvgHoldtime','`state`\x20=\x204,\x20`talktime`,\x20null','predictiveIntervalAvgTalktime','AvgHandleTime','GetVoiceQueueHopperHistory','where','campaign','outboundNoSuchCallsDay','`state`\x20=\x203,\x201,\x20null','outboundNoAnswerCallsDay','`state`\x20=\x205,\x201,\x20null','`state`\x20=\x208,\x201,\x20null','outboundCongestionCallsDay','`state`\x20=\x2010\x20,\x201,\x20null','outboundDropCallsDayTimeout','`state`\x20=\x2011\x20,\x201,\x20null','`state`\x20=\x2012,\x201,\x20null','outboundBlacklistCallsDay','`state`\x20=\x2014,\x201,\x20null'];(function(_0x4a53d,_0x58a95e){var _0x27410e=function(_0x38fc90){while(--_0x38fc90){_0x4a53d['push'](_0x4a53d['shift']());}};_0x27410e(++_0x58a95e);}(_0xdbce,0x150));var _0xedbc=function(_0x57c83a,_0x5866e4){_0x57c83a=_0x57c83a-0x0;var _0x21b624=_0xdbce[_0x57c83a];return _0x21b624;};'use strict';var _=require(_0xedbc('0x0'));var util=require('util');var moment=require(_0xedbc('0x1'));var BPromise=require(_0xedbc('0x2'));var rs=require(_0xedbc('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xedbc('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0xedbc('0x5'))(_0xedbc('0x6'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0xedbc('0x7')][_0xedbc('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x4d3007,_0x30feb1,_0x5a7601){return new BPromise(function(_0x546974,_0x5927b2){return client[_0xedbc('0x9')](_0x4d3007,_0x5a7601)[_0xedbc('0xa')](function(_0xaeb39f){logger[_0xedbc('0xb')]('CmHopperHistory,\x20%s,\x20%s',_0x30feb1,'request\x20sent');logger[_0xedbc('0xc')]('CmHopperHistory,\x20%s,\x20%s,\x20%s',_0x30feb1,'request\x20sent',JSON[_0xedbc('0xd')](_0xaeb39f));if(_0xaeb39f[_0xedbc('0xe')]){if(_0xaeb39f['error'][_0xedbc('0xf')]===0x1f4){logger[_0xedbc('0xe')](_0xedbc('0x10'),_0x30feb1,_0xaeb39f['error'][_0xedbc('0x11')]);return _0x5927b2(_0xaeb39f[_0xedbc('0xe')][_0xedbc('0x11')]);}logger[_0xedbc('0xe')]('CmHopperHistory,\x20%s,\x20%s',_0x30feb1,_0xaeb39f[_0xedbc('0xe')][_0xedbc('0x11')]);return _0x546974(_0xaeb39f['error'][_0xedbc('0x11')]);}else{logger['info']('CmHopperHistory,\x20%s,\x20%s',_0x30feb1,'request\x20sent');_0x546974(_0xaeb39f['result'][_0xedbc('0x11')]);}})[_0xedbc('0x12')](function(_0xb21a67){logger[_0xedbc('0xe')](_0xedbc('0x10'),_0x30feb1,_0xb21a67);_0x5927b2(_0xb21a67);});});}exports[_0xedbc('0x13')]=function(_0x23bb3f){var _0x3731cc=this;return new Promise(function(_0x230922,_0x435a2b){return db[_0xedbc('0x14')]['create'](_0x23bb3f['body'],{'raw':_0x23bb3f['options']?_0x23bb3f['options']['raw']===undefined?!![]:![]:!![]})[_0xedbc('0xa')](function(_0x9a1964){logger['info'](_0xedbc('0x13'),_0x23bb3f);logger['debug'](_0xedbc('0x13'),_0x23bb3f,JSON[_0xedbc('0xd')](_0x9a1964));_0x230922(_0x9a1964);})[_0xedbc('0x12')](function(_0x4d7fa6){logger[_0xedbc('0xe')](_0xedbc('0x13'),_0x4d7fa6['message'],_0x23bb3f);_0x435a2b(_0x3731cc['error'](0x1f4,_0x4d7fa6[_0xedbc('0x11')]));});});};exports['AvgHandleTime']=function(_0x54d0e8){var _0x3d3ee9=this;return new Promise(function(_0x2f4203,_0x798639){return db[_0xedbc('0x14')][_0xedbc('0x15')]({'raw':_0x54d0e8['options']?_0x54d0e8[_0xedbc('0x16')][_0xedbc('0x17')]===undefined?!![]:![]:!![],'where':_0x54d0e8[_0xedbc('0x16')]?_0x54d0e8[_0xedbc('0x16')]['where']||null:null,'attributes':[[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')][_0xedbc('0x1a')]('id')),_0xedbc('0x1b')],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db['sequelize']['fn']('IF',db['sequelize'][_0xedbc('0x1c')](_0xedbc('0x1d')))),'predictiveIntervalAnsweredCalls'],[db['sequelize']['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x1e')))),_0xedbc('0x1f')],[db['sequelize']['fn']('COUNT',db['sequelize']['fn']('IF',db['sequelize']['literal'](_0xedbc('0x20')))),_0xedbc('0x21')],[db[_0xedbc('0x18')]['fn']('AVG',db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x22')))),_0xedbc('0x23')],[db[_0xedbc('0x18')]['fn']('AVG',db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')]['literal'](_0xedbc('0x24')))),_0xedbc('0x25')]]})[_0xedbc('0xa')](function(_0x2b3b12){logger['info'](_0xedbc('0x26'),_0x54d0e8);logger[_0xedbc('0xc')](_0xedbc('0x26'),_0x54d0e8,JSON[_0xedbc('0xd')](_0x2b3b12));_0x2f4203(_0x2b3b12);})[_0xedbc('0x12')](function(_0x3fbc69){logger[_0xedbc('0xe')]('AvgHandleTime',_0x3fbc69[_0xedbc('0x11')],_0x54d0e8);_0x798639(_0x3d3ee9['error'](0x1f4,_0x3fbc69[_0xedbc('0x11')]));});});};exports[_0xedbc('0x27')]=function(_0x229565){var _0x28bfd0=this;return new Promise(function(_0xf6886,_0x544a1f){return db[_0xedbc('0x14')][_0xedbc('0x15')]({'raw':_0x229565['options']?_0x229565[_0xedbc('0x16')][_0xedbc('0x17')]===undefined?!![]:![]:!![],'where':_0x229565[_0xedbc('0x16')]?_0x229565[_0xedbc('0x16')][_0xedbc('0x28')]||null:null,'attributes':[[_0xedbc('0x29'),'name'],[db[_0xedbc('0x18')]['fn']('COUNT',db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')]('`state`\x20=\x200,\x201,\x20null'))),_0xedbc('0x2a')],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x2b')))),_0xedbc('0x2c')],[db['sequelize']['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x1d')))),'outboundAnswerCallsDay'],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db['sequelize'][_0xedbc('0x1c')](_0xedbc('0x2d')))),'outboundBusyCallsDay'],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x2e')))),_0xedbc('0x2f')],[db['sequelize']['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db['sequelize'][_0xedbc('0x1c')](_0xedbc('0x30')))),_0xedbc('0x31')],[db[_0xedbc('0x18')]['fn']('COUNT',db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x32')))),'outboundDropCallsDayCallersExit'],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db['sequelize']['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x33')))),'outboundUnknownCallsDay'],[db['sequelize']['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')]('`state`\x20=\x2013,\x201,\x20null'))),_0xedbc('0x34')],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db['sequelize'][_0xedbc('0x1c')](_0xedbc('0x35')))),_0xedbc('0x36')],[db['sequelize']['fn']('COUNT',db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x37')))),_0xedbc('0x38')],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x39')))),'outboundAnswerAgiCallsDay'],[db[_0xedbc('0x18')]['fn']('COUNT',db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')]['literal'](_0xedbc('0x3a')))),_0xedbc('0x38')],[db['sequelize']['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')]['fn']('IF',db[_0xedbc('0x18')][_0xedbc('0x1c')](_0xedbc('0x3b')))),_0xedbc('0x3c')]],'group':['campaign']})[_0xedbc('0xa')](function(_0x1e1593){logger['info'](_0xedbc('0x27'),_0x229565);logger['debug'](_0xedbc('0x27'),_0x229565,JSON[_0xedbc('0xd')](_0x1e1593));_0xf6886(_0x1e1593);})[_0xedbc('0x12')](function(_0x56c3c7){logger['error'](_0xedbc('0x27'),_0x56c3c7[_0xedbc('0x11')],_0x229565);_0x544a1f(_0x28bfd0[_0xedbc('0xe')](0x1f4,_0x56c3c7[_0xedbc('0x11')]));});});};exports['GetCampaignHopperHistory']=function(_0x12727f){var _0x11d571=this;return new Promise(function(_0x2dd6bb,_0x724465){return db[_0xedbc('0x14')][_0xedbc('0x15')]({'raw':_0x12727f[_0xedbc('0x16')]?_0x12727f[_0xedbc('0x16')][_0xedbc('0x17')]===undefined?!![]:![]:!![],'where':_0x12727f[_0xedbc('0x16')]?_0x12727f['options']['where']||null:null,'attributes':[[_0xedbc('0x29'),_0xedbc('0x3d')],[db[_0xedbc('0x18')]['fn'](_0xedbc('0x19'),db[_0xedbc('0x18')][_0xedbc('0x1a')]('id')),_0xedbc('0x3e')],[db[_0xedbc('0x18')]['fn']('COUNT',db[_0xedbc('0x18')]['fn']('IF',db['sequelize'][_0xedbc('0x1c')](_0xedbc('0x1d')))),_0xedbc('0x3f')]],'group':[_0xedbc('0x29')]})['then'](function(_0x1b1b2a){logger[_0xedbc('0xb')](_0xedbc('0x40'),_0x12727f);logger['debug'](_0xedbc('0x40'),_0x12727f,JSON[_0xedbc('0xd')](_0x1b1b2a));_0x2dd6bb(_0x1b1b2a);})['catch'](function(_0x1d2f79){logger['error'](_0xedbc('0x40'),_0x1d2f79[_0xedbc('0x11')],_0x12727f);_0x724465(_0x11d571[_0xedbc('0xe')](0x1f4,_0x1d2f79['message']));});});};