Browse Source

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

yuanrf 1 year ago
parent
commit
539fe2a0d3

+ 7 - 8
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -30,12 +30,13 @@ namespace OASystem.API.Controllers
         private readonly LoginRepository _loginRep;
         private readonly MessageRepository _message;
         private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
-
+        private readonly MessageRepository _messageRep;
+        
         private readonly IQiYeWeChatApiService _qiYeWeChatApiServic;
         private readonly IHubContext<ServerHub> _hubContext;
 
         public AuthController(IConfiguration config, LoginRepository loginRep, IMapper mapper,MessageRepository message,
-            SystemMenuPermissionRepository systemMenuPermissionRepository, IQiYeWeChatApiService qiYeWeChatApiService, IHubContext<ServerHub> hubContext)
+            SystemMenuPermissionRepository systemMenuPermissionRepository, IQiYeWeChatApiService qiYeWeChatApiService, IHubContext<ServerHub> hubContext, MessageRepository messageRep)
         {
             _config = config;
             _loginRep = loginRep;
@@ -43,6 +44,7 @@ namespace OASystem.API.Controllers
             _message = message;
             _SystemMenuPermissionRepository = systemMenuPermissionRepository;
             _qiYeWeChatApiServic = qiYeWeChatApiService;
+            _messageRep = messageRep;
             _hubContext = hubContext;
         }
 
@@ -68,11 +70,13 @@ namespace OASystem.API.Controllers
             Result authData = null;
             string uName = string.Empty;
             int uId = 0;
+            int unReadCount = 0;
             if (userData.Data != null)
             {
                 uId = (userData.Data as UserLoginInfoView).UserId;
                 uName = (userData.Data as UserLoginInfoView).CnName;
                 authData = _SystemMenuPermissionRepository.QueryMenuLoad(uId, dto.PortType);
+                unReadCount = await _messageRep.GetUnReadCount(uId);
             }
 
             //_hubContext.Login(uId, uName);
@@ -80,6 +84,7 @@ namespace OASystem.API.Controllers
             {
                 UserInfo = userData == null ? null : userData.Data,
                 AuthData = authData == null ? null : authData.Data,
+                UnReadCount = unReadCount
             };
 
             DateTime createZebraTime = DateTime.Now;
@@ -111,12 +116,6 @@ namespace OASystem.API.Controllers
 
             }
 
-
-            #region signalR
-            new MyHub().Login(uId.ToString()); ;
-
-            #endregion
-
             #region 测试添加系统消息
 
             //await _message.AddMsg(new MessageDto()

+ 5 - 0
OASystem/OASystem.Domain/ViewModels/LoginView.cs

@@ -24,4 +24,9 @@ public class LoginView
     /// 返回用户权限信息
     /// </summary>
     public object? AuthData { get; set; }
+
+    /// <summary>
+    /// 未读消息条数
+    /// </summary>
+    public int UnReadCount { get; set; }
 }

+ 51 - 7
OASystem/OASystem.Infrastructure/Repositories/System/MessageRepository.cs

@@ -1,6 +1,8 @@
-using NPOI.SS.Formula.Functions;
+using NPOI.POIFS.Crypt.Dsig;
+using NPOI.SS.Formula.Functions;
 using OASystem.Domain;
 using OASystem.Domain.Dtos.System;
+using OASystem.Domain.ViewModels.QiYeWeChat;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -113,25 +115,37 @@ 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;
+                    int pageSize = dto.PageSize; // 每页显示的记录数量
+                    int currentPage = dto.PageIndex; // 当前页码(从1开始)
+
+                    
                     //操作通知 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();
+                    int operationNotificatioDataCount = operationNotificatioData.Count;
+                    // 计算起始索引和结束索引
+                    int operationStartIndex = (currentPage - 1) * pageSize;
+                    int operationEndIndex = Math.Min(operationStartIndex + pageSize, operationNotificatioDataCount);
+
                     var operationNotificatioDataView = new {
-                        Count = operationNotificatioData.Count,
+                        Count = operationNotificatioDataCount,
                         UnReadCount = operationNotificatioData.Where(it => it.IsRead == 0).Count(),
-                        OperationNotificatioData = operationNotificatioData.Skip(pageIndex).Take(pageSize).ToList()
+                        OperationNotificatioData = operationNotificatioData.Skip(operationStartIndex).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();
+                    int taskNotificatioDataCount = taskNotificatioData.Count;
+                    // 计算起始索引和结束索引
+                    int taskStartIndex = (currentPage - 1) * pageSize;
+                    int taskEndIndex = Math.Min(operationStartIndex + pageSize, operationNotificatioDataCount);
+
                     var taskNotificatioDataView = new
                     {
-                        Count = taskNotificatioData.Count,
+                        Count = taskNotificatioDataCount,
                         UnReadCount = taskNotificatioData.Where(it => it.IsRead == 0).Count(),
-                        TaskNotificatioData = taskNotificatioData.Skip(pageIndex).Take(pageSize).ToList()
+                        TaskNotificatioData = taskNotificatioData.Skip(taskStartIndex).Take(pageSize).ToList()
                     };
 
                     var _view = new {
@@ -152,6 +166,36 @@ namespace OASystem.Infrastructure.Repositories.System
             return result;
         }
 
+        /// <summary>
+        /// 获取消息未读消息条数
+        /// </summary>
+        /// <param name="uId">可读用户Id</param>
+        /// <returns></returns>
+        public async Task<int> GetUnReadCount(int userId)
+        {
+            int _unReadCount = 0;
+
+
+            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
+                                                     Inner Join Sys_Users su On sm.IssuerId = su.Id
+                                                     Inner Join Sys_Department sd On su.DepId = sd.Id
+                                                     Inner Join Sys_Users suAuth On smra.ReadableUId = suAuth.Id
+                                                     Where sm.IsDel = 0
+                                                     And smra.IsDel = 0 
+                                                     And smra.ReadableUId = {0}
+                                                     Order By ReleaseTime Desc ", userId);
+            var _readableMsgList = await _sqlSugar.SqlQueryable<ReadbleMessageView>(msgSqlWhere).ToListAsync();
+            if (_readableMsgList.Count > 0)
+            {
+                _unReadCount = _readableMsgList.Where(it => it.IsRead == 0).Count();
+            }
+
+            return _unReadCount;
+        }
+
         /// <summary>
         /// 获取消息详细
         /// </summary>