|
@@ -8,6 +8,7 @@ using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
|
|
|
@@ -18,10 +19,12 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
public class AnalyseFileController : ControllerBase
|
|
public class AnalyseFileController : ControllerBase
|
|
{
|
|
{
|
|
private readonly IWebHostEnvironment _environment; //读取文件流
|
|
private readonly IWebHostEnvironment _environment; //读取文件流
|
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
|
|
|
- public AnalyseFileController(IWebHostEnvironment environment)
|
|
|
|
|
|
+ public AnalyseFileController(IWebHostEnvironment environment, AzureStorageFactory azureStorage)
|
|
{
|
|
{
|
|
_environment = environment;
|
|
_environment = environment;
|
|
|
|
+ _azureStorage = azureStorage;
|
|
}
|
|
}
|
|
|
|
|
|
[HttpPost("get-visitjson")]
|
|
[HttpPost("get-visitjson")]
|
|
@@ -45,21 +48,52 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
streamReader.Close();
|
|
streamReader.Close();
|
|
string input = visits.ToString();
|
|
string input = visits.ToString();
|
|
List<AGInfo> aGInfos = input.ToObject<List<AGInfo>>();
|
|
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();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ Dictionary<string, object> kvList = new();
|
|
//var ipGroup = aGInfos.GroupBy(g => g.properties.clientIp).ToDictionary(k => k.Key, k => k.Count()).ToList();
|
|
//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 = DateTimeOffset.Parse(s.time).ToString("yyyyMMddHH"), 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<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();
|
|
|
|
|
|
- var apiCnt = recInfo.GroupBy(a => a.api).Select(g => new { api = g.Key, count = g.Count(), hour = g.Select(h => h.hour).First(), hostName = g.Select(h => h.hostName).First(), ip = g.Select(i => i.ip).First() }).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<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);
|
|
|
|
|
|
- var ipCnt = recInfo.GroupBy(a => a.ip).Select(g => new { ip = g.Key, count = g.Count(), hour = g.Select(h => h.hour).First(), hostName = g.Select(h => h.hostName).First(), api = g.Select(i => i.api).First() }).ToList();
|
|
|
|
-
|
|
|
|
|
|
+ var url = await _azureStorage.UploadFileByContainer("0-public", kvList.ToList().ToJsonString(), $"visitCnt/{cDay}", $"{cHour}.json");
|
|
|
|
|
|
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 }); ;
|
|
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 }); ;
|
|
|
|
|
|
//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 });;
|
|
//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 RecCntBas
|
|
|
|
+ {
|
|
|
|
+ public int count { get; set; }
|
|
|
|
+ public List<string> hour { get; set; }
|
|
|
|
+ public List<string> hostName { get; set; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public record RecIpCnt : RecCntBas
|
|
|
|
+ {
|
|
|
|
+ public string ip { get; set; }
|
|
|
|
+ public List<string> api { get; set; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public record RecApiCnt : RecCntBas
|
|
|
|
+ {
|
|
|
|
+ public string api { get; set; }
|
|
|
|
+ public List<string> ip { get; set; }
|
|
|
|
+ }
|
|
|
|
+
|
|
public record RecGWInfo
|
|
public record RecGWInfo
|
|
{
|
|
{
|
|
public string hour { get; set; }
|
|
public string hour { get; set; }
|