update đồng bộ tất cả thiết bị

This commit is contained in:
dongpd 2020-11-04 17:24:56 +07:00
parent 72dfa46c94
commit fa10b73a3d
3 changed files with 38 additions and 5 deletions

View File

@ -48,7 +48,7 @@ $config = [
], ],
'assetManager' => [ 'assetManager' => [
'class' => 'app\\components\\AssetManager', 'class' => 'app\\components\\AssetManager',
'appendVersion' => '1.0.5', 'appendVersion' => '1.0.6',
'bundles' => [ 'bundles' => [
'dmstr\web\AdminLteAsset' => [ 'dmstr\web\AdminLteAsset' => [
'skin' => 'skin-blue', 'skin' => 'skin-blue',

View File

@ -87,6 +87,9 @@ class DeviceController extends Controller {
if ($requestToCardService["Status"] === "ERROR") if ($requestToCardService["Status"] === "ERROR")
return ["status" => false, "type" => "connect"]; return ["status" => false, "type" => "connect"];
if (intval($requestToCardService["LockCount"]) < 1)
return ["status" => false, "type" => "connect"];
$device_id = $model->create([ $device_id = $model->create([
'name' => $data["Name"], 'name' => $data["Name"],
'serial' => isset($device['SN']) ? $device['SN'] : "", 'serial' => isset($device['SN']) ? $device['SN'] : "",
@ -378,10 +381,20 @@ class DeviceController extends Controller {
public function actionSync() { public function actionSync() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
$post = Yii::$app->request->post("lists");
$lists = $post["lists"];
if ($post["all"] && count($lists) >= 20) {
$temp = [];
$devices = Device::find()->all();
foreach ($devices as $key => $value) {
$temp[] = $value->id;
}
$lists = $temp;
}
return [ return [
"title" => Html::tag("i", "", ["class" => "fa fa-refresh"]) . " Đồng bộ dữ liệu đến thiết bị", "title" => Html::tag("i", "", ["class" => "fa fa-refresh"]) . " Đồng bộ dữ liệu đến thiết bị",
"form" => $this->renderPartial("sync"), "form" => $this->renderPartial("sync"),
"lists" => Yii::$app->request->post("lists") "lists" => $lists
]; ];
} }
} }
@ -533,10 +546,20 @@ class DeviceController extends Controller {
public function actionGetLogs() { public function actionGetLogs() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
$post = Yii::$app->request->post("lists");
$lists = $post["lists"];
if ($post["all"] && count($lists) >= 20) {
$temp = [];
$devices = Device::find()->all();
foreach ($devices as $key => $value) {
$temp[] = $value->id;
}
$lists = $temp;
}
return [ return [
"title" => Html::tag("i", "", ["class" => "fa fa-exchange"]) . " Lấy các sự kiện", "title" => Html::tag("i", "", ["class" => "fa fa-exchange"]) . " Lấy các sự kiện",
"form" => $this->renderPartial("logs"), "form" => $this->renderPartial("logs"),
"lists" => Yii::$app->request->post("lists") "lists" => $lists
]; ];
} }
} }

View File

@ -266,6 +266,10 @@ var currentPage = 1;
var secondIncrement = 0; var secondIncrement = 0;
async function _sync(e) { async function _sync(e) {
var checkAll = $("#checkall-device:checked").length;
var all = false;
if (checkAll > 0)
all = true;
var lists = []; var lists = [];
$.each($("input[name='checkbox-device']:checked"), function () { $.each($("input[name='checkbox-device']:checked"), function () {
lists.push({ lists.push({
@ -282,7 +286,8 @@ async function _sync(e) {
url: $(e).attr('data-href'), url: $(e).attr('data-href'),
type: 'POST', type: 'POST',
data: { data: {
lists: lists lists: lists,
all: all
}, },
success: function (data) { success: function (data) {
common.modalBlock(false); common.modalBlock(false);
@ -401,6 +406,10 @@ function getDataSync(data) {
var progressLogs = 0; var progressLogs = 0;
var totalsLogs = 0; var totalsLogs = 0;
function _getLogs(e) { function _getLogs(e) {
var checkAll = $("#checkall-device:checked").length;
var all = false;
if (checkAll > 0)
all = true;
var lists = []; var lists = [];
$.each($("input[name='checkbox-device']:checked"), function () { $.each($("input[name='checkbox-device']:checked"), function () {
lists.push($(this).val()); lists.push($(this).val());
@ -414,7 +423,8 @@ function _getLogs(e) {
url: $(e).attr('data-href'), url: $(e).attr('data-href'),
type: 'POST', type: 'POST',
data: { data: {
lists: lists lists: lists,
all: all
}, },
success: function (data) { success: function (data) {
common.modalBlock(false); common.modalBlock(false);