diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 4ad4a69b..af5cceb6 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -71,7 +71,7 @@ class ApiController extends Controller { "Staff" => $post["id"], "Time" => $time, "Image" => $fileName, - "Confidence" => strval($post["confidence"]) + "Confidence" => strval($post["confidence"]) ]); Yii::$app->response->format = "json"; return ["status" => "success"]; @@ -100,14 +100,14 @@ class ApiController extends Controller { public function actionData() { if (Yii::$app->request->post()) { Yii::$app->response->format = "json"; - return ListManagement::find()->andWhere(["NOT IN", "name", Yii::$app->request->post()])->orderBy(['id' => SORT_DESC])->all(); + return ListManagement::find()->orderBy(['id' => SORT_DESC])->all(); } } public function actionFullData() { if (Yii::$app->request->post()) { Yii::$app->response->format = "json"; - $lists = ListManagement::find()->andWhere(["IN", "id", Yii::$app->request->post()])->orderBy(['id' => SORT_DESC])->all(); + $lists = ListManagement::find()->andWhere(["IN", "code", Yii::$app->request->post()])->orderBy(['id' => SORT_DESC])->all(); $res = []; foreach ($lists as $key => $value) { $f = []; @@ -117,6 +117,7 @@ class ApiController extends Controller { } $res[] = [ "id" => $value->id, + "code" => $value->code, "type" => $value->type, "name" => $value->name, "gender" => $value->gender, diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index 7f4303c1..578dbe8c 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -268,45 +268,6 @@ class ListManagementController extends Controller { } } - public function actionSync($ip) { - if (Yii::$app->request->post()) { - $data = Yii::$app->request->post(); - $results = json_decode(file_get_contents("http://" . $ip . "/api/full-data", false, stream_context_create([ - 'http' => [ - 'header' => "Content-Type: application/json", - 'method' => "POST", - 'content' => json_encode($data['lists']) - ] - ])), true); - foreach ($results as $key => $value) { - $images = []; - foreach ($value['image'] as $k => $v) { - $key = common::generateRandomString(); - $RootFolder = Yii::getAlias('@webroot') . "/data/uploads"; - $targetPath = $RootFolder . "/face"; - $fileName = "face_" . $key . "_" . time() . ".png"; - FileHelper::createDirectory($targetPath, 0777); - file_put_contents($targetPath . "/" . $fileName, base64_decode($v['url'])); - $images[] = ["url" => $fileName, "features" => $v['features']]; - } - $model = new ListManagement(); - $model->create([ - 'type' => $value['type'], - 'name' => $value['name'], - 'image' => json_encode($images), - 'gender' => $value['gender'], - 'birthday' => date("d/m/Y", $value['birthday']), - 'telephone' => $value['telephone'], - 'address' => $value['address'], - 'time' => $value['time'] - ]); - } - file_get_contents("http://localhost:2305/update-feature"); - Yii::$app->response->format = "json"; - return $results; - } - } - public function actionSyncFromServer() { if (Yii::$app->request->isAjax) { $datas = json_decode(file_get_contents("https://dev-dc.beetai.com/api/oem/get_all_image", false, stream_context_create([ @@ -382,6 +343,57 @@ class ListManagementController extends Controller { } } + public function actionSyncFeatureFromDevice() { + if (Yii::$app->request->post()) { + Yii::$app->response->format = "json"; + $data = Yii::$app->request->post(); + $results = json_decode(file_get_contents("http://" . $data['ip'] . "/api/full-data", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([$data['id']]) + ] + ])), true); + foreach ($results as $key => $value) { + $images = []; + foreach ($value['image'] as $k => $v) { + $key = common::generateRandomString(); + $RootFolder = Yii::getAlias('@webroot') . "/data/uploads"; + $targetPath = $RootFolder . "/face"; + $fileName = "face_" . $key . "_" . time() . ".png"; + FileHelper::createDirectory($targetPath, 0777); + file_put_contents($targetPath . "/" . $fileName, base64_decode($v['url'])); + $images[] = ["url" => $fileName, "features" => $v['features']]; + } + $model = ListManagement::findOne(['code' => $value['code']]); + if ($model) { + $model->type = $value['type']; + $model->name = $value['name']; + $model->image = json_encode($images); + $model->gender = $value['gender']; + $model->birthday = date("d/m/Y", $value['birthday']); + $model->telephone = $value['telephone']; + $model->address = $value['address']; + $model->save(); + } else { + $model = new ListManagement(); + $model->create([ + 'code' => $value['code'], + 'type' => $value['type'], + 'name' => $value['name'], + 'image' => json_encode($images), + 'gender' => $value['gender'], + 'birthday' => date("d/m/Y", $value['birthday']), + 'telephone' => $value['telephone'], + 'address' => $value['address'], + 'time' => $value['time'] + ]); + } + } + return ["status" => true]; + } + } + public function actionUpdateFeature() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = "json"; diff --git a/views/list-management/index.tpl b/views/list-management/index.tpl index 1f49eb4c..bfb3cce4 100644 --- a/views/list-management/index.tpl +++ b/views/list-management/index.tpl @@ -29,6 +29,7 @@ +
diff --git a/views/list-management/list-server.tpl b/views/list-management/list-server.tpl index 1b4226fb..e5c38af1 100644 --- a/views/list-management/list-server.tpl +++ b/views/list-management/list-server.tpl @@ -52,7 +52,7 @@ - diff --git a/views/list-management/list.tpl b/views/list-management/list.tpl index f1a6b60f..4a7ddc5f 100644 --- a/views/list-management/list.tpl +++ b/views/list-management/list.tpl @@ -15,8 +15,8 @@ {foreach from=$results item=arr} - - {$arr.id} + + {$arr.code} {$typeArray[$arr.type]} {$arr.name} {$arr.gender} @@ -39,17 +39,27 @@

-
+
Đã lựa chọn 0 đối tượng.
-
+
+ +
+
- diff --git a/web/js/list-management.js b/web/js/list-management.js index 0895a17a..a0e1868a 100644 --- a/web/js/list-management.js +++ b/web/js/list-management.js @@ -332,7 +332,9 @@ function checkAllSync(stt) { } } -function _sync(e) { +var progress = 0; +var totals = 0; +function _sync() { var lists = []; $.each($("#sync-lists").find(".success"), function () { lists.push($(this).attr("data-id")); @@ -342,16 +344,34 @@ function _sync(e) { return; } common.modalBlock(true); + $("#progress-totals").html(lists.length); + $("#progress-form").removeClass("hidden"); + totals = lists.length; + for (var i = 0; i < lists.length; i++) { + syncFeatureFromDevice(lists[i]); + } +} + +function syncFeatureFromDevice(id) { $.ajax({ - url: $(e).attr("data-href"), + url: $("input[name='sync_feature_from_device_url']").val(), type: 'POST', data: { - lists: lists + id: id, + ip: $("input[name='SyncIP']").val() }, success: function (data) { - common.modalBlock(false); - alert("Đồng bộ dữ liệu thành công!"); - window.location.reload(true); + progress++; + $("#progress-current").html(parseInt($("#progress-current").html()) + 1); + var percent = parseInt(progress / totals * 100); + $("#progress").attr("aria-valuenow", percent); + $("#progress").attr("style", "width: " + percent + "%"); + $("#progress").html(percent + "%"); + if (percent >= 100) { + common.modalBlock(false); + updateFeature(); + progress = 0; + } }, error: function (jqXHR, textStatus, errorThrown) { common.modalBlock(false); @@ -375,9 +395,8 @@ function _syncFromServerForm(e) { } }); } -var progress = 0; -var totals = 0; -function _syncFromServer(e) { + +function _syncFromServer() { var lists = []; $.each($("#sync-lists").find(".success"), function () { lists.push($(this).attr("data-id")); @@ -403,7 +422,6 @@ function syncFeature(id) { id: id }, success: function (data) { - console.log(data); progress++; $("#progress-current").html(parseInt($("#progress-current").html()) + 1); var percent = parseInt(progress / totals * 100);