|
@@ -1,8 +1,13 @@
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
using Microsoft.AspNetCore.Mvc.TagHelpers;
|
|
|
+using Microsoft.AspNetCore.SignalR;
|
|
|
using Microsoft.International.Converters.PinYinConverter;
|
|
|
+using NPOI.SS.Formula.PTG;
|
|
|
+using OASystem.API.OAMethodLib.Hub.HubClients;
|
|
|
+using OASystem.API.OAMethodLib.Hub.Hubs;
|
|
|
using OASystem.API.OAMethodLib.JuHeAPI;
|
|
|
+using OASystem.API.OAMethodLib.SignalR.Hubs;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.Financial;
|
|
|
using OASystem.Domain.Entities.Customer;
|
|
@@ -16,14 +21,14 @@ using OASystem.Domain.ViewModels.JuHeExchangeRate;
|
|
|
using OASystem.Domain.ViewModels.PersonnelModule;
|
|
|
using OASystem.Infrastructure.Repositories.CRM;
|
|
|
using OASystem.Infrastructure.Repositories.Groups;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
|
using System.Security.Claims;
|
|
|
+using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
|
|
|
|
|
|
namespace OASystem.API.OAMethodLib
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
public static class GeneralMethod
|
|
|
{
|
|
|
//团组信息
|
|
@@ -32,11 +37,96 @@ namespace OASystem.API.OAMethodLib
|
|
|
private readonly static IJuHeApiService _juHeApiService = AutofacIocManager.Instance.GetService<IJuHeApiService>();
|
|
|
private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
|
|
|
private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
|
|
|
- private readonly static HttpContext _httpContext ;
|
|
|
+ private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
|
|
|
+ private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
|
|
|
+
|
|
|
+ #region 消息
|
|
|
+ /// <summary>
|
|
|
+ /// 消息 发布And 通知
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="msgTypeEnum">
|
|
|
+ /// 消息类型
|
|
|
+ /// 1 公告通知
|
|
|
+ /// 2 团组流程管控通知
|
|
|
+ /// 1 团组业务操作通知
|
|
|
+ /// 2 团组费用审核消息
|
|
|
+ /// 5 团组签证进度通知
|
|
|
+ /// 6 团组任务进度通知
|
|
|
+ /// </param>
|
|
|
+ /// <param name="title">消息标题</param>
|
|
|
+ /// <param name="content">消息内容</param>
|
|
|
+ /// <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)
|
|
|
+ {
|
|
|
+
|
|
|
+ MessageDto messageDto = new()
|
|
|
+ {
|
|
|
+ Type = msgTypeEnum,
|
|
|
+ IssuerId = 4,//管理员
|
|
|
+ DiId = diId,
|
|
|
+ Title = title,
|
|
|
+ Content = content,
|
|
|
+ ReleaseTime = DateTime.Now,
|
|
|
+ UIdList = userIds
|
|
|
+ };
|
|
|
+ var status = await _messageRep.AddMsg(messageDto);//添加消息
|
|
|
+
|
|
|
+ if (status)
|
|
|
+ {
|
|
|
+ //给在线在用户发送消息
|
|
|
+ List<string> connId = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
|
|
|
+
|
|
|
+ string notificationTypeStr = GetMsgNotificationType(msgTypeEnum);
|
|
|
+ var msg = JsonConvert.SerializeObject(
|
|
|
+ new {
|
|
|
+ NotificationType = notificationTypeStr,
|
|
|
+ Issuer = "管理员",
|
|
|
+ Title = title,
|
|
|
+ Content = content,
|
|
|
+ ReleaseTime = messageDto.ReleaseTime
|
|
|
+ }
|
|
|
+ );
|
|
|
+ await _hubContext.Clients.Clients(connId).ReceiveMessage($"您有一条{msg}相关的消息!");
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 根据消息类型 获取 消息通知类型
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static string GetMsgNotificationType(MessgeTypeEnum msgTypeEnum)
|
|
|
+ {
|
|
|
+ int notificationType = 0;
|
|
|
+ string notificationStr = "";
|
|
|
+ List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
|
|
|
+ notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
|
|
|
|
|
|
- #region 消息
|
|
|
+ if (notificationType == 1) notificationStr = "操作";
|
|
|
+ else if (notificationType == 2) notificationStr = "任务";
|
|
|
|
|
|
+ return notificationStr;
|
|
|
+ }
|
|
|
|
|
|
+ public class NotificationTypeView
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 通知类型
|
|
|
+ /// 1 操作通知
|
|
|
+ /// 2 任务通知
|
|
|
+ /// </summary>
|
|
|
+ public int TypeId { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 消息类型id
|
|
|
+ /// </summary>
|
|
|
+ public List<int> MsgTypeIds { get; set; }
|
|
|
+ }
|
|
|
|
|
|
#endregion
|
|
|
|
|
@@ -114,7 +204,7 @@ namespace OASystem.API.OAMethodLib
|
|
|
var indentity = new ClaimsIdentity(claims, "formlogin");
|
|
|
var principal = new ClaimsPrincipal(indentity);
|
|
|
|
|
|
- await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
|
|
|
+ // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
|
|
|
|
|
|
|
|
|
|