Built motion from commit 351e7f9c.|2.6.31
[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 _0x9099=['jayson/promise','client','http','info','request\x20sent','debug','CmHopperHistory,\x20%s,\x20%s,\x20%s','stringify','error','code','CmHopperHistory,\x20%s,\x20%s','message','catch','CreateCmHopperHistory','CmHopperHistory','body','options','raw','then','AvgHandleTime','findAll','where','COUNT','sequelize','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','`state`\x20=\x204,\x20`talktime`,\x20null','predictiveIntervalAvgTalktime','GetVoiceQueueHopperHistory','campaign','name','`state`\x20=\x200,\x201,\x20null','outboundNoSuchCallsDay','outboundNoAnswerCallsDay','`state`\x20=\x205,\x201,\x20null','outboundBusyCallsDay','`state`\x20=\x208,\x201,\x20null','outboundCongestionCallsDay','outboundDropCallsDayTimeout','`state`\x20=\x2011\x20,\x201,\x20null','outboundDropCallsDayCallersExit','`state`\x20=\x2012,\x201,\x20null','outboundBlacklistCallsDay','`state`\x20=\x2014,\x201,\x20null','outboundOriginateFailureCallsDay','`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','outboundAnswerAgiCallsDay','`state`\x20=\x2020,\x201,\x20null','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','outboundReCallsDay','ivrTotalCallsDays','ivrAnswerCallsDay','GetCampaignHopperHistory','lodash','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment'];(function(_0x701c5d,_0x47a566){var _0x617b08=function(_0x41409f){while(--_0x41409f){_0x701c5d['push'](_0x701c5d['shift']());}};_0x617b08(++_0x47a566);}(_0x9099,0x1ac));var _0x9909=function(_0x411add,_0x1aed38){_0x411add=_0x411add-0x0;var _0x238242=_0x9099[_0x411add];return _0x238242;};'use strict';var _=require(_0x9909('0x0'));var util=require('util');var moment=require(_0x9909('0x1'));var BPromise=require(_0x9909('0x2'));var rs=require(_0x9909('0x3'));var fs=require('fs');var Redis=require(_0x9909('0x4'));var db=require(_0x9909('0x5'))['db'];var utils=require(_0x9909('0x6'));var logger=require(_0x9909('0x7'))(_0x9909('0x8'));var config=require(_0x9909('0x9'));var jayson=require(_0x9909('0xa'));var client=jayson[_0x9909('0xb')][_0x9909('0xc')]({'port':0x232a});function respondWithRpcPromise(_0x3b7391,_0x3dc2dd,_0x54011f){return new BPromise(function(_0x6d755a,_0x5dcd39){return client['request'](_0x3b7391,_0x54011f)['then'](function(_0x5023b7){logger[_0x9909('0xd')]('CmHopperHistory,\x20%s,\x20%s',_0x3dc2dd,_0x9909('0xe'));logger[_0x9909('0xf')](_0x9909('0x10'),_0x3dc2dd,'request\x20sent',JSON[_0x9909('0x11')](_0x5023b7));if(_0x5023b7['error']){if(_0x5023b7[_0x9909('0x12')][_0x9909('0x13')]===0x1f4){logger[_0x9909('0x12')](_0x9909('0x14'),_0x3dc2dd,_0x5023b7[_0x9909('0x12')][_0x9909('0x15')]);return _0x5dcd39(_0x5023b7[_0x9909('0x12')][_0x9909('0x15')]);}logger[_0x9909('0x12')](_0x9909('0x14'),_0x3dc2dd,_0x5023b7[_0x9909('0x12')][_0x9909('0x15')]);return _0x6d755a(_0x5023b7[_0x9909('0x12')]['message']);}else{logger[_0x9909('0xd')]('CmHopperHistory,\x20%s,\x20%s',_0x3dc2dd,_0x9909('0xe'));_0x6d755a(_0x5023b7['result'][_0x9909('0x15')]);}})[_0x9909('0x16')](function(_0x245f0d){logger['error'](_0x9909('0x14'),_0x3dc2dd,_0x245f0d);_0x5dcd39(_0x245f0d);});});}exports[_0x9909('0x17')]=function(_0x180929){var _0x2e6c16=this;return new Promise(function(_0x1106e5,_0x3a38ac){return db[_0x9909('0x18')]['create'](_0x180929[_0x9909('0x19')],{'raw':_0x180929[_0x9909('0x1a')]?_0x180929['options'][_0x9909('0x1b')]===undefined?!![]:![]:!![]})[_0x9909('0x1c')](function(_0x20c236){logger[_0x9909('0xd')](_0x9909('0x17'),_0x180929);logger[_0x9909('0xf')](_0x9909('0x17'),_0x180929,JSON['stringify'](_0x20c236));_0x1106e5(_0x20c236);})[_0x9909('0x16')](function(_0x319c31){logger['error']('CreateCmHopperHistory',_0x319c31[_0x9909('0x15')],_0x180929);_0x3a38ac(_0x2e6c16[_0x9909('0x12')](0x1f4,_0x319c31[_0x9909('0x15')]));});});};exports[_0x9909('0x1d')]=function(_0x2f15fa){var _0x59c5c9=this;return new Promise(function(_0x5f3a5a,_0x2d83a5){return db[_0x9909('0x18')][_0x9909('0x1e')]({'raw':_0x2f15fa[_0x9909('0x1a')]?_0x2f15fa['options'][_0x9909('0x1b')]===undefined?!![]:![]:!![],'where':_0x2f15fa[_0x9909('0x1a')]?_0x2f15fa[_0x9909('0x1a')][_0x9909('0x1f')]||null:null,'attributes':[[db['sequelize']['fn'](_0x9909('0x20'),db[_0x9909('0x21')][_0x9909('0x22')]('id')),_0x9909('0x23')],[db['sequelize']['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x25')))),_0x9909('0x26')],[db[_0x9909('0x21')]['fn']('COUNT',db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x27')))),_0x9909('0x28')],[db['sequelize']['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x29')))),_0x9909('0x2a')],[db[_0x9909('0x21')]['fn'](_0x9909('0x2b'),db['sequelize']['fn']('IF',db['sequelize'][_0x9909('0x24')](_0x9909('0x2c')))),'predictiveIntervalAvgHoldtime'],[db[_0x9909('0x21')]['fn'](_0x9909('0x2b'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x2d')))),_0x9909('0x2e')]]})['then'](function(_0x17a7bd){logger[_0x9909('0xd')](_0x9909('0x1d'),_0x2f15fa);logger[_0x9909('0xf')](_0x9909('0x1d'),_0x2f15fa,JSON['stringify'](_0x17a7bd));_0x5f3a5a(_0x17a7bd);})[_0x9909('0x16')](function(_0x362851){logger['error'](_0x9909('0x1d'),_0x362851[_0x9909('0x15')],_0x2f15fa);_0x2d83a5(_0x59c5c9[_0x9909('0x12')](0x1f4,_0x362851[_0x9909('0x15')]));});});};exports[_0x9909('0x2f')]=function(_0x12f896){var _0x4e23ed=this;return new Promise(function(_0x21c1c8,_0x1c48bc){return db[_0x9909('0x18')][_0x9909('0x1e')]({'raw':_0x12f896[_0x9909('0x1a')]?_0x12f896[_0x9909('0x1a')][_0x9909('0x1b')]===undefined?!![]:![]:!![],'where':_0x12f896[_0x9909('0x1a')]?_0x12f896[_0x9909('0x1a')][_0x9909('0x1f')]||null:null,'attributes':[[_0x9909('0x30'),_0x9909('0x31')],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x32')))),_0x9909('0x33')],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')]['literal']('`state`\x20=\x203,\x201,\x20null'))),_0x9909('0x34')],[db['sequelize']['fn']('COUNT',db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x25')))),'outboundAnswerCallsDay'],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db['sequelize'][_0x9909('0x24')](_0x9909('0x35')))),_0x9909('0x36')],[db['sequelize']['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x37')))),_0x9909('0x38')],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db['sequelize']['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')]('`state`\x20=\x2010\x20,\x201,\x20null'))),_0x9909('0x39')],[db[_0x9909('0x21')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x3a')))),_0x9909('0x3b')],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x3c')))),'outboundUnknownCallsDay'],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')]['literal']('`state`\x20=\x2013,\x201,\x20null'))),_0x9909('0x3d')],[db['sequelize']['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')]['literal'](_0x9909('0x3e')))),_0x9909('0x3f')],[db[_0x9909('0x21')]['fn']('COUNT',db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x40')))),_0x9909('0x41')],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db['sequelize']['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')]('`state`\x20=\x2016,\x201,\x20null'))),_0x9909('0x42')],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')]['literal'](_0x9909('0x43')))),'outboundRejectCallsDay'],[db[_0x9909('0x21')]['fn'](_0x9909('0x20'),db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')][_0x9909('0x24')](_0x9909('0x44')))),_0x9909('0x45')]],'group':[_0x9909('0x30')]})['then'](function(_0x51b214){logger[_0x9909('0xd')]('GetVoiceQueueHopperHistory',_0x12f896);logger['debug'](_0x9909('0x2f'),_0x12f896,JSON[_0x9909('0x11')](_0x51b214));_0x21c1c8(_0x51b214);})['catch'](function(_0x1144e0){logger[_0x9909('0x12')](_0x9909('0x2f'),_0x1144e0[_0x9909('0x15')],_0x12f896);_0x1c48bc(_0x4e23ed[_0x9909('0x12')](0x1f4,_0x1144e0[_0x9909('0x15')]));});});};exports['GetCampaignHopperHistory']=function(_0x1702a8){var _0x2517ff=this;return new Promise(function(_0x50ada8,_0x55d31e){return db[_0x9909('0x18')]['findAll']({'raw':_0x1702a8[_0x9909('0x1a')]?_0x1702a8[_0x9909('0x1a')][_0x9909('0x1b')]===undefined?!![]:![]:!![],'where':_0x1702a8[_0x9909('0x1a')]?_0x1702a8['options']['where']||null:null,'attributes':[['campaign',_0x9909('0x31')],[db[_0x9909('0x21')]['fn']('COUNT',db['sequelize'][_0x9909('0x22')]('id')),_0x9909('0x46')],[db[_0x9909('0x21')]['fn']('COUNT',db[_0x9909('0x21')]['fn']('IF',db[_0x9909('0x21')]['literal'](_0x9909('0x25')))),_0x9909('0x47')]],'group':[_0x9909('0x30')]})[_0x9909('0x1c')](function(_0x52aaaa){logger['info'](_0x9909('0x48'),_0x1702a8);logger[_0x9909('0xf')](_0x9909('0x48'),_0x1702a8,JSON[_0x9909('0x11')](_0x52aaaa));_0x50ada8(_0x52aaaa);})[_0x9909('0x16')](function(_0x8b6d28){logger[_0x9909('0x12')](_0x9909('0x48'),_0x8b6d28[_0x9909('0x15')],_0x1702a8);_0x55d31e(_0x2517ff[_0x9909('0x12')](0x1f4,_0x8b6d28['message']));});});};