get logs from device
This commit is contained in:
@@ -15,6 +15,7 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use app\models\Logs;
|
||||
|
||||
/**
|
||||
* DeviceController implements the CRUD actions for Device model.
|
||||
@@ -338,7 +339,7 @@ class DeviceController extends Controller {
|
||||
if (Yii::$app->request->post()) {
|
||||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-exchange"]) . " Đồng bộ dữ liệu đến thiết bị",
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-refresh"]) . " Đồng bộ dữ liệu đến thiết bị",
|
||||
"form" => $this->renderPartial("sync"),
|
||||
"lists" => Yii::$app->request->post("lists")
|
||||
];
|
||||
@@ -444,4 +445,36 @@ class DeviceController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function actionGetLogs() {
|
||||
if (Yii::$app->request->post()) {
|
||||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-exchange"]) . " Lấy các sự kiện",
|
||||
"form" => $this->renderPartial("logs"),
|
||||
"lists" => Yii::$app->request->post("lists")
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSyncLogs() {
|
||||
if (Yii::$app->request->post()) {
|
||||
Yii::$app->response->format = "json";
|
||||
$device = $this->findModel(Yii::$app->request->post("data"));
|
||||
$response = json_decode(common::requestToCardService("/GetDeviceData/GetLog", ["DeviceIP" => $device->ip_address]), true);
|
||||
$datas = [];
|
||||
foreach ($response as $key => $value) {
|
||||
if ($value["Cardno"] !== "0")
|
||||
$datas[] = [$value["Pin"], $value["Cardno"], $device->id, $value["DoorID"], $value["InOutState"], Logs::parseTime($value["Time_second"]), $value["EventType"]];
|
||||
}
|
||||
$model = new Logs();
|
||||
if ($model->multiCreate($datas)) {
|
||||
common::requestToCardService("/DeleteDeviceData/DeleteLog", ["DeviceIP" => $device->ip_address]);
|
||||
}
|
||||
return [
|
||||
"totals" => count($datas),
|
||||
"IP" => $device->ip_address
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user