From 09fbfae8b4ace6a67b9f7f1180f551ea5422162d Mon Sep 17 00:00:00 2001 From: youngq Date: Mon, 12 Aug 2024 09:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E7=BD=AE=E3=80=81?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E7=AE=A1=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Frontend/RoomController.cs | 42 +++++++++++++------ WGShare.API/WGShare.API.xml | 4 +- .../DTOs/Room/RoomManagerInputDTO.cs | 16 +++++++ 3 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 WGShare.Domain/DTOs/Room/RoomManagerInputDTO.cs diff --git a/WGShare.API/Controllers/Frontend/RoomController.cs b/WGShare.API/Controllers/Frontend/RoomController.cs index 5e70848..a56ddf7 100644 --- a/WGShare.API/Controllers/Frontend/RoomController.cs +++ b/WGShare.API/Controllers/Frontend/RoomController.cs @@ -60,21 +60,32 @@ namespace WGShare.API.Controllers.Frontend /// /// [HttpPost("manager")] - public async Task SetRoomManager([FromQuery] string roomId, [FromQuery] string roomNum, [FromBody] string userId) + public async Task SetRoomManager([FromBody] RoomManagerInputDTO inputDTO) { + var user = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, inputDTO.RoomNum), inputDTO.UserId); + + if (user == null) + { + throw Oops.Oh("用户已不在房间内!"); + } + var entities = new RoomManager { - RoomId = roomId, - UserId = userId + RoomId = inputDTO.RoomId, + UserId = inputDTO.UserId }; - var user = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, roomNum), userId); + user.IsRoomManager = true; - await _sqlSugar.Insertable(entities).ExecuteCommandAsync(); - RedisHelper.Instance.HSet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, roomNum), userId, user); + await _sqlSugar.Storageable(entities) + .SplitInsert(x => !x.Any()) + .ToStorage().AsInsertable.ExecuteCommandAsync(); - await _hubContext.Clients.Group(roomNum).ManagerRefresh(user); + //await _sqlSugar.Insertable(entities).ExecuteCommandAsync(); + RedisHelper.Instance.HSet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, inputDTO.RoomNum), inputDTO.UserId, user); + + await _hubContext.Clients.Group(inputDTO.RoomNum).ManagerRefresh(user); } /// @@ -82,17 +93,23 @@ namespace WGShare.API.Controllers.Frontend /// /// [HttpDelete("manager")] - public async Task DelRoomManager([FromQuery] string roomId, [FromQuery] string roomNum, [FromBody] string userId) + public async Task DelRoomManager([FromBody] RoomManagerInputDTO inputDTO) { + + var user = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, inputDTO.RoomNum), inputDTO.UserId); + if (user == null) + { + throw Oops.Oh("用户已不在房间内!"); + } + await _sqlSugar.Deleteable() - .Where(x => x.RoomId == roomId && x.UserId == userId) + .Where(x => x.RoomId == inputDTO.RoomId && x.UserId == inputDTO.UserId) .ExecuteCommandAsync(); - var user = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, roomNum), userId); user.IsRoomManager = false; - RedisHelper.Instance.HSet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, roomNum), userId, user); + RedisHelper.Instance.HSet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, inputDTO.RoomNum), inputDTO.UserId, user); - await _hubContext.Clients.Group(roomNum).ManagerRefresh(user); + await _hubContext.Clients.Group(inputDTO.RoomNum).ManagerRefresh(user); } /// @@ -263,6 +280,7 @@ namespace WGShare.API.Controllers.Frontend userInfo.EnableMicr = enableMicr; RedisHelper.Instance.HSet(RedisKeyConstant.SessionManage.GetChannelUserKey(TenantId, roomNum), uid, userInfo); + _logger.LogInformation($@"开闭麦克分,推送一次,roomNum:{roomNum},enableMicr:{enableMicr},uid:{uid}"); // 通知所有人该用户麦克风状态 await _hubContext.Clients.Group(roomNum).OperMicr(userInfo); } diff --git a/WGShare.API/WGShare.API.xml b/WGShare.API/WGShare.API.xml index a7bc114..bb69696 100644 --- a/WGShare.API/WGShare.API.xml +++ b/WGShare.API/WGShare.API.xml @@ -97,13 +97,13 @@ 会议室接口 - + 设置房间管理员 - + 取消房间管理员 diff --git a/WGShare.Domain/DTOs/Room/RoomManagerInputDTO.cs b/WGShare.Domain/DTOs/Room/RoomManagerInputDTO.cs new file mode 100644 index 0000000..07472ca --- /dev/null +++ b/WGShare.Domain/DTOs/Room/RoomManagerInputDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading.Tasks; + +namespace WGShare.Domain.DTOs.Room +{ + public class RoomManagerInputDTO + { + public string RoomId { get; set; } + public string RoomNum { get; set; } + public string UserId { get; set; } + } +}