This commit is contained in:
parent
0c573029b3
commit
fdf263a308
|
@ -0,0 +1,105 @@
|
||||||
|
using System.Data.Entity;
|
||||||
|
using BITKit;
|
||||||
|
using IDIS;
|
||||||
|
using IDIS_Server_SIM.Data;
|
||||||
|
using IDIS_Server_SIM.Extensions;
|
||||||
|
using IDIS.Models;
|
||||||
|
using IDIS.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace IDIS_Server_SIM.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
public class IDIS_QueryController:Controller
|
||||||
|
{
|
||||||
|
private readonly IDIS_Statistics_MySQLBased _statisticsService;
|
||||||
|
private readonly IDIS_Service_MySQLBased _service;
|
||||||
|
private readonly QueryService _queryService;
|
||||||
|
private readonly ILogger<IDIS_QueryController> _logger;
|
||||||
|
public IDIS_QueryController(IDIS_Statistics_MySQLBased statisticsService, ILogger<IDIS_QueryController> logger, QueryService queryService, IDIS_Service_MySQLBased service)
|
||||||
|
{
|
||||||
|
_statisticsService = statisticsService;
|
||||||
|
_logger = logger;
|
||||||
|
_queryService = queryService;
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询当日的解析的标识
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Route("/api/query/today")]
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetTodayQuery()
|
||||||
|
{
|
||||||
|
var result = await _statisticsService.GetTodayQuery();
|
||||||
|
|
||||||
|
return new IDIS_Response(result).ToActionResult();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询该标识的解析次数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">标识码,标识码为null则是查询所有表示的解析次数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Route("/api/query/count")]
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetQueryCount(string handle=null)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(handle))
|
||||||
|
{
|
||||||
|
var result =await EntityFrameworkQueryableExtensions.ToArrayAsync(_statisticsService.queryCounter);
|
||||||
|
return new IDIS_Response(result).ToActionResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var result = await _statisticsService.GetQueryCount(handle);
|
||||||
|
return new IDIS_Response(result).ToActionResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有标识的解析次数综合
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route(("/api/query/all_count"))]
|
||||||
|
public async Task<IActionResult> GetQueryAllCount()
|
||||||
|
{
|
||||||
|
return new IDIS_Response(await _statisticsService.GetAllQueryCount()).ToActionResult();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取所有标识的数量
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route(("/api/all_count"))]
|
||||||
|
public IActionResult GetAllCount()
|
||||||
|
{
|
||||||
|
var count = _service.handles.Count();
|
||||||
|
return new IDIS_Response(count).ToActionResult();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过标签查询标识
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tags">标签,多个标签使用;分隔</param>
|
||||||
|
/// <param name="today">是否仅查询今日的标识</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route(("/api/query/by"))]
|
||||||
|
public async Task<IActionResult> GetQueryByTag(string tags,bool today=false)
|
||||||
|
{
|
||||||
|
return new IDIS_Response(await _queryService.QueryByTag(today,tags.Split(";"))).ToActionResult();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过Tag获取解析记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tags">标签,多个标签使用;分隔</param>
|
||||||
|
/// <param name="today">是否仅查询今日的标识</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route(("/api/queryRecords/by"))]
|
||||||
|
public async Task<IActionResult> GetQueryRecordsByTag(string tags, bool today = false)
|
||||||
|
{
|
||||||
|
return new IDIS_Response(await _queryService.QueryRecordsByTag(today,tags.Split(";"))).ToActionResult();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,15 +15,51 @@ public class IDIS_ServiceController:Controller
|
||||||
{
|
{
|
||||||
_service = service;
|
_service = service;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取服务器信息
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>主机名称</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("info")]
|
[Route("info")]
|
||||||
public IActionResult Info()
|
public IActionResult Info()
|
||||||
{
|
{
|
||||||
return new ContentResult
|
return Ok(new IDIS_Response(Environment.MachineName));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 一次解析所有标识
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>所有标识的数组</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("/identityv2/data/detail/all")]
|
||||||
|
public async Task<IActionResult> QueryAll()
|
||||||
{
|
{
|
||||||
Content = Environment.MachineName
|
try
|
||||||
|
{
|
||||||
|
var result = await _service.ToArrayAsync();
|
||||||
|
var response = new IDIS_Response(result);
|
||||||
|
var json = JsonConvert.SerializeObject(response);
|
||||||
|
//return Ok(JsonConvert.SerializeObject(response));
|
||||||
|
return new ContentResult()
|
||||||
|
{
|
||||||
|
Content = json,
|
||||||
|
ContentType = "application/json",
|
||||||
|
StatusCode = 200
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return BadRequest(new IDIS_Response(e.Message,false)
|
||||||
|
{
|
||||||
|
Status = 2
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析表示
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">标识码</param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("/identityv2/data/detail")]
|
[Route("/identityv2/data/detail")]
|
||||||
public async Task<IActionResult> Query(string handle)
|
public async Task<IActionResult> Query(string handle)
|
||||||
|
@ -49,14 +85,21 @@ public class IDIS_ServiceController:Controller
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询标识是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="code">标识码</param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("isExist")]
|
[Route("isExist")]
|
||||||
public async Task<IActionResult> IsExist(string code)
|
public async Task<IActionResult> IsExist(string code)
|
||||||
{
|
{
|
||||||
return Ok(new IDIS_Response(await _service.IsExistAsync(code)));
|
return Ok(new IDIS_Response(await _service.IsExistAsync(code)));
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 注册标识
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("/identityv2/data")]
|
[Route("/identityv2/data")]
|
||||||
public async Task<IActionResult> Register()
|
public async Task<IActionResult> Register()
|
||||||
|
@ -78,12 +121,21 @@ public class IDIS_ServiceController:Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 更新标识(目前不可用)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("update")]
|
[Route("update")]
|
||||||
public string Update()
|
public string Update()
|
||||||
{
|
{
|
||||||
return "err:0";
|
return "err:0";
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除标识
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="code">标识码</param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("delete")]
|
[Route("delete")]
|
||||||
public async Task<bool> Delete (string code)
|
public async Task<bool> Delete (string code)
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
using BITKit;
|
|
||||||
using IDIS;
|
|
||||||
using IDIS_Server_SIM.Extensions;
|
|
||||||
using IDIS.Models;
|
|
||||||
using IDIS.Services;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace IDIS_Server_SIM.Controllers;
|
|
||||||
|
|
||||||
[ApiController]
|
|
||||||
public class IDIS_StatisticsController:Controller
|
|
||||||
{
|
|
||||||
private readonly IDIS_Statistics_MySQLBased _service;
|
|
||||||
private readonly ILogger<IDIS_StatisticsController> _logger;
|
|
||||||
public IDIS_StatisticsController(IDIS_Statistics_MySQLBased service, ILogger<IDIS_StatisticsController> logger)
|
|
||||||
{
|
|
||||||
_service = service;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/api/query/today")]
|
|
||||||
public async Task<IActionResult> GetTodayQuery()
|
|
||||||
{
|
|
||||||
var result = await _service.GetTodayQuery();
|
|
||||||
|
|
||||||
return new IDIS_Response(result).ToActionResult();
|
|
||||||
}
|
|
||||||
[Route("/api/query/count")]
|
|
||||||
public async Task<IActionResult> GetQueryCount(string handle)
|
|
||||||
{
|
|
||||||
var result = await _service.GetQueryCount(handle);
|
|
||||||
|
|
||||||
return new IDIS_Response(result).ToActionResult();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,7 +19,12 @@ public class IDIS_TemplateController:Controller
|
||||||
_service = service;
|
_service = service;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询标识模板
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prefix">前缀,例如88.123.99</param>
|
||||||
|
/// <param name="version">版本,例如v0.0.1</param>
|
||||||
|
/// <returns></returns>
|
||||||
[Route("/snms/api/template/v1")]
|
[Route("/snms/api/template/v1")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Query(string prefix, string version)
|
public async Task<IActionResult> Query(string prefix, string version)
|
||||||
|
@ -36,7 +41,10 @@ public class IDIS_TemplateController:Controller
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存标识模板
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[Route("/snms/api/template/v1")]
|
[Route("/snms/api/template/v1")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Save()
|
public async Task<IActionResult> Save()
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma warning disable SYSLIB1045
|
#pragma warning disable SYSLIB1045
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using BITKit;
|
using BITKit;
|
||||||
|
using IDIS_Server_SIM.Data;
|
||||||
using IDIS.Services;
|
using IDIS.Services;
|
||||||
|
|
||||||
await BITAppForNet.InitializeAsync("IDIS");
|
await BITAppForNet.InitializeAsync("IDIS");
|
||||||
|
@ -21,39 +22,47 @@ var cancellationTokenSource = new System.Threading.CancellationTokenSource();
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen(x =>
|
||||||
|
{
|
||||||
|
var currentDirectory = AppContext.BaseDirectory;
|
||||||
|
x.IncludeXmlComments(currentDirectory + "/IDIS_Server-SIM.xml",true);
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddTransient<IDIS_Service, IDIS_Service_MySQLBased>();
|
builder.Services.AddTransient<IDIS_Service, IDIS_Service_MySQLBased>();
|
||||||
|
|
||||||
|
builder.Services.AddTransient<IDIS_Service_MySQLBased>();
|
||||||
|
|
||||||
builder.Services.AddTransient<IDIS_Statistics_MySQLBased>();
|
builder.Services.AddTransient<IDIS_Statistics_MySQLBased>();
|
||||||
|
|
||||||
|
builder.Services.AddTransient<QueryService>();
|
||||||
|
|
||||||
builder.Services.AddTransient<IDIS_TemplateService, IDIS_TemplateService_MySQLBased>();
|
builder.Services.AddTransient<IDIS_TemplateService, IDIS_TemplateService_MySQLBased>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
var logger = app.Services.GetRequiredService<ILogger<Program>>();
|
var logger = app.Services.GetRequiredService<ILogger<Program>>();
|
||||||
|
|
||||||
#region 输入二级节点地址
|
// #region 输入二级节点地址
|
||||||
|
//
|
||||||
logger.LogInformation("请输入二级节点地址,例如:88.123.99");
|
// logger.LogInformation("请输入二级节点地址,例如:88.123.99");
|
||||||
string? str;
|
// string? str;
|
||||||
while (true)
|
// while (true)
|
||||||
{
|
// {
|
||||||
str = Console.ReadLine();
|
// str = Console.ReadLine();
|
||||||
if (string.IsNullOrEmpty(str))
|
// if (string.IsNullOrEmpty(str))
|
||||||
{
|
// {
|
||||||
str = "88.123.99";
|
// str = "88.123.99";
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
const string pattern =@"^\d{1,3}\.\d{1,3}\.\d{1,3}$"; // 正则表达式模式
|
// const string pattern =@"^\d{1,3}\.\d{1,3}\.\d{1,3}$"; // 正则表达式模式
|
||||||
if (Regex.IsMatch(str,pattern))
|
// if (Regex.IsMatch(str,pattern))
|
||||||
{
|
// {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
logger.LogInformation("错误的地址格式,请按照正确格式输入,例如:88.123.99");
|
// logger.LogInformation("错误的地址格式,请按照正确格式输入,例如:88.123.99");
|
||||||
}
|
// }
|
||||||
logger.LogInformation("输入的地址符合要求。");
|
// logger.LogInformation("输入的地址符合要求。");
|
||||||
|
//
|
||||||
#endregion
|
// #endregion
|
||||||
|
|
||||||
var idis_Service = app.Services.GetRequiredService<IDIS_Service>();
|
var idis_Service = app.Services.GetRequiredService<IDIS_Service>();
|
||||||
//idis_Service.PreAddress = str!;
|
//idis_Service.PreAddress = str!;
|
||||||
|
@ -61,10 +70,12 @@ var idis_Service = app.Services.GetRequiredService<IDIS_Service>();
|
||||||
app.Services.GetRequiredService<IDIS_Statistics_MySQLBased>();
|
app.Services.GetRequiredService<IDIS_Statistics_MySQLBased>();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
|
||||||
|
//if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.MapGet("/", () => "Hello World!");
|
app.MapGet("/", () => "Hello World!");
|
||||||
|
|
|
@ -8,12 +8,15 @@
|
||||||
- [x] 删除标识
|
- [x] 删除标识
|
||||||
- [x] 查询数据模板
|
- [x] 查询数据模板
|
||||||
- [x] 保存数据模板
|
- [x] 保存数据模板
|
||||||
|
|
||||||
|
|
||||||
### 已支持的功能
|
### 已支持的功能
|
||||||
- [x] 查询当日解析的标识
|
- [x] 查询当日解析的标识
|
||||||
- [x] 查询标识所有解析记录
|
- [x] 查询标识所有解析记录
|
||||||
## 食用指南
|
## 食用指南
|
||||||
### 基本功能
|
### 基本功能
|
||||||
1. 去寻找`标识解析附件1 SNMS-API-1.2.6.docx`这份文档
|
1. 去寻找
|
||||||
|
这份文档
|
||||||
2. 按照`已支持的功能`去操作
|
2. 按照`已支持的功能`去操作
|
||||||
### 统计功能
|
### 统计功能
|
||||||
#### 查询当日解析的标识
|
#### 查询当日解析的标识
|
||||||
|
|
Loading…
Reference in New Issue