1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| <?php if ('cli' != php_sapi_name()) { echo("ERROR: This program is for command line mode only.\n"); exit(1); }
chdir(dirname(__FILE__)); require('../../.root.php'); require(WEBAPP_ROOT);
using('callcenter_isp_action'); using('CallCenter.GnwayCallCenter'); using('DingDingRobot');
class ServiceIdleStateCheck_page { protected $dbObj; protected $pageObj; protected $callCenterObj; protected $callCenterIspAct;
public function __construct(&$dbObj, &$pageObj) { $this->dbObj = $dbObj; $this->pageObj = $pageObj; $this->callCenterIspAct = new tf_callcenter_isp_action($this->dbObj, $this->pageObj); $this->callCenterAccountObj = new callCenterAccountData($this->dbObj, $this->pageObj); }
public function process() { $aids = MConfig::$current->cc->idlestate->aids ?: '';
$idle_state_notice_limit = MConfig::$current->cc->idlestate->notice_limit ?: 6; $idle_state_min_time = MConfig::$current->cc->idlestate->min_time ?: 10; $idle_state_max_time = MConfig::$current->cc->idlestate->max_time ?: 200;
if (empty($aids)) exit(0); $aids_array = explode(',', $aids);
$ten = $five = []; foreach ($aids_array as $aid) { $serviceListInfo = $this->callCenterIspAct->getCallServicerListInfoByAId($aid); $serviceList = $serviceListInfo['servicerList'] ?: []; unset($serviceListInfo); if (empty($serviceList)) continue;
foreach ($serviceList as $sid) { $detail = $this->callCenterAccountObj->getCallServicerDetailState($sid,[ 'sId', 'passportName', 'mobile', 'state', 'voipStatus', 'idleState', 'channelUuid', 'currCallId', 'channelTime', 'lastServiceEndTime' ]); if (!$detail['idleState']) continue;
$diff = time() - ($detail['channelTime'] ? strtotime($detail['channelTime']) : $detail['lastServiceEndTime']); $detail['lastServiceEndTime'] = date('Y-m-d H:i:s', $detail['lastServiceEndTime']);
if ($diff > $idle_state_min_time && $diff< $idle_state_max_time) $five[$sid] = $detail;
$diff > $idle_state_max_time && $ten[$sid] = $detail; } } $env = defined("PRIVATE_RUN") ? "【private-".PRIVATE_RUN."-".GNWAY_TONGFU_VERSION."】" : "【saas-".GNWAY_TONGFU_VERSION."】";
$title = $content = "### 通话状态异常预警".$env.":".PHP_EOL; $content.= "* 检测时间:".date('Y-m-d H:i:s').PHP_EOL;
$idle_state_max_minute = ceil($idle_state_max_time / 60); $idle_state_min_minute = ceil($idle_state_min_time / 60);
$need_send = false;
$content.= "* 忙碌状态持续{$idle_state_min_minute}>min且<{$idle_state_max_minute}min".PHP_EOL; $request_id = uniqid('idlestate_notice_'); if (!empty($five)) { if (count($five) < $idle_state_notice_limit) { $content.="> ".json_encode($five, JSON_UNESCAPED_UNICODE); } else { $log_data['five_min'] = $ten; $content.= "> 超过{$idle_state_notice_limit}个,请查看日志 RequestId: ".$request_id.PHP_EOL; } $need_send = true; } else { $content.="> 暂无数据".PHP_EOL; } $content.=PHP_EOL; $content.= "* 忙碌状态持续>{$idle_state_max_minute}min".PHP_EOL; if (!empty($ten)) { if (count($ten) < $idle_state_notice_limit) { $content.="> ".json_encode($ten, JSON_UNESCAPED_UNICODE); } else{ $log_data['ten_min'] = $ten; $content.= "> 超过{$idle_state_notice_limit}个请查看阿里云日志 RequestId: ".$request_id.PHP_EOL; } $need_send = true; } else { $content.="> 暂无数据".PHP_EOL; }
if (!empty($log_data)) { Logbw8::getInstance()->write_log('error',$request_id,[ 'title' => '呼叫中心客服状态异常预警', 'script' => __FILE__, 'data' => $log_data, ]); } if ($need_send) { $report = ['title' => $title, 'text' => $content]; $this->sendReport($report); } }
protected $noticeUri = 'https://oapi.dingtalk.com/robot/send?access_token=21f901a7edc9d41ad9c056205c837e6ab3356840c21ace3f6755f0d57424b2d2';
protected function sendReport($report) { $robot = new DingDingRobot($this->noticeUri); $robot->setMarkdownType()->atAll()->setContent($report)->send(); } }
class ServiceIdleStateCheck extends sample_system { private $actionPage;
public function __construct($args) { parent::__construct($args); $this->actionPage = new ServiceIdleStateCheck_page($this->dbo, $this->page); }
public static function main($args) { $myPg = new ServiceIdleStateCheck($args); $myPg->actionPage->process(); } }
ServiceIdleStateCheck::main(array( 'mysql6' ));
|