浏览代码

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

liqk 2 年之前
父节点
当前提交
a96417b894

+ 10 - 1
TEAMModelOS.FunctionV4/Program.cs

@@ -13,6 +13,7 @@ using System.Threading.Tasks;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.DI.Multiple;
 using TEAMModelOS.SDK.Models.Service;
 
 namespace TEAMModelOS.FunctionV4
@@ -45,10 +46,18 @@ namespace TEAMModelOS.FunctionV4
                services.AddCoreAPIHttpService(context.Configuration);
                services.AddAzureCosmos(context.Configuration.GetSection("Azure:Cosmos:ConnectionString").Get<string>());
                services.AddAzureServiceBus(context.Configuration.GetSection("Azure:ServiceBus:ConnectionString").Get<string>());
-               services.AddAzureStorage(context.Configuration.GetSection("Azure:Storage:ConnectionString").Get<string>());
+              
                services.AddAzureRedis(context.Configuration.GetSection("Azure:Redis:ConnectionString").Get<string>());
                services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
                services.AddSnowflakeId(Convert.ToInt64(context.Configuration.GetSection("Option:LocationNum").Get<Int32>()), 1);
+               List<(string name, string connectionString)> storageConnects = new();
+
+               storageConnects.Add(("Default", context.Configuration.GetSection("Azure:Storage:ConnectionString").Get<string>()));      
+               string LogStorageConnectionString = context.Configuration.GetSection("Azure:LogStorage:ConnectionString").Get<string>(); //防火墙日志统计文件
+               if (!string.IsNullOrWhiteSpace(LogStorageConnectionString)) {
+                   storageConnects.Add(("LogStorage", LogStorageConnectionString));   //防火墙日志统计文件
+               }
+               services.AddMultipleAzureStorage(storageConnects);
            })
            .Build();
             await host.RunAsync();

+ 2 - 1
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1370,6 +1370,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     // await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 收到更新", GroupNames.醍摩豆服務運維群組);
                                     BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{_lessonId}/IES/base.json").DownloadContentAsync();
                                     LessonBase lessonBase = baseblobDownload.Content.ToObjectFromJson<LessonBase>();
+                                    await  _dingDing.SendBotMsg($"课例记录文件base.json:{lessonBase.ToJsonString()}", GroupNames.成都开发測試群組);
                                     if (lessonBase != null && lessonBase.summary != null)
                                     {
                                         //lessonRecord.name = lessonBase.summary.activityName;
@@ -1447,7 +1448,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                 }
                                 catch (Exception ex)
                                 {
-                                    // await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}课程读取base.json,{_lessonId}\n{ex.Message}\n{ex.StackTrace}\n\n{lessonRecord.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                                    await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}课程读取base.json,{_lessonId}\n{ex.Message}\n{ex.StackTrace}\n\n{lessonRecord.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                                 }
                                 break;
                             //更新 时间线

+ 3 - 3
TEAMModelOS.FunctionV4/TEAMModelOS.FunctionV4.csproj

@@ -5,9 +5,9 @@
 		<OutputType>Exe</OutputType>
 		<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
 		<SignAssembly>true</SignAssembly>
-		<Version>5.2207.6</Version>
-		<AssemblyVersion>5.2207.6.1</AssemblyVersion>
-		<FileVersion>5.2207.6.1</FileVersion>
+		<Version>5.2207.13</Version>
+		<AssemblyVersion>5.2207.13.1</AssemblyVersion>
+		<FileVersion>5.2207.13.1</FileVersion>
 		<PackageId>TEAMModelOS.FunctionV4</PackageId>
 		<Authors>teammodel</Authors>
 		<Company>醍摩豆(成都)信息技术有限公司</Company>

+ 10 - 8
TEAMModelOS.FunctionV4/HttpTrigger/IESTimerTrigger.cs

@@ -24,7 +24,7 @@ using TEAMModelOS.SDK.Models.Service.BI;
 using TEAMModelOS.SDK.Models.Table;
 using static TEAMModelOS.SDK.Models.Teacher;
 
-namespace TEAMModelOS.FunctionV4.HttpTrigger
+namespace TEAMModelOS.FunctionV4.TimeTrigger
 {
     public class IESTimerTrigger
     {
@@ -43,12 +43,14 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
           /// <param name="req"></param>
           /// <param name="log"></param>
           /// <returns></returns>
-        [Function("FireWallFileLog")]
-        //https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
-        //一天中每小时的第 1 分钟
-        public async Task FireWallFileLog([TimerTrigger("0 1 * * * *")] TimerInfo myTimer, ILogger log) {
-            await _dingDing.SendBotMsg($"FireWallFileLog 防火墙日志记录(测试): {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}", GroupNames.成都开发測試群組);
-            BILogAnalyseService.GetPathAnalyse(_azureStorage,"",);
-        }
+        //[Function("FireWallFileLog")]
+        ////https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
+        ////0 1 * * * * 一天中每小时的第 1 分钟
+        ////0 */1 * * * *  每五分钟一次
+        //public async Task FireWallFileLog([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
+        //{
+        //    await _dingDing.SendBotMsg($"FireWallFileLog 防火墙日志记录(测试): {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}", GroupNames.成都开发測試群組);
+        //    await BILogAnalyseService.GetPathAnalyse(_azureStorage,"", "LogStorage");
+        //}
     }
 }

+ 1 - 1
TEAMModelOS.FunctionV4/local.settings.json

@@ -4,7 +4,7 @@
     "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=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn",
-    "Azure:LogStorage:ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodellog;AccountKey=lxVDrgs+6rKtmASL3k1WrarrEd5Rk42wS1Mu5+sqQlPya1JLSlFDtnZUvMPeHHe7zlESfn/1NY7CZdGviy2UCw==;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://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
     "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",

+ 44 - 41
TEAMModelOS.SDK/Models/Service/BI/BILogAnalyseService.cs

@@ -95,62 +95,65 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="path">防火墙路径</param>
         /// <param name="connectStr">连接字串</param>
         /// <returns></returns>
-        public static async Task<(List<RecCnt> recCnts, List<string> saveUrls)> GetPathAnalyse(AzureStorageFactory _azureStorage,string path, string connectStr)
+        public static async Task<(List<RecCnt> recCnts, List<string> saveUrls)> GetPathAnalyse(AzureStorageFactory _azureStorage,string path, string connectName)
         {
-            var blobClient = _azureStorage.GetBlobContainerClient($"insights-logs-applicationgatewayfirewalllog", name: connectStr);
-
             List<RecCnt> recCnts = new();
             List<string> urls = new();
 
-            await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
-            {
-                StringBuilder visits = new("[");
-                //BlobClient tempBlobClient = blobClient.GetBlobClient(blobItem.Name);
-                //BlobDownloadInfo download = tempBlobClient.Download();
-                BlobDownloadInfo download = blobClient.GetBlobClient(blobItem.Name).Download();
-
-                var content = download.Content;
-                string text;
-                using (var streamReader = new StreamReader(content))
+            try {
+                var blobClient = _azureStorage.GetBlobContainerClient($"insights-logs-applicationgatewayfirewalllog", name: connectName);
+                await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
                 {
-                    while ((text = streamReader.ReadLine()) != null)
+                    StringBuilder visits = new("[");
+                    //BlobClient tempBlobClient = blobClient.GetBlobClient(blobItem.Name);
+                    //BlobDownloadInfo download = tempBlobClient.Download();
+                    BlobDownloadInfo download = blobClient.GetBlobClient(blobItem.Name).Download();
+
+                    var content = download.Content;
+                    string text;
+                    using (var streamReader = new StreamReader(content))
                     {
-                        if (streamReader.EndOfStream)
-                            visits.Append($"{text.ToString()}");
-                        else
-                            visits.Append($"{text.ToString()},");
+                        while ((text = streamReader.ReadLine()) != null)
+                        {
+                            if (streamReader.EndOfStream)
+                                visits.Append($"{text.ToString()}");
+                            else
+                                visits.Append($"{text.ToString()},");
+                        }
+
+                        visits.Append("]");
+                        streamReader.Close();
                     }
 
-                    visits.Append("]");
-                    streamReader.Close();
-                }
+                    string input = visits.ToString();
+                    List<AGInfo> aGInfos = input.ToObject<List<AGInfo>>();
+                    DateTimeOffset dtime = DateTimeOffset.UtcNow;
+                    string cHour = dtime.ToString("yyyyMMddHH");
+                    string cDay = dtime.ToString("yyyyMMdd");
+                    if (aGInfos.Count > 0)
+                    {
+                        cHour = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMddHH")).First();
+                        cDay = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMdd")).First();
+                    }
 
-                string input = visits.ToString();
-                List<AGInfo> aGInfos = input.ToObject<List<AGInfo>>();
-                DateTimeOffset dtime = DateTimeOffset.UtcNow;
-                string cHour = dtime.ToString("yyyyMMddHH");
-                string cDay = dtime.ToString("yyyyMMdd");
-                if (aGInfos.Count > 0)
-                {
-                    cHour = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMddHH")).First();
-                    cDay = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMdd")).First();
-                }
+                    RecCnt saveCnts = new();
 
-                RecCnt saveCnts = new();
+                    List<RecAppGWInfo> recInfo = aGInfos.Select(s => new RecAppGWInfo { hour = cHour, ip = s.properties.clientIp, api = s.properties.requestUri.Split("?").ToList().Count() > 1 ? s.properties.requestUri.Split("?").ToList()[0] : s.properties.requestUri, hostName = s.properties.hostname }).ToList();
 
-                List<RecAppGWInfo> recInfo = aGInfos.Select(s => new RecAppGWInfo { hour = cHour, ip = s.properties.clientIp, api = s.properties.requestUri.Split("?").ToList().Count() > 1 ? s.properties.requestUri.Split("?").ToList()[0] : s.properties.requestUri, hostName = s.properties.hostname }).ToList();
+                    List<RecApiCnt> apiCnt = recInfo.GroupBy(a => a.api).Select(g => new RecApiCnt { api = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), ip = g.Select(i => i.ip).Distinct().ToList() }).ToList();
+                    saveCnts.apiCnt = apiCnt;
 
-                List<RecApiCnt> apiCnt = recInfo.GroupBy(a => a.api).Select(g => new RecApiCnt { api = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), ip = g.Select(i => i.ip).Distinct().ToList() }).ToList();
-                saveCnts.apiCnt = apiCnt;
+                    List<RecIpCnt> ipCnt = recInfo.GroupBy(a => a.ip).Select(g => new RecIpCnt { ip = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), api = g.Select(i => i.api).Distinct().ToList() }).ToList();
+                    saveCnts.ipCnt = ipCnt;
+                    recCnts.Add(saveCnts);
 
-                List<RecIpCnt> ipCnt = recInfo.GroupBy(a => a.ip).Select(g => new RecIpCnt { ip = g.Key, count = g.Count(), hour = cHour, hostName = g.Select(h => h.hostName).Distinct().ToList(), api = g.Select(i => i.api).Distinct().ToList() }).ToList();
-                saveCnts.ipCnt = ipCnt;
-                recCnts.Add(saveCnts);
+                    ////保存存至Blob文件
+                    var url = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(saveCnts.ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
 
-                ////保存存至Blob文件
-                var url = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(saveCnts.ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
+                    urls.Add(url);
+                }
+            } catch (Exception ex) { 
 
-                urls.Add(url);
             }
 
             return (recCnts, urls);

+ 11 - 3
TEAMModelOS/Controllers/Client/HiTAControlller.cs

@@ -282,12 +282,15 @@ namespace TEAMModelOS.Controllers.Client
                                     }
                                 }
                             }
-
+                           
+                          
                             //學校資料生成
                             dynamic schoolExtobj = new ExpandoObject();
                             var schoolJson = await clientc.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{obj.GetProperty("schoolId")}", new PartitionKey("Base"));
                             var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
-                            schoolExtobj.schoolId = obj.GetProperty("schoolId");
+                            try
+                            {
+                                schoolExtobj.schoolId = obj.GetProperty("schoolId");
                             schoolExtobj.name = school.RootElement.GetProperty("name");
                             schoolExtobj.region = school.RootElement.GetProperty("region");
                             schoolExtobj.province = school.RootElement.GetProperty("province");
@@ -303,6 +306,11 @@ namespace TEAMModelOS.Controllers.Client
                             schoolExtobj.courses = coursesch;
 
                             schools.Add(schoolExtobj);
+                            }
+                            catch (Exception)
+                            {
+                                await _dingDing.SendBotMsg($"IES5,{_option.Location},HiTA/Debug()\nJson:{schoolJson}\n schoolExtobj:{schoolExtobj}", GroupNames.醍摩豆服務運維群組);
+                            }
                         }
                     }
                     //預設學校
@@ -484,7 +492,7 @@ namespace TEAMModelOS.Controllers.Client
             }
             catch (Exception ex)
             {
-                //await _dingDing.SendBotMsg($"CoreAPI2,{_option.Location},Channel/Create()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"IES5,{_option.Location},HiTA/GetTeachInfo()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
         }

+ 2 - 2
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -620,7 +620,7 @@ namespace TEAMModelOS.Controllers.Client
             }
             catch (Exception ex)
             {
-                // await _dingDing.SendBotMsg($"CoreAPI2,{_option.Location},hiteach/GetTeacherInfo()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"IES5,{_option.Location},hiteach/GetTeacherInfo()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
         }
@@ -947,7 +947,7 @@ namespace TEAMModelOS.Controllers.Client
             }
             catch (Exception ex)
             {
-                // await _dingDing.SendBotMsg($"CoreAPI2,{_option.Location},hiteach/GetTeacherInfo()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"IES5,{_option.Location},hiteach/GetSchoolInfo()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
         }

+ 3 - 3
TEAMModelOS/TEAMModelOS.csproj

@@ -39,9 +39,9 @@
     <SpaRoot>ClientApp\</SpaRoot>
     <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
     <UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
-    <Version>5.2207.6</Version>
-    <AssemblyVersion>5.2207.6.1</AssemblyVersion>
-    <FileVersion>5.2207.6.1</FileVersion>
+    <Version>5.2207.13</Version>
+    <AssemblyVersion>5.2207.13.1</AssemblyVersion>
+    <FileVersion>5.2207.13.1</FileVersion>
     <Description>TEAMModelOS(IES5)</Description>
     <PackageReleaseNotes>IES版本说明版本切换标记202200701</PackageReleaseNotes>
     <PackageId>TEAMModelOS</PackageId>