cebe02d3d34d425421fcb81746d71ae5a2e7a832
[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 _0x2ceb=['col','predictiveIntervalTotalCalls','`state`\x20=\x204,\x201,\x20null','predictiveIntervalAnsweredCalls','literal','`state`\x20=\x2010,\x201,\x20null','predictiveIntervalDroppedCallsTimeout','`state`\x20=\x2011,\x201,\x20null','AVG','`state`\x20=\x204,\x20`holdtime`,\x20null','predictiveIntervalAvgHoldtime','`state`\x20=\x204,\x20`talktime`,\x20null','predictiveIntervalAvgTalktime','AvgHandleTime','GetVoiceQueueHopperHistory','findAll','campaign','name','`state`\x20=\x200,\x201,\x20null','outboundNoSuchCallsDay','`state`\x20=\x203,\x201,\x20null','outboundNoAnswerCallsDay','outboundAnswerCallsDay','`state`\x20=\x205,\x201,\x20null','outboundBusyCallsDay','`state`\x20=\x208,\x201,\x20null','outboundCongestionCallsDay','`state`\x20=\x2010\x20,\x201,\x20null','`state`\x20=\x2011\x20,\x201,\x20null','outboundDropCallsDayCallersExit','`state`\x20=\x2012,\x201,\x20null','outboundUnknownCallsDay','`state`\x20=\x2013,\x201,\x20null','outboundBlacklistCallsDay','`state`\x20=\x2014,\x201,\x20null','outboundOriginateFailureCallsDay','`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','`state`\x20=\x2016,\x201,\x20null','`state`\x20=\x2020,\x201,\x20null','outboundReCallsDay','GetCampaignHopperHistory','ivrTotalCallsDays','ivrAnswerCallsDay','lodash','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','http','info','request\x20sent','debug','CmHopperHistory,\x20%s,\x20%s,\x20%s','stringify','error','code','CmHopperHistory,\x20%s,\x20%s','message','result','catch','CreateCmHopperHistory','CmHopperHistory','create','body','options','raw','then','where','sequelize','COUNT'];(function(_0xaa7629,_0x219723){var _0x487c07=function(_0x36959c){while(--_0x36959c){_0xaa7629['push'](_0xaa7629['shift']());}};_0x487c07(++_0x219723);}(_0x2ceb,0x110));var _0xb2ce=function(_0x437b27,_0x58bc1d){_0x437b27=_0x437b27-0x0;var _0x5dae64=_0x2ceb[_0x437b27];return _0x5dae64;};'use strict';var _=require(_0xb2ce('0x0'));var util=require(_0xb2ce('0x1'));var moment=require('moment');var BPromise=require(_0xb2ce('0x2'));var rs=require(_0xb2ce('0x3'));var fs=require('fs');var Redis=require(_0xb2ce('0x4'));var db=require(_0xb2ce('0x5'))['db'];var utils=require(_0xb2ce('0x6'));var logger=require(_0xb2ce('0x7'))('rpc');var config=require(_0xb2ce('0x8'));var jayson=require(_0xb2ce('0x9'));var client=jayson['client'][_0xb2ce('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x3dfaee,_0x51040c,_0x39120a){return new BPromise(function(_0x9fb07c,_0x10c67c){return client['request'](_0x3dfaee,_0x39120a)['then'](function(_0x17f7da){logger[_0xb2ce('0xb')]('CmHopperHistory,\x20%s,\x20%s',_0x51040c,_0xb2ce('0xc'));logger[_0xb2ce('0xd')](_0xb2ce('0xe'),_0x51040c,_0xb2ce('0xc'),JSON[_0xb2ce('0xf')](_0x17f7da));if(_0x17f7da[_0xb2ce('0x10')]){if(_0x17f7da['error'][_0xb2ce('0x11')]===0x1f4){logger[_0xb2ce('0x10')](_0xb2ce('0x12'),_0x51040c,_0x17f7da[_0xb2ce('0x10')][_0xb2ce('0x13')]);return _0x10c67c(_0x17f7da['error']['message']);}logger[_0xb2ce('0x10')](_0xb2ce('0x12'),_0x51040c,_0x17f7da[_0xb2ce('0x10')][_0xb2ce('0x13')]);return _0x9fb07c(_0x17f7da[_0xb2ce('0x10')][_0xb2ce('0x13')]);}else{logger[_0xb2ce('0xb')](_0xb2ce('0x12'),_0x51040c,_0xb2ce('0xc'));_0x9fb07c(_0x17f7da[_0xb2ce('0x14')][_0xb2ce('0x13')]);}})[_0xb2ce('0x15')](function(_0x13ee00){logger[_0xb2ce('0x10')](_0xb2ce('0x12'),_0x51040c,_0x13ee00);_0x10c67c(_0x13ee00);});});}exports[_0xb2ce('0x16')]=function(_0x2e0336){var _0x3f135e=this;return new Promise(function(_0x2563f6,_0x3715d3){return db[_0xb2ce('0x17')][_0xb2ce('0x18')](_0x2e0336[_0xb2ce('0x19')],{'raw':_0x2e0336[_0xb2ce('0x1a')]?_0x2e0336['options'][_0xb2ce('0x1b')]===undefined?!![]:![]:!![]})[_0xb2ce('0x1c')](function(_0x4d3f52){logger[_0xb2ce('0xb')]('CreateCmHopperHistory',_0x2e0336);logger[_0xb2ce('0xd')](_0xb2ce('0x16'),_0x2e0336,JSON[_0xb2ce('0xf')](_0x4d3f52));_0x2563f6(_0x4d3f52);})[_0xb2ce('0x15')](function(_0x59d256){logger['error'](_0xb2ce('0x16'),_0x59d256['message'],_0x2e0336);_0x3715d3(_0x3f135e[_0xb2ce('0x10')](0x1f4,_0x59d256[_0xb2ce('0x13')]));});});};exports['AvgHandleTime']=function(_0xfdbed0){var _0xf61e9a=this;return new Promise(function(_0x2cc3d2,_0x1ef31a){return db[_0xb2ce('0x17')]['findAll']({'raw':_0xfdbed0[_0xb2ce('0x1a')]?_0xfdbed0['options'][_0xb2ce('0x1b')]===undefined?!![]:![]:!![],'where':_0xfdbed0['options']?_0xfdbed0['options'][_0xb2ce('0x1d')]||null:null,'attributes':[[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db['sequelize'][_0xb2ce('0x20')]('id')),_0xb2ce('0x21')],[db['sequelize']['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')]['literal'](_0xb2ce('0x22')))),_0xb2ce('0x23')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')][_0xb2ce('0x24')](_0xb2ce('0x25')))),_0xb2ce('0x26')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db['sequelize'][_0xb2ce('0x24')](_0xb2ce('0x27')))),'predictiveIntervalDroppedCallsCallersExit'],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x28'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')]['literal'](_0xb2ce('0x29')))),_0xb2ce('0x2a')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x28'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')]['literal'](_0xb2ce('0x2b')))),_0xb2ce('0x2c')]]})[_0xb2ce('0x1c')](function(_0x2dae39){logger[_0xb2ce('0xb')](_0xb2ce('0x2d'),_0xfdbed0);logger['debug']('AvgHandleTime',_0xfdbed0,JSON[_0xb2ce('0xf')](_0x2dae39));_0x2cc3d2(_0x2dae39);})[_0xb2ce('0x15')](function(_0x3078c7){logger[_0xb2ce('0x10')](_0xb2ce('0x2d'),_0x3078c7[_0xb2ce('0x13')],_0xfdbed0);_0x1ef31a(_0xf61e9a[_0xb2ce('0x10')](0x1f4,_0x3078c7[_0xb2ce('0x13')]));});});};exports[_0xb2ce('0x2e')]=function(_0x2dbb1e){var _0x4a4ee4=this;return new Promise(function(_0x2dfba6,_0x601c90){return db['CmHopperHistory'][_0xb2ce('0x2f')]({'raw':_0x2dbb1e[_0xb2ce('0x1a')]?_0x2dbb1e[_0xb2ce('0x1a')][_0xb2ce('0x1b')]===undefined?!![]:![]:!![],'where':_0x2dbb1e[_0xb2ce('0x1a')]?_0x2dbb1e[_0xb2ce('0x1a')][_0xb2ce('0x1d')]||null:null,'attributes':[[_0xb2ce('0x30'),_0xb2ce('0x31')],[db['sequelize']['fn'](_0xb2ce('0x1f'),db['sequelize']['fn']('IF',db[_0xb2ce('0x1e')][_0xb2ce('0x24')](_0xb2ce('0x32')))),_0xb2ce('0x33')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db['sequelize']['fn']('IF',db[_0xb2ce('0x1e')]['literal'](_0xb2ce('0x34')))),_0xb2ce('0x35')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db['sequelize']['fn']('IF',db[_0xb2ce('0x1e')][_0xb2ce('0x24')]('`state`\x20=\x204,\x201,\x20null'))),_0xb2ce('0x36')],[db[_0xb2ce('0x1e')]['fn']('COUNT',db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')]['literal'](_0xb2ce('0x37')))),_0xb2ce('0x38')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db['sequelize'][_0xb2ce('0x24')](_0xb2ce('0x39')))),_0xb2ce('0x3a')],[db[_0xb2ce('0x1e')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0xb2ce('0x1e')]['literal'](_0xb2ce('0x3b')))),'outboundDropCallsDayTimeout'],[db['sequelize']['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')][_0xb2ce('0x24')](_0xb2ce('0x3c')))),_0xb2ce('0x3d')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db['sequelize']['literal'](_0xb2ce('0x3e')))),_0xb2ce('0x3f')],[db['sequelize']['fn']('COUNT',db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')][_0xb2ce('0x24')](_0xb2ce('0x40')))),_0xb2ce('0x41')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')][_0xb2ce('0x24')](_0xb2ce('0x42')))),_0xb2ce('0x43')],[db[_0xb2ce('0x1e')]['fn']('COUNT',db[_0xb2ce('0x1e')]['fn']('IF',db['sequelize'][_0xb2ce('0x24')](_0xb2ce('0x44')))),_0xb2ce('0x45')],[db[_0xb2ce('0x1e')]['fn']('COUNT',db[_0xb2ce('0x1e')]['fn']('IF',db['sequelize'][_0xb2ce('0x24')](_0xb2ce('0x46')))),'outboundAnswerAgiCallsDay'],[db['sequelize']['fn'](_0xb2ce('0x1f'),db['sequelize']['fn']('IF',db['sequelize']['literal'](_0xb2ce('0x47')))),_0xb2ce('0x45')],[db['sequelize']['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')][_0xb2ce('0x24')]('`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null'))),_0xb2ce('0x48')]],'group':[_0xb2ce('0x30')]})[_0xb2ce('0x1c')](function(_0xb00431){logger[_0xb2ce('0xb')](_0xb2ce('0x2e'),_0x2dbb1e);logger[_0xb2ce('0xd')](_0xb2ce('0x2e'),_0x2dbb1e,JSON[_0xb2ce('0xf')](_0xb00431));_0x2dfba6(_0xb00431);})['catch'](function(_0x30020d){logger[_0xb2ce('0x10')](_0xb2ce('0x2e'),_0x30020d[_0xb2ce('0x13')],_0x2dbb1e);_0x601c90(_0x4a4ee4[_0xb2ce('0x10')](0x1f4,_0x30020d[_0xb2ce('0x13')]));});});};exports[_0xb2ce('0x49')]=function(_0x508820){var _0x3792ab=this;return new Promise(function(_0x2e5dc4,_0xd1757){return db[_0xb2ce('0x17')][_0xb2ce('0x2f')]({'raw':_0x508820['options']?_0x508820['options'][_0xb2ce('0x1b')]===undefined?!![]:![]:!![],'where':_0x508820[_0xb2ce('0x1a')]?_0x508820[_0xb2ce('0x1a')][_0xb2ce('0x1d')]||null:null,'attributes':[[_0xb2ce('0x30'),_0xb2ce('0x31')],[db['sequelize']['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')][_0xb2ce('0x20')]('id')),_0xb2ce('0x4a')],[db[_0xb2ce('0x1e')]['fn'](_0xb2ce('0x1f'),db[_0xb2ce('0x1e')]['fn']('IF',db[_0xb2ce('0x1e')]['literal']('`state`\x20=\x204,\x201,\x20null'))),_0xb2ce('0x4b')]],'group':['campaign']})['then'](function(_0x17e13b){logger['info'](_0xb2ce('0x49'),_0x508820);logger[_0xb2ce('0xd')](_0xb2ce('0x49'),_0x508820,JSON[_0xb2ce('0xf')](_0x17e13b));_0x2e5dc4(_0x17e13b);})['catch'](function(_0x366309){logger['error'](_0xb2ce('0x49'),_0x366309['message'],_0x508820);_0xd1757(_0x3792ab[_0xb2ce('0x10')](0x1f4,_0x366309['message']));});});};