leiy 1 year ago
parent
commit
f58103263a

+ 1 - 0
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -522,6 +522,7 @@ namespace OASystem.API.Controllers
                     var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
                     var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
                     if (userIds.Count > 0)
                     if (userIds.Count > 0)
                     {
                     {
+                        userIds.Add(208);
                         //创建团组管控
                         //创建团组管控
                         GroupStepForDelegation.CreateWorkStep(diId);
                         GroupStepForDelegation.CreateWorkStep(diId);
                         //发送消息
                         //发送消息

+ 2 - 13
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -1,31 +1,20 @@
-using Microsoft.AspNetCore.Authentication;
-using Microsoft.AspNetCore.Authentication.Cookies;
-using Microsoft.AspNetCore.Mvc.TagHelpers;
+
 using Microsoft.AspNetCore.SignalR;
 using Microsoft.AspNetCore.SignalR;
 using Microsoft.International.Converters.PinYinConverter;
 using Microsoft.International.Converters.PinYinConverter;
-using NPOI.SS.Formula.PTG;
 using OASystem.API.OAMethodLib.Hub.HubClients;
 using OASystem.API.OAMethodLib.Hub.HubClients;
 using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.JuHeAPI;
 using OASystem.API.OAMethodLib.JuHeAPI;
 using OASystem.API.OAMethodLib.SignalR.Hubs;
 using OASystem.API.OAMethodLib.SignalR.Hubs;
-using OASystem.Domain;
-using OASystem.Domain.Dtos.Financial;
 using OASystem.Domain.Entities.Customer;
 using OASystem.Domain.Entities.Customer;
 using OASystem.Domain.Entities.District;
 using OASystem.Domain.Entities.District;
 using OASystem.Domain.Entities.Financial;
 using OASystem.Domain.Entities.Financial;
 using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.Entities.Groups;
-using OASystem.Domain.Entities.PersonnelModule;
-using OASystem.Domain.Entities.System;
 using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.JuHeExchangeRate;
 using OASystem.Domain.ViewModels.JuHeExchangeRate;
-using OASystem.Domain.ViewModels.PersonnelModule;
 using OASystem.Infrastructure.Repositories.CRM;
 using OASystem.Infrastructure.Repositories.CRM;
 using OASystem.Infrastructure.Repositories.Groups;
 using OASystem.Infrastructure.Repositories.Groups;
-using System.Collections;
-using System.Collections.Generic;
 using System.IdentityModel.Tokens.Jwt;
 using System.IdentityModel.Tokens.Jwt;
 using System.Security.Claims;
 using System.Security.Claims;
-using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
 
 
 namespace OASystem.API.OAMethodLib
 namespace OASystem.API.OAMethodLib
 {
 {
@@ -87,7 +76,7 @@ namespace OASystem.API.OAMethodLib
                        }
                        }
                    );
                    );
                 await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
                 await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
-
+                
                 return true;
                 return true;
             }
             }
 
 

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

@@ -1,12 +0,0 @@
-using Microsoft.AspNetCore.SignalR;
-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
-    {
-       
-    }
-}

+ 141 - 0
OASystem/OASystem.Api/OAMethodLib/Quartz/Business/TaskNotification.cs

@@ -0,0 +1,141 @@
+using Microsoft.AspNetCore.SignalR;
+using OASystem.API.OAMethodLib.Hub.HubClients;
+using OASystem.API.OAMethodLib.Hub.Hubs;
+using OASystem.API.OAMethodLib.SignalR.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 TaskNotification
+    {
+
+        private readonly static ILogger _logger;
+        private readonly static TaskAllocationRepository _taskAllocationRep = AutofacIocManager.Instance.GetService<TaskAllocationRepository>();
+        private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
+
+        /// <summary>
+        /// 任务通知
+        /// </summary>
+        public static async void PostTaskMessageNotification() 
+        {
+            _logger.LogInformation("调用任务消息推送 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "【在线人数】:" + JsonConvert.SerializeObject(UserStore.OnlineUser));
+
+            //在此处编写任务业务代码
+            #region 消息处理
+
+            var data = _taskAllocationRep._sqlSugar
+                                         .Queryable<Domain.Entities.PersonnelModule.Pm_TaskAllocation>()
+                                         .Where(it => it.IsDel == 0 &&
+                                                      !string.IsNullOrEmpty(it.PredictEndTime) &&
+                                                      Convert.ToDateTime(it.PredictEndTime).ToString("yyyy-MM-dd").Equals(DateTime.Now.ToString("yyyy-MM-dd"))
+                                               )
+                                         .ToList();
+            if (data.Count > 0)
+            {
+                //处理要任务提醒的员工
+                List<int> primaryIds = new List<int>();
+                primaryIds = data.Select(it => it.Id).ToList();
+                var subData = _taskAllocationRep._sqlSugar
+                                                .Queryable<Domain.Entities.PersonnelModule.Pm_TaskRelevanceUser>()
+                                                .Where(it => it.IsDel == 0 &&
+                                                             primaryIds.Contains(it.TAId) &&
+                                                             (int)it.TaskStatus <= (int)TaskEnum.UnderWay
+                                                      )
+                                                .ToList();
+
+                _taskAllocationRep._sqlSugar.BeginTran();
+                var depDatas = _taskAllocationRep._sqlSugar.Queryable<Sys_Department>().Where(it => it.IsDel == 0).ToList();
+                var groupDatas = _taskAllocationRep._sqlSugar.Queryable<Domain.Entities.Groups.Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
+                var userDatas = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0).ToList();
+
+                List<int> userIds = new List<int>();
+
+                foreach (var item in data)
+                {
+                    string depName = string.Empty;
+                    string groupName = string.Empty;
+                    var depData = depDatas.Where(it => it.Id == item.DepId).FirstOrDefault();
+                    if (depData != null) { depName = depData.DepName; }
+                    if (item.DiId == -1) { groupName = "其他"; }
+                    else
+                    {
+                        var groupData = groupDatas.Where(it => it.Id == item.DiId).FirstOrDefault();
+                        if (groupData != null) { groupName = groupData.TeamName; }
+                    }
+
+                    var subData1 = subData.Where(it => it.TAId == item.Id).ToList();
+
+                    foreach (var subItem in subData1)
+                    {
+                        string realityStartTime = string.Empty;
+                        string userName = string.Empty;
+                        if (!string.IsNullOrEmpty(subItem.BeginTime))
+                        {
+                            realityStartTime = subItem.BeginTime;
+                        }
+                        else
+                        {
+                            if (subItem.TaskStatus == TaskerEnum.NotStarted) realityStartTime = "未开始";
+                            else if (subItem.TaskStatus == TaskerEnum.HaveKnown) realityStartTime = "已知晓";
+                        }
+
+                        var userData = userDatas.Where(it => it.Id == subItem.UserId).FirstOrDefault();
+                        if (userData != null) { userName = userData.CnName; }
+                        string msgContent = string.Format(@"归属团组:{1}<br/>
+                                                            预计起止时间:{2} 至 {3}<br/>
+                                                            任务参与者:{4}",
+                                                            groupName, item.PredictBeginTime, item.PredictEndTime, userName);
+                        Sys_Message _Message = new Sys_Message()
+                        {
+                            Type = MessageTypeEnum.TaskProgressUpdate,
+                            Title = item.TaskName,
+                            IssuerId = 4, //管理员
+                            Content = msgContent,
+                            ReleaseTime = DateTime.Now,
+                            CreateUserId = 4,
+                            CreateTime = DateTime.Now,
+                            DeleteTime = "1990-01-01 00:00:00.000",
+                            DiId = item.DiId,
+                        };
+                        var msgAddId = _taskAllocationRep._sqlSugar.Insertable<Sys_Message>(_Message).ExecuteReturnIdentity();
+                        if (msgAddId < 0)
+                        {
+                            _taskAllocationRep._sqlSugar.RollbackTran();
+                            _logger.LogError("任务通知消息推送失败!");
+                            return;
+                        }
+
+                        Sys_MessageReadAuth _MessageReadAuth = new Sys_MessageReadAuth()
+                        {
+                            MsgId = msgAddId,
+                            ReadableUId = subItem.UserId,
+                            IsRead = 0,
+                            ReadTime = Convert.ToDateTime("1990-01-01 00:00:00.000"),
+                            CreateUserId = 4,
+                            CreateTime = DateTime.Now,
+                            DeleteTime = "1990-01-01 00:00:00.000"
+                        };
+
+                        var msgAuthAddId = _taskAllocationRep._sqlSugar.Insertable<Sys_MessageReadAuth>(_MessageReadAuth).ExecuteReturnIdentity();
+                        if (msgAuthAddId < 0)
+                        {
+                            _taskAllocationRep._sqlSugar.RollbackTran();
+                            _logger.LogError("任务通知消息推送失败!");
+                            return;
+                        }
+                        userIds.Add(subItem.UserId);
+                    }
+                }
+                _taskAllocationRep._sqlSugar.CommitTran();
+                //推送消息
+                _hubContext.Clients.Clients(UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList()).ReceiveMessage("您有新的任务相关消息");
+
+                _logger.LogInformation("任务消息推送成功 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "【在线人数】:" + JsonConvert.SerializeObject(UserStore.OnlineUser));
+            }
+            #endregion
+        }
+
+    }
+}

+ 6 - 131
OASystem/OASystem.Api/OAMethodLib/Quartz/Jobs/TaskNewsFeedJob.cs

@@ -1,6 +1,8 @@
 using Microsoft.AspNetCore.SignalR;
 using Microsoft.AspNetCore.SignalR;
+using OASystem.API.OAMethodLib.Hub.HubClients;
 using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.Quartz.Business;
 using OASystem.API.OAMethodLib.Quartz.Business;
+using OASystem.API.OAMethodLib.SignalR.Hubs;
 using OASystem.Infrastructure.Repositories.PersonnelModule;
 using OASystem.Infrastructure.Repositories.PersonnelModule;
 using Quartz;
 using Quartz;
 
 
@@ -13,14 +15,11 @@ namespace OASystem.API.OAMethodLib.Quartz.Jobs
     public class TaskNewsFeedJob : IJob
     public class TaskNewsFeedJob : IJob
     {
     {
         private readonly ILogger<TaskNewsFeedJob> _logger;
         private readonly ILogger<TaskNewsFeedJob> _logger;
-        private readonly TaskAllocationRepository _taskAllocationRep = AutofacIocManager.Instance.GetService<TaskAllocationRepository>();
 
 
-        public TaskNewsFeedJob(ILogger<TaskNewsFeedJob> logger, TaskAllocationRepository taskAllocationRep)
+        public TaskNewsFeedJob(ILogger<TaskNewsFeedJob> logger)
         {
         {
             _logger = logger;
             _logger = logger;
-            _taskAllocationRep = taskAllocationRep;
         }
         }
-
         /// <summary>
         /// <summary>
         /// 任务消息推送
         /// 任务消息推送
         /// </summary>
         /// </summary>
@@ -28,136 +27,12 @@ namespace OASystem.API.OAMethodLib.Quartz.Jobs
         /// <returns></returns>
         /// <returns></returns>
         public async Task Execute(IJobExecutionContext context)
         public async Task Execute(IJobExecutionContext context)
         {
         {
-            //_logger.LogInformation("调用任务消息推送 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"【在线人数】:"+JsonConvert.SerializeObject(ServerHub.OnlineUser));
-
-            //在此处编写任务业务代码
-            #region 消息处理
-
-            //var data = _taskAllocationRep._sqlSugar
-            //                             .Queryable<Pm_TaskAllocation>()
-            //                             .Where(it => it.IsDel == 0 &&
-            //                                          !string.IsNullOrEmpty(it.PredictEndTime) &&
-            //                                          Convert.ToDateTime(it.PredictEndTime).ToString("yyyy-MM-dd").Equals(DateTime.Now.ToString("yyyy-MM-dd"))
-            //                                   )
-            //                             .ToList();
-            //if (data.Count > 0)
-            //{
-            //    //处理要任务提醒的员工
-            //    List<int> primaryIds = new List<int>();
-            //    primaryIds = data.Select(it => it.Id).ToList();
-            //    var subData = _taskAllocationRep._sqlSugar
-            //                                    .Queryable<Pm_TaskRelevanceUser>()
-            //                                    .Where(it => it.IsDel == 0 &&
-            //                                                 primaryIds.Contains(it.TAId) &&
-            //                                                 it.TaskStatus <= (int)TaskEnum.UnderWay
-            //                                          )
-            //                                    .ToList();
-
-            //    _taskAllocationRep._sqlSugar.BeginTran();
-            //    var depDatas = _taskAllocationRep._sqlSugar.Queryable<Sys_Department>().Where(it => it.IsDel == 0).ToList();
-            //    var groupDatas = _taskAllocationRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
-            //    var userDatas = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0).ToList();
-
-            //    foreach (var item in data)
-            //    {
-            //        string depName = string.Empty;
-            //        string groupName = string.Empty;
-            //        var depData = depDatas.Where(it => it.Id == item.DepId).FirstOrDefault();
-            //        if (depData != null) { depName = depData.DepName; }
-            //        if (item.DiId == -1) { groupName = "其他"; }
-            //        else
-            //        {
-            //            var groupData = groupDatas.Where(it => it.Id == item.DiId).FirstOrDefault();
-            //            if (groupData != null) { groupName = groupData.TeamName; }
-            //        }
 
 
-            //        var subData1 = subData.Where(it => it.TAId == item.Id).ToList();
+            _logger.LogInformation("调用任务状态变更Function " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 
 
-            //        foreach (var subItem in subData1)
-            //        {
-            //            string realityStartTime = string.Empty;
-            //            string userName = string.Empty;
-            //            if (!string.IsNullOrEmpty(subItem.BeginTime))
-            //            {
-            //                realityStartTime = subItem.BeginTime;
-            //            }
-            //            else
-            //            {
-            //                if (subItem.TaskStatus == -1) realityStartTime = "未开始";
-            //                else if (subItem.TaskStatus == 0) realityStartTime = "已知晓";
-            //            }
-
-            //            var userData = userDatas.Where(it => it.Id == subItem.UserId).FirstOrDefault();
-            //            if (userData != null) { userName = userData.CnName; }
-            //            string msgContent = string.Format(@"任务归属:{0}<br/>
-            //                                                归属团组:{1}<br/>
-            //                                                预计起止时间:{2} 至 {3}<br/>
-            //                                                实际开始时间:{4}<br/>
-            //                                                任务优先级:{5}<br/>
-            //                                                任务参与者:{6}<br/>
-            //                                                任务内容:{7}", depName, groupName, item.PredictBeginTime, item.PredictEndTime,
-            //                                                realityStartTime, item.TaskPriority, userName, item.TaskContent);
-            //            Sys_Message _Message = new Sys_Message()
-            //            {
-            //                Type = MessgeTypeEnum.TaskProgressUpdate,
-            //                Title = item.TaskName,
-            //                IssuerId = 4, //管理员
-            //                Content = msgContent,
-            //                ReleaseTime = DateTime.Now,
-            //                CreateUserId = 4,
-            //                CreateTime = DateTime.Now,
-            //                DeleteTime = "1990-01-01 00:00:00.000",
-            //                DiId = item.DiId,
-            //            };
-            //            var msgAddId = _taskAllocationRep._sqlSugar.Insertable<Sys_Message>(_Message).ExecuteReturnIdentity();
-            //            if (msgAddId < 0)
-            //            {
-            //                _taskAllocationRep._sqlSugar.RollbackTran();
-            //                _logger.LogError("任务通知消息推送失败!");
-            //                return;
-            //            }
-
-            //            Sys_MessageReadAuth _MessageReadAuth = new Sys_MessageReadAuth()
-            //            {
-            //                MsgId = msgAddId,
-            //                ReadableUId = subItem.UserId,
-            //                IsRead = 0,
-            //                ReadTime = Convert.ToDateTime("1990-01-01 00:00:00.000"),
-            //                CreateUserId = 4,
-            //                CreateTime = DateTime.Now,
-            //                DeleteTime = "1990-01-01 00:00:00.000"
-            //            };
-
-            //            var msgAuthAddId = _taskAllocationRep._sqlSugar.Insertable<Sys_MessageReadAuth>(_MessageReadAuth).ExecuteReturnIdentity();
-            //            if (msgAuthAddId < 0)
-            //            {
-            //                _taskAllocationRep._sqlSugar.RollbackTran();
-            //                _logger.LogError("任务通知消息推送失败!");
-            //                return;
-            //            }
-            //        }
-            //    }
-            //    _taskAllocationRep._sqlSugar.CommitTran();
-            //}
-            #endregion
-
-            string msg = string.Empty;
-            
-                //查询需要提示的消息 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();
-                msg = JsonConvert.SerializeObject(datas);
+            //在此处编写任务业务代码
+             TaskNotification.PostTaskMessageNotification();
 
 
-                //_hubContext.Clients.All.SendAsync("ReceiveMessage", "系统通知", $"最新消息{DateTime.Now}");
-                //推送给所有连接ID的第一条数据
-           
-            //await _hubContext.Clients.Clients(ServerHub.OnlineUser.Select(q => q.ConnectionId).ToList()).SendAsync("SendMessageResponse", $"最新消息{DateTime.Now}");
             //return Task.CompletedTask;
             //return Task.CompletedTask;
         }
         }
     }
     }

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

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