auto sync data, remove crontab
This commit is contained in:
@@ -66,13 +66,50 @@ class ApiController extends Controller {
|
||||
FileHelper::createDirectory($targetPath, 0777);
|
||||
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->create([
|
||||
$logs = $model->create([
|
||||
"Staff" => $post["id"],
|
||||
"Time" => $time,
|
||||
"Image" => $fileName,
|
||||
"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";
|
||||
return ["status" => "success"];
|
||||
}
|
||||
@@ -185,7 +222,51 @@ class ApiController extends Controller {
|
||||
|
||||
public function actionSync() {
|
||||
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];
|
||||
}
|
||||
|
||||
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');
|
||||
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
|
||||
if ($from !== "" && $to !== "") {
|
||||
@@ -40,9 +40,9 @@ class CaptureLogsController extends Controller {
|
||||
$this->view->title = "Capture Log";
|
||||
$searchModel = new CaptureLogsSearch();
|
||||
$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->orderBy(["time" => SORT_DESC]);
|
||||
|
||||
// $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
|
||||
// 'http' => [
|
||||
|
||||
@@ -48,7 +48,6 @@ class ControlLogsController extends Controller {
|
||||
$dataProvider->query->andWhere(["list_management.type" => $type]);
|
||||
if ($gender !== "all")
|
||||
$dataProvider->query->andWhere(["list_management.gender" => $gender]);
|
||||
$dataProvider->query->orderBy(["time" => SORT_DESC]);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
|
||||
@@ -516,8 +516,7 @@ class ListManagementController extends Controller {
|
||||
])
|
||||
]
|
||||
])), true);
|
||||
return $res;
|
||||
//["status" => true];
|
||||
return ["status" => true];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user