|
|
@ -1,4 +1,5 @@ |
|
|
|
using BBWYB.Server.Business; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using QYMessageCenter.Common.Extensions; |
|
|
|
using QYMessageCenter.Common.Http; |
|
|
@ -13,10 +14,13 @@ namespace QYMessageCenter.Business |
|
|
|
public class MessageBusiness : BaseBusiness, IDenpendency |
|
|
|
{ |
|
|
|
private readonly string Key = "BC-8cf10d7731c8417bae1c437818b7f8b3"; |
|
|
|
private IMemoryCache memoryCache; |
|
|
|
private TimeSpan msgCacheTimeSpan; |
|
|
|
|
|
|
|
public MessageBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, RestApiService restApiService) : base(fsql, nLogManager, idGenerator, restApiService) |
|
|
|
public MessageBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, RestApiService restApiService, IMemoryCache memoryCache) : base(fsql, nLogManager, idGenerator, restApiService) |
|
|
|
{ |
|
|
|
|
|
|
|
this.memoryCache = memoryCache; |
|
|
|
this.msgCacheTimeSpan = new TimeSpan(12, 0, 0); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -25,10 +29,17 @@ namespace QYMessageCenter.Business |
|
|
|
/// <param name="request"></param>
|
|
|
|
public void Send(SendMessageRequest request) |
|
|
|
{ |
|
|
|
#region 检查消息md5
|
|
|
|
var md5 = $"{request.AppCode}_{request.TeamId}_{request.CustomTypeCode}_{request.Content}".Md5Encrypt(); |
|
|
|
if (memoryCache.TryGetValue(md5, out _)) |
|
|
|
return; |
|
|
|
#endregion
|
|
|
|
|
|
|
|
var msg = request.Map<QYNotification>(); |
|
|
|
msg.Id = idGenerator.NewLong(); |
|
|
|
msg.CreateTime = DateTime.Now; |
|
|
|
|
|
|
|
|
|
|
|
#region 调用goeasy
|
|
|
|
var goeasy_httpResult = restApiService.SendRequest("https://rest-hz.goeasy.io/", "v2/pubsub/publish", new |
|
|
|
{ |
|
|
@ -44,6 +55,10 @@ namespace QYMessageCenter.Business |
|
|
|
#region 保存入库
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 缓存消息
|
|
|
|
memoryCache.Set(md5, msg, msgCacheTimeSpan); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|