update not insert duplicate logs

This commit is contained in:
dongpd 2023-06-14 13:49:01 +07:00
parent 21cc5f2050
commit 82a5b0d0ad
2 changed files with 8 additions and 3 deletions

View File

@ -7,5 +7,5 @@ return [
"maxPicture" => 9999, "maxPicture" => 9999,
"version" => "1.0.7", "version" => "1.0.7",
"autoSyncLog" => false, "autoSyncLog" => false,
"timeoutRequestServer" => 10 "timeoutRequestServer" => 4
]; ];

View File

@ -58,6 +58,7 @@ class ApiController extends Controller {
public function actionGetLogs() { public function actionGetLogs() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$post = Yii::$app->request->bodyParams; $post = Yii::$app->request->bodyParams;
$time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U'); $time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U');
$key = common::generateRandomString(); $key = common::generateRandomString();
@ -73,6 +74,11 @@ class ApiController extends Controller {
@unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $lastLogs->image); @unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $lastLogs->image);
$lastLogs->delete(); $lastLogs->delete();
} }
$lastLogs = CaptureLogs::find()->andWhere(["staff_id" => $post['id']])->orderBy(["time" => SORT_DESC])->limit(1)->one();
if (($time - $lastLogs->time) < 1) {
file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "] duplicate face " . $post["id"], FILE_APPEND);
return ["status" => "success"];
}
$model = new CaptureLogs(); $model = new CaptureLogs();
$logs = $model->create([ $logs = $model->create([
@ -126,7 +132,6 @@ class ApiController extends Controller {
file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "] /api/box/face_recognition_auth_v2 timeout " . $ip, FILE_APPEND); file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "] /api/box/face_recognition_auth_v2 timeout " . $ip, FILE_APPEND);
} }
} }
Yii::$app->response->format = "json";
return ["status" => "success"]; return ["status" => "success"];
} }
} }
@ -407,7 +412,7 @@ class ApiController extends Controller {
// file_put_contents("log_connect_server.txt", "\n" . date("H:i:s d/m/Y") . " connected " . $host . ":" . $port, FILE_APPEND); // file_put_contents("log_connect_server.txt", "\n" . date("H:i:s d/m/Y") . " connected " . $host . ":" . $port, FILE_APPEND);
} else { } else {
$is_conn = false; //action in connection failure $is_conn = false; //action in connection failure
// file_put_contents("log_connect_server.txt", "\n" . date("H:i:s d/m/Y") . " disconnected " . $host . ":" . $port, FILE_APPEND); file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "] disconnected " . $host . ":" . $port, FILE_APPEND);
} }
return $is_conn; return $is_conn;
} }