info(date('H:i') . ' 开始处理预警组信息'); $groupList = WarnGroup::query()->get(); foreach($groupList as $groupInfo) { $userList = WarnGroupUser::query()->where('group_id', $groupInfo->id)->where('enable', 1) ->get(); $userIdList = $userList->isNotEmpty() ? array_column($userList->toArray(), 'user_id') : []; $userListStr = implode(',', $userIdList); $djUserList = WarnGroupDjuser::query()->where('group_id', $groupInfo->id)->where('enable', 1) ->selectRaw('djcorp_id as corpid, djuser_id as user_id')->get(); $djUserListStr = $djUserList->isNotEmpty() ? json_encode($djUserList, 256) : []; $update = [ 'user_list' => $userListStr, 'dj_user_list' => $djUserListStr, ]; WarnGroup::query()->where('id', $groupInfo->id)->update($update); } $this->info(date('H:i') . ' 预警组信息处理完成,开始清除已经失效的预警人ID'); $warnUserList = WarnUser::query()->where('enable', 0)->get(); if($warnUserList->isEmpty()) { $this->info(date('H:i') . ' 暂无已失效的预警人,处理完成'); return true; } foreach($warnUserList as $value) { $userId = $value['id']; $warnGroupList = WarnGroup::query()->whereRaw('find_in_set('.$userId.',`user_list`)')->get(); if($warnGroupList->isNotEmpty()) { foreach($warnGroupList as $groupInfo) { $userList = explode(',', $groupInfo->user_list); $key = array_search($userId, $userList); unset($userList[$key]); $newUserList = implode(',', $userList); WarnGroup::query()->where('id', $groupInfo->id)->update(['user_list' => $newUserList]); } } } $this->info(date('H:i') . ' 清除已经失效的预警人ID完成,全部信息处理完成'); return true; } }