3b3ffde38ca6e4d9470033cedd139a8950d9e074
[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 _0x976a=['name','`state`\x20=\x200,\x201,\x20null','`state`\x20=\x203,\x201,\x20null','outboundNoAnswerCallsDay','`state`\x20=\x204,\x201,\x20null','outboundAnswerCallsDay','`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','`state`\x20=\x2013,\x201,\x20null','outboundBlacklistCallsDay','`state`\x20=\x2014,\x201,\x20null','outboundOriginateFailureCallsDay','outboundRejectCallsDay','`state`\x20=\x2016,\x201,\x20null','outboundAnswerAgiCallsDay','`state`\x20=\x2020,\x201,\x20null','outboundReCallsDay','campaign','GetCampaignHopperHistory','ivrTotalCallsDays','ivrAnswerCallsDay','lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','request','then','info','CmHopperHistory,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','CmHopperHistory,\x20%s,\x20%s','message','result','CmHopperHistory','create','options','raw','debug','CreateCmHopperHistory','catch','AvgHandleTime','findAll','where','sequelize','COUNT','col','predictiveIntervalTotalCalls','literal','`state`\x20=\x2010,\x201,\x20null','`state`\x20=\x2011,\x201,\x20null','predictiveIntervalDroppedCallsCallersExit','AVG','`state`\x20=\x204,\x20`holdtime`,\x20null','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','GetVoiceQueueHopperHistory'];(function(_0x16af3c,_0x5e3ff4){var _0x358a59=function(_0x4970ee){while(--_0x4970ee){_0x16af3c['push'](_0x16af3c['shift']());}};_0x358a59(++_0x5e3ff4);}(_0x976a,0xf4));var _0xa976=function(_0x4dca38,_0x5dfae1){_0x4dca38=_0x4dca38-0x0;var _0x44656c=_0x976a[_0x4dca38];return _0x44656c;};'use strict';var _=require(_0xa976('0x0'));var util=require(_0xa976('0x1'));var moment=require(_0xa976('0x2'));var BPromise=require('bluebird');var rs=require(_0xa976('0x3'));var fs=require('fs');var Redis=require(_0xa976('0x4'));var db=require(_0xa976('0x5'))['db'];var utils=require(_0xa976('0x6'));var logger=require(_0xa976('0x7'))(_0xa976('0x8'));var config=require(_0xa976('0x9'));var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x5caa7a,_0x3a4a2,_0x12a073){return new BPromise(function(_0x1a9983,_0xc3661d){return client[_0xa976('0xa')](_0x5caa7a,_0x12a073)[_0xa976('0xb')](function(_0x197ebf){logger[_0xa976('0xc')]('CmHopperHistory,\x20%s,\x20%s',_0x3a4a2,'request\x20sent');logger['debug'](_0xa976('0xd'),_0x3a4a2,_0xa976('0xe'),JSON[_0xa976('0xf')](_0x197ebf));if(_0x197ebf[_0xa976('0x10')]){if(_0x197ebf['error'][_0xa976('0x11')]===0x1f4){logger[_0xa976('0x10')](_0xa976('0x12'),_0x3a4a2,_0x197ebf[_0xa976('0x10')][_0xa976('0x13')]);return _0xc3661d(_0x197ebf[_0xa976('0x10')]['message']);}logger[_0xa976('0x10')](_0xa976('0x12'),_0x3a4a2,_0x197ebf[_0xa976('0x10')][_0xa976('0x13')]);return _0x1a9983(_0x197ebf[_0xa976('0x10')][_0xa976('0x13')]);}else{logger[_0xa976('0xc')](_0xa976('0x12'),_0x3a4a2,_0xa976('0xe'));_0x1a9983(_0x197ebf[_0xa976('0x14')][_0xa976('0x13')]);}})['catch'](function(_0xf5f9b){logger[_0xa976('0x10')](_0xa976('0x12'),_0x3a4a2,_0xf5f9b);_0xc3661d(_0xf5f9b);});});}exports['CreateCmHopperHistory']=function(_0x4848d8){var _0x3f2cd5=this;return new Promise(function(_0x36b47a,_0x3ca2dd){return db[_0xa976('0x15')][_0xa976('0x16')](_0x4848d8['body'],{'raw':_0x4848d8[_0xa976('0x17')]?_0x4848d8[_0xa976('0x17')][_0xa976('0x18')]===undefined?!![]:![]:!![]})[_0xa976('0xb')](function(_0x44f7d4){logger['info']('CreateCmHopperHistory',_0x4848d8);logger[_0xa976('0x19')](_0xa976('0x1a'),_0x4848d8,JSON['stringify'](_0x44f7d4));_0x36b47a(_0x44f7d4);})[_0xa976('0x1b')](function(_0x4f60ff){logger['error'](_0xa976('0x1a'),_0x4f60ff[_0xa976('0x13')],_0x4848d8);_0x3ca2dd(_0x3f2cd5[_0xa976('0x10')](0x1f4,_0x4f60ff[_0xa976('0x13')]));});});};exports[_0xa976('0x1c')]=function(_0xe572fe){var _0x31231f=this;return new Promise(function(_0x54b5ba,_0x5a2f6f){return db['CmHopperHistory'][_0xa976('0x1d')]({'raw':_0xe572fe[_0xa976('0x17')]?_0xe572fe[_0xa976('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0xe572fe['options']?_0xe572fe[_0xa976('0x17')][_0xa976('0x1e')]||null:null,'attributes':[[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')][_0xa976('0x21')]('id')),_0xa976('0x22')],[db[_0xa976('0x1f')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')]('`state`\x20=\x204,\x201,\x20null'))),'predictiveIntervalAnsweredCalls'],[db[_0xa976('0x1f')]['fn']('COUNT',db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x24')))),'predictiveIntervalDroppedCallsTimeout'],[db['sequelize']['fn'](_0xa976('0x20'),db['sequelize']['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x25')))),_0xa976('0x26')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x27'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x28')))),_0xa976('0x29')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x27'),db[_0xa976('0x1f')]['fn']('IF',db['sequelize'][_0xa976('0x23')]('`state`\x20=\x204,\x20`talktime`,\x20null'))),_0xa976('0x2a')]]})[_0xa976('0xb')](function(_0x1f8e7e){logger[_0xa976('0xc')](_0xa976('0x1c'),_0xe572fe);logger[_0xa976('0x19')](_0xa976('0x1c'),_0xe572fe,JSON[_0xa976('0xf')](_0x1f8e7e));_0x54b5ba(_0x1f8e7e);})[_0xa976('0x1b')](function(_0x3e9baa){logger[_0xa976('0x10')](_0xa976('0x1c'),_0x3e9baa[_0xa976('0x13')],_0xe572fe);_0x5a2f6f(_0x31231f['error'](0x1f4,_0x3e9baa[_0xa976('0x13')]));});});};exports[_0xa976('0x2b')]=function(_0x16c6b4){var _0x545320=this;return new Promise(function(_0x1c6728,_0x37eeb7){return db[_0xa976('0x15')][_0xa976('0x1d')]({'raw':_0x16c6b4[_0xa976('0x17')]?_0x16c6b4['options'][_0xa976('0x18')]===undefined?!![]:![]:!![],'where':_0x16c6b4['options']?_0x16c6b4[_0xa976('0x17')][_0xa976('0x1e')]||null:null,'attributes':[['campaign',_0xa976('0x2c')],[db[_0xa976('0x1f')]['fn']('COUNT',db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')]['literal'](_0xa976('0x2d')))),'outboundNoSuchCallsDay'],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db['sequelize']['fn']('IF',db['sequelize'][_0xa976('0x23')](_0xa976('0x2e')))),_0xa976('0x2f')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x30')))),_0xa976('0x31')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x32')))),_0xa976('0x33')],[db[_0xa976('0x1f')]['fn']('COUNT',db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x34')))),_0xa976('0x35')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db['sequelize']['fn']('IF',db['sequelize']['literal'](_0xa976('0x36')))),_0xa976('0x37')],[db['sequelize']['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x38')))),_0xa976('0x39')],[db[_0xa976('0x1f')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x3a')))),'outboundUnknownCallsDay'],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')]['literal'](_0xa976('0x3b')))),_0xa976('0x3c')],[db['sequelize']['fn'](_0xa976('0x20'),db['sequelize']['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x3d')))),_0xa976('0x3e')],[db['sequelize']['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')]('`state`\x20=\x2018,\x201,\x20null'))),_0xa976('0x3f')],[db['sequelize']['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x40')))),_0xa976('0x41')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')](_0xa976('0x42')))),_0xa976('0x3f')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')][_0xa976('0x23')]('`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null'))),_0xa976('0x43')]],'group':[_0xa976('0x44')]})[_0xa976('0xb')](function(_0x9b72a){logger['info']('GetVoiceQueueHopperHistory',_0x16c6b4);logger['debug']('GetVoiceQueueHopperHistory',_0x16c6b4,JSON[_0xa976('0xf')](_0x9b72a));_0x1c6728(_0x9b72a);})[_0xa976('0x1b')](function(_0x1fdf63){logger['error'](_0xa976('0x2b'),_0x1fdf63['message'],_0x16c6b4);_0x37eeb7(_0x545320[_0xa976('0x10')](0x1f4,_0x1fdf63[_0xa976('0x13')]));});});};exports[_0xa976('0x45')]=function(_0x3e6893){var _0x50b875=this;return new Promise(function(_0x89b850,_0x830789){return db[_0xa976('0x15')][_0xa976('0x1d')]({'raw':_0x3e6893[_0xa976('0x17')]?_0x3e6893[_0xa976('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0x3e6893[_0xa976('0x17')]?_0x3e6893[_0xa976('0x17')][_0xa976('0x1e')]||null:null,'attributes':[['campaign',_0xa976('0x2c')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')][_0xa976('0x21')]('id')),_0xa976('0x46')],[db[_0xa976('0x1f')]['fn'](_0xa976('0x20'),db[_0xa976('0x1f')]['fn']('IF',db[_0xa976('0x1f')]['literal'](_0xa976('0x30')))),_0xa976('0x47')]],'group':['campaign']})[_0xa976('0xb')](function(_0x4f7178){logger['info']('GetCampaignHopperHistory',_0x3e6893);logger[_0xa976('0x19')]('GetCampaignHopperHistory',_0x3e6893,JSON[_0xa976('0xf')](_0x4f7178));_0x89b850(_0x4f7178);})[_0xa976('0x1b')](function(_0x40da22){logger['error'](_0xa976('0x45'),_0x40da22['message'],_0x3e6893);_0x830789(_0x50b875[_0xa976('0x10')](0x1f4,_0x40da22[_0xa976('0x13')]));});});};