auto sync data, remove crontab
This commit is contained in:
parent
bba20c9c17
commit
3f289ddc9d
|
@ -2,4 +2,5 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'adminEmail' => 'admin@example.com',
|
'adminEmail' => 'admin@example.com',
|
||||||
|
"maxLogs" => 100000
|
||||||
];
|
];
|
||||||
|
|
|
@ -66,13 +66,50 @@ class ApiController extends Controller {
|
||||||
FileHelper::createDirectory($targetPath, 0777);
|
FileHelper::createDirectory($targetPath, 0777);
|
||||||
file_put_contents($targetPath . "/" . $fileName, base64_decode($post['image']));
|
file_put_contents($targetPath . "/" . $fileName, base64_decode($post['image']));
|
||||||
|
|
||||||
|
$totalsLogs = CaptureLogs::find()->count();
|
||||||
|
if ($totalsLogs >= \Yii::$app->params['maxLogs']) {
|
||||||
|
$lastLogs = CaptureLogs::find()->orderBy(["id" => SORT_ASC])->limit(1)->one();
|
||||||
|
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $lastLogs->image);
|
||||||
|
$lastLogs->delete();
|
||||||
|
}
|
||||||
|
|
||||||
$model = new CaptureLogs();
|
$model = new CaptureLogs();
|
||||||
$model->create([
|
$logs = $model->create([
|
||||||
"Staff" => $post["id"],
|
"Staff" => $post["id"],
|
||||||
"Time" => $time,
|
"Time" => $time,
|
||||||
"Image" => $fileName,
|
"Image" => $fileName,
|
||||||
"Confidence" => strval($post["confidence"])
|
"Confidence" => strval($post["confidence"])
|
||||||
]);
|
]);
|
||||||
|
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
||||||
|
$ip = "dev-dc.beetai.com";
|
||||||
|
if ($server_ip)
|
||||||
|
$ip = $server_ip->data;
|
||||||
|
if ($this->is_connected($ip) && $logs) {
|
||||||
|
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
||||||
|
$id_camera = 209;
|
||||||
|
if ($device_id)
|
||||||
|
$id_camera = intval($device_id->data);
|
||||||
|
$logsInfo = CaptureLogs::findOne($logs);
|
||||||
|
$staffInfo = ListManagement::findOne($post['id']);
|
||||||
|
$res = json_decode(file_get_contents("https://" . $ip . "/api/oem/face_recognition", false, stream_context_create([
|
||||||
|
'http' => [
|
||||||
|
'header' => "Content-Type: application/json",
|
||||||
|
'method' => "POST",
|
||||||
|
'content' => json_encode([
|
||||||
|
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName)),
|
||||||
|
'camera_id' => strval($id_camera),
|
||||||
|
'frametime' => date("Y-m-d H:i:s", $time),
|
||||||
|
'idCard' => $staffInfo ? strval($staffInfo->code) : "0",
|
||||||
|
"person_id" => "123",
|
||||||
|
"timezone" => "+7"
|
||||||
|
])
|
||||||
|
]
|
||||||
|
])), true);
|
||||||
|
if ($res['status'] == 10000) {
|
||||||
|
$logsInfo->sync_status = 1;
|
||||||
|
$logsInfo->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
Yii::$app->response->format = "json";
|
Yii::$app->response->format = "json";
|
||||||
return ["status" => "success"];
|
return ["status" => "success"];
|
||||||
}
|
}
|
||||||
|
@ -185,7 +222,51 @@ class ApiController extends Controller {
|
||||||
|
|
||||||
public function actionSync() {
|
public function actionSync() {
|
||||||
Yii::$app->response->format = "json";
|
Yii::$app->response->format = "json";
|
||||||
|
if ($this->is_connected()) {
|
||||||
|
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
||||||
|
$ip = "dev-dc.beetai.com";
|
||||||
|
if ($server_ip)
|
||||||
|
$ip = $server_ip->data;
|
||||||
|
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
||||||
|
$id_camera = 209;
|
||||||
|
if ($device_id)
|
||||||
|
$id_camera = intval($device_id->data);
|
||||||
|
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all();
|
||||||
|
foreach ($ls as $key => $value) {
|
||||||
|
$staffInfo = ListManagement::findOne($value->staff_id);
|
||||||
|
$res = json_decode(file_get_contents("https://" . $ip . "/api/oem/face_recognition", false, stream_context_create([
|
||||||
|
'http' => [
|
||||||
|
'header' => "Content-Type: application/json",
|
||||||
|
'method' => "POST",
|
||||||
|
'content' => json_encode([
|
||||||
|
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)),
|
||||||
|
'camera_id' => strval($id_camera),
|
||||||
|
'frametime' => date("Y-m-d H:i:s", $value->time),
|
||||||
|
'idCard' => $staffInfo ? strval($staffInfo->code) : "0",
|
||||||
|
"person_id" => "123",
|
||||||
|
"timezone" => "+7"
|
||||||
|
])
|
||||||
|
]
|
||||||
|
])), true);
|
||||||
|
if ($res['status'] == 10000) {
|
||||||
|
$value->sync_status = 1;
|
||||||
|
$value->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return ["status" => true];
|
return ["status" => true];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_connected($ip = "google.com") {
|
||||||
|
$connected = @fsockopen($ip, 80);
|
||||||
|
//website, port (try 80 or 443)
|
||||||
|
if ($connected) {
|
||||||
|
$is_conn = true; //action when connected
|
||||||
|
fclose($connected);
|
||||||
|
} else {
|
||||||
|
$is_conn = false; //action in connection failure
|
||||||
|
}
|
||||||
|
return $is_conn;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class CaptureLogsController extends Controller {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionIndex($from = "", $to = "") {
|
public function actionIndex($from = "", $to = "", $all = false) {
|
||||||
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
|
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
|
||||||
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
|
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
|
||||||
if ($from !== "" && $to !== "") {
|
if ($from !== "" && $to !== "") {
|
||||||
|
@ -40,9 +40,9 @@ class CaptureLogsController extends Controller {
|
||||||
$this->view->title = "Capture Log";
|
$this->view->title = "Capture Log";
|
||||||
$searchModel = new CaptureLogsSearch();
|
$searchModel = new CaptureLogsSearch();
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
$dataProvider->query->andWhere(["capture_logs.staff_id" => 0]);
|
if (!$all)
|
||||||
|
$dataProvider->query->andWhere(["capture_logs.staff_id" => 0]);
|
||||||
$dataProvider->query->andWhere(["BETWEEN", "capture_logs.time", $f, $t]);
|
$dataProvider->query->andWhere(["BETWEEN", "capture_logs.time", $f, $t]);
|
||||||
$dataProvider->query->orderBy(["time" => SORT_DESC]);
|
|
||||||
|
|
||||||
// $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
|
// $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
|
||||||
// 'http' => [
|
// 'http' => [
|
||||||
|
|
|
@ -48,7 +48,6 @@ class ControlLogsController extends Controller {
|
||||||
$dataProvider->query->andWhere(["list_management.type" => $type]);
|
$dataProvider->query->andWhere(["list_management.type" => $type]);
|
||||||
if ($gender !== "all")
|
if ($gender !== "all")
|
||||||
$dataProvider->query->andWhere(["list_management.gender" => $gender]);
|
$dataProvider->query->andWhere(["list_management.gender" => $gender]);
|
||||||
$dataProvider->query->orderBy(["time" => SORT_DESC]);
|
|
||||||
|
|
||||||
return $this->render('index', [
|
return $this->render('index', [
|
||||||
'searchModel' => $searchModel,
|
'searchModel' => $searchModel,
|
||||||
|
|
|
@ -516,8 +516,7 @@ class ListManagementController extends Controller {
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
])), true);
|
])), true);
|
||||||
return $res;
|
return ["status" => true];
|
||||||
//["status" => true];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,12 @@ class CaptureLogsGrid {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function confidence() {
|
||||||
|
return function($model) {
|
||||||
|
return number_format($model->confidence, 2);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static function rows() {
|
public static function rows() {
|
||||||
return function($model, $index, $widget, $grid) {
|
return function($model, $index, $widget, $grid) {
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CaptureLogsSearch extends CaptureLogs {
|
||||||
public function rules() {
|
public function rules() {
|
||||||
return [
|
return [
|
||||||
[['id', 'time', 'status'], 'integer'],
|
[['id', 'time', 'status'], 'integer'],
|
||||||
[['image', 'remark', 'staff_name'], 'safe'],
|
[['image', 'remark', 'staff_name', 'confidence'], 'safe'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ class CaptureLogsSearch extends CaptureLogs {
|
||||||
|
|
||||||
$dataProvider = new ActiveDataProvider([
|
$dataProvider = new ActiveDataProvider([
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
|
'sort' => ['defaultOrder' => ['time' => SORT_DESC]],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->load($params);
|
$this->load($params);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
border-color: green;
|
border-color: green;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<input type="hidden" value="{Url::to(['/capture-logs'])}" name="URL">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-10" style="max-height: 850px;overflow-y: auto;">
|
<div class="col-md-10" style="max-height: 850px;overflow-y: auto;">
|
||||||
{GridView::widget([
|
{GridView::widget([
|
||||||
|
@ -51,16 +52,17 @@
|
||||||
'value' => \app\helpers\CaptureLogsGrid::image()
|
'value' => \app\helpers\CaptureLogsGrid::image()
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'attribute' => 'status',
|
'attribute' => 'confidence',
|
||||||
'contentOptions' => ['class' => 'text-center'],
|
'contentOptions' => ['class' => 'text-center'],
|
||||||
'headerOptions' => ['class' => 'text-center'],
|
'headerOptions' => ['class' => 'text-center'],
|
||||||
'value' => \app\helpers\CaptureLogsGrid::status($statusArray)
|
'value' => \app\helpers\CaptureLogsGrid::confidence()
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'attribute' => 'remark',
|
'attribute' => 'remark',
|
||||||
'contentOptions' => ['class' => 'text-center'],
|
'contentOptions' => ['class' => 'text-center'],
|
||||||
'headerOptions' => ['class' => 'text-center']
|
'headerOptions' => ['class' => 'text-center']
|
||||||
]
|
],
|
||||||
|
'sync_status'
|
||||||
]
|
]
|
||||||
])}
|
])}
|
||||||
</div>
|
</div>
|
||||||
|
@ -79,6 +81,10 @@
|
||||||
<i class="fa fa-search"></i> Tìm kiếm
|
<i class="fa fa-search"></i> Tìm kiếm
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<hr style="border-top: 1px solid #000;">
|
||||||
|
<div>
|
||||||
|
<input type="checkbox" name="AllData" style="width: inherit;" {if Yii::$app->request->get("all")}checked=""{/if}> Hiển thị toàn bộ dữ liệu
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="width: 500px;position: absolute;right:0;top: 250px;" id='form' class="hidden">
|
<div style="width: 500px;position: absolute;right:0;top: 250px;" id='form' class="hidden">
|
||||||
|
|
|
@ -54,7 +54,8 @@
|
||||||
[
|
[
|
||||||
'attribute' => 'confidence',
|
'attribute' => 'confidence',
|
||||||
'contentOptions' => ['class' => 'text-center'],
|
'contentOptions' => ['class' => 'text-center'],
|
||||||
'headerOptions' => ['class' => 'text-center']
|
'headerOptions' => ['class' => 'text-center'],
|
||||||
|
'value' => \app\helpers\CaptureLogsGrid::confidence()
|
||||||
],
|
],
|
||||||
'listManagement.name',
|
'listManagement.name',
|
||||||
'listManagement.gender',
|
'listManagement.gender',
|
||||||
|
|
|
@ -2,10 +2,21 @@ $(function () {
|
||||||
common.dateTimePickerByClass("datepicker", "HH:mm DD/MM/YYYY");
|
common.dateTimePickerByClass("datepicker", "HH:mm DD/MM/YYYY");
|
||||||
common.dateTimePickerDay("birthday");
|
common.dateTimePickerDay("birthday");
|
||||||
$("#Code").select2();
|
$("#Code").select2();
|
||||||
|
$("input[name='AllData']").change(function () {
|
||||||
|
if ($('input[name=AllData]').is(':checked')) {
|
||||||
|
window.location = $("input[name='URL']").val() + "?all=true" + "&from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val();
|
||||||
|
} else {
|
||||||
|
window.location = $("input[name='URL']").val() + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function _search(e) {
|
function _search(e) {
|
||||||
window.location = $(e).attr("data-href") + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val();
|
var all = "";
|
||||||
|
if ($('input[name=AllData]').is(':checked')) {
|
||||||
|
all = "&all=true";
|
||||||
|
}
|
||||||
|
window.location = $(e).attr("data-href") + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val() + all;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _form(e) {
|
function _form(e) {
|
||||||
|
|
|
@ -538,8 +538,10 @@ function syncFeatureToServer(id) {
|
||||||
$("#progress").html(percent + "%");
|
$("#progress").html(percent + "%");
|
||||||
if (percent >= 100) {
|
if (percent >= 100) {
|
||||||
common.modalBlock(false);
|
common.modalBlock(false);
|
||||||
alert("Đồng bộ dữ liệu hoàn thành");
|
setTimeout(function () {
|
||||||
window.location.reload(true);
|
alert("Đồng bộ dữ liệu hoàn thành");
|
||||||
|
window.location.reload(true);
|
||||||
|
}, 2000)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user