123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using Azure.Storage.Blobs.Models;
- using Azure.Storage.Blobs.Specialized;
- using HTEX.Complex.Service.AzureRedis;
- using System.Collections.Concurrent;
- using System.Text;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using static HTEX.Complex.Service.SystemService;
- namespace HTEX.Complex.Service.CoreHangfire
- {
- public class VisitSettleJob
- {
- private readonly IConfiguration _configuration;
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureStorageFactory _azureStorage;
- private readonly DingDing _dingDing;
- private readonly IPSearcher _ipSearcher;
- private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
- public VisitSettleJob(Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator,IPSearcher ipSearcher, DingDing dingDing,IConfiguration configuration, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage)
- {
- _azureRedis = azureRedis;
- _configuration = configuration;
- _azureStorage = azureStorage;
- _dingDing=dingDing;
- _ipSearcher=ipSearcher;
- _longitudeLatitudeTranslator=longitudeLatitudeTranslator;
- }
- public async Task Run()
- {
- var gmt8Time = DateTimeOffset.Now.GetGMTTime(8).AddHours(-1);
- await _dingDing.SendBotMsg($"{DateTimeOffset.Now.GetGMTTime(8):yyyy-MM-dd HH:mm:ss}Http日志访问统计开始,统计时间:{gmt8Time:yyyy-MM-dd HH}", GroupNames.成都开发測試群組);
- try
- {
- // string location = _configuration.GetValue<string>("Option:Location");
- //获取上一个小时的数据
- var appendBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/{gmt8Time:HH}.log");
- if (await appendBlob.ExistsAsync())
- {
- BlobDownloadResult result = await appendBlob.DownloadContentAsync();
- var content = result.Content.ToString();
- content= content.Substring(0, content.Length-2);
- if (content.EndsWith("}"))
- {
- content=$"[{content}]";
- }
- else
- {
- content=$"[{content}}}]";
- }
- var httpLogList = content.ToObject<List<HttpLog>>();
- (ConcurrentBag<ApiVisit> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) =
- await SystemService.ConvertHttpLog(httpLogList, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator, gmt8Time);
- if (vists!=null && vists.Count>0)
- {
- var appendDayBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/index.log");
- if (!await appendDayBlob.ExistsAsync())
- {
- await appendDayBlob.CreateAsync();
- }
- StringBuilder sb = new StringBuilder();
- foreach (var item in vists)
- {
- sb.Append($"{item.ToJsonString()},\n");
- }
- using (var stream = new MemoryStream(Encoding.UTF8.GetBytes($"{sb}")))
- {
- await appendDayBlob.AppendBlockAsync(stream);
- }
- }
- }
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"日志访问统计异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- }
- await _dingDing.SendBotMsg($"{DateTimeOffset.Now.GetGMTTime(8):yyyy-MM-dd HH:mm:ss}Http日志访问统计结束,统计时间:{gmt8Time:yyyy-MM-dd HH}", GroupNames.成都开发測試群組);
- }
- }
- }
|