|
@@ -1,4 +1,6 @@
|
|
|
-using Microsoft.AspNetCore.Hosting;
|
|
|
+using Azure.Storage.Blobs;
|
|
|
+using Azure.Storage.Blobs.Models;
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using System;
|
|
@@ -57,28 +59,60 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
cDay = aGInfos.Select(s => DateTimeOffset.Parse(s.time).ToString("yyyyMMdd")).First();
|
|
|
}
|
|
|
|
|
|
- Dictionary<string, object> kvList = new();
|
|
|
+ RecCnt saveCnts = new();
|
|
|
//var ipGroup = aGInfos.GroupBy(g => g.properties.clientIp).ToDictionary(k => k.Key, k => k.Count()).ToList();
|
|
|
|
|
|
List<RecGWInfo> recInfo = aGInfos.Select(s => new RecGWInfo { 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 = g.Select(h => h.hour).Distinct().ToList(), hostName = g.Select(h => h.hostName).Distinct().ToList(), ip = g.Select(i => i.ip).Distinct().ToList() }).ToList();
|
|
|
- kvList.Add("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 = g.Select(h => h.hour).Distinct().ToList(), hostName = g.Select(h => h.hostName).Distinct().ToList(), api = g.Select(i => i.api).Distinct().ToList() }).ToList();
|
|
|
- kvList.Add("ipCnt", ipCnt);
|
|
|
+ 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;
|
|
|
|
|
|
- var url = await _azureStorage.UploadFileByContainer("0-public", kvList.ToList().ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
|
|
|
+ ////保存存至Blob文件
|
|
|
+ var url = await _azureStorage.UploadFileByContainer("0-public", saveCnts.ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
|
|
|
+ var blob = _azureStorage.GetBlobContainerClient($"0-public");
|
|
|
|
|
|
- return Ok(new { state = 200, apiCon = apiCnt.Count(), apiSum = apiCnt.Select(ap => ap.count).Sum(), ipCount = ipCnt.Count, ipSum = ipCnt.Select(ip => ip.count).Sum(), ipCnt, apiCnt }); ;
|
|
|
+ List<RecCnt> recCnts = new();
|
|
|
+ await foreach (BlobItem blobItem in blob.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"visitCnt/{cDay}"))
|
|
|
+ {
|
|
|
+
|
|
|
+ BlobClient blobClient = blob.GetBlobClient(blobItem.Name);
|
|
|
+ if (await blobClient.ExistsAsync())
|
|
|
+ {
|
|
|
+ using (var meomoryStream = new MemoryStream())
|
|
|
+ {
|
|
|
+ var response = blob.GetBlobClient($"{blobItem.Name}").DownloadTo(meomoryStream);
|
|
|
+ //var response = await blob.GetBlobClient($"{blobItem.Name}").DownloadToAsync(meomoryStream);
|
|
|
+
|
|
|
+ var temps = meomoryStream.ToString();
|
|
|
+ var temp1 = Encoding.UTF8.GetString(meomoryStream.ToArray());
|
|
|
+ var temp = Encoding.UTF8.GetString(meomoryStream.ToArray()).ToObject<RecCnt>();
|
|
|
+
|
|
|
+ RecCnt recCnt = Encoding.UTF8.GetString(meomoryStream.ToArray()).ToString().ToObject<RecCnt>();
|
|
|
+ recCnts.Add(recCnt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //var url = await _azureStorage.UploadFileByContainer("0-public", kvList.ToList().ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
|
|
|
+ return Ok(new { state = 200, recCnts, apiCon = apiCnt.Count(), apiSum = apiCnt.Select(ap => ap.count).Sum(), ipCount = ipCnt.Count, ipSum = ipCnt.Select(ip => ip.count).Sum(), ipCnt, apiCnt }); ;
|
|
|
|
|
|
//return Ok(new { state = 200, cnt = recInfo.Count, apiCon = apiCnt.Count(), apiSum = apiCnt.Select(ap=> ap.count).Sum(), ipCount = ipCnt.Count, ipSum = ipCnt.Select(ip=>ip.count).Sum(), ipCnt,apiCnt, recInfo });;
|
|
|
}
|
|
|
|
|
|
+ public record RecCnt
|
|
|
+ {
|
|
|
+ public List<RecApiCnt> apiCnt { get; set; }
|
|
|
+ public List<RecIpCnt> ipCnt { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
public record RecCntBas
|
|
|
{
|
|
|
public int count { get; set; }
|
|
|
- public List<string> hour { get; set; }
|
|
|
+ public string hour { get; set; }
|
|
|
public List<string> hostName { get; set; }
|
|
|
}
|
|
|
|