diff --git a/assets/RealTimeAsset.php b/assets/RealTimeAsset.php
new file mode 100644
index 00000000..68f33395
--- /dev/null
+++ b/assets/RealTimeAsset.php
@@ -0,0 +1,23 @@
+ false,
"TCTECH" => true,
- "CardService" => "192.168.10.200:2001",
+ "CardService" => "192.168.1.245:2001",
+ "ServerIP" => "192.168.1.244:4004",
"dataPath" => "AC/",
"time" => 1623171599,
"pageSize" => 200
diff --git a/controllers/RealTimeController.php b/controllers/RealTimeController.php
new file mode 100644
index 00000000..1c257e5a
--- /dev/null
+++ b/controllers/RealTimeController.php
@@ -0,0 +1,90 @@
+ 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", []);
+ }
+ }
+
+}
diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php
index d83abb97..ea400b5e 100644
--- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php
+++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php
@@ -30,7 +30,7 @@ use yii\widgets\ActiveForm;
Thiết bị
-
">
+ ">
Kiểm soát truy cập
diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php
index 75e45634..992865e3 100644
--- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php
+++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php
@@ -18,10 +18,11 @@
['label' => 'Tìm kiếm thiết bị', 'url' => ['/device/search'], 'icon' => 'search', 'visible' => Yii::$app->user->can("deviceSearch")]
];
}
- if (in_array($this->context->id, ['schedule', 'assign'])) {
+ if (in_array($this->context->id, ['schedule', 'assign', 'real-time'])) {
$items = [
['label' => 'Lịch trình', 'url' => ['/schedule'], 'icon' => 'calendar'],
- ['label' => 'Cấp quyền truy cập', 'url' => ['/assign'], 'icon' => 'cogs', 'visible' => Yii::$app->user->can("scheduleAssign")]
+ ['label' => 'Cấp quyền truy cập', 'url' => ['/assign'], 'icon' => 'cogs', 'visible' => Yii::$app->user->can("scheduleAssign")],
+ ['label' => 'Theo dõi trực tuyến', 'url' => ['/real-time'], 'icon' => 'bar-chart', 'visible' => Yii::$app->user->can("scheduleAssign")]
];
}
if (in_array($this->context->id, ['user', 'auth-item'])) {
diff --git a/views/real-time/index.tpl b/views/real-time/index.tpl
new file mode 100644
index 00000000..fe5eeda4
--- /dev/null
+++ b/views/real-time/index.tpl
@@ -0,0 +1,34 @@
+{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
+{use class="yii\helpers\Url"}
+{use class="yii\grid\GridView"}
+{use class="yii\widgets\Pjax" type="block"}
+{use class="app\assets\RealTimeAsset"}
+{RealTimeAsset::register($this)|void}
+{block name='content'}
+
+
+
+
+
+
+
+
+
+
+ Thời gian |
+ Thiết bị |
+ Cửa |
+ Mô tả sự kiện |
+ Mã thẻ |
+ Mã nhân viên |
+ Tên nhân viên |
+ Phòng ban |
+
+
+
+
+
+
+{/block}
\ No newline at end of file
diff --git a/web/js/real-time.js b/web/js/real-time.js
new file mode 100644
index 00000000..c633beab
--- /dev/null
+++ b/web/js/real-time.js
@@ -0,0 +1,60 @@
+$(function () {
+ var socket = io.connect("http://" + $("input[name='serverIP']").val());
+ socket.on('realtime', function (data) {
+ render(data);
+ });
+});
+
+function render(cardValue) {
+ $.ajax({
+ url: $("input[name='check_data_url']").val(),
+ type: 'POST',
+ data: {
+ DeviceIP: cardValue.DeviceIP,
+ StaffID: cardValue.RTLogInfo.Pin,
+ DoorNo: cardValue.RTLogInfo.DoorNo,
+ EventCode: cardValue.RTLogInfo.EventCode
+ },
+ success: function (data) {
+ if (data.eventType) {
+ var color = "orange";
+ if (cardValue.RTLogInfo.EventCode == 0)
+ color = "green";
+ var html = `
+ ` + cardValue.RTLogInfo.Time + ` |
+ ` + data.device + ` |
+ ` + data.door + ` |
+ ` + data.eventType + ` |
+ ` + cardValue.RTLogInfo.CardNo + ` |
+ ` + data.staff_code + ` |
+ ` + data.staff_name + ` |
+ ` + data.staff_department + ` |
+
`;
+ var totals = $("#table-lists").find("tr").length;
+ if (totals >= 100) {
+ $("#table-lists").find("tr").last().remove();
+ }
+ $("#table-lists").prepend(html);
+ }
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+
+ }
+ });
+}
+
+function stopRealTime(e) {
+ common.modalBlock(true);
+ $.ajax({
+ url: $(e).attr("data-href"),
+ type: 'POST',
+ success: function (data) {
+ common.modalBlock(false);
+ alert("Đã ngừng theo dõi trực tuyến!");
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.modalBlock(false);
+ common.ajaxError();
+ }
+ });
+}
\ No newline at end of file