|
@@ -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 消息
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int TypeId { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
|
|
|
|
|
|
|