f0ade75476a9d0c0a55123a1432329f12a3fa7bd
[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 _0xa9f4=['`state`\x20=\x2014,\x201,\x20null','`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','outboundAnswerAgiCallsDay','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','outboundReCallsDay','GetCampaignHopperHistory','name','ivrAnswerCallsDay','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','info','CmHopperHistory,\x20%s,\x20%s','request\x20sent','debug','CmHopperHistory,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','CreateCmHopperHistory','CmHopperHistory','options','raw','then','findAll','where','COUNT','sequelize','col','predictiveIntervalTotalCalls','literal','predictiveIntervalAnsweredCalls','`state`\x20=\x2010,\x201,\x20null','`state`\x20=\x204,\x20`holdtime`,\x20null','predictiveIntervalAvgHoldtime','AVG','`state`\x20=\x204,\x20`talktime`,\x20null','predictiveIntervalAvgTalktime','AvgHandleTime','GetVoiceQueueHopperHistory','campaign','outboundNoSuchCallsDay','`state`\x20=\x203,\x201,\x20null','outboundNoAnswerCallsDay','`state`\x20=\x204,\x201,\x20null','`state`\x20=\x205,\x201,\x20null','outboundBusyCallsDay','`state`\x20=\x208,\x201,\x20null','outboundCongestionCallsDay','`state`\x20=\x2010\x20,\x201,\x20null','outboundDropCallsDayTimeout','`state`\x20=\x2011\x20,\x201,\x20null','outboundDropCallsDayCallersExit','`state`\x20=\x2012,\x201,\x20null','outboundUnknownCallsDay','`state`\x20=\x2013,\x201,\x20null','outboundBlacklistCallsDay'];(function(_0x58bcd0,_0x17d4aa){var _0x1a7310=function(_0x4f7003){while(--_0x4f7003){_0x58bcd0['push'](_0x58bcd0['shift']());}};_0x1a7310(++_0x17d4aa);}(_0xa9f4,0xd2));var _0x4a9f=function(_0x167364,_0x592b96){_0x167364=_0x167364-0x0;var _0x403674=_0xa9f4[_0x167364];return _0x403674;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x4a9f('0x0'));var BPromise=require(_0x4a9f('0x1'));var rs=require(_0x4a9f('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x4a9f('0x3'))['db'];var utils=require(_0x4a9f('0x4'));var logger=require(_0x4a9f('0x5'))(_0x4a9f('0x6'));var config=require(_0x4a9f('0x7'));var jayson=require(_0x4a9f('0x8'));var client=jayson[_0x4a9f('0x9')][_0x4a9f('0xa')]({'port':0x232a});function respondWithRpcPromise(_0xfbbc1b,_0x481155,_0x167c26){return new BPromise(function(_0x58ed25,_0x31a905){return client['request'](_0xfbbc1b,_0x167c26)['then'](function(_0x33ecc8){logger[_0x4a9f('0xb')](_0x4a9f('0xc'),_0x481155,_0x4a9f('0xd'));logger[_0x4a9f('0xe')](_0x4a9f('0xf'),_0x481155,_0x4a9f('0xd'),JSON[_0x4a9f('0x10')](_0x33ecc8));if(_0x33ecc8['error']){if(_0x33ecc8[_0x4a9f('0x11')]['code']===0x1f4){logger['error'](_0x4a9f('0xc'),_0x481155,_0x33ecc8[_0x4a9f('0x11')][_0x4a9f('0x12')]);return _0x31a905(_0x33ecc8[_0x4a9f('0x11')][_0x4a9f('0x12')]);}logger[_0x4a9f('0x11')]('CmHopperHistory,\x20%s,\x20%s',_0x481155,_0x33ecc8[_0x4a9f('0x11')][_0x4a9f('0x12')]);return _0x58ed25(_0x33ecc8[_0x4a9f('0x11')][_0x4a9f('0x12')]);}else{logger[_0x4a9f('0xb')](_0x4a9f('0xc'),_0x481155,_0x4a9f('0xd'));_0x58ed25(_0x33ecc8['result'][_0x4a9f('0x12')]);}})[_0x4a9f('0x13')](function(_0x54a193){logger['error'](_0x4a9f('0xc'),_0x481155,_0x54a193);_0x31a905(_0x54a193);});});}exports[_0x4a9f('0x14')]=function(_0x86d23d){var _0x44aeae=this;return new Promise(function(_0x46c119,_0x27f775){return db[_0x4a9f('0x15')]['create'](_0x86d23d['body'],{'raw':_0x86d23d[_0x4a9f('0x16')]?_0x86d23d['options'][_0x4a9f('0x17')]===undefined?!![]:![]:!![]})[_0x4a9f('0x18')](function(_0x465035){logger['info'](_0x4a9f('0x14'),_0x86d23d);logger[_0x4a9f('0xe')](_0x4a9f('0x14'),_0x86d23d,JSON[_0x4a9f('0x10')](_0x465035));_0x46c119(_0x465035);})[_0x4a9f('0x13')](function(_0x1b7c42){logger['error'](_0x4a9f('0x14'),_0x1b7c42['message'],_0x86d23d);_0x27f775(_0x44aeae[_0x4a9f('0x11')](0x1f4,_0x1b7c42['message']));});});};exports['AvgHandleTime']=function(_0x547c6c){var _0x37ac8e=this;return new Promise(function(_0x16ea37,_0x32bdd3){return db[_0x4a9f('0x15')][_0x4a9f('0x19')]({'raw':_0x547c6c[_0x4a9f('0x16')]?_0x547c6c[_0x4a9f('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x547c6c['options']?_0x547c6c[_0x4a9f('0x16')][_0x4a9f('0x1a')]||null:null,'attributes':[[db['sequelize']['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')][_0x4a9f('0x1d')]('id')),_0x4a9f('0x1e')],[db[_0x4a9f('0x1c')]['fn']('COUNT',db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')]('`state`\x20=\x204,\x201,\x20null'))),_0x4a9f('0x20')],[db['sequelize']['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x21')))),'predictiveIntervalDroppedCallsTimeout'],[db['sequelize']['fn'](_0x4a9f('0x1b'),db['sequelize']['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')]('`state`\x20=\x2011,\x201,\x20null'))),'predictiveIntervalDroppedCallsCallersExit'],[db[_0x4a9f('0x1c')]['fn']('AVG',db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')]['literal'](_0x4a9f('0x22')))),_0x4a9f('0x23')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x24'),db[_0x4a9f('0x1c')]['fn']('IF',db['sequelize'][_0x4a9f('0x1f')](_0x4a9f('0x25')))),_0x4a9f('0x26')]]})[_0x4a9f('0x18')](function(_0x4d23e3){logger[_0x4a9f('0xb')]('AvgHandleTime',_0x547c6c);logger[_0x4a9f('0xe')](_0x4a9f('0x27'),_0x547c6c,JSON[_0x4a9f('0x10')](_0x4d23e3));_0x16ea37(_0x4d23e3);})['catch'](function(_0xe9ac92){logger[_0x4a9f('0x11')](_0x4a9f('0x27'),_0xe9ac92[_0x4a9f('0x12')],_0x547c6c);_0x32bdd3(_0x37ac8e[_0x4a9f('0x11')](0x1f4,_0xe9ac92[_0x4a9f('0x12')]));});});};exports[_0x4a9f('0x28')]=function(_0xe4719b){var _0x4e2a66=this;return new Promise(function(_0x17a6f5,_0x54947f){return db['CmHopperHistory'][_0x4a9f('0x19')]({'raw':_0xe4719b[_0x4a9f('0x16')]?_0xe4719b[_0x4a9f('0x16')][_0x4a9f('0x17')]===undefined?!![]:![]:!![],'where':_0xe4719b[_0x4a9f('0x16')]?_0xe4719b[_0x4a9f('0x16')][_0x4a9f('0x1a')]||null:null,'attributes':[[_0x4a9f('0x29'),'name'],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')]('`state`\x20=\x200,\x201,\x20null'))),_0x4a9f('0x2a')],[db[_0x4a9f('0x1c')]['fn']('COUNT',db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x2b')))),_0x4a9f('0x2c')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x2d')))),'outboundAnswerCallsDay'],[db[_0x4a9f('0x1c')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x2e')))),_0x4a9f('0x2f')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x30')))),_0x4a9f('0x31')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')]['literal'](_0x4a9f('0x32')))),_0x4a9f('0x33')],[db['sequelize']['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db['sequelize']['literal'](_0x4a9f('0x34')))),_0x4a9f('0x35')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db['sequelize']['fn']('IF',db['sequelize']['literal'](_0x4a9f('0x36')))),_0x4a9f('0x37')],[db['sequelize']['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x38')))),_0x4a9f('0x39')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x3a')))),'outboundOriginateFailureCallsDay'],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db['sequelize'][_0x4a9f('0x1f')](_0x4a9f('0x3b')))),_0x4a9f('0x3c')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')]('`state`\x20=\x2016,\x201,\x20null'))),_0x4a9f('0x3d')],[db['sequelize']['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')]['fn']('IF',db['sequelize'][_0x4a9f('0x1f')]('`state`\x20=\x2020,\x201,\x20null'))),_0x4a9f('0x3c')],[db[_0x4a9f('0x1c')]['fn']('COUNT',db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x3e')))),_0x4a9f('0x3f')]],'group':[_0x4a9f('0x29')]})[_0x4a9f('0x18')](function(_0x2822d6){logger['info']('GetVoiceQueueHopperHistory',_0xe4719b);logger[_0x4a9f('0xe')](_0x4a9f('0x28'),_0xe4719b,JSON[_0x4a9f('0x10')](_0x2822d6));_0x17a6f5(_0x2822d6);})[_0x4a9f('0x13')](function(_0x27ea85){logger[_0x4a9f('0x11')]('GetVoiceQueueHopperHistory',_0x27ea85[_0x4a9f('0x12')],_0xe4719b);_0x54947f(_0x4e2a66[_0x4a9f('0x11')](0x1f4,_0x27ea85[_0x4a9f('0x12')]));});});};exports[_0x4a9f('0x40')]=function(_0x512d52){var _0x847c4=this;return new Promise(function(_0xd4582d,_0x9d36a1){return db[_0x4a9f('0x15')][_0x4a9f('0x19')]({'raw':_0x512d52[_0x4a9f('0x16')]?_0x512d52[_0x4a9f('0x16')][_0x4a9f('0x17')]===undefined?!![]:![]:!![],'where':_0x512d52[_0x4a9f('0x16')]?_0x512d52[_0x4a9f('0x16')][_0x4a9f('0x1a')]||null:null,'attributes':[[_0x4a9f('0x29'),_0x4a9f('0x41')],[db[_0x4a9f('0x1c')]['fn'](_0x4a9f('0x1b'),db[_0x4a9f('0x1c')][_0x4a9f('0x1d')]('id')),'ivrTotalCallsDays'],[db[_0x4a9f('0x1c')]['fn']('COUNT',db[_0x4a9f('0x1c')]['fn']('IF',db[_0x4a9f('0x1c')][_0x4a9f('0x1f')](_0x4a9f('0x2d')))),_0x4a9f('0x42')]],'group':['campaign']})[_0x4a9f('0x18')](function(_0x551c59){logger[_0x4a9f('0xb')](_0x4a9f('0x40'),_0x512d52);logger[_0x4a9f('0xe')](_0x4a9f('0x40'),_0x512d52,JSON['stringify'](_0x551c59));_0xd4582d(_0x551c59);})[_0x4a9f('0x13')](function(_0x4202b3){logger[_0x4a9f('0x11')](_0x4a9f('0x40'),_0x4202b3[_0x4a9f('0x12')],_0x512d52);_0x9d36a1(_0x847c4[_0x4a9f('0x11')](0x1f4,_0x4202b3['message']));});});};