đồng bộ dữ liệu từ cloud
This commit is contained in:
parent
75073b956d
commit
7ff0f1b976
|
@ -307,8 +307,80 @@ class ListManagementController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionTest() {
|
public function actionSyncFromServer() {
|
||||||
return base64_encode(file_get_contents("http://api.demo.beetai.com/view/image/5fd0845d9a4eb65bcfb0ea3b"));
|
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([
|
||||||
|
'http' => [
|
||||||
|
'header' => "Content-Type: application/json",
|
||||||
|
'method' => "POST",
|
||||||
|
'content' => json_encode([
|
||||||
|
"id_camera" => 209,
|
||||||
|
"ids_staff" => []
|
||||||
|
])
|
||||||
|
]
|
||||||
|
])), true);
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
return [
|
||||||
|
"title" => "<i class='fa fa-download'></i> Đồng bộ từ máy chủ",
|
||||||
|
"form" => $this->renderPartial("list-server", [
|
||||||
|
"datas" => $datas['data']
|
||||||
|
])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionSyncFeature() {
|
||||||
|
if (Yii::$app->request->post()) {
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
$res = json_decode(file_get_contents("https://dev-dc.beetai.com/api/oem/get_all_image", false, stream_context_create([
|
||||||
|
'http' => [
|
||||||
|
'header' => "Content-Type: application/json",
|
||||||
|
'method' => "POST",
|
||||||
|
'content' => json_encode([
|
||||||
|
"id_camera" => 209,
|
||||||
|
"ids_staff" => [strval(Yii::$app->request->post("id"))]
|
||||||
|
])
|
||||||
|
]
|
||||||
|
])), true);
|
||||||
|
$data = $res['data'][0];
|
||||||
|
$ft = [];
|
||||||
|
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
|
||||||
|
$targetPath = $RootFolder . "/face";
|
||||||
|
FileHelper::createDirectory($targetPath, 0777);
|
||||||
|
foreach ($data['images'] as $key => $value) {
|
||||||
|
$key = common::generateRandomString();
|
||||||
|
$fileName = "face_" . $key . "_" . time() . ".png";
|
||||||
|
file_put_contents($targetPath . "/" . $fileName, file_get_contents($value));
|
||||||
|
$features = json_decode(common::requestToEngine("/get-feature", [
|
||||||
|
"image_paths" => [
|
||||||
|
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
|
||||||
|
]
|
||||||
|
]), true);
|
||||||
|
$ft[] = ["url" => $fileName, "features" => $features['results'][0]['feature']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$model = new ListManagement();
|
||||||
|
$model->create([
|
||||||
|
'code' => $data['idStaff'],
|
||||||
|
'type' => "wl",
|
||||||
|
'name' => $data['name'],
|
||||||
|
'image' => json_encode($ft),
|
||||||
|
'gender' => "",
|
||||||
|
'birthday' => "",
|
||||||
|
'telephone' => "",
|
||||||
|
'address' => ""
|
||||||
|
]);
|
||||||
|
// file_get_contents("http://localhost:2305/update-feature");
|
||||||
|
return ["status" => true];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionUpdateFeature() {
|
||||||
|
if (Yii::$app->request->isAjax) {
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
file_get_contents("http://localhost:2305/update-feature");
|
||||||
|
return ["status" => true];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
</style>
|
</style>
|
||||||
<input type="hidden" value="{Url::to(["/list-management/add"])}" name="create_url">
|
<input type="hidden" value="{Url::to(["/list-management/add"])}" name="create_url">
|
||||||
<input type="hidden" value="{Url::to(["/list-management/update"])}" name="update_url">
|
<input type="hidden" value="{Url::to(["/list-management/update"])}" name="update_url">
|
||||||
|
<input type="hidden" value="{Url::to(["/list-management/sync-feature"])}" name="sync_feature_url">
|
||||||
|
<input type="hidden" value="{Url::to(["/list-management/update-feature"])}" name="update_feature_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([
|
||||||
|
@ -143,6 +145,9 @@
|
||||||
<button class="btn btn-info" onclick="_form();">
|
<button class="btn btn-info" onclick="_form();">
|
||||||
<i class="fa fa-plus-circle"></i> Thêm mới
|
<i class="fa fa-plus-circle"></i> Thêm mới
|
||||||
</button>
|
</button>
|
||||||
|
<button class="btn btn-info" onclick="_syncFromServerForm(this);" data-href="{Url::to(['/list-management/sync-from-server'])}">
|
||||||
|
<i class="fa fa-download"></i> Đồng bộ từ máy chủ
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<hr style="border-top: 1px solid #000;">
|
<hr style="border-top: 1px solid #000;">
|
||||||
<h4>Đồng bộ từ thiết bị khác</h4>
|
<h4>Đồng bộ từ thiết bị khác</h4>
|
||||||
|
|
60
views/list-management/list-server.tpl
Normal file
60
views/list-management/list-server.tpl
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<div style="max-height: 750px;overflow-y: auto;">
|
||||||
|
<table class="table table-bordered table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Department</th>
|
||||||
|
<th>Registration Image</th>
|
||||||
|
<th>Code</th>
|
||||||
|
<th>Company ID</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="sync-lists">
|
||||||
|
{foreach from=$datas item=arr}
|
||||||
|
<tr onclick="choooseToSync(this);" style="cursor: pointer;" data-stt="false" data-id="{$arr.idStaff}">
|
||||||
|
<td>{$arr.idStaff}</td>
|
||||||
|
<td>{$arr.name}</td>
|
||||||
|
<td>{$arr.department}</td>
|
||||||
|
<td>
|
||||||
|
{foreach from=$arr.images item=img}
|
||||||
|
<div class='feature-img'>
|
||||||
|
<img src="{$img}" class="img-thumbnail" style="width: 100px;height:100px;">
|
||||||
|
</div>
|
||||||
|
{/foreach}
|
||||||
|
</td>
|
||||||
|
<td>{$arr.code}</td>
|
||||||
|
<td>{$arr.id_company}</td>
|
||||||
|
</tr>
|
||||||
|
{/foreach}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<i class="fa fa-info-circle"></i> Đã lựa chọn <b class="text-red" id="totals-choose">0</b> đối tượng.
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="hidden" id="progress-form">
|
||||||
|
Đồng bộ <b id="progress-current" class="text-green">0</b>/<b id="progress-totals" class="text-red">0</b> đối tượng.
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar progress-bar-primary progress-bar-striped" id='progress' role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
|
||||||
|
0%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 text-right">
|
||||||
|
<button class="btn btn-default" onclick="checkAllSync(true);">
|
||||||
|
Chọn tất cả
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-default" onclick="checkAllSync(false);">
|
||||||
|
Bỏ chọn tất cả
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary" onclick="_syncFromServer(this);" data-href="{yii\helpers\Url::to(['sync-from-server'])}">
|
||||||
|
<i class="fa fa-refresh"></i> Đồng bộ
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-remove"></span> Đóng lại</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -358,4 +358,78 @@ function _sync(e) {
|
||||||
alert("Mất kết nối tới thiết bị");
|
alert("Mất kết nối tới thiết bị");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _syncFromServerForm(e) {
|
||||||
|
common.modalBlock(true);
|
||||||
|
$.ajax({
|
||||||
|
url: $(e).attr("data-href"),
|
||||||
|
type: 'POST',
|
||||||
|
success: function (data) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.modalOpenFullScreen(data.form, data.title);
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.ajaxError();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var progress = 0;
|
||||||
|
var totals = 0;
|
||||||
|
function _syncFromServer(e) {
|
||||||
|
var lists = [];
|
||||||
|
$.each($("#sync-lists").find(".success"), function () {
|
||||||
|
lists.push($(this).attr("data-id"));
|
||||||
|
});
|
||||||
|
if (lists.length == 0) {
|
||||||
|
alert("Không có dữ liệu đồng bộ!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
common.modalBlock(true);
|
||||||
|
$("#progress-totals").html(lists.length);
|
||||||
|
$("#progress-form").removeClass("hidden");
|
||||||
|
totals = lists.length;
|
||||||
|
for (var i = 0; i < lists.length; i++) {
|
||||||
|
syncFeature(lists[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncFeature(id) {
|
||||||
|
$.ajax({
|
||||||
|
url: $("input[name='sync_feature_url']").val(),
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
console.log(data);
|
||||||
|
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) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateFeature() {
|
||||||
|
console.log("abc");
|
||||||
|
$.ajax({
|
||||||
|
url: $("input[name='update_feature_url']").val(),
|
||||||
|
type: 'POST',
|
||||||
|
success: function (data) {
|
||||||
|
window.location.reload(true);
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user