Built motion from commit cafec4f3.|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 _0xe235=['`state`\x20=\x2010\x20,\x201,\x20null','outboundDropCallsDayTimeout','`state`\x20=\x2011\x20,\x201,\x20null','outboundDropCallsDayCallersExit','outboundUnknownCallsDay','outboundBlacklistCallsDay','`state`\x20=\x2018,\x201,\x20null','`state`\x20=\x2016,\x201,\x20null','outboundAnswerAgiCallsDay','`state`\x20=\x2020,\x201,\x20null','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','outboundReCallsDay','GetCampaignHopperHistory','ivrTotalCallsDays','ivrAnswerCallsDay','lodash','util','moment','bluebird','../../mysqldb','../../config/utils','../../config/logger','jayson/promise','client','http','request','then','info','CmHopperHistory,\x20%s,\x20%s','request\x20sent','CmHopperHistory,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','CreateCmHopperHistory','CmHopperHistory','body','options','raw','debug','AvgHandleTime','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','predictiveIntervalAvgHoldtime','`state`\x20=\x204,\x20`talktime`,\x20null','predictiveIntervalAvgTalktime','GetVoiceQueueHopperHistory','campaign','name','`state`\x20=\x200,\x201,\x20null','outboundNoSuchCallsDay','`state`\x20=\x203,\x201,\x20null','outboundNoAnswerCallsDay','outboundAnswerCallsDay','outboundBusyCallsDay','`state`\x20=\x208,\x201,\x20null','outboundCongestionCallsDay'];(function(_0x1969a7,_0x5a133a){var _0x3d665f=function(_0x39c64b){while(--_0x39c64b){_0x1969a7['push'](_0x1969a7['shift']());}};_0x3d665f(++_0x5a133a);}(_0xe235,0xe4));var _0x5e23=function(_0x442f02,_0x47d845){_0x442f02=_0x442f02-0x0;var _0xab6ef1=_0xe235[_0x442f02];return _0xab6ef1;};'use strict';var _=require(_0x5e23('0x0'));var util=require(_0x5e23('0x1'));var moment=require(_0x5e23('0x2'));var BPromise=require(_0x5e23('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x5e23('0x4'))['db'];var utils=require(_0x5e23('0x5'));var logger=require(_0x5e23('0x6'))('rpc');var config=require('../../config/environment');var jayson=require(_0x5e23('0x7'));var client=jayson[_0x5e23('0x8')][_0x5e23('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x1c9b2b,_0x16454c,_0xd7f262){return new BPromise(function(_0x1f0008,_0x92ae38){return client[_0x5e23('0xa')](_0x1c9b2b,_0xd7f262)[_0x5e23('0xb')](function(_0x3bd7d5){logger[_0x5e23('0xc')](_0x5e23('0xd'),_0x16454c,_0x5e23('0xe'));logger['debug'](_0x5e23('0xf'),_0x16454c,_0x5e23('0xe'),JSON[_0x5e23('0x10')](_0x3bd7d5));if(_0x3bd7d5['error']){if(_0x3bd7d5[_0x5e23('0x11')]['code']===0x1f4){logger[_0x5e23('0x11')](_0x5e23('0xd'),_0x16454c,_0x3bd7d5['error'][_0x5e23('0x12')]);return _0x92ae38(_0x3bd7d5[_0x5e23('0x11')][_0x5e23('0x12')]);}logger[_0x5e23('0x11')]('CmHopperHistory,\x20%s,\x20%s',_0x16454c,_0x3bd7d5['error'][_0x5e23('0x12')]);return _0x1f0008(_0x3bd7d5[_0x5e23('0x11')][_0x5e23('0x12')]);}else{logger[_0x5e23('0xc')](_0x5e23('0xd'),_0x16454c,_0x5e23('0xe'));_0x1f0008(_0x3bd7d5[_0x5e23('0x13')][_0x5e23('0x12')]);}})[_0x5e23('0x14')](function(_0x149a3f){logger[_0x5e23('0x11')](_0x5e23('0xd'),_0x16454c,_0x149a3f);_0x92ae38(_0x149a3f);});});}exports[_0x5e23('0x15')]=function(_0x1fb1fc){var _0x5c9d00=this;return new Promise(function(_0x25cd9e,_0x412725){return db[_0x5e23('0x16')]['create'](_0x1fb1fc[_0x5e23('0x17')],{'raw':_0x1fb1fc[_0x5e23('0x18')]?_0x1fb1fc[_0x5e23('0x18')][_0x5e23('0x19')]===undefined?!![]:![]:!![]})[_0x5e23('0xb')](function(_0x1d0ce0){logger['info'](_0x5e23('0x15'),_0x1fb1fc);logger[_0x5e23('0x1a')]('CreateCmHopperHistory',_0x1fb1fc,JSON[_0x5e23('0x10')](_0x1d0ce0));_0x25cd9e(_0x1d0ce0);})[_0x5e23('0x14')](function(_0x4312de){logger['error'](_0x5e23('0x15'),_0x4312de[_0x5e23('0x12')],_0x1fb1fc);_0x412725(_0x5c9d00['error'](0x1f4,_0x4312de['message']));});});};exports[_0x5e23('0x1b')]=function(_0x2b7cc8){var _0x408619=this;return new Promise(function(_0x53dd05,_0x2351d6){return db['CmHopperHistory'][_0x5e23('0x1c')]({'raw':_0x2b7cc8[_0x5e23('0x18')]?_0x2b7cc8[_0x5e23('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x2b7cc8[_0x5e23('0x18')]?_0x2b7cc8['options'][_0x5e23('0x1d')]||null:null,'attributes':[[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')][_0x5e23('0x20')]('id')),_0x5e23('0x21')],[db['sequelize']['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x23')))),_0x5e23('0x24')],[db['sequelize']['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x25')))),_0x5e23('0x26')],[db['sequelize']['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x27')))),_0x5e23('0x28')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x29'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')]('`state`\x20=\x204,\x20`holdtime`,\x20null'))),_0x5e23('0x2a')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x29'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x2b')))),_0x5e23('0x2c')]]})[_0x5e23('0xb')](function(_0x3cf236){logger[_0x5e23('0xc')](_0x5e23('0x1b'),_0x2b7cc8);logger[_0x5e23('0x1a')]('AvgHandleTime',_0x2b7cc8,JSON['stringify'](_0x3cf236));_0x53dd05(_0x3cf236);})[_0x5e23('0x14')](function(_0x50647e){logger['error'](_0x5e23('0x1b'),_0x50647e[_0x5e23('0x12')],_0x2b7cc8);_0x2351d6(_0x408619[_0x5e23('0x11')](0x1f4,_0x50647e['message']));});});};exports[_0x5e23('0x2d')]=function(_0x4dbcbd){var _0x18c06f=this;return new Promise(function(_0x4645bc,_0x43fe17){return db['CmHopperHistory']['findAll']({'raw':_0x4dbcbd[_0x5e23('0x18')]?_0x4dbcbd['options'][_0x5e23('0x19')]===undefined?!![]:![]:!![],'where':_0x4dbcbd[_0x5e23('0x18')]?_0x4dbcbd[_0x5e23('0x18')][_0x5e23('0x1d')]||null:null,'attributes':[[_0x5e23('0x2e'),_0x5e23('0x2f')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db['sequelize']['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x30')))),_0x5e23('0x31')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db['sequelize']['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x32')))),_0x5e23('0x33')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')]('`state`\x20=\x204,\x201,\x20null'))),_0x5e23('0x34')],[db[_0x5e23('0x1e')]['fn']('COUNT',db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')]('`state`\x20=\x205,\x201,\x20null'))),_0x5e23('0x35')],[db['sequelize']['fn']('COUNT',db[_0x5e23('0x1e')]['fn']('IF',db['sequelize'][_0x5e23('0x22')](_0x5e23('0x36')))),_0x5e23('0x37')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x38')))),_0x5e23('0x39')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db['sequelize']['fn']('IF',db['sequelize'][_0x5e23('0x22')](_0x5e23('0x3a')))),_0x5e23('0x3b')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')]['literal']('`state`\x20=\x2012,\x201,\x20null'))),_0x5e23('0x3c')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')]('`state`\x20=\x2013,\x201,\x20null'))),_0x5e23('0x3d')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db['sequelize']['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')]('`state`\x20=\x2014,\x201,\x20null'))),'outboundOriginateFailureCallsDay'],[db[_0x5e23('0x1e')]['fn']('COUNT',db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x3e')))),'outboundRejectCallsDay'],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x3f')))),_0x5e23('0x40')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x41')))),'outboundRejectCallsDay'],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db['sequelize'][_0x5e23('0x22')](_0x5e23('0x42')))),_0x5e23('0x43')]],'group':[_0x5e23('0x2e')]})[_0x5e23('0xb')](function(_0x338234){logger[_0x5e23('0xc')](_0x5e23('0x2d'),_0x4dbcbd);logger[_0x5e23('0x1a')]('GetVoiceQueueHopperHistory',_0x4dbcbd,JSON[_0x5e23('0x10')](_0x338234));_0x4645bc(_0x338234);})['catch'](function(_0x12b772){logger[_0x5e23('0x11')](_0x5e23('0x2d'),_0x12b772[_0x5e23('0x12')],_0x4dbcbd);_0x43fe17(_0x18c06f['error'](0x1f4,_0x12b772[_0x5e23('0x12')]));});});};exports[_0x5e23('0x44')]=function(_0xc23b7b){var _0x10f231=this;return new Promise(function(_0x5d9fb9,_0x525b40){return db[_0x5e23('0x16')]['findAll']({'raw':_0xc23b7b[_0x5e23('0x18')]?_0xc23b7b['options'][_0x5e23('0x19')]===undefined?!![]:![]:!![],'where':_0xc23b7b[_0x5e23('0x18')]?_0xc23b7b[_0x5e23('0x18')][_0x5e23('0x1d')]||null:null,'attributes':[['campaign',_0x5e23('0x2f')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')][_0x5e23('0x20')]('id')),_0x5e23('0x45')],[db[_0x5e23('0x1e')]['fn'](_0x5e23('0x1f'),db[_0x5e23('0x1e')]['fn']('IF',db[_0x5e23('0x1e')][_0x5e23('0x22')](_0x5e23('0x23')))),_0x5e23('0x46')]],'group':['campaign']})[_0x5e23('0xb')](function(_0x1c494d){logger[_0x5e23('0xc')](_0x5e23('0x44'),_0xc23b7b);logger['debug']('GetCampaignHopperHistory',_0xc23b7b,JSON[_0x5e23('0x10')](_0x1c494d));_0x5d9fb9(_0x1c494d);})[_0x5e23('0x14')](function(_0xf62092){logger[_0x5e23('0x11')](_0x5e23('0x44'),_0xf62092['message'],_0xc23b7b);_0x525b40(_0x10f231['error'](0x1f4,_0xf62092[_0x5e23('0x12')]));});});};