1
This commit is contained in:
63
IDIS_Server-SIM/Data/QueryService.cs
Normal file
63
IDIS_Server-SIM/Data/QueryService.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using IDIS.Models;
|
||||
using IDIS.Services;
|
||||
using IDIS.Services.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IDIS_Server_SIM.Data;
|
||||
|
||||
public class QueryService:DbContext
|
||||
{
|
||||
private readonly IDIS_Service _service;
|
||||
private readonly IDIS_Statistics_MySQLBased _statistics;
|
||||
|
||||
public QueryService(IDIS_Service service, IDIS_Statistics_MySQLBased statistics)
|
||||
{
|
||||
_service = service;
|
||||
_statistics = statistics;
|
||||
}
|
||||
|
||||
private DbSet<IDIS_SQL_Data> values { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
var connectionString = BITKit.Data.Get<string>("DefaultConnection");
|
||||
|
||||
optionsBuilder.UseMySQL(connectionString);
|
||||
|
||||
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll);
|
||||
}
|
||||
public async UniTask<IDIS_QueryRecord[]> QueryRecordsByTag(bool today=false,params string[] tags)
|
||||
{
|
||||
var handles = await QueryByTag(today,tags);
|
||||
var record = (await _statistics.queryRecords.ToArrayAsync())
|
||||
.Where(x => handles.Contains(x.Handle))
|
||||
.OrderBy(x=>x.QueryTime)
|
||||
.DistinctBy(x=>x.Handle);
|
||||
return record.ToArray();
|
||||
}
|
||||
public async UniTask<string[]> QueryByTag(bool today = false,params string[] tags)
|
||||
{
|
||||
var tagRecords =
|
||||
(await values.ToArrayAsync())
|
||||
.Where(x => x.Type is "Tags" or "tags")
|
||||
.DistinctBy(x=>x.Handle);
|
||||
|
||||
var list = new List<string>();
|
||||
|
||||
foreach (var x in tagRecords)
|
||||
{
|
||||
if (today)
|
||||
{
|
||||
if(x.CreateTime.Day != DateTime.Now.Day)
|
||||
continue;
|
||||
}
|
||||
if(string.IsNullOrEmpty(x.Value))continue;
|
||||
var currentTags = x.Value.Split(";");
|
||||
if (tags.All(currentTags.Contains))
|
||||
list.Add(x.Handle);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user