a75a5447da51c8ab3927ee9873a331ea40df8b07
[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 _0x6836=['outboundNoAnswerCallsDay','outboundAnswerCallsDay','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','outboundUnknownCallsDay','`state`\x20=\x2013,\x201,\x20null','`state`\x20=\x2014,\x201,\x20null','`state`\x20=\x2018,\x201,\x20null','outboundRejectCallsDay','`state`\x20=\x2016,\x201,\x20null','outboundAnswerAgiCallsDay','`state`\x20=\x2020,\x201,\x20null','`state`\x20=\x2022\x20or\x20`state`\x20=\x2023,\x201,\x20null','outboundReCallsDay','GetCampaignHopperHistory','ivrAnswerCallsDay','lodash','util','moment','randomstring','../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','http','request','then','CmHopperHistory,\x20%s,\x20%s','request\x20sent','debug','error','code','message','info','result','catch','CreateCmHopperHistory','CmHopperHistory','body','options','raw','stringify','AvgHandleTime','findAll','where','sequelize','COUNT','col','predictiveIntervalTotalCalls','literal','`state`\x20=\x204,\x201,\x20null','predictiveIntervalAnsweredCalls','`state`\x20=\x2010,\x201,\x20null','`state`\x20=\x2011,\x201,\x20null','AVG','`state`\x20=\x204,\x20`holdtime`,\x20null','predictiveIntervalAvgHoldtime','`state`\x20=\x204,\x20`talktime`,\x20null','predictiveIntervalAvgTalktime','GetVoiceQueueHopperHistory','campaign','name','`state`\x20=\x200,\x201,\x20null','`state`\x20=\x203,\x201,\x20null'];(function(_0x24ea0d,_0x220ee4){var _0x37dd84=function(_0x17d34e){while(--_0x17d34e){_0x24ea0d['push'](_0x24ea0d['shift']());}};_0x37dd84(++_0x220ee4);}(_0x6836,0x1c0));var _0x6683=function(_0x2b4411,_0x2625ed){_0x2b4411=_0x2b4411-0x0;var _0x8e41ef=_0x6836[_0x2b4411];return _0x8e41ef;};'use strict';var _=require(_0x6683('0x0'));var util=require(_0x6683('0x1'));var moment=require(_0x6683('0x2'));var BPromise=require('bluebird');var rs=require(_0x6683('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x6683('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x6683('0x5'))('rpc');var config=require(_0x6683('0x6'));var jayson=require(_0x6683('0x7'));var client=jayson[_0x6683('0x8')][_0x6683('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x4d2235,_0xb31219,_0x2c7cb0){return new BPromise(function(_0x3d5224,_0x4673ea){return client[_0x6683('0xa')](_0x4d2235,_0x2c7cb0)[_0x6683('0xb')](function(_0x5ccb97){logger['info'](_0x6683('0xc'),_0xb31219,_0x6683('0xd'));logger[_0x6683('0xe')]('CmHopperHistory,\x20%s,\x20%s,\x20%s',_0xb31219,_0x6683('0xd'),JSON['stringify'](_0x5ccb97));if(_0x5ccb97[_0x6683('0xf')]){if(_0x5ccb97[_0x6683('0xf')][_0x6683('0x10')]===0x1f4){logger[_0x6683('0xf')](_0x6683('0xc'),_0xb31219,_0x5ccb97[_0x6683('0xf')][_0x6683('0x11')]);return _0x4673ea(_0x5ccb97[_0x6683('0xf')]['message']);}logger[_0x6683('0xf')](_0x6683('0xc'),_0xb31219,_0x5ccb97[_0x6683('0xf')][_0x6683('0x11')]);return _0x3d5224(_0x5ccb97[_0x6683('0xf')]['message']);}else{logger[_0x6683('0x12')](_0x6683('0xc'),_0xb31219,_0x6683('0xd'));_0x3d5224(_0x5ccb97[_0x6683('0x13')][_0x6683('0x11')]);}})[_0x6683('0x14')](function(_0x286695){logger[_0x6683('0xf')](_0x6683('0xc'),_0xb31219,_0x286695);_0x4673ea(_0x286695);});});}exports[_0x6683('0x15')]=function(_0x4cad41){var _0x3afbec=this;return new Promise(function(_0x1be466,_0x1b5f32){return db[_0x6683('0x16')]['create'](_0x4cad41[_0x6683('0x17')],{'raw':_0x4cad41[_0x6683('0x18')]?_0x4cad41[_0x6683('0x18')][_0x6683('0x19')]===undefined?!![]:![]:!![]})[_0x6683('0xb')](function(_0x2d3775){logger[_0x6683('0x12')](_0x6683('0x15'),_0x4cad41);logger[_0x6683('0xe')](_0x6683('0x15'),_0x4cad41,JSON[_0x6683('0x1a')](_0x2d3775));_0x1be466(_0x2d3775);})[_0x6683('0x14')](function(_0x34680f){logger[_0x6683('0xf')](_0x6683('0x15'),_0x34680f[_0x6683('0x11')],_0x4cad41);_0x1b5f32(_0x3afbec['error'](0x1f4,_0x34680f[_0x6683('0x11')]));});});};exports[_0x6683('0x1b')]=function(_0x49c1ce){var _0x3250e5=this;return new Promise(function(_0x4579d9,_0x457b3c){return db['CmHopperHistory'][_0x6683('0x1c')]({'raw':_0x49c1ce[_0x6683('0x18')]?_0x49c1ce[_0x6683('0x18')][_0x6683('0x19')]===undefined?!![]:![]:!![],'where':_0x49c1ce['options']?_0x49c1ce[_0x6683('0x18')][_0x6683('0x1d')]||null:null,'attributes':[[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db['sequelize'][_0x6683('0x20')]('id')),_0x6683('0x21')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x23')))),_0x6683('0x24')],[db['sequelize']['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db['sequelize'][_0x6683('0x22')](_0x6683('0x25')))),'predictiveIntervalDroppedCallsTimeout'],[db[_0x6683('0x1e')]['fn']('COUNT',db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x26')))),'predictiveIntervalDroppedCallsCallersExit'],[db[_0x6683('0x1e')]['fn'](_0x6683('0x27'),db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x28')))),_0x6683('0x29')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x27'),db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x2a')))),_0x6683('0x2b')]]})[_0x6683('0xb')](function(_0x4d58ef){logger[_0x6683('0x12')]('AvgHandleTime',_0x49c1ce);logger['debug'](_0x6683('0x1b'),_0x49c1ce,JSON[_0x6683('0x1a')](_0x4d58ef));_0x4579d9(_0x4d58ef);})[_0x6683('0x14')](function(_0x31e0a7){logger[_0x6683('0xf')](_0x6683('0x1b'),_0x31e0a7[_0x6683('0x11')],_0x49c1ce);_0x457b3c(_0x3250e5[_0x6683('0xf')](0x1f4,_0x31e0a7['message']));});});};exports[_0x6683('0x2c')]=function(_0x3161c9){var _0x27ff1e=this;return new Promise(function(_0x50e98c,_0x4f572b){return db[_0x6683('0x16')]['findAll']({'raw':_0x3161c9[_0x6683('0x18')]?_0x3161c9[_0x6683('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x3161c9[_0x6683('0x18')]?_0x3161c9[_0x6683('0x18')][_0x6683('0x1d')]||null:null,'attributes':[[_0x6683('0x2d'),_0x6683('0x2e')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db['sequelize']['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x2f')))),'outboundNoSuchCallsDay'],[db['sequelize']['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db['sequelize'][_0x6683('0x22')](_0x6683('0x30')))),_0x6683('0x31')],[db['sequelize']['fn']('COUNT',db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x23')))),_0x6683('0x32')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db['sequelize'][_0x6683('0x22')]('`state`\x20=\x205,\x201,\x20null'))),_0x6683('0x33')],[db[_0x6683('0x1e')]['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x34')))),_0x6683('0x35')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db['sequelize'][_0x6683('0x22')](_0x6683('0x36')))),_0x6683('0x37')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x38')))),_0x6683('0x39')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x3a')))),_0x6683('0x3b')],[db['sequelize']['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x3c')))),'outboundBlacklistCallsDay'],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db['sequelize'][_0x6683('0x22')](_0x6683('0x3d')))),'outboundOriginateFailureCallsDay'],[db['sequelize']['fn']('COUNT',db['sequelize']['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x3e')))),_0x6683('0x3f')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db['sequelize'][_0x6683('0x22')](_0x6683('0x40')))),_0x6683('0x41')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db['sequelize']['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x42')))),_0x6683('0x3f')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')]['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x43')))),_0x6683('0x44')]],'group':[_0x6683('0x2d')]})[_0x6683('0xb')](function(_0x41d082){logger[_0x6683('0x12')](_0x6683('0x2c'),_0x3161c9);logger['debug'](_0x6683('0x2c'),_0x3161c9,JSON['stringify'](_0x41d082));_0x50e98c(_0x41d082);})[_0x6683('0x14')](function(_0x5e66e3){logger[_0x6683('0xf')](_0x6683('0x2c'),_0x5e66e3['message'],_0x3161c9);_0x4f572b(_0x27ff1e[_0x6683('0xf')](0x1f4,_0x5e66e3[_0x6683('0x11')]));});});};exports[_0x6683('0x45')]=function(_0x15cddc){var _0x347522=this;return new Promise(function(_0x40bcc8,_0x45499e){return db[_0x6683('0x16')][_0x6683('0x1c')]({'raw':_0x15cddc['options']?_0x15cddc[_0x6683('0x18')][_0x6683('0x19')]===undefined?!![]:![]:!![],'where':_0x15cddc[_0x6683('0x18')]?_0x15cddc[_0x6683('0x18')][_0x6683('0x1d')]||null:null,'attributes':[[_0x6683('0x2d'),_0x6683('0x2e')],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db[_0x6683('0x1e')][_0x6683('0x20')]('id')),'ivrTotalCallsDays'],[db[_0x6683('0x1e')]['fn'](_0x6683('0x1f'),db['sequelize']['fn']('IF',db[_0x6683('0x1e')][_0x6683('0x22')](_0x6683('0x23')))),_0x6683('0x46')]],'group':[_0x6683('0x2d')]})[_0x6683('0xb')](function(_0x44b050){logger[_0x6683('0x12')](_0x6683('0x45'),_0x15cddc);logger[_0x6683('0xe')](_0x6683('0x45'),_0x15cddc,JSON[_0x6683('0x1a')](_0x44b050));_0x40bcc8(_0x44b050);})[_0x6683('0x14')](function(_0x3d5be5){logger['error'](_0x6683('0x45'),_0x3d5be5[_0x6683('0x11')],_0x15cddc);_0x45499e(_0x347522[_0x6683('0xf')](0x1f4,_0x3d5be5[_0x6683('0x11')]));});});};