fix lỗi đồng bộ dữ liệu không xóa các dữ liệu cũ
This commit is contained in:
parent
88ff9d32bd
commit
3c8300c74b
4135
access_control.sql
4135
access_control.sql
File diff suppressed because it is too large
Load Diff
|
@ -4,5 +4,6 @@ return [
|
|||
"hideInfomation" => false,
|
||||
"TCTECH" => true,
|
||||
"CardService" => "192.168.1.245:2001",
|
||||
"time" => 1606755599
|
||||
"time" => 1606755599,
|
||||
"pageSize" => 200
|
||||
];
|
||||
|
|
|
@ -91,7 +91,13 @@ class AssignController extends Controller {
|
|||
public function actionSetSchedule() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$post = Yii::$app->request->post();
|
||||
Staff::updateAll(["schedule_id" => $post["schedule"], "door_access" => json_encode($post["doors"])], ["IN", "id", $post["staffs"]]);
|
||||
$lists = Staff::find()->andWhere(["IN", "id", $post["staffs"]])->all();
|
||||
foreach ($lists as $key => $value) {
|
||||
$value->schedule_id = $post["schedule"];
|
||||
$value->door_access_old = $value->door_access;
|
||||
$value->door_access = json_encode($post["doors"]);
|
||||
$value->save();
|
||||
}
|
||||
$doors = [];
|
||||
foreach ($post["doors"] as $key => $value) {
|
||||
$doors[] = Door::findOne($value)->name;
|
||||
|
|
|
@ -358,6 +358,7 @@ class DeviceController extends Controller {
|
|||
$filter = ["OR"];
|
||||
foreach ($doors as $key => $value) {
|
||||
$filter[] = ["LIKE", "door_access", '"' . $value->id . '"'];
|
||||
$filter[] = ["LIKE", "door_access_old", '"' . $value->id . '"'];
|
||||
}
|
||||
$staffs = Staff::find()->andWhere($filter)->all();
|
||||
|
||||
|
@ -405,11 +406,13 @@ class DeviceController extends Controller {
|
|||
$filter = ["OR"];
|
||||
foreach ($doors as $key => $value) {
|
||||
$filter[] = ["LIKE", "door_access", '"' . $value->id . '"'];
|
||||
$filter[] = ["LIKE", "door_access_old", '"' . $value->id . '"'];
|
||||
}
|
||||
$offset = ($page - 1) * 200;
|
||||
$staff_lists = Staff::find()->andWhere($filter)->limit(200)->offset($offset)->all();
|
||||
$offset = ($page - 1) * Yii::$app->params["pageSize"];
|
||||
$staff_lists = Staff::find()->andWhere($filter)->limit(Yii::$app->params["pageSize"])->offset($offset)->all();
|
||||
$UserInfos = [];
|
||||
$UserAuthorizeInfos = [];
|
||||
$UserAuthorizeInfosDelete = [];
|
||||
|
||||
$doorOfDevice = Door::find()->andWhere(['device_id' => $device_id])->all();
|
||||
|
||||
|
@ -423,6 +426,7 @@ class DeviceController extends Controller {
|
|||
"EndTime" => ""
|
||||
];
|
||||
$doors = json_decode($value["door_access"], true);
|
||||
$doorsOld = json_decode($value["door_access_old"], true);
|
||||
foreach ($doorOfDevice as $k => $v) {
|
||||
if (in_array($v->id, $doors)) {
|
||||
$UserAuthorizeInfos[] = [
|
||||
|
@ -431,12 +435,25 @@ class DeviceController extends Controller {
|
|||
"AuthorizeDoorId" => $v->code
|
||||
];
|
||||
}
|
||||
if ($value["door_access_old"] != null) {
|
||||
if (in_array($v->id, $doorsOld) && !in_array($v->id, $doors)) {
|
||||
$UserAuthorizeInfosDelete[] = [
|
||||
"Pin" => $value["id"],
|
||||
"AuthorizeTimezoneId" => $value["schedule_id"],
|
||||
"AuthorizeDoorId" => $v->code
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
json_decode(common::requestToCardService("/SetDeviceData/User", [
|
||||
"DeviceIP" => $deviceInfo->ip_address,
|
||||
"UserInfos" => $UserInfos
|
||||
]), true);
|
||||
common::requestToCardService("/DeleteDeviceData/UserAuthorize", [
|
||||
"DeviceIP" => $deviceInfo->ip_address,
|
||||
"UserAuthorizeInfos" => $UserAuthorizeInfosDelete
|
||||
]);
|
||||
common::requestToCardService("/SetDeviceData/User", [
|
||||
"DeviceIP" => $deviceInfo->ip_address,
|
||||
"UserInfos" => $UserInfos
|
||||
]);
|
||||
common::requestToCardService("/SetDeviceData/UserAuthorize", [
|
||||
"DeviceIP" => $deviceInfo->ip_address,
|
||||
"UserAuthorizeInfos" => $UserAuthorizeInfos
|
||||
|
|
|
@ -23,6 +23,7 @@ use Yii;
|
|||
* @property int $card_register_time
|
||||
* @property int $schedule_id
|
||||
* @property string $door_access
|
||||
* @property string $door_access_old
|
||||
*/
|
||||
class Staff extends \yii\db\ActiveRecord {
|
||||
|
||||
|
@ -40,7 +41,7 @@ class Staff extends \yii\db\ActiveRecord {
|
|||
return [
|
||||
[['code', 'name', 'gender'], 'required'],
|
||||
[['code', 'card_number', 'department_id', 'birthday', 'date_in', 'created_at', 'modified_at', 'card_register_time', 'schedule_id'], 'integer'],
|
||||
[['address', 'door_access'], 'string'],
|
||||
[['address', 'door_access', 'door_access_old'], 'string'],
|
||||
[['name', 'email'], 'string', 'max' => 100],
|
||||
[['gender'], 'string', 'max' => 10],
|
||||
[['phone'], 'string', 'max' => 20],
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<div class="device-index">
|
||||
<input type='hidden' name='URL_sync_schedule' value="{Url::to(['sync-schedule'])}">
|
||||
<input type='hidden' name='URL_sync_staff' value="{Url::to(['sync-staff'])}">
|
||||
<input type='hidden' name='pageSize' value="{Yii::$app->params["pageSize"]}">
|
||||
|
||||
<input type='hidden' name='get_data_sync_url' value="{Url::to(['get-data-sync'])}">
|
||||
<input type='hidden' name='sync_schedule_url' value="{Url::to(['sync-schedule'])}">
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -297,18 +297,18 @@ function syncSchedule(device_id, device_ip, fullData) {
|
|||
},
|
||||
success: function (data) {
|
||||
var totalsStaff = data.staffs;
|
||||
totalPage = parseInt(totalsStaff / 200);
|
||||
if (totalsStaff % 200 > 0)
|
||||
totalPage = parseInt(totalsStaff / parseInt($("input[name='pageSize']").val()));
|
||||
if (totalsStaff % parseInt($("input[name='pageSize']").val()) > 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");
|
||||
processProgress(1);
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user