4db0a7d901157da9aeee26aa2d47c7cf03814ffa
[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 _0xf409=['outboundNoSuchCallsDay','`state`\x20=\x203,\x201,\x20null','outboundNoAnswerCallsDay','outboundAnswerCallsDay','`state`\x20=\x205,\x201,\x20null','outboundBusyCallsDay','`state`\x20=\x208,\x201,\x20null','outboundCongestionCallsDay','`state`\x20=\x2010\x20,\x201,\x20null','outboundDropCallsDayTimeout','outboundDropCallsDayCallersExit','`state`\x20=\x2012,\x201,\x20null','outboundUnknownCallsDay','outboundBlacklistCallsDay','`state`\x20=\x2014,\x201,\x20null','outboundOriginateFailureCallsDay','`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','`state`\x20=\x2020,\x201,\x20null','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','campaign','GetCampaignHopperHistory','ivrTotalCallsDays','ivrAnswerCallsDay','lodash','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','jayson/promise','http','request','then','info','CmHopperHistory,\x20%s,\x20%s','request\x20sent','debug','CmHopperHistory,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','CmHopperHistory','create','body','options','raw','CreateCmHopperHistory','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','predictiveIntervalAvgTalktime','AvgHandleTime','GetVoiceQueueHopperHistory','name','`state`\x20=\x200,\x201,\x20null'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xf409,0x18a));var _0x9f40=function(_0x2b7764,_0x2606f1){_0x2b7764=_0x2b7764-0x0;var _0x848dcb=_0xf409[_0x2b7764];return _0x848dcb;};'use strict';var _=require(_0x9f40('0x0'));var util=require('util');var moment=require(_0x9f40('0x1'));var BPromise=require('bluebird');var rs=require(_0x9f40('0x2'));var fs=require('fs');var Redis=require(_0x9f40('0x3'));var db=require(_0x9f40('0x4'))['db'];var utils=require(_0x9f40('0x5'));var logger=require(_0x9f40('0x6'))('rpc');var config=require('../../config/environment');var jayson=require(_0x9f40('0x7'));var client=jayson['client'][_0x9f40('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x747bee,_0xfae9d4,_0x5cccb6){return new BPromise(function(_0x1f474d,_0x489d89){return client[_0x9f40('0x9')](_0x747bee,_0x5cccb6)[_0x9f40('0xa')](function(_0x1a3476){logger[_0x9f40('0xb')](_0x9f40('0xc'),_0xfae9d4,_0x9f40('0xd'));logger[_0x9f40('0xe')](_0x9f40('0xf'),_0xfae9d4,_0x9f40('0xd'),JSON[_0x9f40('0x10')](_0x1a3476));if(_0x1a3476['error']){if(_0x1a3476[_0x9f40('0x11')][_0x9f40('0x12')]===0x1f4){logger[_0x9f40('0x11')](_0x9f40('0xc'),_0xfae9d4,_0x1a3476[_0x9f40('0x11')][_0x9f40('0x13')]);return _0x489d89(_0x1a3476[_0x9f40('0x11')][_0x9f40('0x13')]);}logger['error']('CmHopperHistory,\x20%s,\x20%s',_0xfae9d4,_0x1a3476[_0x9f40('0x11')]['message']);return _0x1f474d(_0x1a3476[_0x9f40('0x11')][_0x9f40('0x13')]);}else{logger[_0x9f40('0xb')](_0x9f40('0xc'),_0xfae9d4,_0x9f40('0xd'));_0x1f474d(_0x1a3476[_0x9f40('0x14')][_0x9f40('0x13')]);}})[_0x9f40('0x15')](function(_0x4f07b0){logger[_0x9f40('0x11')](_0x9f40('0xc'),_0xfae9d4,_0x4f07b0);_0x489d89(_0x4f07b0);});});}exports['CreateCmHopperHistory']=function(_0x3f4015){var _0x1dbf13=this;return new Promise(function(_0x2bd3b4,_0x46a831){return db[_0x9f40('0x16')][_0x9f40('0x17')](_0x3f4015[_0x9f40('0x18')],{'raw':_0x3f4015[_0x9f40('0x19')]?_0x3f4015[_0x9f40('0x19')][_0x9f40('0x1a')]===undefined?!![]:![]:!![]})[_0x9f40('0xa')](function(_0xe6ce9e){logger[_0x9f40('0xb')](_0x9f40('0x1b'),_0x3f4015);logger[_0x9f40('0xe')](_0x9f40('0x1b'),_0x3f4015,JSON['stringify'](_0xe6ce9e));_0x2bd3b4(_0xe6ce9e);})[_0x9f40('0x15')](function(_0x20eb39){logger['error'](_0x9f40('0x1b'),_0x20eb39[_0x9f40('0x13')],_0x3f4015);_0x46a831(_0x1dbf13[_0x9f40('0x11')](0x1f4,_0x20eb39[_0x9f40('0x13')]));});});};exports['AvgHandleTime']=function(_0x178ac6){var _0x100ffa=this;return new Promise(function(_0x4bfce1,_0x361171){return db['CmHopperHistory'][_0x9f40('0x1c')]({'raw':_0x178ac6[_0x9f40('0x19')]?_0x178ac6[_0x9f40('0x19')][_0x9f40('0x1a')]===undefined?!![]:![]:!![],'where':_0x178ac6[_0x9f40('0x19')]?_0x178ac6[_0x9f40('0x19')][_0x9f40('0x1d')]||null:null,'attributes':[[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')][_0x9f40('0x20')]('id')),_0x9f40('0x21')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db['sequelize'][_0x9f40('0x22')](_0x9f40('0x23')))),_0x9f40('0x24')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db['sequelize'][_0x9f40('0x22')](_0x9f40('0x25')))),_0x9f40('0x26')],[db[_0x9f40('0x1e')]['fn']('COUNT',db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')]['literal'](_0x9f40('0x27')))),_0x9f40('0x28')],[db['sequelize']['fn'](_0x9f40('0x29'),db['sequelize']['fn']('IF',db['sequelize'][_0x9f40('0x22')](_0x9f40('0x2a')))),_0x9f40('0x2b')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x29'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')]['literal'](_0x9f40('0x2c')))),_0x9f40('0x2d')]]})[_0x9f40('0xa')](function(_0x50272c){logger['info']('AvgHandleTime',_0x178ac6);logger[_0x9f40('0xe')](_0x9f40('0x2e'),_0x178ac6,JSON[_0x9f40('0x10')](_0x50272c));_0x4bfce1(_0x50272c);})[_0x9f40('0x15')](function(_0x5a75d3){logger['error'](_0x9f40('0x2e'),_0x5a75d3[_0x9f40('0x13')],_0x178ac6);_0x361171(_0x100ffa[_0x9f40('0x11')](0x1f4,_0x5a75d3[_0x9f40('0x13')]));});});};exports[_0x9f40('0x2f')]=function(_0x285a45){var _0x2baa89=this;return new Promise(function(_0x21fc20,_0x259335){return db['CmHopperHistory'][_0x9f40('0x1c')]({'raw':_0x285a45[_0x9f40('0x19')]?_0x285a45[_0x9f40('0x19')][_0x9f40('0x1a')]===undefined?!![]:![]:!![],'where':_0x285a45[_0x9f40('0x19')]?_0x285a45[_0x9f40('0x19')][_0x9f40('0x1d')]||null:null,'attributes':[['campaign',_0x9f40('0x30')],[db['sequelize']['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')][_0x9f40('0x22')](_0x9f40('0x31')))),_0x9f40('0x32')],[db['sequelize']['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')][_0x9f40('0x22')](_0x9f40('0x33')))),_0x9f40('0x34')],[db[_0x9f40('0x1e')]['fn']('COUNT',db[_0x9f40('0x1e')]['fn']('IF',db['sequelize'][_0x9f40('0x22')](_0x9f40('0x23')))),_0x9f40('0x35')],[db['sequelize']['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')]['literal'](_0x9f40('0x36')))),_0x9f40('0x37')],[db[_0x9f40('0x1e')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x9f40('0x1e')]['literal'](_0x9f40('0x38')))),_0x9f40('0x39')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')][_0x9f40('0x22')](_0x9f40('0x3a')))),_0x9f40('0x3b')],[db['sequelize']['fn']('COUNT',db[_0x9f40('0x1e')]['fn']('IF',db['sequelize'][_0x9f40('0x22')]('`state`\x20=\x2011\x20,\x201,\x20null'))),_0x9f40('0x3c')],[db['sequelize']['fn']('COUNT',db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')][_0x9f40('0x22')](_0x9f40('0x3d')))),_0x9f40('0x3e')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')][_0x9f40('0x22')]('`state`\x20=\x2013,\x201,\x20null'))),_0x9f40('0x3f')],[db[_0x9f40('0x1e')]['fn']('COUNT',db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')]['literal'](_0x9f40('0x40')))),_0x9f40('0x41')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')]['literal'](_0x9f40('0x42')))),_0x9f40('0x43')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')][_0x9f40('0x22')]('`state`\x20=\x2016,\x201,\x20null'))),'outboundAnswerAgiCallsDay'],[db[_0x9f40('0x1e')]['fn']('COUNT',db[_0x9f40('0x1e')]['fn']('IF',db['sequelize'][_0x9f40('0x22')](_0x9f40('0x44')))),_0x9f40('0x43')],[db[_0x9f40('0x1e')]['fn']('COUNT',db[_0x9f40('0x1e')]['fn']('IF',db[_0x9f40('0x1e')]['literal'](_0x9f40('0x45')))),'outboundReCallsDay']],'group':[_0x9f40('0x46')]})[_0x9f40('0xa')](function(_0x1f484c){logger[_0x9f40('0xb')]('GetVoiceQueueHopperHistory',_0x285a45);logger[_0x9f40('0xe')](_0x9f40('0x2f'),_0x285a45,JSON['stringify'](_0x1f484c));_0x21fc20(_0x1f484c);})['catch'](function(_0x448fc5){logger[_0x9f40('0x11')](_0x9f40('0x2f'),_0x448fc5[_0x9f40('0x13')],_0x285a45);_0x259335(_0x2baa89[_0x9f40('0x11')](0x1f4,_0x448fc5[_0x9f40('0x13')]));});});};exports[_0x9f40('0x47')]=function(_0x4de552){var _0x2821d5=this;return new Promise(function(_0x5f44f6,_0x5b19e0){return db[_0x9f40('0x16')][_0x9f40('0x1c')]({'raw':_0x4de552[_0x9f40('0x19')]?_0x4de552['options'][_0x9f40('0x1a')]===undefined?!![]:![]:!![],'where':_0x4de552['options']?_0x4de552[_0x9f40('0x19')][_0x9f40('0x1d')]||null:null,'attributes':[[_0x9f40('0x46'),_0x9f40('0x30')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')][_0x9f40('0x20')]('id')),_0x9f40('0x48')],[db[_0x9f40('0x1e')]['fn'](_0x9f40('0x1f'),db[_0x9f40('0x1e')]['fn']('IF',db['sequelize'][_0x9f40('0x22')](_0x9f40('0x23')))),_0x9f40('0x49')]],'group':['campaign']})[_0x9f40('0xa')](function(_0x4c78fb){logger['info'](_0x9f40('0x47'),_0x4de552);logger['debug']('GetCampaignHopperHistory',_0x4de552,JSON[_0x9f40('0x10')](_0x4c78fb));_0x5f44f6(_0x4c78fb);})['catch'](function(_0x4f5cc8){logger[_0x9f40('0x11')](_0x9f40('0x47'),_0x4f5cc8[_0x9f40('0x13')],_0x4de552);_0x5b19e0(_0x2821d5[_0x9f40('0x11')](0x1f4,_0x4f5cc8[_0x9f40('0x13')]));});});};