Built motion from commit f16df95f.|2.5.40
[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 _0x9567=['outboundAnswerAgiCallsDay','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','outboundReCallsDay','GetVoiceQueueHopperHistory','GetCampaignHopperHistory','col','ivrTotalCallsDays','lodash','util','moment','bluebird','randomstring','../../config/utils','../../config/logger','../../config/environment','client','request','then','info','CmHopperHistory,\x20%s,\x20%s','debug','CmHopperHistory,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','result','catch','CreateCmHopperHistory','create','options','stringify','AvgHandleTime','CmHopperHistory','findAll','where','sequelize','COUNT','predictiveIntervalTotalCalls','literal','`state`\x20=\x204,\x201,\x20null','predictiveIntervalAnsweredCalls','`state`\x20=\x2010,\x201,\x20null','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit','AVG','predictiveIntervalAvgHoldtime','`state`\x20=\x204,\x20`talktime`,\x20null','predictiveIntervalAvgTalktime','raw','campaign','name','`state`\x20=\x200,\x201,\x20null','outboundNoSuchCallsDay','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','outboundUnknownCallsDay','`state`\x20=\x2013,\x201,\x20null','outboundBlacklistCallsDay','`state`\x20=\x2014,\x201,\x20null','outboundOriginateFailureCallsDay','`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','`state`\x20=\x2016,\x201,\x20null'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x9567,0xdc));var _0x7956=function(_0x4b6e11,_0x56b4b8){_0x4b6e11=_0x4b6e11-0x0;var _0x43ecb5=_0x9567[_0x4b6e11];return _0x43ecb5;};'use strict';var _=require(_0x7956('0x0'));var util=require(_0x7956('0x1'));var moment=require(_0x7956('0x2'));var BPromise=require(_0x7956('0x3'));var rs=require(_0x7956('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x7956('0x5'));var logger=require(_0x7956('0x6'))('rpc');var config=require(_0x7956('0x7'));var jayson=require('jayson/promise');var client=jayson[_0x7956('0x8')]['http']({'port':0x232a});function respondWithRpcPromise(_0x1819b6,_0x31b50d,_0x48b2b3){return new BPromise(function(_0x3c213a,_0x50038a){return client[_0x7956('0x9')](_0x1819b6,_0x48b2b3)[_0x7956('0xa')](function(_0x53310c){logger[_0x7956('0xb')](_0x7956('0xc'),_0x31b50d,'request\x20sent');logger[_0x7956('0xd')](_0x7956('0xe'),_0x31b50d,_0x7956('0xf'),JSON['stringify'](_0x53310c));if(_0x53310c[_0x7956('0x10')]){if(_0x53310c[_0x7956('0x10')][_0x7956('0x11')]===0x1f4){logger[_0x7956('0x10')]('CmHopperHistory,\x20%s,\x20%s',_0x31b50d,_0x53310c[_0x7956('0x10')][_0x7956('0x12')]);return _0x50038a(_0x53310c[_0x7956('0x10')]['message']);}logger[_0x7956('0x10')](_0x7956('0xc'),_0x31b50d,_0x53310c[_0x7956('0x10')][_0x7956('0x12')]);return _0x3c213a(_0x53310c[_0x7956('0x10')][_0x7956('0x12')]);}else{logger[_0x7956('0xb')](_0x7956('0xc'),_0x31b50d,_0x7956('0xf'));_0x3c213a(_0x53310c[_0x7956('0x13')][_0x7956('0x12')]);}})[_0x7956('0x14')](function(_0x18ae51){logger[_0x7956('0x10')](_0x7956('0xc'),_0x31b50d,_0x18ae51);_0x50038a(_0x18ae51);});});}exports[_0x7956('0x15')]=function(_0x5e6b90){var _0x5c3afb=this;return new Promise(function(_0x10b29c,_0x811122){return db['CmHopperHistory'][_0x7956('0x16')](_0x5e6b90['body'],{'raw':_0x5e6b90[_0x7956('0x17')]?_0x5e6b90[_0x7956('0x17')]['raw']===undefined?!![]:![]:!![]})[_0x7956('0xa')](function(_0x2e31cd){logger[_0x7956('0xb')]('CreateCmHopperHistory',_0x5e6b90);logger[_0x7956('0xd')]('CreateCmHopperHistory',_0x5e6b90,JSON[_0x7956('0x18')](_0x2e31cd));_0x10b29c(_0x2e31cd);})['catch'](function(_0x427500){logger[_0x7956('0x10')](_0x7956('0x15'),_0x427500[_0x7956('0x12')],_0x5e6b90);_0x811122(_0x5c3afb['error'](0x1f4,_0x427500[_0x7956('0x12')]));});});};exports[_0x7956('0x19')]=function(_0x432a2d){var _0x51020f=this;return new Promise(function(_0x53d1c4,_0x45f866){return db[_0x7956('0x1a')][_0x7956('0x1b')]({'raw':_0x432a2d[_0x7956('0x17')]?_0x432a2d[_0x7956('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0x432a2d[_0x7956('0x17')]?_0x432a2d[_0x7956('0x17')][_0x7956('0x1c')]||null:null,'attributes':[[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['col']('id')),_0x7956('0x1f')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')](_0x7956('0x21')))),_0x7956('0x22')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')](_0x7956('0x23')))),_0x7956('0x24')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')]('`state`\x20=\x2011,\x201,\x20null'))),_0x7956('0x25')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x26'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')]('`state`\x20=\x204,\x20`holdtime`,\x20null'))),_0x7956('0x27')],[db[_0x7956('0x1d')]['fn']('AVG',db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')](_0x7956('0x28')))),_0x7956('0x29')]]})[_0x7956('0xa')](function(_0x22c3fe){logger[_0x7956('0xb')](_0x7956('0x19'),_0x432a2d);logger[_0x7956('0xd')](_0x7956('0x19'),_0x432a2d,JSON[_0x7956('0x18')](_0x22c3fe));_0x53d1c4(_0x22c3fe);})[_0x7956('0x14')](function(_0x322108){logger[_0x7956('0x10')](_0x7956('0x19'),_0x322108['message'],_0x432a2d);_0x45f866(_0x51020f[_0x7956('0x10')](0x1f4,_0x322108[_0x7956('0x12')]));});});};exports['GetVoiceQueueHopperHistory']=function(_0x3a758b){var _0x4fd2a9=this;return new Promise(function(_0x56f18a,_0x4d7dcd){return db['CmHopperHistory'][_0x7956('0x1b')]({'raw':_0x3a758b['options']?_0x3a758b[_0x7956('0x17')][_0x7956('0x2a')]===undefined?!![]:![]:!![],'where':_0x3a758b[_0x7956('0x17')]?_0x3a758b[_0x7956('0x17')][_0x7956('0x1c')]||null:null,'attributes':[[_0x7956('0x2b'),_0x7956('0x2c')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db['sequelize']['fn']('IF',db[_0x7956('0x1d')]['literal'](_0x7956('0x2d')))),_0x7956('0x2e')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db['sequelize']['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')]('`state`\x20=\x203,\x201,\x20null'))),'outboundNoAnswerCallsDay'],[db[_0x7956('0x1d')]['fn']('COUNT',db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')]('`state`\x20=\x204,\x201,\x20null'))),_0x7956('0x2f')],[db[_0x7956('0x1d')]['fn']('COUNT',db[_0x7956('0x1d')]['fn']('IF',db['sequelize'][_0x7956('0x20')](_0x7956('0x30')))),_0x7956('0x31')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db['sequelize']['fn']('IF',db['sequelize'][_0x7956('0x20')](_0x7956('0x32')))),_0x7956('0x33')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db['sequelize'][_0x7956('0x20')](_0x7956('0x34')))),_0x7956('0x35')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')](_0x7956('0x36')))),_0x7956('0x37')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')]('`state`\x20=\x2012,\x201,\x20null'))),_0x7956('0x38')],[db['sequelize']['fn']('COUNT',db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')](_0x7956('0x39')))),_0x7956('0x3a')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')](_0x7956('0x3b')))),_0x7956('0x3c')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')](_0x7956('0x3d')))),_0x7956('0x3e')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db['sequelize'][_0x7956('0x20')](_0x7956('0x3f')))),_0x7956('0x40')],[db['sequelize']['fn'](_0x7956('0x1e'),db['sequelize']['fn']('IF',db[_0x7956('0x1d')][_0x7956('0x20')]('`state`\x20=\x2020,\x201,\x20null'))),_0x7956('0x3e')],[db[_0x7956('0x1d')]['fn']('COUNT',db[_0x7956('0x1d')]['fn']('IF',db[_0x7956('0x1d')]['literal'](_0x7956('0x41')))),_0x7956('0x42')]],'group':[_0x7956('0x2b')]})[_0x7956('0xa')](function(_0x3c592a){logger[_0x7956('0xb')](_0x7956('0x43'),_0x3a758b);logger['debug'](_0x7956('0x43'),_0x3a758b,JSON[_0x7956('0x18')](_0x3c592a));_0x56f18a(_0x3c592a);})[_0x7956('0x14')](function(_0x43e920){logger['error'](_0x7956('0x43'),_0x43e920[_0x7956('0x12')],_0x3a758b);_0x4d7dcd(_0x4fd2a9[_0x7956('0x10')](0x1f4,_0x43e920[_0x7956('0x12')]));});});};exports[_0x7956('0x44')]=function(_0x125c46){var _0x23e7ee=this;return new Promise(function(_0x277d78,_0x3d7a33){return db[_0x7956('0x1a')][_0x7956('0x1b')]({'raw':_0x125c46[_0x7956('0x17')]?_0x125c46[_0x7956('0x17')][_0x7956('0x2a')]===undefined?!![]:![]:!![],'where':_0x125c46['options']?_0x125c46[_0x7956('0x17')][_0x7956('0x1c')]||null:null,'attributes':[[_0x7956('0x2b'),_0x7956('0x2c')],[db['sequelize']['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')][_0x7956('0x45')]('id')),_0x7956('0x46')],[db[_0x7956('0x1d')]['fn'](_0x7956('0x1e'),db[_0x7956('0x1d')]['fn']('IF',db['sequelize']['literal'](_0x7956('0x21')))),'ivrAnswerCallsDay']],'group':[_0x7956('0x2b')]})[_0x7956('0xa')](function(_0x27619d){logger[_0x7956('0xb')](_0x7956('0x44'),_0x125c46);logger[_0x7956('0xd')](_0x7956('0x44'),_0x125c46,JSON[_0x7956('0x18')](_0x27619d));_0x277d78(_0x27619d);})[_0x7956('0x14')](function(_0x5d41ca){logger[_0x7956('0x10')](_0x7956('0x44'),_0x5d41ca[_0x7956('0x12')],_0x125c46);_0x3d7a33(_0x23e7ee['error'](0x1f4,_0x5d41ca[_0x7956('0x12')]));});});};