CrazyIter_Bin 1 年之前
父節點
當前提交
83f642ebdd

+ 2 - 0
TEAMModelOS.FunctionV4/TimeTrigger/IESTimerTrigger.cs

@@ -56,6 +56,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
             _httpClient = httpClient;
             _ipSearcher = ipSearcher;
         }
+      
+
         /// <summary>
         /// 防火墙日志记录文件
         /// </summary>

+ 99 - 6
TEAMModelOS/Controllers/XTest/BillController.cs

@@ -72,19 +72,25 @@ namespace TEAMModelOS.Controllers.XTest
                 List<KeyBillDetail> monthData = new List<KeyBillDetail>();
                 List<DayBillDetail> dayData = new List<DayBillDetail>();
                 List<DayBillDetail> resourceGroupDataGroup = new List<DayBillDetail>();
+                List<DayBillDetail> cloudServiceDataGroup = new List<DayBillDetail>();
                 List<DayBillDetail> meterCategoryDataGroup = new List<DayBillDetail>();
                 List<DayBillDetail> consumedServiceDataGroup = new List<DayBillDetail>();
                 string BillToken = _configuration.GetValue<string>("Azure:Bill:Token");
                 List<string> times = json.GetProperty("times").ToObject<List<string>>();
 
                 List<string> ResourceGroup = new List<string>();
+                List<string> CloudService = new List<string>();
                 List<string> Product = new List<string>();
                 List<string> MeterCategory = new List<string>();
                 List<string> MeterSubCategory = new List<string>();
                 List<string> MeterName = new List<string>();
                 List<string> ConsumedService = new List<string>();
                 
-                if (json.TryGetProperty("ResourceGroup", out JsonElement _ResourceGroup)) {
+                if (json.TryGetProperty("CloudService", out JsonElement _CloudService)) {
+                    CloudService= _CloudService.ToObject<List<string>>();
+                }
+                if (json.TryGetProperty("ResourceGroup", out JsonElement _ResourceGroup))
+                {
                     ResourceGroup= _ResourceGroup.ToObject<List<string>>();
                 }
                 if (json.TryGetProperty("Product", out JsonElement _Product))
@@ -156,8 +162,42 @@ namespace TEAMModelOS.Controllers.XTest
                             var bill = content.ToObject<List<BillDetail>>();
                             //移除金额0的项目
                             bill=  bill.FindAll(x => x.ExtendedCost>0);
-                            bill.ForEach(x => { x.ResourceGroup= x.ResourceGroup.ToUpper(); });
-                            var group = bill.GroupBy(x => $"{x.Date}{x.ResourceGroup}{x.Product}{x.MeterCategory}{x.MeterSubCategory}{x.MeterName}{x.ConsumedService}").Select(x=>new { x.Key,list=x.ToList()});
+                            bill.ForEach(x => { 
+                                x.ResourceGroup= x.ResourceGroup.ToLower();
+                                x.MeterCategory=x.MeterCategory.ToLower();
+                                x.ConsumedService=x.ConsumedService.ToLower();
+                                if (string.IsNullOrWhiteSpace(x.ConsumedService)) {
+                                    x.ConsumedService="default";
+                                }
+                                if (string.IsNullOrWhiteSpace(x.ResourceGroup))
+                                {
+                                    x.ResourceGroup="default";
+                                }
+                                if (string.IsNullOrWhiteSpace(x.MeterCategory))
+                                {
+                                    x.MeterCategory="default";
+                                }
+                                if (x.ResourceGroup.Equals("teammodelchengdu")) {
+                                    x.CloudService="ies5"; 
+                                }
+                                else if (x.ResourceGroup.Equals("coreservicerg"))
+                                {
+                                    x.CloudService="core";
+                                }
+                                else if (x.ResourceGroup.Equals("mc_iesresourcegroup_sokcluster_chinaeast2")||x.ResourceGroup.Equals("iesresourcegroup"))
+                                {
+                                    x.CloudService="sokrates";
+                                }
+                                else if (x.ResourceGroup.Equals("coreserviceresourcegroupcn"))
+                                {
+                                    x.CloudService="ies3";
+                                }
+                                else 
+                                {
+                                    x.CloudService="other";
+                                }
+                            });
+                            var group = bill.GroupBy(x => $"{x.Date}{x.ResourceGroup}{x.CloudService}{x.Product}{x.MeterCategory}{x.MeterSubCategory}{x.MeterName}{x.ConsumedService}").Select(x=>new { x.Key,list=x.ToList()});
                             List<BillDetail> details = new List<BillDetail>();
                             foreach ( var item in group )
                             {
@@ -224,9 +264,27 @@ namespace TEAMModelOS.Controllers.XTest
                                     dict.Add("ConsumedService", newKey);
                                 }
                             }
+                            //CloudService 资源组
+                            {
+                                var newKey = billDetails.Select(x => x.CloudService.ToLower()).ToHashSet();
+                                if (dict.ContainsKey("CloudService"))
+                                {
+                                    var moreKey = newKey.Except(dict["CloudService"]);
+                                    foreach (var key in moreKey)
+                                    {
+                                        change=true;
+                                        dict["CloudService"].Add(key);
+                                    }
+                                }
+                                else
+                                {
+                                    change=true;
+                                    dict.Add("CloudService", newKey);
+                                }
+                            }
                             //ResourceGroup 资源组
                             {
-                                var newKey = billDetails.Select(x => x.ResourceGroup.ToUpper()).ToHashSet();
+                                var newKey = billDetails.Select(x => x.ResourceGroup.ToLower()).ToHashSet();
                                 if (dict.ContainsKey("ResourceGroup"))
                                 {
                                     var moreKey = newKey.Except(dict["ResourceGroup"]);
@@ -280,6 +338,10 @@ namespace TEAMModelOS.Controllers.XTest
                             }
                         }
                     }
+                    if (CloudService.IsNotEmpty())
+                    {
+                        billDetails=  billDetails.Where(x => CloudService.Contains(x.CloudService));
+                    }
                     if (ResourceGroup.IsNotEmpty()) {
                         billDetails=  billDetails.Where(x => ResourceGroup.Contains(x.ResourceGroup));
                     }
@@ -358,9 +420,28 @@ namespace TEAMModelOS.Controllers.XTest
                                 dictCond.Add("ConsumedService", newKey);
                             }
                         }
+                        //CloudService 资源组
+                        {
+                            var newKey = billDetails.Select(x => x.CloudService.ToLower()).ToHashSet();
+                            if (dictCond.ContainsKey("CloudService"))
+                            {
+                                var moreKey = newKey.Except(dictCond["CloudService"]);
+                                foreach (var key in moreKey)
+                                {
+                                    change=true;
+                                    dictCond["CloudService"].Add(key);
+                                }
+                            }
+                            else
+                            {
+                                change=true;
+                                dictCond.Add("CloudService", newKey);
+                            }
+                        }
+
                         //ResourceGroup 资源组
                         {
-                            var newKey = billDetails.Select(x => x.ResourceGroup.ToUpper()).ToHashSet();
+                            var newKey = billDetails.Select(x => x.ResourceGroup.ToLower()).ToHashSet();
                             if (dictCond.ContainsKey("ResourceGroup"))
                             {
                                 var moreKey = newKey.Except(dictCond["ResourceGroup"]);
@@ -428,6 +509,16 @@ namespace TEAMModelOS.Controllers.XTest
                     resourceGroupDataGroup.Add(ResourceGroupDataBillDetail);
 
 
+
+                    var CloudServiceData = billDetails.GroupBy(x => x.CloudService);
+                    DayBillDetail CloudServiceDataBillDetail = new DayBillDetail() { month= time };
+                    foreach (var group in CloudServiceData)
+                    {
+                        CloudServiceDataBillDetail.bills.Add(new KeyBillDetail() { key= group.Key, cost= group.Select(x => x.ExtendedCost).Sum() });
+                    }
+                    CloudServiceDataBillDetail.bills= CloudServiceDataBillDetail.bills.OrderByDescending(x => x.cost).ToList();
+                    cloudServiceDataGroup.Add(CloudServiceDataBillDetail);
+
                     var MeterCategoryData = billDetails.GroupBy(x => x.MeterCategory);
                     DayBillDetail MeterCategoryDataBillDetail = new DayBillDetail() { month= time };
                     foreach (var group in MeterCategoryData) {
@@ -470,7 +561,7 @@ namespace TEAMModelOS.Controllers.XTest
                 {
                     await _azureStorage.GetBlobContainerClient("teammodelos").UploadFileByContainer(dict.ToJsonString(), "bill", $"dict.json", true);
                 }
-                return Ok(new {   monthData, dayData, dict, dictCond, code=200, consumedServiceDataGroup ,meterCategoryDataGroup,resourceGroupDataGroup});
+                return Ok(new {   monthData, dayData, dict, dictCond, code=200, consumedServiceDataGroup ,meterCategoryDataGroup, cloudServiceDataGroup, resourceGroupDataGroup});
 
 
             } catch (Exception ex) {
@@ -617,6 +708,8 @@ namespace TEAMModelOS.Controllers.XTest
             /// 
             /// </summary>
             public string ResourceGroup { get; set; }
+            public string CloudService { get; set; }
+            public string CloudServiceName { get; set; }
         }
 
     }

+ 2 - 3
TEAMModelOS/Startup.cs

@@ -194,7 +194,7 @@ namespace TEAMModelOS
             services.AddXkwAPIHttpService(Configuration);
             //services.AddHostedService<>
             //services.AddSingleton<ILoggerProvider, BlobLoggerProvider>();
-            // services.AddMvcFilter<RequestAuditFilter>();
+            //services.AddMvcFilter<RequestAuditFilter>();
             services.AddNetMail(Configuration.GetSection("MailOption").Get<MailOptions>());
 #if !DEBUG
  //第一步: 配置gzip与br的压缩等级为最优
@@ -259,10 +259,9 @@ namespace TEAMModelOS
             app.UseSpaStaticFiles();            
             
             app.UseRouting();
-
+            
             app.UseCors(MyAllowSpecificOrigins); //使用跨域設定
             app.UseHttpsRedirection(); //開發中暫時關掉
-
             //如果应用使用身份验证/授权功能(如 AuthorizePage 或 [Authorize]),请将对 UseAuthentication 和 UseAuthorization的
             //调用放在之后、UseRouting 和 UseCors,但在 UseEndpoints之前
             app.UseAuthentication();