Ver Fonte

优化学校发送消息端口,优化统计活动时报错的问题。

Li há 2 anos atrás
pai
commit
6c62f7cd53

+ 5 - 3
TEAMModelBI/Controllers/BICommon/BINoticeController.cs

@@ -128,7 +128,8 @@ namespace TEAMModelBI.Controllers.BICommon
 
                 jsonElement.TryGetProperty("type", out JsonElement type);
                 jsonElement.TryGetProperty("jumpUrl", out JsonElement jumpUrl);
-                jsonElement.TryGetProperty("callbackUrl", out JsonElement callbackUrl);
+                jsonElement.TryGetProperty("callbackName", out JsonElement callbackName);
+                jsonElement.TryGetProperty("refuseName", out JsonElement refuseName);
                 if (!jsonElement.TryGetProperty("theme", out JsonElement theme)) return BadRequest();
                 if (!jsonElement.TryGetProperty("content", out JsonElement content)) return BadRequest();
                 jsonElement.TryGetProperty("tmdIds", out JsonElement _tmdIds);
@@ -219,7 +220,8 @@ namespace TEAMModelBI.Controllers.BICommon
                     code = "BINotice",
                     type = !string.IsNullOrEmpty($"{type}") ? type.GetInt32() : 0,
                     jumpUrl = !string.IsNullOrEmpty($"{jumpUrl}") ? $"{jumpUrl}" : "",
-                    callbackUrl = !string.IsNullOrEmpty($"{callbackUrl}") ? $"{callbackUrl}" : "",
+                    callbackName = !string.IsNullOrEmpty($"{callbackName}") ? $"{callbackName}" : "",
+                    refuseName = !string.IsNullOrEmpty($"{refuseName}") ? $"{refuseName}" : "",
                     theme = $"{theme}",
                     content = $"{content}",
                     crowd = crowd,
@@ -238,7 +240,7 @@ namespace TEAMModelBI.Controllers.BICommon
             }
             catch (Exception ex)
             {
-                //_ = _dingDing.SendBotMsg($"BI,{_option.Location},notion/PushNotion() \n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
+                _ = _dingDing.SendBotMsg($"BI,{_option.Location},notion/PushNotion() \n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
                 return BadRequest();
             }
         }

+ 44 - 7
TEAMModelOS.SDK/DI/CoreAPI/CoreAPIHttpService.cs

@@ -1,3 +1,4 @@
+using DocumentFormat.OpenXml.Wordprocessing;
 using HTEXLib.COMM.Helpers;
 using HTEXLib.Helpers.ShapeHelpers;
 using Microsoft.AspNetCore.Hosting;
@@ -351,7 +352,7 @@ namespace TEAMModelOS.SDK
         /// <param name="location"></param>
         /// <param name="_configuration"></param>
         /// <param name="_dingDing"></param>
-        public void BIPushNotify(BINotice bINotice, Dictionary<string, object> replaceData,string location, IConfiguration _configuration, DI.DingDing _dingDing)
+        public void BIPushNotify(BINotice bINotice, Dictionary<string, object> replaceData,string location, IConfiguration _configuration, DingDing _dingDing)
         {
 
             try
@@ -360,16 +361,47 @@ namespace TEAMModelOS.SDK
                 var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
                 var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
                 string site = location;
-                if (location.Contains("China"))
+                string sendSite = "";
+                //处理action
+                string urlAction = "";
+                List<dynamic> actions = new List<dynamic>();
+                if (site.Equals("Global"))
                 {
-                    location = "China";
+                    sendSite = "Global";
+                    urlAction = "https://www.teammodel.net/core/process-notify";
                 }
-                else if (location.Contains("Global"))
+                if (site.Equals("Global-Test") || site.Equals("Global-Dep"))
                 {
-                    location = "Global";
+                    sendSite = "Global";
+                    urlAction = "https://test.teammodel.net/core/process-notify";
+                }
+                if (site.Equals("China"))
+                {
+                    sendSite = "China";
+                    urlAction = "https://www.teammodel.cn/core/process-notify";
+                }
+                if (site.Equals("China-Test") || site.Equals("China-Dep"))
+                {
+                    sendSite = "China";
+                    urlAction = "https://test.teammodel.cn/core/process-notify";
+                }
+
+                if (bINotice.callbackName != null && bINotice.refuseName != null)
+                {
+                    string urlA = $"{urlAction}&notifyEvent=1&ticket=";
+                    string urlB = $"{urlAction}&notifyEvent=2&ticket=";
+                    actions.Add(new { type = "click", label = bINotice.callbackName, url = urlA, tokenbindtype = 1 });
+                    actions.Add(new { type = "click", label = bINotice.refuseName, url = urlB, tokenbindtype = 1 });
+
+                }
+                else if (bINotice.callbackName != null && bINotice.refuseName == null)
+                {
+                    string urlA = $"{urlAction}&notifyEvent=1&ticket=";
+                    actions.Add(new { type = "click", label = bINotice.callbackName, url = urlA, tokenbindtype = 1 });
                 }
+
                 var client = _httpClient;
-                var token = CoreTokenExtensions.CreateAccessToken(clientID, clientSecret, location).Result;
+                var token = CoreTokenExtensions.CreateAccessToken(clientID, clientSecret, sendSite).Result;
                 if (client.DefaultRequestHeaders.Contains("Authorization"))
                 {
                     client.DefaultRequestHeaders.Remove("Authorization");
@@ -380,6 +412,11 @@ namespace TEAMModelOS.SDK
                     client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
                 }
 
+                string data = new { value = replaceData }.ToJsonString();
+                if (actions.Any())
+                {
+                    data = new { value = replaceData, action = actions }.ToJsonString();
+                }
                 NotifyData notifyData = new()
                 {
                     hubName = string.Join(",", bINotice.crowd.types),
@@ -389,7 +426,7 @@ namespace TEAMModelOS.SDK
                     body = bINotice.content,
                     eventId = $"BI-send",
                     eventName = $"BI_SendNotice",
-                    data = bINotice.ToString()
+                    data = data
                 };
 
                 string result = "";

+ 10 - 2
TEAMModelOS.SDK/Models/Cosmos/BI/BICommon/Notice.cs

@@ -19,14 +19,22 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// 消息类型  0系统  1普通类型  2提示类型   3 特殊类型  
         /// </summary>
         public int type { get; set; } = 0;
+
         /// <summary>
         /// 跳转地址
         /// </summary>
         public string jumpUrl { get; set; }
+
+        /// <summary>
+        /// 回调名称拒绝 查看
+        /// </summary>
+        public string callbackName { get; set; }
+
         /// <summary>
-        /// 回调方法
+        /// 拒绝
         /// </summary>
-        public string callbackUrl { get; set; }
+        public string refuseName { get; set; }
+
         /// <summary>
         /// 消息标题
         /// </summary>

+ 4 - 2
TEAMModelOS.SDK/Models/Service/BIStatsWay/ActivityStatsWay.cs

@@ -164,8 +164,10 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                 if (actYear.Count < 366)
                     actYear.Add(0);
             }
-
-            actStats.year = actYear;
+            if (actYear.Count > 0)
+            {
+                actStats.year = actYear;
+            }
 
             //string lastDaySql = $"c.createTime >= {lastDayS} and c.createTime <= {lastdayE}";
             //string daySql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";

+ 13 - 2
TEAMModelOS.SDK/Models/Service/BIStatsWay/LessonRecordStatsWay.cs

@@ -77,8 +77,14 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                 Inters.Add((double)lessRelStats.FindAll(f => (f.startTime >= everyDay[i].start && f.startTime <= everyDay[i].end)).Select(s => s.clientInteractionCount).Sum());
             }
             if (Inters.Count < 366)
+            {
                 Inters.Add(0);
-            lessStats.yearInters = Inters;
+            }
+
+            if (Inters.Count > 0)
+            {
+                lessStats.yearInters = Inters;
+            }
 
             List<double> lessYear = new();
             for (int i = 0; i < everyDay.Count; i++)
@@ -86,9 +92,14 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                 lessYear.Add(lessRelStats.FindAll(f => (f.startTime >= everyDay[i].start && f.startTime <= everyDay[i].end)).Count);
             }
             if (lessYear.Count < 366)
+            {
                 lessYear.Add(0);
-            lessStats.year = lessYear;
+            }
 
+            if (Inters.Count > 0)
+            {
+                lessStats.year = lessYear;
+            }
             lessStats.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); 
 
             return lessStats;