đồng bộ dữ liệu lên máy chủ

This commit is contained in:
dongpd 2020-12-11 14:00:23 +07:00
parent e27b8de414
commit 5d5de05f85
5 changed files with 38 additions and 31 deletions

View File

@ -10,6 +10,8 @@ namespace app\commands;
use yii\console\Controller; use yii\console\Controller;
use yii\console\ExitCode; use yii\console\ExitCode;
use app\models\CaptureLogs;
use app\models\ListManagement;
/** /**
* This command echoes the first argument that you have entered. * This command echoes the first argument that you have entered.
@ -28,32 +30,33 @@ class SyncController extends Controller {
*/ */
public function actionIndex() { public function actionIndex() {
if ($this->is_connected()) { if ($this->is_connected()) {
$sync = \app\models\SyncUrl::find()->one(); $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
if ($sync) { $ip = "dev-dc.beetai.com";
$logs = \app\models\FaceLogs::find()->all(); if ($server_ip)
foreach ($logs as $key => $value) { $ip = $server_ip->data;
$options = [ $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(['<>', 'staff_id', 0])->andWhere(['sync_status' => 0])->all();
foreach ($ls as $key => $value) {
$staffInfo = ListManagement::findOne($value->staff_id);
$res = json_decode(file_get_contents("https://" . $ip . "/api/box/oem_face_recognition", false, stream_context_create([
'http' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",
'content' => json_encode([ 'content' => json_encode([
"camera_id" => $value->camera_id, 'image' => base64_encode(file_get_contents(Yii::getAlias('@webroot') . "/data/uploads/face/" . $value->image)),
"confidence" => $value->confidence, 'camera_id' => strval($id_camera),
"enable_door" => $value->enable_door, 'frametime' => date("Y-m-d H:i:s", $value->time),
"encoded_person_image" => $value->encoded_person_image, 'idCard' => $staffInfo ? strval($staffInfo->code) : "0"
"frametime" => $value->frametime, ])
"id" => $value->face_id,
"image" => $value->image,
"name" => $value->name,
"person_id" => $value->person_id,
"status" => $value->status,
"stt" => $value->stt,
"timezone" => $value->timezone
]),
] ]
]; ])), true);
file_get_contents($sync->data, false, stream_context_create($options)); if ($res['status'] == 10000) {
$value->delete(); $value->sync_status = 1;
$value->save();
} }
} }
} }

View File

@ -339,7 +339,7 @@ class ListManagementController extends Controller {
$model = ListManagement::findOne(['code' => $data['idStaff']]); $model = ListManagement::findOne(['code' => $data['idStaff']]);
if ($model) { if ($model) {
$model->name = $data['name']; $model->name = $data['code'];
$model->image = json_encode($ft); $model->image = json_encode($ft);
$model->last_modified = time(); $model->last_modified = time();
$model->save(); $model->save();
@ -348,7 +348,7 @@ class ListManagementController extends Controller {
$model->create([ $model->create([
'code' => $data['idStaff'], 'code' => $data['idStaff'],
'type' => "wl", 'type' => "wl",
'name' => $data['name'], 'name' => $data['code'],
'image' => json_encode($ft), 'image' => json_encode($ft),
'gender' => "", 'gender' => "",
'birthday' => "", 'birthday' => "",

BIN
db/app.db

Binary file not shown.

View File

@ -14,6 +14,7 @@ use Yii;
* @property int $status * @property int $status
* @property string $remark * @property string $remark
* @property string $confidence * @property string $confidence
* @property int $sync_status
*/ */
class CaptureLogs extends \yii\db\ActiveRecord { class CaptureLogs extends \yii\db\ActiveRecord {
@ -29,7 +30,7 @@ class CaptureLogs extends \yii\db\ActiveRecord {
*/ */
public function rules() { public function rules() {
return [ return [
[['staff_id', 'time', 'status'], 'integer'], [['staff_id', 'time', 'status', 'sync_status'], 'integer'],
[['image', 'remark', 'confidence'], 'string'], [['image', 'remark', 'confidence'], 'string'],
]; ];
} }
@ -46,7 +47,8 @@ class CaptureLogs extends \yii\db\ActiveRecord {
'remark' => 'Remark', 'remark' => 'Remark',
'staff_name' => "Name", 'staff_name' => "Name",
'staff_image' => "Registration Image", 'staff_image' => "Registration Image",
'confidence' => 'Confidence' 'confidence' => 'Confidence',
'sync_status' => 'Sync Status'
]; ];
} }

View File

@ -4,6 +4,7 @@
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>Name</th> <th>Name</th>
<th>Code</th>
<th>Department</th> <th>Department</th>
<th>Registration Image</th> <th>Registration Image</th>
<th>Code</th> <th>Code</th>
@ -15,6 +16,7 @@
<tr onclick="choooseToSync(this);" style="cursor: pointer;" data-stt="false" data-id="{$arr.idStaff}"> <tr onclick="choooseToSync(this);" style="cursor: pointer;" data-stt="false" data-id="{$arr.idStaff}">
<td>{$arr.idStaff}</td> <td>{$arr.idStaff}</td>
<td>{$arr.name}</td> <td>{$arr.name}</td>
<td>{$arr.code}</td>
<td>{$arr.department}</td> <td>{$arr.department}</td>
<td> <td>
{foreach from=$arr.images item=img} {foreach from=$arr.images item=img}