diff --git a/24Hour/Controllers/Common/DeviceController.cs b/24Hour/Controllers/Common/DeviceController.cs new file mode 100644 index 0000000..85303a1 --- /dev/null +++ b/24Hour/Controllers/Common/DeviceController.cs @@ -0,0 +1,179 @@ +using Elight.Entity; +using Elight.Logic; +using Elight.Utility; +using Elight.Utility.Code; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; + +namespace _24Hour.Controllers.Common +{ + /// + /// 设备管理 + /// + [Authorize] + [ApiController] + [Route("api/Device")] + public class DeviceController : Controller + { + #region Identity + private readonly SqlSugarClient _db;//数据库 + private readonly WriteSysLog _logs;//操作日志 + App_Sys_UserModel _userdata = new App_Sys_UserModel();//当前用户 + private readonly ILogger _logger;//日志 + Result result = new Result(); + public DeviceController(ILogger logger, SqlSugarClient db, WriteSysLog logs, User user) + { + _logger = logger; + _db = db; + _logs = logs; + _userdata = user.Userdata(); + } + + #endregion + + #region 设备管理 + /// + /// 根据当前登录人单位查询设备信息分页查询 + /// + /// + /// + [HttpPost] + [Route("QueryDeviceuser")] + public async Task QueryDeviceuser(App_DeviceInput Devicedata) + { + var Receptionlist = new List(); + //查询远程会见记录 + var list = await _db.Queryable() + .WhereIF(Devicedata.deviceno != null, q => q.deviceno.Contains(Devicedata.deviceno)) + .WhereIF(Devicedata.name != null, q => q.name.Contains(Devicedata.name)) + .WhereIF(Devicedata.state != null, q => q.state == Devicedata.state) + .Where(q => q.IsDeleted == 0 && q.unitId == _userdata.unitCode).ToPageListAsync(Devicedata.PageIndex, Devicedata.PageSize); + var data = new QueryResult(Devicedata, list.OrderByDescending(q => q.creationtime).ToList()); + result.IsSucceed = true; + result.result = data; + return result; + } + + /// + /// 设备分页查询 + /// + /// + /// + [HttpPost] + [Route("QueryDevice")] + public async Task QueryDevice(App_DeviceInput Devicedata) + { + var Receptionlist = new List(); + //查询远程会见记录 + var list = await _db.Queryable() + .WhereIF(Devicedata.deviceno != null, q => q.deviceno.Contains(Devicedata.deviceno)) + .WhereIF(Devicedata.name != null, q => q.name.Contains(Devicedata.name)) + .WhereIF(Devicedata.unitId != null, q => q.unitId.Contains(Devicedata.unitId)) + .WhereIF(Devicedata.state != null, q => q.state == Devicedata.state) + .Where(q => q.IsDeleted == 0).ToPageListAsync(Devicedata.PageIndex, Devicedata.PageSize); + var data = new QueryResult(Devicedata, list.OrderByDescending(q => q.creationtime).ToList()); + result.IsSucceed = true; + result.result = data; + return result; + } + /// + /// 添加设备 + /// + /// + /// + [HttpPost] + [Route("AddDevice")] + public async Task AddDevice(App_DeviceModel Devicedata) + { + try + { + _db.BeginTran(); + Devicedata.Id = Guid.NewGuid().ToString(); + Devicedata.createuserId = _userdata.Id.ToString(); + Devicedata.createusername = _userdata.name; + var num = await _db.Insertable(Devicedata).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "添加成功"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("远程会见管理", "添加远程会见", result, _db); + return result; + } + + /// + /// 修改设备 + /// + /// + /// + [HttpPost] + [Route("UpdateDevice")] + public async Task UpdateDevice(App_DeviceModel Devicedata) + { + try + { + _db.BeginTran(); + var num = await _db.Updateable(Devicedata).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "修改成功"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("远程会见管理", "修改远程会见", result, _db); + return result; + } + + /// + /// 删除设备 + /// + /// + /// + [HttpPost] + [Route("DeleteDevice")] + public async Task DeleteDevice(CurrencyDelete Currency) + { + try + { + _db.BeginTran(); + var Receptionlist = await _db.Queryable().In(q => q.Id, Currency.id).ToListAsync(); + Receptionlist.ForEach(q => + { + q.IsDeleted = 1; + }); + var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "删除成功"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("设备管理", "删除设备", result, _db); + return result; + } + #endregion + } +} diff --git a/24Hour/Controllers/Common/RemoteController.cs b/24Hour/Controllers/Common/RemoteController.cs new file mode 100644 index 0000000..54a7109 --- /dev/null +++ b/24Hour/Controllers/Common/RemoteController.cs @@ -0,0 +1,249 @@ +using Elight.Entity; +using Elight.Logic; +using Elight.Utility; +using Elight.Utility.Code; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; + +namespace _24Hour.Controllers.Common +{ + /// + /// 远程会见 + /// + [Authorize] + [ApiController] + [Route("api/Remote")] + public class RemoteController : Controller + { + #region Identity + private readonly SqlSugarClient _db;//数据库 + private readonly WriteSysLog _logs;//操作日志 + App_Sys_UserModel _userdata = new App_Sys_UserModel();//当前用户 + private readonly ILogger _logger;//日志 + Result result = new Result(); + public RemoteController(ILogger logger, SqlSugarClient db, WriteSysLog logs, User user) + { + _logger = logger; + _db = db; + _logs = logs; + _userdata = user.Userdata(); + } + + #endregion + + + #region 远程会见管理 + + /// + /// 根据当前登录人查询远程会见信息分页查询 + /// + /// + /// + [HttpPost] + [Route("QueryRemoteuser")] + public async Task QueryRemoteuser(App_RemoteInput Remotedata) + { + var Receptionlist = new List(); + //查询远程会见记录 + var list = await _db.Queryable() + .WhereIF(Remotedata.Code != null, q => q.Code.Contains(Remotedata.Code)) + .WhereIF(Remotedata.name != null, q => q.name.Contains(Remotedata.name)) + .WhereIF(Remotedata.meetwitname != null, q => q.meetwitname.Contains(Remotedata.meetwitname)) + .WhereIF(Remotedata.state != null, q => q.state == Remotedata.state) + .Where(q => q.IsDeleted == 0 && q.unitId == _userdata.unitCode).ToPageListAsync(Remotedata.PageIndex, Remotedata.PageSize); + var data = new QueryResult(Remotedata, list.OrderByDescending(q => q.creationtime).ToList()); + result.IsSucceed = true; + result.result = data; + return result; + } + + /// + /// 远程会见分页查询 + /// + /// + /// + [HttpPost] + [Route("QueryRemote")] + public async Task QueryRemote(App_RemoteInput Remotedata) + { + var Receptionlist = new List(); + //查询远程会见记录 + var list = await _db.Queryable() + .WhereIF(Remotedata.Code != null, q => q.Code.Contains(Remotedata.Code)) + .WhereIF(Remotedata.name != null, q => q.name.Contains(Remotedata.name)) + .WhereIF(Remotedata.meetwitname != null, q => q.meetwitname.Contains(Remotedata.meetwitname)) + .WhereIF(Remotedata.state != null, q => q.state == Remotedata.state) + .Where(q => q.IsDeleted == 0).ToPageListAsync(Remotedata.PageIndex, Remotedata.PageSize); + var data = new QueryResult(Remotedata, list.OrderByDescending(q => q.creationtime).ToList()); + result.IsSucceed = true; + result.result = data; + return result; + } + /// + /// 添加远程会见 + /// + /// + /// + [HttpPost] + [Route("AddRemote")] + public async Task AddRemote(App_RemoteModel Remotedata) + { + try + { + _db.BeginTran(); + Remotedata.Id = Guid.NewGuid().ToString(); + //Remotedata.unitId = _userdata.unitCode.ToString(); + Remotedata.createuserId = _userdata.Id.ToString(); + Remotedata.createusername = _userdata.name; + var num = await _db.Insertable(Remotedata).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "添加成功"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("远程会见管理", "添加远程会见", result, _db); + return result; + } + + /// + /// 修改远程会见 + /// + /// + /// + [HttpPost] + [Route("UpdateRemote")] + public async Task UpdateRemote(App_RemoteModel Remotedata) + { + try + { + _db.BeginTran(); + var num = await _db.Updateable(Remotedata).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "修改成功"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("远程会见管理", "修改远程会见", result, _db); + return result; + } + + /// + /// 删除远程会见 + /// + /// + /// + [HttpPost] + [Route("DeleteRemote")] + public async Task DeleteRemote(CurrencyDelete Currency) + { + try + { + _db.BeginTran(); + var Receptionlist = await _db.Queryable().In(q => q.Id, Currency.id).ToListAsync(); + Receptionlist.ForEach(q => + { + q.IsDeleted = 1; + }); + var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "删除成功"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("远程会见管理", "删除远程会见", result, _db); + return result; + } + + + /// + /// 结束远程会见 + /// + /// + /// + [HttpPost] + [Route("UpdateRemote_state")] + public async Task UpdateRemote_state(CurrencyDelete Currency) + { + try + { + var Receptionlist = await _db.Queryable().Where(q => Currency.id.Contains(q.Id)).ToListAsync(); + Receptionlist.ForEach(q => { q.state = 1; }); + _db.BeginTran(); + var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "结束成功"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("远程会见管理", "结束远程会见", result, _db); + return result; + } + + + /// + /// 取消远程会见 + /// + /// + /// + [HttpPost] + [Route("Updatecancellation_state")] + public async Task Updatecancellation_state(CurrencyDelete Currency) + { + try + { + var Receptionlist = await _db.Queryable().Where(q => Currency.id.Contains(q.Id)).ToListAsync(); + Receptionlist.ForEach(q => { q.state = 2; }); + _db.BeginTran(); + var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = "已取消"; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("远程会见管理", "取消远程会见", result, _db); + return result; + } + #endregion + } +} diff --git a/24Hour/Controllers/Common/ReservationController.cs b/24Hour/Controllers/Common/ReservationController.cs index 3de0c86..4c25f7e 100644 --- a/24Hour/Controllers/Common/ReservationController.cs +++ b/24Hour/Controllers/Common/ReservationController.cs @@ -199,362 +199,5 @@ namespace _24Hour.Controllers.Common return result; } #endregion - - #region 远程会见管理 - - /// - /// 根据当前登录人查询远程会见信息分页查询 - /// - /// - /// - [HttpPost] - [Route("QueryRemoteuser")] - public async Task QueryRemoteuser(App_RemoteInput Remotedata) - { - var Receptionlist = new List(); - //查询远程会见记录 - var list = await _db.Queryable() - .WhereIF(Remotedata.Code != null, q => q.Code.Contains(Remotedata.Code)) - .WhereIF(Remotedata.name != null, q => q.name.Contains(Remotedata.name)) - .WhereIF(Remotedata.meetwitname != null, q => q.meetwitname.Contains(Remotedata.meetwitname)) - .WhereIF(Remotedata.state != null, q => q.state == Remotedata.state) - .Where(q => q.IsDeleted == 0&&q.unitId==_userdata.unitCode).ToPageListAsync(Remotedata.PageIndex, Remotedata.PageSize); - var data = new QueryResult(Remotedata, list.OrderByDescending(q => q.creationtime).ToList()); - result.IsSucceed = true; - result.result = data; - return result; - } - - /// - /// 远程会见分页查询 - /// - /// - /// - [HttpPost] - [Route("QueryRemote")] - public async Task QueryRemote(App_RemoteInput Remotedata) - { - var Receptionlist = new List(); - //查询远程会见记录 - var list = await _db.Queryable() - .WhereIF(Remotedata.Code != null, q => q.Code.Contains(Remotedata.Code)) - .WhereIF(Remotedata.name != null, q => q.name.Contains(Remotedata.name)) - .WhereIF(Remotedata.meetwitname != null, q => q.meetwitname.Contains(Remotedata.meetwitname)) - .WhereIF(Remotedata.state != null, q => q.state == Remotedata.state) - .Where(q => q.IsDeleted == 0).ToPageListAsync(Remotedata.PageIndex, Remotedata.PageSize); - var data = new QueryResult(Remotedata, list.OrderByDescending(q => q.creationtime).ToList()); - result.IsSucceed = true; - result.result = data; - return result; - } - /// - /// 添加远程会见 - /// - /// - /// - [HttpPost] - [Route("AddRemote")] - public async Task AddRemote(App_RemoteModel Remotedata) - { - try - { - _db.BeginTran(); - Remotedata.Id = Guid.NewGuid().ToString(); - Remotedata.unitId = _userdata.unitCode.ToString(); - Remotedata.createuserId = _userdata.Id.ToString(); - Remotedata.createusername = _userdata.name; - var num = await _db.Insertable(Remotedata).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "添加成功"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("远程会见管理", "添加远程会见", result, _db); - return result; - } - - /// - /// 修改远程会见 - /// - /// - /// - [HttpPost] - [Route("UpdateRemote")] - public async Task UpdateRemote(App_RemoteModel Remotedata) - { - try - { - _db.BeginTran(); - var num = await _db.Updateable(Remotedata).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "修改成功"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("远程会见管理", "修改远程会见", result, _db); - return result; - } - - /// - /// 删除远程会见 - /// - /// - /// - [HttpPost] - [Route("DeleteRemote")] - public async Task DeleteRemote(CurrencyDelete Currency) - { - try - { - _db.BeginTran(); - var Receptionlist = await _db.Queryable().In(q => q.Id, Currency.id).ToListAsync(); - Receptionlist.ForEach(q => - { - q.IsDeleted = 1; - }); - var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "删除成功"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("远程会见管理", "删除远程会见", result, _db); - return result; - } - - - /// - /// 结束远程会见 - /// - /// - /// - [HttpPost] - [Route("UpdateRemote_state")] - public async Task UpdateRemote_state(CurrencyDelete Currency) - { - try - { - var Receptionlist = await _db.Queryable().Where(q => Currency.id.Contains(q.Id)).ToListAsync(); - Receptionlist.ForEach(q => { q.state = 1; }); - _db.BeginTran(); - var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "结束成功"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("远程会见管理", "结束远程会见", result, _db); - return result; - } - - - /// - /// 取消远程会见 - /// - /// - /// - [HttpPost] - [Route("Updatecancellation_state")] - public async Task Updatecancellation_state(CurrencyDelete Currency) - { - try - { - var Receptionlist = await _db.Queryable().Where(q => Currency.id.Contains(q.Id)).ToListAsync(); - Receptionlist.ForEach(q => { q.state = 2; }); - _db.BeginTran(); - var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "已取消"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("远程会见管理", "取消远程会见", result, _db); - return result; - } - #endregion - - #region 设备管理 - /// - /// 根据当前登录人查询设备信息分页查询 - /// - /// - /// - [HttpPost] - [Route("QueryDeviceuser")] - public async Task QueryDeviceuser(App_DeviceInput Devicedata) - { - var Receptionlist = new List(); - //查询远程会见记录 - var list = await _db.Queryable() - .WhereIF(Devicedata.deviceno != null, q => q.Code.Contains(Devicedata.deviceno)) - .WhereIF(Devicedata.name != null, q => q.name.Contains(Devicedata.name)) - .WhereIF(Devicedata.state != null, q => q.state == Devicedata.state) - .Where(q => q.IsDeleted == 0 && q.unitId == _userdata.unitCode).ToPageListAsync(Devicedata.PageIndex, Devicedata.PageSize); - var data = new QueryResult(Devicedata, list.OrderByDescending(q => q.creationtime).ToList()); - result.IsSucceed = true; - result.result = data; - return result; - } - - /// - /// 设备分页查询 - /// - /// - /// - [HttpPost] - [Route("QueryDevice")] - public async Task QueryDevice(App_DeviceInput Devicedata) - { - var Receptionlist = new List(); - //查询远程会见记录 - var list = await _db.Queryable() - .WhereIF(Devicedata.deviceno != null, q => q.deviceno.Contains(Devicedata.deviceno)) - .WhereIF(Devicedata.name != null, q => q.name.Contains(Devicedata.name)) - .WhereIF(Devicedata.state != null, q => q.state == Devicedata.state) - .Where(q => q.IsDeleted == 0).ToPageListAsync(Devicedata.PageIndex, Devicedata.PageSize); - var data = new QueryResult(Devicedata, list.OrderByDescending(q => q.creationtime).ToList()); - result.IsSucceed = true; - result.result = data; - return result; - } - /// - /// 添加设备 - /// - /// - /// - [HttpPost] - [Route("AddDevice")] - public async Task AddDevice(App_DeviceModel Devicedata) - { - try - { - _db.BeginTran(); - Devicedata.Id = Guid.NewGuid().ToString(); - Devicedata.unitId = _userdata.unitCode.ToString(); - Devicedata.createuserId = _userdata.Id.ToString(); - Devicedata.createusername = _userdata.name; - var num = await _db.Insertable(Devicedata).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "添加成功"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("远程会见管理", "添加远程会见", result, _db); - return result; - } - - /// - /// 修改设备 - /// - /// - /// - [HttpPost] - [Route("UpdateDevice")] - public async Task UpdateDevice(App_DeviceModel Devicedata) - { - try - { - _db.BeginTran(); - var num = await _db.Updateable(Devicedata).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "修改成功"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("远程会见管理", "修改远程会见", result, _db); - return result; - } - - /// - /// 删除设备 - /// - /// - /// - [HttpPost] - [Route("DeleteDevice")] - public async Task DeleteDevice(CurrencyDelete Currency) - { - try - { - _db.BeginTran(); - var Receptionlist = await _db.Queryable().In(q => q.Id, Currency.id).ToListAsync(); - Receptionlist.ForEach(q => - { - q.IsDeleted = 1; - }); - var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync(); - _db.CommitTran(); - if (num > 0) - { - result.IsSucceed = true; - result.result = "删除成功"; - } - } - catch (System.Exception ex) - { - _db.RollbackTran(); - result.IsSucceed = false; - result.Message = ex.Message; - } - _logs.WriteSysLogadd("设备管理", "删除设备", result, _db); - return result; - } - #endregion } } diff --git a/24Hour/Controllers/Common/WebSocketController.cs b/24Hour/Controllers/Common/WebSocketController.cs index 648ab53..a190a3c 100644 --- a/24Hour/Controllers/Common/WebSocketController.cs +++ b/24Hour/Controllers/Common/WebSocketController.cs @@ -7,25 +7,32 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using SqlSugar; +using System.Data; using System.Net.WebSockets; +using System.Runtime.Serialization; using System.Text; +using static com.sun.tools.@internal.xjc.reader.xmlschema.bindinfo.BIConversion; +using User = Elight.Utility.User; namespace _24Hour.Controllers.Common { [Authorize] + [ApiController] public class WebSocketController : Controller { private readonly SqlSugarClient _db;//数据库 App_Sys_UserModel _userdata = new App_Sys_UserModel();//当前用户 private readonly ILogger _logger;//日志 + private readonly IConfiguration _configuration; Result result = new Result(); private static Dictionary CONNECT_POOL = new Dictionary();//用户连接池 //private static Dictionary> MESSAGE_POOL = new Dictionary>();//离线消息池 - public WebSocketController(ILogger logger, SqlSugarClient db, User user) + public WebSocketController(ILogger logger, SqlSugarClient db,User userdata,IConfiguration configuration) { _logger = logger; _db = db; - _userdata = user.Userdata(); + _userdata = userdata.Userdata(); + _configuration = configuration; } [HttpGet("/ws")] public async Task WebSocketServer() @@ -35,7 +42,7 @@ namespace _24Hour.Controllers.Common try { var socket = await HttpContext.WebSockets.AcceptWebSocketAsync(); - await ProcessChat(socket); + await ProcessChat(socket); } catch (Exception ex) { @@ -64,10 +71,15 @@ namespace _24Hour.Controllers.Common { ArraySegment buffer = new ArraySegment(new byte[2048]); WebSocketReceiveResult result = await socket.ReceiveAsync(buffer, CancellationToken.None); - if (result.MessageType==WebSocketMessageType.Close) + if (result.MessageType == WebSocketMessageType.Close) { await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); } + else + { + var data = Encoding.UTF8.GetString(buffer); + Console.WriteLine(data); + } } else { @@ -218,6 +230,102 @@ namespace _24Hour.Controllers.Common result.result = ""; return result; } + + + /// + /// 视频推送 + /// + /// + /// + [HttpPost] + [Route("Video")] + public async Task Video(WebSocketSending Senddata) + { + try + { + //获取发送人连接 + var socket = CONNECT_POOL.Where(q => q.Key == _userdata.Id).Select(q => q.Value).FirstOrDefault(); + if (socket!=null&&socket.State == WebSocketState.Open) + { + ArraySegment buffer = new ArraySegment(new byte[2048]); + //WebSocketReceiveResult result = await socket.ReceiveAsync(buffer, CancellationToken.None); + + #region 消息处理(消息转发) + try + { + #region 关闭Socket处理,删除连接池 + if (socket.State != WebSocketState.Open)//连接关闭 + { + if (CONNECT_POOL.ContainsKey(_userdata.Id)) CONNECT_POOL.Remove(_userdata.Id);//删除连接池 + result.IsSucceed = true; + result.result = "未上线"; + return result; + } + #endregion + + #region 消息发送 + var content = ""; + //data.type等于1 为视频推送 + if (Senddata.typenum == "1" && Senddata.deviceno != "") + { + //设备发送给app + //查询远程会见记录 + var Devicedata = await _db.Queryable().Where(q => q.deviceno == Senddata.deviceno).ToListAsync(); + Senddata.content = $"{_configuration.GetSection("Videoaddress:rtsp").Value}{Devicedata.FirstOrDefault()?.deviceno}"; + //对象序列化 + content = JsonConvert.SerializeObject(Senddata); + buffer = new ArraySegment(Encoding.UTF8.GetBytes(content)); + } + else + { + //app发送给设备 + Senddata.content = $"{_configuration.GetSection("Videoaddress:rtmp").Value}{_userdata.Id}"; + //对象序列化 + content = JsonConvert.SerializeObject(Senddata); + buffer = new ArraySegment(Encoding.UTF8.GetBytes(content)); + } + //判断客户端是否在线 + if (CONNECT_POOL.ContainsKey(Senddata.recipient)) + { + //获取目的客户端 + WebSocket destSocket = CONNECT_POOL[Senddata.recipient]; + //判断客户端是否连接 + if (destSocket != null && destSocket.State == WebSocketState.Open) + await socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None); + else + { + result.IsSucceed = false; + result.result = "用户未上线"; + return result; + } + } + else + { + result.IsSucceed = false; + result.result = "用户未上线"; + return result; + } + #endregion + } + catch (Exception exs) + { + //消息转发异常处理,本次消息忽略 继续监听接下来的消息 + } + #endregion + } + else + { + } + } + catch (Exception) + { + //整体异常处理 + if (CONNECT_POOL.ContainsKey(_userdata.Id)) CONNECT_POOL.Remove(_userdata.Id); + } + result.IsSucceed = true; + result.result = ""; + return result; + } } /// @@ -228,18 +336,27 @@ namespace _24Hour.Controllers.Common /// /// 发送人 /// + [DataMember] public string? sender { get; set; } /// /// 发送内容 /// + [DataMember] public string? content { get; set; } /// /// 接收人 /// + [DataMember] public string? recipient { get; set; } /// /// 类型 0:消息,1:视频地址 /// - public string? type { get; set; } + [DataMember] + public string? typenum { get; set; } + /// + /// 设备编号 + /// + [DataMember] + public string? deviceno { get; set; } } } diff --git a/24Hour/Controllers/LoginController.cs b/24Hour/Controllers/LoginController.cs index 60e8241..927d003 100644 --- a/24Hour/Controllers/LoginController.cs +++ b/24Hour/Controllers/LoginController.cs @@ -31,11 +31,10 @@ namespace _24Hour.Controllers private readonly WriteSysLog _logs;//־ private readonly ILogger _logger;//־ Result ret = new Result(); - public LoginController(ILogger logger, SqlSugarClient db, IConfiguration configuration, WriteSysLog logs) + public LoginController(ILogger logger, SqlSugarClient db, IConfiguration configuration) { _logger = logger; _db = db; - _logs = logs; _configuration = configuration; } [HttpPost] @@ -189,7 +188,6 @@ namespace _24Hour.Controllers /// /// /// - [AllowAnonymous] [HttpPost] [Route("AddUser1")] public async Task AddUser1(App_Sys_UserModel UserModel) @@ -222,7 +220,6 @@ namespace _24Hour.Controllers ret.IsSucceed = false; ret.Message = ex.Message; } - _logs.WriteSysLogadd("û", "APPû", ret, _db); return ret; } diff --git a/24Hour/Controllers/system/SystemControllerController.cs b/24Hour/Controllers/system/SystemControllerController.cs index a487623..6ef5172 100644 --- a/24Hour/Controllers/system/SystemControllerController.cs +++ b/24Hour/Controllers/system/SystemControllerController.cs @@ -113,12 +113,11 @@ namespace _24Hour.Controllers.system { try { - var data = await _db.Queryable().Where(q => q.phone == UserModel.phone).FirstAsync(); + var data = await _db.Queryable().Where(q =>q.IsDeleted==0&& q.phone == UserModel.phone|| q.cardId == UserModel.cardId).FirstAsync(); if (data != null) { - result.IsSucceed = false; - result.Message = "电话号码已存在!"; + result.Message = "电话号码或身份证号已存在!"; return result; } _db.BeginTran(); @@ -695,8 +694,6 @@ namespace _24Hour.Controllers.system { var totalCount = 0; var list = await _db.Queryable() - .WhereIF(!unitId.IsNull(), q => q.unitId.Contains(unitId)) - .WhereIF(!unitId.IsNull(), q => q.unitId.Contains(unitId)) .WhereIF(!unitId.IsNull(), q => q.unitId.Contains(unitId)) .Where(q => q.IsDelete == 0).ToListAsync(); result.IsSucceed = true; diff --git a/24Hour/Program.cs b/24Hour/Program.cs index e72ae17..89b9b74 100644 --- a/24Hour/Program.cs +++ b/24Hour/Program.cs @@ -26,8 +26,7 @@ builder.WebHost.UseUrls(Configuration.GetSection("UrlsConfiguration:Urls").Value builder.Services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = null; - options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); - options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); + options.JsonSerializerOptions.Converters.Add(new Elight.Utility.DateTimeNullableConverter()); options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); diff --git a/24Hour/appsettings.json b/24Hour/appsettings.json index b970f09..e5a2d15 100644 --- a/24Hour/appsettings.json +++ b/24Hour/appsettings.json @@ -40,5 +40,9 @@ /* DomainUrl:["http://localhost:api端口号"] */ "DomainUrl": "http://localhost:8006", "HubCorUrls": [] + }, + "Videoaddress": { + "rtmp": "rtmp://192.168.0.24:1935/live/", + "rtsp": "rtsp://192.168.0.24:8554/live/" } } diff --git a/24Hour/wwwroot/CaseFile/logs/Logs/ExceptionLog/20230615/18.log b/24Hour/wwwroot/CaseFile/logs/Logs/ExceptionLog/20230615/18.log new file mode 100644 index 0000000..e688d5f --- /dev/null +++ b/24Hour/wwwroot/CaseFile/logs/Logs/ExceptionLog/20230615/18.log @@ -0,0 +1,36 @@ +日志时间:2023-06-15 18:17:55 +************************Exception Start******************************** +Exception Remark:添加数据库日志信息_WriteSysLog_1 发生异常 +Exception Date:2023/6/15 18:17:55 +Exception Type:MySqlConnector.MySqlException +Exception Message:Data too long for column 'OperatingManual' at row 1 +Exception Source:SqlSugar +Exception StackTrace: at SqlSugar.AdoProvider.ExecuteCommand(String sql, SugarParameter[] parameters) + at SqlSugar.InsertableProvider`1.ExecuteCommand() + at Elight.Logic.WriteSysLog.WriteSysLogadd(String operationType, String content, Result result, SqlSugarClient _db, String opeCasDepAccCas) in E:\Code\24Hour.Service\Elight.Logic\WriteSysLog.cs:line 52 +************************Exception End************************************ + +日志时间:2023-06-15 18:18:09 +************************Exception Start******************************** +Exception Remark:添加数据库日志信息_WriteSysLog_1 发生异常 +Exception Date:2023/6/15 18:18:09 +Exception Type:MySqlConnector.MySqlException +Exception Message:Data too long for column 'OperatingManual' at row 1 +Exception Source:SqlSugar +Exception StackTrace: at SqlSugar.AdoProvider.ExecuteCommand(String sql, SugarParameter[] parameters) + at SqlSugar.InsertableProvider`1.ExecuteCommand() + at Elight.Logic.WriteSysLog.WriteSysLogadd(String operationType, String content, Result result, SqlSugarClient _db, String opeCasDepAccCas) in E:\Code\24Hour.Service\Elight.Logic\WriteSysLog.cs:line 52 +************************Exception End************************************ + +日志时间:2023-06-15 18:47:38 +************************Exception Start******************************** +Exception Remark:添加数据库日志信息_WriteSysLog_1 发生异常 +Exception Date:2023/6/15 18:47:38 +Exception Type:MySqlConnector.MySqlException +Exception Message:Data too long for column 'OperatingManual' at row 1 +Exception Source:SqlSugar +Exception StackTrace: at SqlSugar.AdoProvider.ExecuteCommand(String sql, SugarParameter[] parameters) + at SqlSugar.InsertableProvider`1.ExecuteCommand() + at Elight.Logic.WriteSysLog.WriteSysLogadd(String operationType, String content, Result result, SqlSugarClient _db, String opeCasDepAccCas) in E:\Code\24Hour.Service\Elight.Logic\WriteSysLog.cs:line 52 +************************Exception End************************************ + diff --git a/24Hour/wwwroot/CaseFile/logs/Logs/ExceptionLog/20230615/19.log b/24Hour/wwwroot/CaseFile/logs/Logs/ExceptionLog/20230615/19.log new file mode 100644 index 0000000..5c4ccd4 --- /dev/null +++ b/24Hour/wwwroot/CaseFile/logs/Logs/ExceptionLog/20230615/19.log @@ -0,0 +1,12 @@ +日志时间:2023-06-15 19:33:41 +************************Exception Start******************************** +Exception Remark:添加数据库日志信息_WriteSysLog_1 发生异常 +Exception Date:2023/6/15 19:33:41 +Exception Type:MySqlConnector.MySqlException +Exception Message:Data too long for column 'OperatingManual' at row 1 +Exception Source:SqlSugar +Exception StackTrace: at SqlSugar.AdoProvider.ExecuteCommand(String sql, SugarParameter[] parameters) + at SqlSugar.InsertableProvider`1.ExecuteCommand() + at Elight.Logic.WriteSysLog.WriteSysLogadd(String operationType, String content, Result result, SqlSugarClient _db, String opeCasDepAccCas) in E:\Code\24Hour.Service\Elight.Logic\WriteSysLog.cs:line 52 +************************Exception End************************************ + diff --git a/Elight.Entity/AppMode/App_RemoteModel.cs b/Elight.Entity/AppMode/App_RemoteModel.cs index fe27fcc..103395a 100644 --- a/Elight.Entity/AppMode/App_RemoteModel.cs +++ b/Elight.Entity/AppMode/App_RemoteModel.cs @@ -71,7 +71,7 @@ namespace Elight.Entity /// 0:待开始,1已结束,2:会议取消 /// [DataMember] - public int? state { get; set; } + public int state { get; set; } [DataMember] public string? createusername { get; set; } diff --git a/Elight.Entity/SystemModel/Func_Dossier_LogRecordModel.cs b/Elight.Entity/SystemModel/Func_Dossier_LogRecordModel.cs index 9db08e1..64b4d6c 100644 --- a/Elight.Entity/SystemModel/Func_Dossier_LogRecordModel.cs +++ b/Elight.Entity/SystemModel/Func_Dossier_LogRecordModel.cs @@ -13,7 +13,7 @@ namespace Elight.Entity.SystemModel /// [DataContract] [Serializable] - [SugarTable("app_sys_depart")] + [SugarTable("func_dossier_logrecord")] public class Func_Dossier_LogRecordModel { diff --git a/Elight.Logic/WriteSysLog.cs b/Elight.Logic/WriteSysLog.cs index 8c1b01e..ebbd637 100644 --- a/Elight.Logic/WriteSysLog.cs +++ b/Elight.Logic/WriteSysLog.cs @@ -31,7 +31,7 @@ namespace Elight.Logic /// 添加数据库日志信息 /// /// - public void WriteSysLogadd(string operationType, string content, Result result, SqlSugarClient _db=null, string opeCasDepAccCas = null) + public void WriteSysLogadd(string operationType, string content, Result result, SqlSugarClient _db = null, string opeCasDepAccCas = null) { try { @@ -39,6 +39,7 @@ namespace Elight.Logic { UnitCode = _userdata.unitCode, OperationType = operationType, + SerialNumber = Guid.NewGuid().ToString(), NameEntity = "", LogContents = result.IsSucceed ? $"{content}成功" : $"{content}失败:{result.Message}", ParColCreTimTakYeaTri = DateTime.Now.Year.ToString(), @@ -48,7 +49,7 @@ namespace Elight.Logic OperatingManual = _userdata.Id, OpeCasDepAccCas = opeCasDepAccCas ?? string.Empty }; - var sss= _db.Insertable(model).ExecuteCommand(); + var sss = _db.Insertable(model).ExecuteCommand(); } catch (Exception ex) { diff --git a/Elight.Utility/NullableConverter.cs b/Elight.Utility/NullableConverter.cs index 10fffd5..167cb7e 100644 --- a/Elight.Utility/NullableConverter.cs +++ b/Elight.Utility/NullableConverter.cs @@ -33,4 +33,23 @@ namespace Elight.Utility } } + + public class DateTimeNullableConverter : JsonConverter + { + public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.String) + { + if (DateTime.TryParse(reader.GetString(), out DateTime date)) return date; + return default(DateTime?); + + } + return reader.GetDateTime(); + } + + public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options) + { + writer.WriteStringValue(value?.ToString("yyyy-MM-dd HH:mm:ss")); + } + } }