Browse Source

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

yuanrf 1 year ago
parent
commit
af182ae49c

+ 60 - 0
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -60,6 +60,14 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
         {
+            #region 参数验证
+            if (dto.OperationUserId < 0)
+                return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
+
+            if (dto.PortType < 0)
+                return Ok(JsonView(false, "请传入有效的PortType参数!"));
+            #endregion
+
             JsonView jw = new JsonView();
             try
             {
@@ -94,6 +102,17 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
         {
+            #region 参数验证
+            if (dto.Id < 0)
+                return Ok(JsonView(false, "请传入有效的Id参数!"));
+
+            if (dto.UserId < 0)
+                return Ok(JsonView(false, "请传入有效的UserId参数!"));
+
+            if (dto.PortType < 0)
+                return Ok(JsonView(false, "请传入有效的PortType参数!"));
+            #endregion
+
             JsonView jw = new JsonView();
             try
             {
@@ -127,6 +146,19 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
         {
+            #region 参数验证
+
+            if (dto.CreateUserId < 0)
+            {
+                return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
+            }
+
+            if (dto.PortType < 0)
+            {
+                return Ok(JsonView(false, "请传入有效的PortType参数!"));
+            }
+            #endregion
+
             try
             {
                 Domain.Result result = await _clientDataRepository.NewClientOp(dto);
@@ -163,6 +195,22 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> NewClientDel(DelBaseDto dto)
         {
+            #region 参数验证
+            if (dto.Id < 0)
+            {
+                return Ok(JsonView(false, "请传入有效的Id参数!"));
+            }
+
+            if (dto.DeleteUserId < 0)
+            {
+                return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
+            }
+
+            if (dto.PortType < 0 )
+            {
+                return Ok(JsonView(false, "请传入有效的PortType参数!"));
+            }
+            #endregion
             var res = await _clientDataRepository.DelNewClientData(dto);
             if (res.Code != 0)
             {
@@ -247,6 +295,18 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
         {
+            #region 参数验证
+            if (dto.UserId < 0)
+            {
+                return Ok(JsonView(false, "请传入有效的UserId参数!"));
+            }
+
+            if (dto.PortType < 0)
+            {
+                return Ok(JsonView(false, "请传入有效的PortType参数!"));
+            }
+            #endregion
+
             var res = await _clientDataRepository._BatchAssignment(dto);
             if (res.Code != 0)
             {

+ 0 - 9
OASystem/OASystem.Api/OAMethodLib/Hubs/IChatClient.cs

@@ -1,9 +0,0 @@
-namespace OASystem.API.OAMethodLib.Hubs
-{
-    public interface IChatClient
-    {
-        Task ReceiveMessage(string user, string message);
-        Task ReceiveMessage(object message);
-        Task ReceiveCaller(object message);
-    }
-}

+ 0 - 67
OASystem/OASystem.Api/OAMethodLib/Hubs/MyHub.cs

@@ -1,67 +0,0 @@
-using Microsoft.AspNetCore.SignalR;
-
-namespace OASystem.API.OAMethodLib.Hubs
-{
-    /// <summary>
-    /// 定义集线器
-    /// </summary>
-    public class MyHub : Hub
-    {
-        /// <summary>
-        /// 用户字典
-        /// </summary>
-        private static Dictionary<string, string> dictUsers = new Dictionary<string, string>();
-
-        /// <summary>
-        /// 建立连接回调
-        /// </summary>
-        /// <returns></returns>
-        public override Task OnConnectedAsync()
-        {
-            Console.WriteLine($"ID:{Context.ConnectionId} 已连接");
-            return base.OnConnectedAsync();
-        }
-
-        /// <summary>
-        /// 断开连接回调
-        /// </summary>
-        /// <param name="exception"></param>
-        /// <returns></returns>
-        public override Task OnDisconnectedAsync(Exception? exception)
-        {
-            Console.WriteLine($"ID:{Context.ConnectionId} 已断开");
-            return base.OnDisconnectedAsync(exception);
-        }
-
-
-        /// <summary>
-        /// 登录功能,将用户ID和ConntectionId关联起来
-        /// </summary>
-        /// <param name="userId"></param>
-        public void Login(string userId)
-        {
-            if (!dictUsers.ContainsKey(userId))
-            {
-                dictUsers[userId] = Context.ConnectionId;
-            }
-            Console.WriteLine($"{userId}登录成功,ConnectionId={Context.ConnectionId}");
-            //向所有用户发送当前在线的用户列表
-            Clients.All.SendAsync("Users", dictUsers.Keys.ToList());
-        }
-
-        /// <summary>
-        /// 退出功能,当客户端退出时调用
-        /// </summary>
-        /// <param name="userId"></param>
-        public void Logout(string userId)
-        {
-            if (dictUsers.ContainsKey(userId))
-            {
-                dictUsers.Remove(userId);
-            }
-            Console.WriteLine($"{userId}退出成功,ConnectionId={Context.ConnectionId}");
-        }
-
-    }
-
-}

+ 7 - 2
OASystem/OASystem.Api/OAMethodLib/Hubs/ServerHub.cs

@@ -46,7 +46,7 @@ namespace OASystem.API.OAMethodLib.Hubs
             //连接用户 这里可以存在Redis
             var model = new UserModel
             {
-                Uid = user.Uid,
+                UserId = user.Uid,
                 ConnectionId = connId,
                 Token = token,
                 UserName = user.UserName
@@ -88,11 +88,16 @@ namespace OASystem.API.OAMethodLib.Hubs
                     Data = "true",
                     Msg = "断开连接"
                 });
-
             }
             return base.OnDisconnectedAsync(exception);
         }
 
+        public async Task Send(string name, string message)
+        {
+            // Call the broadcastMessage method to update clients.
+            await Clients.All.SendAsync("broadcastMessage", name, message);
+        }
+
         /// <summary>
         /// 接受用户的数进行推送
         /// </summary>

+ 1 - 1
OASystem/OASystem.Api/OAMethodLib/Hubs/UserModel.cs

@@ -2,7 +2,7 @@
 {
     public class UserModel
     {
-        public long Uid { get; set; }
+        public long UserId { get; set; }
 
         public string ConnectionId { get; set; }
 

+ 13 - 0
OASystem/OASystem.Api/OAMethodLib/Quartz/Business/TaskNewsFeedJob.cs

@@ -0,0 +1,13 @@
+using Microsoft.AspNetCore.SignalR;
+using OASystem.API.OAMethodLib.Hubs;
+using OASystem.Domain.Entities.PersonnelModule;
+using OASystem.Infrastructure.Repositories.PersonnelModule;
+using ILogger = Microsoft.Extensions.Logging.ILogger;
+
+namespace OASystem.API.OAMethodLib.Quartz.Business
+{
+    public static class TaskNewsFeedJob
+    {
+       
+    }
+}

+ 21 - 7
OASystem/OASystem.Api/OAMethodLib/Quartz/Jobs/TaskNewsFeedJob.cs

@@ -23,9 +23,14 @@ namespace OASystem.API.OAMethodLib.Quartz.Jobs
             _hubContext = hubContext;
         }
 
-        public Task Execute(IJobExecutionContext context)
+        /// <summary>
+        /// 任务消息推送
+        /// </summary>
+        /// <param name="context"></param>
+        /// <returns></returns>
+        public async Task Execute(IJobExecutionContext context)
         {
-            _logger.LogInformation("调用任务消息推送 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
+            //_logger.LogInformation("调用任务消息推送 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"【在线人数】:"+JsonConvert.SerializeObject(ServerHub.OnlineUser));
 
             //在此处编写任务业务代码
             #region 消息处理
@@ -138,19 +143,28 @@ namespace OASystem.API.OAMethodLib.Quartz.Jobs
             //}
             #endregion
 
-            //查询需要提示的消息 Singlr
-            string sql = string.Format(@"Select smra.Id,su.CnName As Issuer,sm.ReleaseTime,sm.Title,
+            string msg = string.Empty;
+            if (ServerHub.OnlineUser.Count  > 0)
+            {
+                //查询需要提示的消息 Singlr
+                string sql = string.Format(@"Select smra.Id,su.CnName As Issuer,sm.ReleaseTime,sm.Title,
 										 sm.Content,smra.ReadableUId,smra.IsRead,smra.CreateTime
 										 From Sys_Message sm
 										 Left Join Sys_MessageReadAuth smra On sm.Id = smra.MsgId
 										 Left Join Sys_Users su On sm.IssuerId = su.Id
 										 Where sm.IsDel = 0 And sm.Type = 6 And smra.IsRead = 0
 										 Order By smra.ReadableUId,smra.CreateTime Desc");
-            //var datas = _taskAllocationRep._sqlSugar.SqlQueryable<MessageReadAuthPushView>(sql).ToList();
+                var datas = _taskAllocationRep._sqlSugar.SqlQueryable<MessageReadAuthPushView>(sql).ToList();
+                msg = JsonConvert.SerializeObject(datas);
 
-             _hubContext.Clients.All.SendAsync("ReceiveMessage", "系统通知", $"最新消息{DateTime.Now}");
+                //_hubContext.Clients.All.SendAsync("ReceiveMessage", "系统通知", $"最新消息{DateTime.Now}");
+                //推送给所有连接ID的第一条数据
+            }
 
-            return Task.CompletedTask;
+            _logger.LogInformation("调用任务消息推送 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "【在线人数】:" + JsonConvert.SerializeObject(ServerHub.OnlineUser) +"【推送消息】:"+ msg);
+
+            await _hubContext.Clients.Clients(ServerHub.OnlineUser.Select(q => q.ConnectionId).ToList()).SendAsync("SendMessageResponse", $"最新消息{DateTime.Now}");
+            //return Task.CompletedTask;
         }
     }
 }

+ 1 - 1
OASystem/OASystem.Api/OAMethodLib/Quartz/QuartzFactory.cs

@@ -37,7 +37,7 @@ namespace QuzrtzJob.Factory
                             .WithCronSchedule("0 0 18 * * ?")
                             .Build();
             var taskMsgTrigger = TriggerBuilder.Create()
-                            .WithSimpleSchedule(x => x.WithIntervalInSeconds(30).RepeatForever())//每六十秒执行一次
+                            .WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever())//每六十秒执行一次
                             //.WithCronSchedule("0 0 14 * * ?")
                             .Build();
 

+ 1 - 0
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -48,6 +48,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 //负责人下拉框
                 List<dynamic> _Users = new List<dynamic>();
                 List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>().Where(u => u.IsDel == 0 && u.CompanyId == 2).ToList();
+
                 foreach (Sys_Users user in users)
                 {
                     var data = new