187997e944839c85afc60000dbbc1ce7965ebcba
[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 _0xc678=['`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','`state`\x20=\x2016,\x201,\x20null','outboundAnswerAgiCallsDay','`state`\x20=\x2020,\x201,\x20null','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','campaign','GetVoiceQueueHopperHistory','GetCampaignHopperHistory','ivrTotalCallsDays','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','http','request','then','info','request\x20sent','debug','CmHopperHistory,\x20%s,\x20%s,\x20%s','stringify','error','code','CmHopperHistory,\x20%s,\x20%s','message','result','catch','CreateCmHopperHistory','CmHopperHistory','body','options','raw','findAll','where','sequelize','COUNT','col','predictiveIntervalTotalCalls','literal','`state`\x20=\x204,\x201,\x20null','predictiveIntervalAnsweredCalls','`state`\x20=\x2010,\x201,\x20null','predictiveIntervalDroppedCallsTimeout','`state`\x20=\x2011,\x201,\x20null','predictiveIntervalDroppedCallsCallersExit','AVG','`state`\x20=\x204,\x20`holdtime`,\x20null','predictiveIntervalAvgHoldtime','`state`\x20=\x204,\x20`talktime`,\x20null','AvgHandleTime','name','`state`\x20=\x200,\x201,\x20null','`state`\x20=\x203,\x201,\x20null','outboundNoAnswerCallsDay','outboundAnswerCallsDay','outboundBusyCallsDay','`state`\x20=\x208,\x201,\x20null','`state`\x20=\x2010\x20,\x201,\x20null','outboundDropCallsDayTimeout','`state`\x20=\x2011\x20,\x201,\x20null','outboundDropCallsDayCallersExit','`state`\x20=\x2012,\x201,\x20null','outboundUnknownCallsDay','outboundBlacklistCallsDay','`state`\x20=\x2014,\x201,\x20null','outboundOriginateFailureCallsDay'];(function(_0x16f856,_0x15f98f){var _0x3e4d9e=function(_0x1d7b47){while(--_0x1d7b47){_0x16f856['push'](_0x16f856['shift']());}};_0x3e4d9e(++_0x15f98f);}(_0xc678,0x1b4));var _0x8c67=function(_0x4bf878,_0x9b8efa){_0x4bf878=_0x4bf878-0x0;var _0xf4fa65=_0xc678[_0x4bf878];return _0xf4fa65;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x8c67('0x0'));var BPromise=require(_0x8c67('0x1'));var rs=require(_0x8c67('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x8c67('0x3'))['db'];var utils=require(_0x8c67('0x4'));var logger=require(_0x8c67('0x5'))(_0x8c67('0x6'));var config=require('../../config/environment');var jayson=require(_0x8c67('0x7'));var client=jayson['client'][_0x8c67('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x1b4ceb,_0x4c2ffe,_0x207de1){return new BPromise(function(_0x22d7e4,_0x41ac88){return client[_0x8c67('0x9')](_0x1b4ceb,_0x207de1)[_0x8c67('0xa')](function(_0x5bac97){logger[_0x8c67('0xb')]('CmHopperHistory,\x20%s,\x20%s',_0x4c2ffe,_0x8c67('0xc'));logger[_0x8c67('0xd')](_0x8c67('0xe'),_0x4c2ffe,'request\x20sent',JSON[_0x8c67('0xf')](_0x5bac97));if(_0x5bac97[_0x8c67('0x10')]){if(_0x5bac97[_0x8c67('0x10')][_0x8c67('0x11')]===0x1f4){logger['error'](_0x8c67('0x12'),_0x4c2ffe,_0x5bac97['error']['message']);return _0x41ac88(_0x5bac97['error']['message']);}logger[_0x8c67('0x10')]('CmHopperHistory,\x20%s,\x20%s',_0x4c2ffe,_0x5bac97[_0x8c67('0x10')]['message']);return _0x22d7e4(_0x5bac97[_0x8c67('0x10')][_0x8c67('0x13')]);}else{logger[_0x8c67('0xb')](_0x8c67('0x12'),_0x4c2ffe,'request\x20sent');_0x22d7e4(_0x5bac97[_0x8c67('0x14')][_0x8c67('0x13')]);}})[_0x8c67('0x15')](function(_0x1bae2f){logger['error']('CmHopperHistory,\x20%s,\x20%s',_0x4c2ffe,_0x1bae2f);_0x41ac88(_0x1bae2f);});});}exports[_0x8c67('0x16')]=function(_0x3e9ab8){var _0x215d52=this;return new Promise(function(_0x544717,_0xe7f0b6){return db[_0x8c67('0x17')]['create'](_0x3e9ab8[_0x8c67('0x18')],{'raw':_0x3e9ab8['options']?_0x3e9ab8[_0x8c67('0x19')][_0x8c67('0x1a')]===undefined?!![]:![]:!![]})[_0x8c67('0xa')](function(_0x2bd6b3){logger[_0x8c67('0xb')]('CreateCmHopperHistory',_0x3e9ab8);logger[_0x8c67('0xd')](_0x8c67('0x16'),_0x3e9ab8,JSON['stringify'](_0x2bd6b3));_0x544717(_0x2bd6b3);})[_0x8c67('0x15')](function(_0x5486e8){logger[_0x8c67('0x10')](_0x8c67('0x16'),_0x5486e8[_0x8c67('0x13')],_0x3e9ab8);_0xe7f0b6(_0x215d52[_0x8c67('0x10')](0x1f4,_0x5486e8[_0x8c67('0x13')]));});});};exports['AvgHandleTime']=function(_0x2658a1){var _0x26fb02=this;return new Promise(function(_0x94d19b,_0xbb787e){return db[_0x8c67('0x17')][_0x8c67('0x1b')]({'raw':_0x2658a1['options']?_0x2658a1['options'][_0x8c67('0x1a')]===undefined?!![]:![]:!![],'where':_0x2658a1['options']?_0x2658a1['options'][_0x8c67('0x1c')]||null:null,'attributes':[[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db['sequelize'][_0x8c67('0x1f')]('id')),_0x8c67('0x20')],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db['sequelize']['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x22')))),_0x8c67('0x23')],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db['sequelize'][_0x8c67('0x21')](_0x8c67('0x24')))),_0x8c67('0x25')],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db['sequelize']['fn']('IF',db['sequelize'][_0x8c67('0x21')](_0x8c67('0x26')))),_0x8c67('0x27')],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x28'),db['sequelize']['fn']('IF',db['sequelize'][_0x8c67('0x21')](_0x8c67('0x29')))),_0x8c67('0x2a')],[db['sequelize']['fn'](_0x8c67('0x28'),db[_0x8c67('0x1d')]['fn']('IF',db['sequelize']['literal'](_0x8c67('0x2b')))),'predictiveIntervalAvgTalktime']]})['then'](function(_0x2a855a){logger[_0x8c67('0xb')](_0x8c67('0x2c'),_0x2658a1);logger[_0x8c67('0xd')](_0x8c67('0x2c'),_0x2658a1,JSON[_0x8c67('0xf')](_0x2a855a));_0x94d19b(_0x2a855a);})[_0x8c67('0x15')](function(_0x435ece){logger['error']('AvgHandleTime',_0x435ece[_0x8c67('0x13')],_0x2658a1);_0xbb787e(_0x26fb02['error'](0x1f4,_0x435ece[_0x8c67('0x13')]));});});};exports['GetVoiceQueueHopperHistory']=function(_0x34684a){var _0x3a956a=this;return new Promise(function(_0x2a37b4,_0x2145b4){return db['CmHopperHistory'][_0x8c67('0x1b')]({'raw':_0x34684a[_0x8c67('0x19')]?_0x34684a['options'][_0x8c67('0x1a')]===undefined?!![]:![]:!![],'where':_0x34684a[_0x8c67('0x19')]?_0x34684a[_0x8c67('0x19')]['where']||null:null,'attributes':[['campaign',_0x8c67('0x2d')],[db[_0x8c67('0x1d')]['fn']('COUNT',db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x2e')))),'outboundNoSuchCallsDay'],[db['sequelize']['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db['sequelize']['literal'](_0x8c67('0x2f')))),_0x8c67('0x30')],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x22')))),_0x8c67('0x31')],[db[_0x8c67('0x1d')]['fn']('COUNT',db[_0x8c67('0x1d')]['fn']('IF',db['sequelize']['literal']('`state`\x20=\x205,\x201,\x20null'))),_0x8c67('0x32')],[db['sequelize']['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x33')))),'outboundCongestionCallsDay'],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')]['literal'](_0x8c67('0x34')))),_0x8c67('0x35')],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db['sequelize'][_0x8c67('0x21')](_0x8c67('0x36')))),_0x8c67('0x37')],[db[_0x8c67('0x1d')]['fn']('COUNT',db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x38')))),_0x8c67('0x39')],[db[_0x8c67('0x1d')]['fn']('COUNT',db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')]['literal']('`state`\x20=\x2013,\x201,\x20null'))),_0x8c67('0x3a')],[db['sequelize']['fn'](_0x8c67('0x1e'),db['sequelize']['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x3b')))),_0x8c67('0x3c')],[db['sequelize']['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x3d')))),_0x8c67('0x3e')],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x3f')))),_0x8c67('0x40')],[db['sequelize']['fn'](_0x8c67('0x1e'),db[_0x8c67('0x1d')]['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x41')))),'outboundRejectCallsDay'],[db[_0x8c67('0x1d')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x8c67('0x1d')][_0x8c67('0x21')](_0x8c67('0x42')))),'outboundReCallsDay']],'group':[_0x8c67('0x43')]})['then'](function(_0x50fb02){logger[_0x8c67('0xb')](_0x8c67('0x44'),_0x34684a);logger[_0x8c67('0xd')](_0x8c67('0x44'),_0x34684a,JSON[_0x8c67('0xf')](_0x50fb02));_0x2a37b4(_0x50fb02);})['catch'](function(_0xc9ff67){logger[_0x8c67('0x10')]('GetVoiceQueueHopperHistory',_0xc9ff67[_0x8c67('0x13')],_0x34684a);_0x2145b4(_0x3a956a[_0x8c67('0x10')](0x1f4,_0xc9ff67[_0x8c67('0x13')]));});});};exports[_0x8c67('0x45')]=function(_0x4724c7){var _0x51555f=this;return new Promise(function(_0x31bd72,_0x3344ce){return db[_0x8c67('0x17')][_0x8c67('0x1b')]({'raw':_0x4724c7['options']?_0x4724c7['options']['raw']===undefined?!![]:![]:!![],'where':_0x4724c7[_0x8c67('0x19')]?_0x4724c7[_0x8c67('0x19')][_0x8c67('0x1c')]||null:null,'attributes':[[_0x8c67('0x43'),'name'],[db[_0x8c67('0x1d')]['fn'](_0x8c67('0x1e'),db['sequelize']['col']('id')),_0x8c67('0x46')],[db[_0x8c67('0x1d')]['fn']('COUNT',db[_0x8c67('0x1d')]['fn']('IF',db['sequelize'][_0x8c67('0x21')]('`state`\x20=\x204,\x201,\x20null'))),'ivrAnswerCallsDay']],'group':[_0x8c67('0x43')]})[_0x8c67('0xa')](function(_0x4465e2){logger['info']('GetCampaignHopperHistory',_0x4724c7);logger[_0x8c67('0xd')]('GetCampaignHopperHistory',_0x4724c7,JSON[_0x8c67('0xf')](_0x4465e2));_0x31bd72(_0x4465e2);})[_0x8c67('0x15')](function(_0x278377){logger['error'](_0x8c67('0x45'),_0x278377['message'],_0x4724c7);_0x3344ce(_0x51555f['error'](0x1f4,_0x278377['message']));});});};