update real time monitoring
This commit is contained in:
90
controllers/RealTimeController.php
Normal file
90
controllers/RealTimeController.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use app\models\common;
|
||||
use app\models\Device;
|
||||
use app\models\Door;
|
||||
use app\models\EventType;
|
||||
use app\models\Staff;
|
||||
use app\models\Department;
|
||||
|
||||
/**
|
||||
* LogsController implements the CRUD actions for Logs model.
|
||||
*/
|
||||
class RealTimeController extends Controller {
|
||||
|
||||
public function init() {
|
||||
parent::init();
|
||||
if (time() > Yii::$app->params["time"])
|
||||
$this->redirect(["/dashboard"]);
|
||||
if (Yii::$app->user->isGuest)
|
||||
return $this->redirect(['/site/login']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors() {
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionIndex() {
|
||||
$this->view->title = 'Theo dõi trực tuyến';
|
||||
$deviceLists = Device::find()->all();
|
||||
$devices = [];
|
||||
foreach ($deviceLists as $key => $value) {
|
||||
$devices[] = $value->ip_address;
|
||||
}
|
||||
common::requestToCardService("/GetRTLog/Start", [
|
||||
"DeviceIPs" => implode(",", $devices)
|
||||
]);
|
||||
return $this->render('index', [
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionData() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$post = Yii::$app->request->post();
|
||||
Yii::$app->response->format = "json";
|
||||
$Device = Device::findOne(['ip_address' => $post['DeviceIP']]);
|
||||
$Door = false;
|
||||
if ($Device)
|
||||
$Door = Door::findOne(['device_id' => $Device->id, 'code' => $post['DoorNo']]);
|
||||
|
||||
$EventType = EventType::eventTypeArray();
|
||||
$Staff = Staff::findOne($post['StaffID']);
|
||||
$department = "";
|
||||
if ($Staff) {
|
||||
$dept = Department::findOne($Staff->department_id);
|
||||
$department = $dept ? $dept->name : "";
|
||||
}
|
||||
|
||||
return [
|
||||
"device" => $Device ? $Device->name : $post['DeviceIP'],
|
||||
"door" => $Door ? $Door->name : $post['DoorNo'],
|
||||
"eventType" => isset($EventType[$post['EventCode']]) ? $EventType[$post['EventCode']] : false,
|
||||
"staff_code" => $Staff ? $Staff->code : "",
|
||||
"staff_name" => $Staff ? $Staff->name : "",
|
||||
"staff_department" => $department
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionStop() {
|
||||
if (Yii::$app->request->isAjax) {
|
||||
return common::requestToCardService("/GetRTLog/Stop", []);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user