làm lại quy trình đồng bộ dữ liệu
This commit is contained in:
167
web/js/device.js
167
web/js/device.js
@@ -248,10 +248,18 @@ function changeIP(e) {
|
||||
|
||||
var progress = 0;
|
||||
var totals = 0;
|
||||
function _sync(e) {
|
||||
var index = 0;
|
||||
var totalPage = 0;
|
||||
var currentPage = 1;
|
||||
var secondIncrement = 0;
|
||||
|
||||
async function _sync(e) {
|
||||
var lists = [];
|
||||
$.each($("input[name='checkbox-device']:checked"), function () {
|
||||
lists.push($(this).val());
|
||||
lists.push({
|
||||
id: $(this).val(),
|
||||
ip: $(this).attr("data")
|
||||
});
|
||||
});
|
||||
if (lists.length == 0) {
|
||||
alert("Vui lòng lựa chọn đối tượng!");
|
||||
@@ -269,10 +277,8 @@ function _sync(e) {
|
||||
common.modalOpen(data.form, false, data.title);
|
||||
$("#close-modal").attr("disabled", true);
|
||||
$("#modalHeader").find("button").remove();
|
||||
totals = data.lists.length * 2;
|
||||
for (var i = 0; i < data.lists.length; i++) {
|
||||
getDataSync(data.lists[i]);
|
||||
}
|
||||
totals = data.lists.length;
|
||||
syncSchedule(data.lists[index].id, data.lists[index].ip, data);
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
@@ -281,6 +287,71 @@ function _sync(e) {
|
||||
});
|
||||
}
|
||||
|
||||
function syncSchedule(device_id, device_ip, fullData) {
|
||||
appendLogs("[" + device_ip + "] Bắt đầu đồng bộ dữ liệu tới thiết bị", "blue", "minus");
|
||||
$.ajax({
|
||||
url: $("input[name='URL_sync_schedule']").val(),
|
||||
type: 'POST',
|
||||
data: {
|
||||
data: device_id
|
||||
},
|
||||
success: function (data) {
|
||||
var totalsStaff = data.staffs;
|
||||
totalPage = parseInt(totalsStaff / 200);
|
||||
if (totalsStaff % 200 > 0)
|
||||
totalPage++;
|
||||
secondIncrement = 1 / (totalPage + 1);
|
||||
if (data.res.ErrorCode == "-1") {
|
||||
appendLogs("[" + data.IP + "] Đồng bộ lịch trình tới thiết bị thất bại", "red", "remove");
|
||||
index++;
|
||||
if (index < totals)
|
||||
syncSchedule(fullData.lists[index].id, fullData.lists[index].ip, fullData);
|
||||
else {
|
||||
index = 0;
|
||||
processProgress(1);
|
||||
}
|
||||
} else {
|
||||
appendLogs("[" + data.IP + "] Đồng bộ lịch trình tới thiết bị thành công", "green", "check");
|
||||
syncStaffs(device_id, device_ip, currentPage, fullData);
|
||||
processProgress(secondIncrement);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function syncStaffs(device_id, device_ip, page, fullData) {
|
||||
appendLogs("[" + device_ip + "] Đồng bộ dữ liệu nhân viên tới thiết bị", "", "minus");
|
||||
$.ajax({
|
||||
url: $("input[name='URL_sync_staff']").val() + "?page=" + page,
|
||||
type: 'POST',
|
||||
data: {
|
||||
data: device_id
|
||||
},
|
||||
success: function (data) {
|
||||
appendLogs("[" + data.IP + "] Đồng bộ dữ liệu " + data.staff + " nhân viên từ " + data.from + " đến " + data.to + " tới thiết bị", "green", "check");
|
||||
processProgress(secondIncrement);
|
||||
currentPage++;
|
||||
if (currentPage <= totalPage)
|
||||
syncStaffs(device_id, device_ip, currentPage, fullData);
|
||||
else {
|
||||
currentPage = 1;
|
||||
index++;
|
||||
if (index < totals)
|
||||
syncSchedule(fullData.lists[index].id, fullData.lists[index].ip, fullData);
|
||||
else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getDataSync(data) {
|
||||
$.ajax({
|
||||
url: $("input[name='get_data_sync_url']").val(),
|
||||
@@ -315,72 +386,6 @@ function getDataSync(data) {
|
||||
});
|
||||
}
|
||||
|
||||
function syncSchedule(schedule, ip) {
|
||||
$.ajax({
|
||||
url: $("input[name='sync_schedule_url']").val(),
|
||||
type: 'POST',
|
||||
data: {
|
||||
data: schedule,
|
||||
ip: ip
|
||||
},
|
||||
success: function (data) {
|
||||
console.log("sync schedule: ", data.res);
|
||||
var html = "";
|
||||
html = "<span class='text-green'><i class='fa fa-check'></i> Đồng bộ lịch trình tới thiết bị <b>" + data.IP + "</b>.</span><br>";
|
||||
progress++;
|
||||
if (data.res.ErrorCode == "-1") {
|
||||
html = "<span class='text-red'><i class='fa fa-remove'></i> Đồng bộ tới thiết bị <b>" + data.IP + "</b> thất bại.</span><br>";
|
||||
progress++;
|
||||
} else {
|
||||
syncStaffs(ip);
|
||||
}
|
||||
$("#logs-response").append(html);
|
||||
var percent = parseInt(progress / totals * 100);
|
||||
$("#progress").attr("aria-valuenow", percent);
|
||||
$("#progress").attr("style", "width: " + percent + "%");
|
||||
$("#progress").html(percent + "%");
|
||||
if (percent >= 100) {
|
||||
progress = 0;
|
||||
$("#close-modal").attr("disabled", false);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function syncStaffs(ip) {
|
||||
$.ajax({
|
||||
url: $("input[name='sync_staffs_url']").val(),
|
||||
type: 'POST',
|
||||
data: {
|
||||
ip: ip
|
||||
},
|
||||
success: function (data) {
|
||||
console.log("sync user: ", data.resUser);
|
||||
var html = "";
|
||||
html = "<span class='text-green'><i class='fa fa-check'></i> Đồng bộ nhân viên tới thiết bị <b>" + data.IP + "</b>.</span><br>";
|
||||
if (data.res.ErrorCode == "-1") {
|
||||
html = "<span class='text-red'><i class='fa fa-remove'></i> Đồng bộ nhân viên tới thiết bị <b>" + data.IP + "</b> thất bại.</span><br>";
|
||||
}
|
||||
$("#logs-response").append(html);
|
||||
progress++;
|
||||
var percent = parseInt(progress / totals * 100);
|
||||
$("#progress").attr("aria-valuenow", percent);
|
||||
$("#progress").attr("style", "width: " + percent + "%");
|
||||
$("#progress").html(percent + "%");
|
||||
if (percent >= 100) {
|
||||
progress = 0;
|
||||
$("#close-modal").attr("disabled", false);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var progressLogs = 0;
|
||||
var totalsLogs = 0;
|
||||
function _getLogs(e) {
|
||||
@@ -443,3 +448,21 @@ function syncLogs(data) {
|
||||
});
|
||||
}
|
||||
|
||||
function appendLogs(text, cls, icon) {
|
||||
var html = "<span class='text-" + cls + "'><i class='fa fa-" + icon + "'></i> " + text + "</span><br>";
|
||||
$("#logs-response").prepend(html);
|
||||
}
|
||||
|
||||
function processProgress(ai) {
|
||||
progress = progress + ai;
|
||||
var percent = parseInt(progress / totals * 100);
|
||||
if (percent >= 98)
|
||||
percent = 100;
|
||||
$("#progress").attr("aria-valuenow", percent);
|
||||
$("#progress").attr("style", "width: " + percent + "%");
|
||||
$("#progress").html(percent + "%");
|
||||
if (percent >= 100) {
|
||||
progress = 0;
|
||||
$("#close-modal").attr("disabled", false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user