Browse Source

signalR 7 添加通知
1、任务分配 2、审核通知(通过或不通过时通知) 3、、建团完成时通知(经理、主管)

leiy 1 year ago
parent
commit
94e5820335

+ 69 - 5
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -48,6 +48,9 @@ using Aspose.Cells.Charts;
 using static NPOI.HSSF.Util.HSSFColor;
 using Quartz.Util;
 using Google.Protobuf.WellKnownTypes;
+using Microsoft.AspNetCore.SignalR;
+using OASystem.API.OAMethodLib.Hub.HubClients;
+using OASystem.API.OAMethodLib.Hub.Hubs;
 
 namespace OASystem.API.Controllers
 {
@@ -76,6 +79,7 @@ namespace OASystem.API.Controllers
         private readonly TourClientListRepository _tourClientListRep;
         private readonly TeamRateRepository _teamRateRep;
 
+
         #region 成本相关
         private readonly CheckBoxsRepository _checkBoxs;
         private readonly GroupCostRepository _GroupCostRepository;
@@ -88,6 +92,8 @@ namespace OASystem.API.Controllers
         private string path;
 
         private readonly EnterExitCostRepository _enterExitCostRep;
+        private readonly IHubContext<ChatHub, IChatClient> _hubContext;
+        private readonly UsersRepository _usersRep;
 
         public GroupsController(IMapper mapper, SqlSugarClient sqlSugar, GrpScheduleRepository grpScheduleRep, DelegationInfoRepository groupRepository,
             TaskAssignmentRepository taskAssignmentRep, AirTicketResRepository airTicketResRep, DecreasePaymentsRepository decreasePaymentsRep,
@@ -95,7 +101,7 @@ namespace OASystem.API.Controllers
             , DelegationVisaRepository delegationVisaRep, MessageRepository message, VisaPriceRepository visaPriceRep, CarTouristGuideGroundRepository carTouristGuideGroundRep,
             CheckBoxsRepository checkBoxs, GroupCostRepository GroupCostRepository, CostTypeHotelNumberRepository CostTypeHotelNumberRepository,
             GroupCostParameterRepository GroupCostParameterRepository, HotelPriceRepository hotelPriceRep, CustomersRepository customersRep, SetDataRepository setDataRep,
-            TourClientListRepository tourClientListRep, TeamRateRepository teamRateRep)
+            TourClientListRepository tourClientListRep, TeamRateRepository teamRateRep, IHubContext<ChatHub, IChatClient> hubContext, UsersRepository usersRep)
         {
             _mapper = mapper;
             _grpScheduleRep = grpScheduleRep;
@@ -126,6 +132,8 @@ namespace OASystem.API.Controllers
             _setDataRep = setDataRep;
             _tourClientListRep = tourClientListRep;
             _teamRateRep = teamRateRep;
+            _hubContext = hubContext;
+            _usersRep = usersRep;
         }
 
         #region 流程管控
@@ -504,10 +512,31 @@ namespace OASystem.API.Controllers
 
                 int diId = 0;
                 //添加时 默认加入团组汇率
-                if (dto.Status == 1)
+                if (dto.Status == 1) //添加
                 {
                     diId = groupData.Data;
-                    GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
+                    GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);//添加默认币种
+
+                    //消息提示
+                    List<int> _managerIds = new List<int>() { 22, 32 };
+                    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)
+                    {
+                        //创建团组管控
+                        GroupStepForDelegation.CreateWorkStep(diId);
+                        //发送消息
+                        string groupName = dto.TeamName;
+                        string createGroupUser = string.Empty;
+
+                        var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
+                        if (userInfo != null) createGroupUser = userInfo.CnName;
+
+                        string title = $"新建团组";
+                        string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
+                        await GeneralMethod.MessageIssueAndNotification(MessgeTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
+
+                    }
+
                 }
                 else if(dto.Status == 2)
                 {
@@ -1658,6 +1687,12 @@ namespace OASystem.API.Controllers
             DateTime dtNow = DateTime.Now;
             _groupRepository.BeginTran();
             int rst = 0;
+            var creditDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && idList.Contains(it.Id.ToString())).ToList();
+            var creditTypeDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
+            var creditCurrencyDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
+            var groupDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
+
+            List<dynamic> msgDatas = new List<dynamic>();
             foreach (var item in idList)
             {
                 int CreditId = int.Parse(item);
@@ -1673,13 +1708,42 @@ namespace OASystem.API.Controllers
                     _groupRepository.RollbackTran();
                     return Ok(JsonView(false, "操作失败并回滚!"));
                 }
-                else
+
+                var creditData = creditDatas.Where(it => it.Id == CreditId).FirstOrDefault();
+                if (creditData != null)
                 {
+                    string auditStr = _dto.AuditCode == 1 ? "已通过" : _dto.AuditCode == 2 ? "未通过" : "未审核";
+
+                    string groupNameStr = string.Empty;
+                    var groupData = groupDatas.Where(it => it.Id == creditData.DIId).FirstOrDefault();
+                    if (groupData != null) groupNameStr = groupData.TeamName;
+                    
+
+                    string creditTypeStr = string.Empty;
+                    var creditTypeData = creditTypeDatas.Where(it => it.Id == creditData.CTable).FirstOrDefault();
+                    if (creditTypeData != null) creditTypeStr = creditTypeData.Name;
+
+                    string creditCurrency = string.Empty;
+                    var creditCurrencyData = creditCurrencyDatas.Where(it => it.Id == creditData.PaymentCurrency).FirstOrDefault();
+                    if (creditCurrencyData != null) creditCurrency = creditCurrencyData.Name;
+
+
+                    decimal CNYPrice = (creditData.PayMoney * (creditData.PayPercentage / 100)) * creditData.DayRate;
+                    string msgTitle = $"[{groupNameStr}({creditTypeStr})]的费用申请";
+                    string msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice.ToString("0.##")} CNY({creditData.PayMoney.ToString("0.##")} {creditCurrency})) {auditStr}!";
+                    msgDatas.Add(new {DiId = creditData.DIId, UserId = creditData.CreateUserId, MsgTitle = msgTitle, MsgContent = msgContent });
                 }
+                
             }
-            _groupRepository.CommitTran();
             if (rst == 0)
             {
+                foreach (var item in msgDatas)
+                {
+                    //发送消息
+                  await  GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupExpenseAudit, item.MsgTitle, item.msgContent, new List<int>() { item.UserId }, item.DiId);
+                }
+
+                _groupRepository.CommitTran();
                 return Ok(JsonView(true, "操作成功!"));
             }
 

+ 153 - 4
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -1,6 +1,9 @@
 using Aspose.Cells;
+using Microsoft.AspNetCore.SignalR;
 using NPOI.POIFS.Crypt.Dsig;
 using OASystem.API.OAMethodLib;
+using OASystem.API.OAMethodLib.Hub.HubClients;
+using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI;
 using OASystem.Domain.Dtos.PersonnelModule;
 using OASystem.Domain.Entities.PersonnelModule;
@@ -32,6 +35,7 @@ namespace OASystem.API.Controllers
 
         private string url;
         private string path;
+        private readonly IHubContext<ChatHub, IChatClient> _hubContext;
 
         /// <summary>
         /// 初始化
@@ -41,7 +45,7 @@ namespace OASystem.API.Controllers
         /// <param name="usersRep"></param>
         /// <param name="mapper"></param>
         public PersonnelModuleController(IQiYeWeChatApiService qiYeWeChatApiService,WageSheetRepository wageSheetRep, UsersRepository usersRep, IMapper mapper, 
-            TaskAllocationRepository taskAllocationRep)
+            TaskAllocationRepository taskAllocationRep, IHubContext<ChatHub, IChatClient> hubContext)
         {
             _mapper = mapper;
             _usersRep = usersRep;
@@ -57,6 +61,7 @@ namespace OASystem.API.Controllers
             }
 
             this._taskAllocationRep = taskAllocationRep;
+            _hubContext = hubContext;
         }
 
         #region 工资表单
@@ -1183,6 +1188,15 @@ namespace OASystem.API.Controllers
                 var _view = await _taskAllocationRep._AddOrEdit(_dto);
                 if (_view.Code == 0)
                 {
+
+                    if (_dto.Id == 0) //添加提示任务单创建
+                    {
+                        string title = $"[{_dto.TaskName}] 任务新建成功!";
+                        string content = $"[{_dto.TaskName}] 任务新建成功,请前往任务页面查看详情!";
+
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate,title,content,_dto.UserIds);
+                    }
+
                     return Ok(JsonView(true, "操作成功!"));
                 }
 
@@ -1233,6 +1247,34 @@ namespace OASystem.API.Controllers
                 var _view = await _taskAllocationRep._TaskerSetStartStatus(_dto.UserId, _dto.Id);
                 if (_view.Code == 0)
                 {
+                    //发送消息
+                    var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == _dto.Id).First();
+                    if (taskData != null)
+                    {
+                        var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.TAId == _dto.Id).Select(it => it.UserId).ToList();
+                        if (taskUserIds.Count > 0)
+                        {
+                            taskUserIds.Remove(_dto.UserId);
+                        }
+
+                        var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == _dto.UserId).Select(it => it.CnName).First();
+
+                        string title_createUser = $"[{taskData.TaskName}] 进度更新!";
+                        string conten_createUser = $"[{UserName}] 已开始任务,请注意该工作人员任务进度!";
+
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title_createUser, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
+
+                        string title = $"[{taskData.TaskName}] 进度更新!";
+                        string content = $"[{UserName}] 已开始任务.若需查看,请前往任务页面查看详情!";
+
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //其他人发送消息
+
+
+                        string content1 = $"任务已开始,请在规定时间完成!若需查看,请前往任务页面查看详情!";
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content1, new List<int>() { _dto.UserId }); //设置任务人 发送消息
+
+                    }
+                   
                     return Ok(JsonView(true, "操作成功!"));
                 }
 
@@ -1258,6 +1300,34 @@ namespace OASystem.API.Controllers
                 var _view = await _taskAllocationRep._TaskerSetOverStatus(_dto.UserId, _dto.Id);
                 if (_view.Code == 0)
                 {
+                    //发送消息
+                    var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == _dto.Id).First();
+                    if (taskData != null)
+                    {
+                        var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.TAId == _dto.Id).Select(it => it.UserId).ToList();
+                        if (taskUserIds.Count > 0)
+                        {
+                            taskUserIds.Remove(_dto.UserId);
+                        }
+
+                        var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == _dto.UserId).Select(it => it.CnName).First();
+
+                        string title_createUser = $"[{taskData.TaskName}] 进度更新!";
+                        string conten_createUser = $"[{UserName}] 已完成任务,请前往任务页面进行审核操作!";
+
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title_createUser, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
+
+                        string title = $"[{taskData.TaskName}] 进度更新!";
+                        string content = $"[{UserName}] 已完成任务,请注意在规定时间内完成任务.若需查看,请前往任务页面查看详情!";
+
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //其他人发送消息
+
+
+                        string content1 = $"任务已完成,等待任务发布人审核!若需查看,请前往任务页面查看详情!";
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content1, new List<int>() { _dto.UserId }); //设置任务人 发送消息
+
+                    }
+
                     return Ok(JsonView(true, "操作成功!"));
                 }
 
@@ -1280,10 +1350,31 @@ namespace OASystem.API.Controllers
         {
             try
             {
-
                 var _view = await _taskAllocationRep._TaskSetHaveStatus(_dto.SubId);
                 if (_view.Code == 0)
                 {
+                    //发送消息
+                    var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == _dto.SubId).First();
+                    if (taskUserData != null)
+                    {
+                        var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
+                        
+                        if (taskData != null)
+                        {
+
+                            var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == taskData.CreateUserId).Select(it => it.CnName).First();
+
+                            string title = $"[{taskData.TaskName}] 进度更新!";
+                            string conten_createUser = $"[{UserName}] 已知晓任务.若需查看,请前往任务页面查看详情!";
+
+                            await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
+
+                            string content = $"请注意任务完成时间!若需查看,请前往任务页面查看详情!";
+                            await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
+
+                        }
+                    }
+
                     return Ok(JsonView(true, "操作成功!"));
                 }
 
@@ -1306,10 +1397,24 @@ namespace OASystem.API.Controllers
         {
             try
             {
-
                 var _view = await _taskAllocationRep._TaskSetAuditStatus(_dto.SubId);
                 if (_view.Code == 0)
                 {
+                    //发送消息
+                    var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == _dto.SubId).First();
+                    if (taskUserData != null)
+                    {
+                        var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
+
+                        if (taskData != null)
+                        {
+                            string title = $"[{taskData.TaskName}] 进度更新!";
+                            string content = $"任务已完成!若需查看,请前往任务页面查看详情!";
+                            await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
+
+                        }
+                    }
+
                     return Ok(JsonView(true, "操作成功!"));
                 }
 
@@ -1336,6 +1441,21 @@ namespace OASystem.API.Controllers
                 var _view = await _taskAllocationRep._TaskSetUnFinishedStatus(_dto.SubId,_dto.Cause);
                 if (_view.Code == 0)
                 {
+                    //发送消息
+                    var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == _dto.SubId).First();
+                    if (taskUserData != null)
+                    {
+                        var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
+
+                        if (taskData != null)
+                        {
+                            string title = $"[{taskData.TaskName}] 进度更新!";
+                            string content = $"任务未完成!若需查看,请前往任务页面查看详情!";
+                            await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
+
+                        }
+                    }
+
                     return Ok(JsonView(true, "操作成功!"));
                 }
 
@@ -1456,6 +1576,21 @@ namespace OASystem.API.Controllers
                 var _view = await _taskAllocationRep._TaskScore(_dto);
                 if (_view.Code == 0)
                 {
+                    //发送消息
+                    var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == _dto.SubId).First();
+                    if (taskUserData != null)
+                    {
+                        var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
+
+                        if (taskData != null)
+                        {
+                            string title = $"[{taskData.TaskName}] 进度更新!";
+                            string content = $"任务评分已完成!若需查看,请前往任务页面查看详情!";
+                            await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
+
+                        }
+                    }
+
                     return Ok(JsonView(true, "操作成功!"));
                 }
 
@@ -1469,7 +1604,7 @@ namespace OASystem.API.Controllers
 
         /// <summary>
         /// 任务分配
-        ///  任务发布者 任务终止
+        /// 任务发布者 任务终止
         /// </summary>
         /// <returns></returns>
         [HttpPost]
@@ -1496,6 +1631,20 @@ namespace OASystem.API.Controllers
                 var _view = await _taskAllocationRep._TaskTermination(_dto.Id);
                 if (_view.Code == 0)
                 {
+                    //发送消息
+                    var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == _dto.Id).First();
+                    if (taskData != null)
+                    {
+                        var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == _dto.Id).Select(it => it.UserId).ToList();
+                        taskUserIds.Add(taskData.CreateUserId);
+
+
+                        string title = $"[{taskData.TaskName}] 进度更新!";
+                        string content = $"任务已终止!若需查看,请前往任务页面查看详情!";
+                        await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //设置任务人 发送消息
+
+                    }
+
                     return Ok(JsonView(true, "操作成功!"));
                 }
 

+ 4 - 4
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -48,8 +48,8 @@ namespace OASystem.API.OAMethodLib
         /// 消息类型 
         /// 1 公告通知
         /// 2 团组流程管控通知
-        /// 1 团组业务操作通知
-        /// 2 团组费用审核消息
+        /// 3 团组业务操作通知
+        /// 4 团组费用审核消息
         /// 5 团组签证进度通知
         /// 6 团组任务进度通知
         /// </param>
@@ -58,7 +58,7 @@ namespace OASystem.API.OAMethodLib
         /// <param name="userIds"></param>
         /// <param name="diId">团组id</param>
         /// <returns></returns>
-        public static async Task<bool> MessageIssueAndNotification(MessgeTypeEnum msgTypeEnum,string title,string content, List<int> userIds,int diId = 0)
+        public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum,string title,string content, List<int> userIds,int diId = 0)
         {
             
             MessageDto messageDto = new()
@@ -98,7 +98,7 @@ namespace OASystem.API.OAMethodLib
         /// 根据消息类型 获取 消息通知类型
         /// </summary>
         /// <returns></returns>
-        public static string GetMsgNotificationType(MessgeTypeEnum msgTypeEnum)
+        public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
         {
             int notificationType = 0;
             string notificationStr = "";

+ 1 - 1
OASystem/OASystem.Domain/Dtos/System/MessageDto.cs

@@ -21,7 +21,7 @@ namespace OASystem.Domain.Dtos.System
         /// 5 团组签证进度通知
         /// 6 团组任务进度通知
         /// </summary>
-        public MessgeTypeEnum Type { get; set; }
+        public MessageTypeEnum Type { get; set; }
 
         /// <summary>
         /// 发布人

+ 6 - 6
OASystem/OASystem.Domain/Enums/MessgeTypeEnum.cs

@@ -10,7 +10,7 @@ namespace OASystem.Domain.Enums
     /// <summary>
     /// 消息类型
     /// </summary>
-    public enum MessgeTypeEnum :int
+    public enum MessageTypeEnum :int
     {
         /// <summary>
         /// 公告消息
@@ -20,27 +20,27 @@ namespace OASystem.Domain.Enums
         /// <summary>
         /// 团组流程管控消息
         /// </summary>
-        [Description("团组流程管控消息")]
+        [Description("团组流程管控消息通知")]
         GroupProcessControl = 2,
         /// <summary>
         /// 团组业务操作消息
         /// </summary>
-        [Description("团组业务操作消息")]
+        [Description("团组业务操作消息通知")]
         GroupBusinessOperations = 3,
         /// <summary>
         /// 团组费用审核消息
         /// </summary>
-        [Description("团组费用审核消息")]
+        [Description("团组费用审核消息通知")]
         GroupExpenseAudit = 4,
         /// <summary>
         /// 团组签证进度更新消息
         /// </summary>
-        [Description("团组签证进度更新消息")]
+        [Description("团组签证进度更新消息通知")]
         GroupVisaProgressUpdate = 5,
         /// <summary>
         /// 任务进度更新消息
         /// </summary>
-        [Description("任务相关消息")]
+        [Description("团组任务进度消息通知")]
         TaskProgressUpdate = 6,
     }
 }

+ 0 - 1
OASystem/OASystem.Infrastructure/Repositories/PersonnelModule/TaskAllocationRepository.cs

@@ -434,7 +434,6 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             return _result;
         }
 
-
         /// <summary>
         /// 任务归属人状态
         /// </summary>