dong bo du lieu mau khuon mat len may chu
This commit is contained in:
parent
df644d539d
commit
bba20c9c17
|
@ -183,4 +183,9 @@ class ApiController extends Controller {
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionSync() {
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
return ["status" => true];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -467,4 +467,58 @@ class ListManagementController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionSyncToServer() {
|
||||||
|
if (Yii::$app->request->isAjax) {
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
return [
|
||||||
|
"title" => "<i class='fa fa-upload'></i> Đồng bộ lên máy chủ",
|
||||||
|
"form" => $this->renderPartial("list-to-server", [
|
||||||
|
"datas" => ListManagement::find()->orderBy(["code" => SORT_ASC])->all()
|
||||||
|
])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionSyncFeatureToServer() {
|
||||||
|
if (Yii::$app->request->post()) {
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$StaffInfo = ListManagement::findOne(["code" => Yii::$app->request->post("id")]);
|
||||||
|
$lsImgs = json_decode($StaffInfo->image, true);
|
||||||
|
$images = [];
|
||||||
|
foreach ($lsImgs as $key => $value) {
|
||||||
|
$images[] = base64_encode(file_get_contents(Yii::$app->request->hostInfo . "/data/uploads/face/" . $value['url']));
|
||||||
|
}
|
||||||
|
$items = [
|
||||||
|
"name" => $StaffInfo->name,
|
||||||
|
"code" => $StaffInfo->code,
|
||||||
|
"department" => $StaffInfo->address,
|
||||||
|
"birthday" => date("Y-m-d", $StaffInfo->birthday),
|
||||||
|
"gender" => $StaffInfo == "Male" ? 1 : 0,
|
||||||
|
"telephone" => $StaffInfo->telephone,
|
||||||
|
"images" => $images
|
||||||
|
];
|
||||||
|
$res = json_decode(file_get_contents("https://" . $ip . "/api/oem/data_sync_pro", false, stream_context_create([
|
||||||
|
'http' => [
|
||||||
|
'header' => "Content-Type: application/json",
|
||||||
|
'method' => "POST",
|
||||||
|
'content' => json_encode([
|
||||||
|
"id_camera" => $id_camera,
|
||||||
|
"items" => [$items]
|
||||||
|
])
|
||||||
|
]
|
||||||
|
])), true);
|
||||||
|
return $res;
|
||||||
|
//["status" => true];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
<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/sync-feature"])}" name="sync_feature_url">
|
||||||
|
<input type="hidden" value="{Url::to(["/list-management/sync-feature-to-server"])}" name="sync_feature_to_server_url">
|
||||||
<input type="hidden" value="{Url::to(["/list-management/sync-feature-from-device"])}" name="sync_feature_from_device_url">
|
<input type="hidden" value="{Url::to(["/list-management/sync-feature-from-device"])}" name="sync_feature_from_device_url">
|
||||||
<input type="hidden" value="{Url::to(["/list-management/update-feature"])}" name="update_feature_url">
|
<input type="hidden" value="{Url::to(["/list-management/update-feature"])}" name="update_feature_url">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -135,7 +136,7 @@
|
||||||
<hr style="border-top: 1px solid #000;">
|
<hr style="border-top: 1px solid #000;">
|
||||||
<div>
|
<div>
|
||||||
<input type="checkbox" name="BatchDelete" style="width: inherit;"> Xóa nhiều dữ liệu
|
<input type="checkbox" name="BatchDelete" style="width: inherit;"> Xóa nhiều dữ liệu
|
||||||
<br><br>
|
<br>
|
||||||
<div class="hidden" id="delete-btn-group">
|
<div class="hidden" id="delete-btn-group">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button onclick="checkAll(true);">Chọn toàn bộ trang</button>
|
<button onclick="checkAll(true);">Chọn toàn bộ trang</button>
|
||||||
|
@ -148,13 +149,17 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr style="border-top: 1px solid #000;">
|
<hr style="border-top: 1px solid #000;">
|
||||||
|
<h4>Đồng bộ với máy chủ</h4>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
{*<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'])}">
|
<button class="btn btn-info btn-block" onclick="_syncFromServerForm(this);" data-href="{Url::to(['/list-management/sync-from-server'])}">
|
||||||
<i class="fa fa-download"></i> Đồng bộ từ máy chủ
|
<i class="fa fa-download"></i> Đồng bộ từ máy chủ
|
||||||
</button>
|
</button>
|
||||||
|
<button class="btn btn-success btn-block" onclick="_syncToServerForm(this);" data-href="{Url::to(['/list-management/sync-to-server'])}">
|
||||||
|
<i class="fa fa-upload"></i> Đồng bộ lên 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>
|
||||||
|
|
63
views/list-management/list-to-server.tpl
Normal file
63
views/list-management/list-to-server.tpl
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<div style="max-height: 750px;overflow-y: auto;">
|
||||||
|
<table class="table table-bordered table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Gender</th>
|
||||||
|
<th>Registration Image</th>
|
||||||
|
<th>Birthday</th>
|
||||||
|
<th>Telephone</th>
|
||||||
|
<th>Department</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->code}">
|
||||||
|
<td>{$arr->code}</td>
|
||||||
|
<td>{$arr->name}</td>
|
||||||
|
<td>{$arr->gender}</td>
|
||||||
|
<td>
|
||||||
|
{$images = json_decode($arr->image, true)}
|
||||||
|
{foreach from=$images item=img}
|
||||||
|
<div class='feature-img'>
|
||||||
|
<img src="/data/uploads/face/{$img.url}" class="img-thumbnail" style="width: 100px;height:100px;">
|
||||||
|
</div>
|
||||||
|
{/foreach}
|
||||||
|
</td>
|
||||||
|
<td>{$arr->birthday|date_format:"%d/%m/%Y"}</td>
|
||||||
|
<td>{$arr->telephone}</td>
|
||||||
|
<td>{$arr->address}</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="_syncToServer();">
|
||||||
|
<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>
|
|
@ -485,3 +485,64 @@ function chooseStaff(e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _syncToServerForm(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 progressToServer = 0;
|
||||||
|
var totalsToServer = 0;
|
||||||
|
function _syncToServer() {
|
||||||
|
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");
|
||||||
|
totalsToServer = lists.length;
|
||||||
|
for (var i = 0; i < lists.length; i++) {
|
||||||
|
syncFeatureToServer(lists[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncFeatureToServer(id) {
|
||||||
|
$.ajax({
|
||||||
|
url: $("input[name='sync_feature_to_server_url']").val(),
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
progressToServer++;
|
||||||
|
$("#progress-current").html(parseInt($("#progress-current").html()) + 1);
|
||||||
|
var percent = parseInt(progressToServer / totalsToServer * 100);
|
||||||
|
$("#progress").attr("aria-valuenow", percent);
|
||||||
|
$("#progress").attr("style", "width: " + percent + "%");
|
||||||
|
$("#progress").html(percent + "%");
|
||||||
|
if (percent >= 100) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
alert("Đồng bộ dữ liệu hoàn thành");
|
||||||
|
window.location.reload(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user