CrazyIter_Bin 2 年 前
コミット
aa37f3b787

+ 1 - 1
TEAMModelOS.FunctionV4/HttpTrigger/BIHttpTrigger.cs

@@ -25,7 +25,7 @@ using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
 using TEAMModelOS.SDK.Models.Service.BI;
 using TEAMModelOS.SDK.Models.Service.BIStatsWay;
 
-namespace TEAMModelOS.FunctionV4.HttpTrigger
+namespace TEAMModelOS.FunctionV4
 {
     public class BIHttpTrigger
     {

+ 1 - 1
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -30,7 +30,7 @@ using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Table;
 using static TEAMModelOS.SDK.Models.Teacher;
 
-namespace TEAMModelOS.FunctionV4.HttpTrigger
+namespace TEAMModelOS.FunctionV4
 {
     public class IESHttpTrigger
     {

+ 1 - 1
TEAMModelOS.FunctionV4/HttpTrigger/ScsYxptApis.cs

@@ -16,7 +16,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 
-namespace TEAMModelOS.FunctionV4.HttpTrigger
+namespace TEAMModelOS.FunctionV4
 {
     public class ScsYxptApis
     {

+ 2 - 1
TEAMModelOS.FunctionV4/Program.cs

@@ -17,7 +17,7 @@ using System.Text.Json;
 using System.Text.RegularExpressions;
 using System.Threading;
 using System.Threading.Tasks;
-using TEAMModelOS.FunctionV4.HttpTrigger;
+using TEAMModelOS.FunctionV4;
 using TEAMModelOS.FunctionV4.ServiceBus;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
@@ -52,6 +52,7 @@ namespace TEAMModelOS.FunctionV4
                //services.Configure<Option>(options => context. Configuration.GetSection("Option").Bind(options));
                services.AddHttpClient();
                services.AddHttpClient<DingDing>();
+               services.AddHttpClient<HttpTrigger>();
                //services.AddCoreAPIHttpService(context.Configuration);
                services.AddHttpClient<CoreAPIHttpService>().ConfigureHttpMessageHandlerBuilder(builder =>
                {

+ 8 - 4
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -34,7 +34,7 @@ using DocumentFormat.OpenXml.Wordprocessing;
 using System.Xml.Linq;
 using Azure.Storage.Sas;
 using DocumentFormat.OpenXml.Drawing;
-using static TEAMModelOS.FunctionV4.HttpTrigger.IESHttpTrigger;
+using static TEAMModelOS.FunctionV4.IESHttpTrigger;
 using System.Net.Http;
 using System.Web;
 using System.Net;
@@ -61,7 +61,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
         private readonly IConfiguration _configuration;
         private readonly IConverter _converter;
         private readonly SnowflakeId _snowflakeId;
-        public ActiveTaskTopic(SnowflakeId snowflakeId, IConverter converter, CoreAPIHttpService coreAPIHttpService,
+        private readonly HttpTrigger _httpTrigger;
+        public ActiveTaskTopic(HttpTrigger httpTrigger,SnowflakeId snowflakeId, IConverter converter, CoreAPIHttpService coreAPIHttpService,
             AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis,
             AzureServiceBusFactory serviceBus, IOptionsSnapshot<Option> option,
              IConfiguration configuration)
@@ -76,6 +77,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             _coreAPIHttpService = coreAPIHttpService;
             _converter = converter;
             _snowflakeId = snowflakeId;
+            _httpTrigger=httpTrigger;
         }
         [Function("Exam")]
         public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
@@ -490,6 +492,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             try
             {
                 //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-名单成员变更-GroupChange\n{msg}", GroupNames.醍摩豆服務運維群組);
+               await _dingDing.SendBotMsg($"名单变化{msg}", GroupNames.成都开发測試群組);
                 var jsonMsg = JsonDocument.Parse(msg);
                 GroupChange groupChange = msg.ToObject<GroupChange>();
                 //名单变动修改学生课程关联信息
@@ -511,8 +514,9 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "Art");
                 //TODO学习活动
                 //await FixActivity(client, stuListChange, "Learn");
-                if (groupChange.type.Equals("class") || groupChange.type.Equals("student"))
+                if (groupChange.type.Equals("class") || groupChange.type.Equals("teach") || groupChange.type.Equals("student") )
                 {
+                    await _httpTrigger.RequestHttpTrigger(new { data = groupChange }, Environment.GetEnvironmentVariable("Option:Location"), "webhook/group-member-change");
                     if (groupChange.stujoin.Count > 0)
                         await BIStats.SetTypeAddStats(client,_dingDing, groupChange.school, "Student", groupChange.stujoin.Count);//BI统计增/减量
                     if (groupChange.stuleave.Count > 0)
@@ -525,7 +529,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                     await ActivityService.FixStuCourse(client, _dingDing, groupChange);
                     //名单变动修改课例关联信息
                     //await ActivityService.FixLessonRecord(client, _dingDing, groupChange);
-
+                   
                 }
             }
             catch (Exception ex)

+ 1 - 1
TEAMModelOS.FunctionV4/ServiceBus/ServiceBusSub.cs

@@ -14,7 +14,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Services;
-using static TEAMModelOS.FunctionV4.HttpTrigger.IESHttpTrigger;
+using static TEAMModelOS.FunctionV4.IESHttpTrigger;
 
 namespace TEAMModelOS.FunctionV4
 {

+ 7 - 6
TEAMModelOS.FunctionV4/local.settings.json

@@ -18,21 +18,22 @@
     "HaBookAuth:CoreService:clientSecret": "kguxh:V.PLmxBdaI@jnrTrDSth]A3346",
     "Option:LocationNum": 1
   }
-
   //"Values": {
   //  "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=teammodellog;AccountKey=lxVDrgs+6rKtmASL3k1WrarrEd5Rk42wS1Mu5+sqQlPya1JLSlFDtnZUvMPeHHe7zlESfn/1NY7CZdGviy2UCw==;EndpointSuffix=core.chinacloudapi.cn",
   //  "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
   //  "Azure:Storage:ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelos;AccountKey=Dl04mfZ9hE9cdPVO1UtqTUQYN/kz/dD/p1nGvSq4tUu/4WhiKcNRVdY9tbe8620nPXo/RaXxs+1F9sVrWRo0bg==;EndpointSuffix=core.chinacloudapi.cn",
+  //  "Azure:LogStorage:ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodellog;AccountKey=lxVDrgs+6rKtmASL3k1WrarrEd5Rk42wS1Mu5+sqQlPya1JLSlFDtnZUvMPeHHe7zlESfn/1NY7CZdGviy2UCw==;EndpointSuffix=core.chinacloudapi.cn",
   //  "Azure:ServiceBus:ConnectionString": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
-  //  "Azure:Cosmos:ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;",
-  //  "Azure:Redis:ConnectionString": "CoreRedisCN.redis.cache.chinacloudapi.cn:6380,password=LyJWP1ORJdv+poXWofAF97lhCEQPg1wXWqvtzXGXQuE=,ssl=True,abortConnect=False",
+  //  "Azure:Cosmos:ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;",
+  //  "Azure:Redis:ConnectionString": "52.130.252.100:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240",
   //  "Azure:ServiceBus:ActiveTask": "active-task",
   //  "Azure:ServiceBus:ItemCondQueue": "itemcond",
-  //  "Option:Location": "China-Dep",
+  //  "Azure:ServiceBus:GenPdfQueue": "genpdf",
+  //  "Option:Location": "China",
   //  "HaBookAuth:CoreService:sendnotification": "https://api2.teammodel.cn/service/sendnotification",
   //  "HaBookAuth:CoreAPI": "https://api2.teammodel.cn",
   //  "HaBookAuth:CoreService:clientID": "c7317f88-7cea-4e48-ac57-a16071f7b884",
-  //  "HaBookAuth:CoreService:clientSecret": "kguxh:V.PLmxBdaI@jnrTrDSth]A3346"
-  //  "Option:LocationNum": 2
+  //  "HaBookAuth:CoreService:clientSecret": "kguxh:V.PLmxBdaI@jnrTrDSth]A3346",
+  //  "Option:LocationNum": 1
   //}
 }

+ 3 - 4
TEAMModelOS.SDK/DI/HttpTrigger/WebHookHttpTrigger.cs

@@ -65,7 +65,7 @@ namespace TEAMModelOS.SDK.DI
                 data = _data.ToObject<SchoolAuthChange>();
             }
 
-            (List<BizConfig> businessConfigs, List<(List<string> urls, string head, string token, BizConfig config)> webhooks) = await WebHookService.GetRequestData(json, _azureCosmos, _azureRedis, _azureStorage);
+            (List<BizConfig> businessConfigs, List<(List<string> urls, string head, string token, BizConfig config)> webhooks) = await WebHookService.GetRequestData(_data, _azureCosmos, _azureRedis, _azureStorage);
             if (webhooks.IsNotEmpty())
             {
                 foreach (var webhook in webhooks)
@@ -101,9 +101,8 @@ namespace TEAMModelOS.SDK.DI
             if (json.TryGetProperty("data", out JsonElement _data)){
                 data= _data.ToObject<GroupChange>();
             }
-           
-            (List<BizConfig> businessConfigs, List<(List<string> urls, string head, string token, BizConfig config)> webhooks ) = await WebHookService.GetRequestData(json,_azureCosmos,_azureRedis,_azureStorage);
-            if (webhooks.IsNotEmpty() && string.IsNullOrWhiteSpace(data.school))
+            (List<BizConfig> businessConfigs, List<(List<string> urls, string head, string token, BizConfig config)> webhooks ) = await WebHookService.GetRequestData(_data, _azureCosmos,_azureRedis,_azureStorage);
+            if (webhooks.IsNotEmpty() && !string.IsNullOrWhiteSpace(data.school))
             {
                 foreach (var webhook in webhooks)
                 {

+ 10 - 9
TEAMModelOS.SDK/Models/Service/Common/WebHookService.cs

@@ -25,12 +25,18 @@ namespace TEAMModelOS.SDK.Models.Service
         /// <param name="data"></param>
         /// <param name="domain"></param>
         /// <param name="notice"></param>
-        public static async Task<HttpStatusCode> Send(dynamic data, (string url, string head, string token, BizConfig config) webhook, string notice, IHttpClientFactory _httpClient,DingDing _dingDing,int timeout= 60)
+        public static async Task<HttpStatusCode> Send(dynamic data, (string url, string head, string token, BizConfig config) webhook, string notice, IHttpClientFactory _httpClient,DingDing _dingDing,int timeout= 5)
         {
             try
             {
-                
                 var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                var sendData = new
+                {
+                    time = timestamp,
+                    notice = notice,
+                    data = data
+                };
+                var s = sendData.ToJsonString();
                 var client = _httpClient.CreateClient();
                 client.Timeout= new TimeSpan(0, 0, timeout);
                 if (!string.IsNullOrWhiteSpace(webhook.head) && !string.IsNullOrWhiteSpace(webhook.token))
@@ -39,12 +45,8 @@ namespace TEAMModelOS.SDK.Models.Service
                     client.DefaultRequestHeaders.Add(webhook.head, webhook.token);
                 }
             
-                HttpResponseMessage httpResponse = await client.PostAsJsonAsync($"{webhook.url}", new
-                {
-                    time = timestamp,
-                    notice = notice,
-                    data = data
-                });
+                HttpResponseMessage httpResponse = await client.PostAsJsonAsync($"{webhook.url}", sendData);
+                await _dingDing.SendBotMsg($"第三方webhook回调成功:\n企业:{webhook.config.name}({webhook.config.id})\n地址:{webhook.url}\n通知:{notice}\n数据:{sendData.ToJsonString()}", GroupNames.成都开发測試群組);
                 return httpResponse.StatusCode;
             }
             catch (Exception e)
@@ -68,7 +70,6 @@ namespace TEAMModelOS.SDK.Models.Service
             List<BizConfig> bizConfigs = new List<BizConfig>();
             try
             {
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("IESOpenApi");
                 if (json.TryGetProperty("school", out JsonElement _school) && !string.IsNullOrWhiteSpace($"{_school}"))
                 {
                     string sql = $"select distinct value c from c join s in c.schools where s.id='{_school}' and c.webhook<>null and c.webhook<>'' ";