ソースを参照

消息列表
增加类型分页

leiy 1 年間 前
コミット
4eca3d5c42

+ 5 - 1
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -100,7 +100,6 @@ namespace OASystem.API.Controllers
 
                 view.Expires = expDt;
                 view.Token = authorToken;
-
             }
             else
             {
@@ -113,6 +112,11 @@ namespace OASystem.API.Controllers
             }
 
 
+            #region signalR
+            new MyHub().Login(uId.ToString()); ;
+
+            #endregion
+
             #region 测试添加系统消息
 
             //await _message.AddMsg(new MessageDto()

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

@@ -0,0 +1,67 @@
+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}");
+        }
+
+    }
+
+}

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

@@ -112,8 +112,6 @@ namespace OASystem.API.OAMethodLib.Hubs
             //推送给所有连接ID的第一条数据
             await Clients.Clients(OnlineUser.Select(q => q.ConnectionId).ToList()).SendAsync("SendMessage", result);
         }
-
-
     }
 }
 

+ 1 - 1
OASystem/OASystem.Api/OASystem.API.csproj

@@ -42,7 +42,7 @@
     <PackageReference Include="TencentCloudSDK.Ocr" Version="3.0.734" />
     <PackageReference Include="TinyPinyin.Net" Version="1.0.2" />
   </ItemGroup>
-
+	
   <ItemGroup>
     <ProjectReference Include="..\OASystem.Domain\OASystem.Domain.csproj" />
     <ProjectReference Include="..\OASystem.Infrastructure\OASystem.Infrastructure.csproj" />

+ 4 - 9
OASystem/OASystem.Api/Program.cs

@@ -19,6 +19,7 @@ using OASystem.API.OAMethodLib.Quartz.Jobs;
 using Microsoft.AspNetCore.Cors.Infrastructure;
 using Microsoft.AspNetCore.SignalR;
 using OASystem.API.OAMethodLib.Hubs;
+using SqlSugar.DistributedSystem.Snowflake;
 
 var builder = WebApplication.CreateBuilder(args);
 var basePath = AppContext.BaseDirectory;
@@ -48,7 +49,6 @@ builder.Services.AddControllers()
         //options.JsonSerializerOptions.Converters.Add(new JsonConverterDecimal(0.0000M));
     });
 
-
 #region Cors
 builder.Services.AddCors(policy =>
 {
@@ -57,6 +57,7 @@ builder.Services.AddCors(policy =>
     .AllowAnyHeader()
     .AllowAnyMethod()
     .WithExposedHeaders("X-Pagination"));
+
 });
 #endregion
 
@@ -281,13 +282,9 @@ builder.Services.AddSingleton<IJobFactory, IOCJobFactory>();
 
 #endregion
 
-#region SignalR
-builder.Services.AddSignalR().AddJsonProtocol(options =>
-{
-    //加配置可以传给客户端对象,否则只能传字符串
-    options.PayloadSerializerOptions.PropertyNamingPolicy = null;
-});
 
+#region SignalR
+builder.Services.AddSignalR();
 #endregion
 
 var app = builder.Build();
@@ -304,8 +301,6 @@ app.UseRouting();
 app.UseAuthentication(); // 认证
 app.UseAuthorization();  // 授权
 app.UseCors("Cors");  //Cors
-//app.UseCors("AllowSpecificOrigin");  //Cors
-
 
 #region 启用swaggerUI
 if (AppSettingsHelper.Get("UseSwagger").ToBool())

+ 3 - 2
OASystem/OASystem.Domain/ViewModels/System/MessageView.cs

@@ -12,13 +12,14 @@ namespace OASystem.Domain.ViewModels.System
     }
 
     /// <summary>
-    /// 于都消息返回视图
+    /// 于都消息返回视图
     /// </summary>
     public class ReadbleMessageView
     {
+        public int Id { get; set; }
+
         /// <summary>
         /// 消息类型
-        /// 0 
         /// 1 公告消息
         /// 2 团组流程管控消息
         /// 3 团组业务操作消息

+ 32 - 4
OASystem/OASystem.Infrastructure/Repositories/System/MessageRepository.cs

@@ -1,10 +1,12 @@
-using OASystem.Domain;
+using NPOI.SS.Formula.Functions;
+using OASystem.Domain;
 using OASystem.Domain.Dtos.System;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Security.Cryptography;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 
 namespace OASystem.Infrastructure.Repositories.System
@@ -95,9 +97,9 @@ namespace OASystem.Infrastructure.Repositories.System
         {
             Result result = new Result() { Code = -1, Msg = "未知错误", Data = null };
 
-            if (dto.PortType == 1 || dto.PortType == 2)  // web/android
+            if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)  // web/android
             {
-                string msgSqlWhere = string.Format(@"Select sm.Type,sm.Title,sm.Content,sd.DepName issuerDep,su.CnName issuerUser, 
+                string msgSqlWhere = string.Format(@"Select sm.Id,sm.Type,sm.Title,sm.Content,sd.DepName issuerDep,su.CnName issuerUser, 
                                                             sm.ReleaseTime,smra.Id AuthId,smra.ReadableUId,smra.IsRead,smra.ReadTime 
                                                      From Sys_Message sm 
                                                      Inner Join Sys_MessageReadAuth smra On sm.Id = smra.MsgId
@@ -111,9 +113,35 @@ namespace OASystem.Infrastructure.Repositories.System
                 var _readableMsgList = await _sqlSugar.SqlQueryable<ReadbleMessageView>(msgSqlWhere).ToListAsync();
                 if (_readableMsgList.Count > 0)
                 {
+                    int pageIndex = dto.PageIndex;
+                    int pageSize = pageIndex + 9;
+                    //操作通知 OperationNotification
+                    List<int> operationTypeList = new List<int>() {1,2,3,4,5 };
+                    var operationNotificatioData = _readableMsgList.Where(it => operationTypeList.Contains(it.Type)).OrderBy(it => it.IsRead).ToList();
+                    var operationNotificatioDataView = new {
+                        Count = operationNotificatioData.Count,
+                        UnReadCount = operationNotificatioData.Where(it => it.IsRead == 0).Count(),
+                        OperationNotificatioData = operationNotificatioData.Skip(pageIndex).Take(pageSize).ToList()
+                    };
+
+                    //任务通知 TaskNotification
+                    List<int> taskTypeList = new List<int>() { 6 };
+                    var taskNotificatioData = _readableMsgList.Where(it => taskTypeList.Contains(it.Type)).OrderBy(it => it.IsRead).ToList();
+                    var taskNotificatioDataView = new
+                    {
+                        Count = taskNotificatioData.Count,
+                        UnReadCount = taskNotificatioData.Where(it => it.IsRead == 0).Count(),
+                        TaskNotificatioData = taskNotificatioData.Skip(pageIndex).Take(pageSize).ToList()
+                    };
+
+                    var _view = new {
+                        OperationNotificatio = operationNotificatioDataView,
+                        TaskNotificatio = taskNotificatioDataView
+                    };
+
                     result.Code = 0;
                     result.Msg = "成功!";
-                    result.Data = _readableMsgList;
+                    result.Data = _view;
                 }
                 else
                 {