diff --git a/IDIS_Server-SIM/Controllers/IDISController.cs b/IDIS_Server-SIM/Controllers/IDISController.cs deleted file mode 100644 index 7e7acc0..0000000 --- a/IDIS_Server-SIM/Controllers/IDISController.cs +++ /dev/null @@ -1,75 +0,0 @@ -using BITKit; -using IDIS; -using IDIS.Models; -using IDIS.Services; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; - -namespace IDIS_Server_SIM.Controllers; - -[ApiController] -[Route("api")] -public class IDISController:Controller -{ - private readonly IDIS_Service _service; - - public IDISController(IDIS_Service service) - { - _service = service; - } - - [HttpGet] - [Route("info")] - public IActionResult Info() - { - return new ContentResult - { - Content = Environment.MachineName - }; - } - - [HttpGet] - [Route("query")] - public async Task Query(string key) - { - try - { - return Ok(await _service.QueryAsync(key)); - } - catch (Exception e) - { - return BadRequest(ContextModel.Error(e.ToString())); - } - } - - [HttpGet] - [Route("isExist")] - public async Task IsExist(string key) - { - return await _service.IsExistAsync(key); - } - - [HttpPost] - [Route("register")] - public async Task Register() - { - using var reader = new StreamReader(Request.Body); - var json = await reader.ReadToEndAsync(); - var data = JsonConvert.DeserializeObject(json)!; - var response = await _service.RegisterAsync(data.Handle, data.TemplateVersion, data.Value); - return Ok(response); - } - [HttpGet] - [Route("update")] - public string Update([FromBody] string json) - { - return "err:0"; - } - [HttpGet] - [Route("delete")] - public async Task Delete (string handle) - { - await _service.DeleteAsync(handle); - return true; - } -} \ No newline at end of file diff --git a/IDIS_Server-SIM/Controllers/IDIS_ServiceController.cs b/IDIS_Server-SIM/Controllers/IDIS_ServiceController.cs new file mode 100644 index 0000000..fa656fe --- /dev/null +++ b/IDIS_Server-SIM/Controllers/IDIS_ServiceController.cs @@ -0,0 +1,94 @@ +using BITKit; +using IDIS; +using IDIS.Models; +using IDIS.Services; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; + +namespace IDIS_Server_SIM.Controllers; + +[ApiController] +public class IDIS_ServiceController:Controller +{ + private readonly IDIS_Service _service; + public IDIS_ServiceController(IDIS_Service service) + { + _service = service; + } + [HttpGet] + [Route("info")] + public IActionResult Info() + { + return new ContentResult + { + Content = Environment.MachineName + }; + } + [HttpGet] + [Route("/identityv2/data/detail")] + public async Task Query(string handle) + { + try + { + var result = await _service.QueryAsync(handle); + 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 + }); + } + } + + [HttpGet] + [Route("isExist")] + public async Task IsExist(string code) + { + return Ok(new IDIS_Response(await _service.IsExistAsync(code))); + } + + [HttpPost] + [Route("/identityv2/data")] + public async Task Register() + { + try + { + using var reader = new StreamReader(Request.Body); + var json = await reader.ReadToEndAsync(); + var data = JsonConvert.DeserializeObject(json)!; + await _service.RegisterAsync(data.Handle, data.TemplateVersion, data.Value); + return Ok(new IDIS_Response()); + } + catch (Exception e) + { + return BadRequest(new IDIS_Response(e.Message,false) + { + Status = 2 + }); + + } + } + [HttpGet] + [Route("update")] + public string Update() + { + return "err:0"; + } + [HttpGet] + [Route("delete")] + public async Task Delete (string code) + { + await _service.DeleteAsync(code); + return true; + } +} \ No newline at end of file diff --git a/IDIS_Server-SIM/Controllers/IDIS_StatisticsController.cs b/IDIS_Server-SIM/Controllers/IDIS_StatisticsController.cs new file mode 100644 index 0000000..4765659 --- /dev/null +++ b/IDIS_Server-SIM/Controllers/IDIS_StatisticsController.cs @@ -0,0 +1,36 @@ +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 _logger; + public IDIS_StatisticsController(IDIS_Statistics_MySQLBased service, ILogger logger) + { + _service = service; + _logger = logger; + } + + [Route("/api/query/today")] + public async Task GetTodayQuery() + { + var result = await _service.GetTodayQuery(); + + return new IDIS_Response(result).ToActionResult(); + } + [Route("/api/query/count")] + public async Task GetQueryCount(string handle) + { + var result = await _service.GetQueryCount(handle); + + return new IDIS_Response(result).ToActionResult(); + } +} \ No newline at end of file diff --git a/IDIS_Server-SIM/Controllers/IDIS_TemplateController.cs b/IDIS_Server-SIM/Controllers/IDIS_TemplateController.cs new file mode 100644 index 0000000..9f69b71 --- /dev/null +++ b/IDIS_Server-SIM/Controllers/IDIS_TemplateController.cs @@ -0,0 +1,61 @@ +using BITKit; +using IDIS; +using IDIS.Models; +using IDIS.Services; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; + +namespace IDIS_Server_SIM.Controllers; + +[ApiController] + +public class IDIS_TemplateController:Controller +{ + private readonly IDIS_TemplateService _service; + private readonly ILogger _logger; + + public IDIS_TemplateController(IDIS_TemplateService service, ILogger logger) + { + _service = service; + _logger = logger; + } + + [Route("/snms/api/template/v1")] + [HttpGet] + public async Task Query(string prefix, string version) + { + try + { + return Ok(new IDIS_Response(await _service.QueryAsync(prefix, version))); + } + catch (Exception e) + { + return BadRequest(new IDIS_Response(e.Message,false) + { + Status = 2 + }); + } + } + + [Route("/snms/api/template/v1")] + [HttpPost] + public async Task Save() + { + using var reader = new StreamReader(Request.Body); + var json = await reader.ReadToEndAsync(); + + try + { + var data = JsonConvert.DeserializeObject(json)!; + await _service.SaveAsync(data); + return Ok(new IDIS_Response()); + } + catch (Exception e) + { + return BadRequest(new IDIS_Response(e.Message, false) + { + Status = 2 + }); + } + } +} \ No newline at end of file diff --git a/IDIS_Server-SIM/Extensions/IDISExtensions.cs b/IDIS_Server-SIM/Extensions/IDISExtensions.cs new file mode 100644 index 0000000..1054fec --- /dev/null +++ b/IDIS_Server-SIM/Extensions/IDISExtensions.cs @@ -0,0 +1,18 @@ +using IDIS; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; + +namespace IDIS_Server_SIM.Extensions; + +public static class IDISExtensions +{ + public static IActionResult ToActionResult(this IDIS_Response response) + { + return new ContentResult() + { + Content = JsonConvert.SerializeObject(response), + ContentType = "application/json", + StatusCode = 200 + }; + } +} \ No newline at end of file diff --git a/IDIS_Server-SIM/Program.cs b/IDIS_Server-SIM/Program.cs index e0afaa9..3217d5c 100644 --- a/IDIS_Server-SIM/Program.cs +++ b/IDIS_Server-SIM/Program.cs @@ -5,6 +5,13 @@ using IDIS.Services; await BITAppForNet.InitializeAsync("IDIS"); +var config = Path.Combine(Environment.CurrentDirectory,"appsettings.json"); +if (File.Exists(config)) +{ + var json = File.ReadAllText(config); + DataParser.Set(json); +} + var builder = WebApplication.CreateBuilder(args); var cancellationTokenSource = new System.Threading.CancellationTokenSource(); @@ -16,7 +23,11 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); + +builder.Services.AddTransient(); var app = builder.Build(); var logger = app.Services.GetRequiredService>(); @@ -25,24 +36,30 @@ var logger = app.Services.GetRequiredService>(); logger.LogInformation("请输入二级节点地址,例如:88.123.99"); string? str; -while (string.IsNullOrEmpty(str = Console.ReadLine()) is false) +while (true) { + str = Console.ReadLine(); + if (string.IsNullOrEmpty(str)) + { + str = "88.123.99"; + break; + } const string pattern =@"^\d{1,3}\.\d{1,3}\.\d{1,3}$"; // 正则表达式模式 - if (Regex.IsMatch(str,pattern)) { - logger.LogInformation("输入的地址符合要求。"); break; } logger.LogInformation("错误的地址格式,请按照正确格式输入,例如:88.123.99"); } +logger.LogInformation("输入的地址符合要求。"); #endregion var idis_Service = app.Services.GetRequiredService(); - //idis_Service.PreAddress = str!; +app.Services.GetRequiredService(); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/IDIS_Server-SIM/appsettings.json b/IDIS_Server-SIM/appsettings.json index 53b04a1..e658cb9 100644 --- a/IDIS_Server-SIM/appsettings.json +++ b/IDIS_Server-SIM/appsettings.json @@ -6,5 +6,6 @@ } }, "Urls": "http://+:5242", + "DefaultConnection":"server=server.bitfall.icu;port=3306;database=ifactory;uid=ifactory;password=JdBfKR2dxhm76Ss2", "AllowedHosts": "*" } diff --git a/ReadMe.md b/ReadMe.md index 279074b..09325e3 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,45 +1,24 @@ # IDIS Server Console ### IDIS 标识解析服务器控制台 -指南版本`v0.1` +指南版本`v0.2` -未包括所有功能 +### 已支持的功能 +- [x] 查询标识 +- [x] 注册标识 +- [x] 删除标识 +- [x] 查询数据模板 +- [x] 保存数据模板 +### 已支持的功能 +- [x] 查询当日解析的标识 +- [x] 查询标识所有解析记录 ## 食用指南 -### 注册: -![Clip_20240428_161137.png](ReadMe%2FClip_20240428_161137.png) -#### WebApi:`localhost:5242/api/register` -```json -{ - "handle": "88.123.99/202404281606", - "templateVersion": "1.0", - "value": { - "key1": "value1", - "key2": "value2" - } -} -``` -### 查询: -![Clip_20240428_161438.png](ReadMe%2FClip_20240428_161438.png) -#### WebApi:`localhost:5242/api/query?key={handle}` - -### 删除: -```csharp -[HttpGet] - [Route("delete")] - public async Task Delete (string handle) - { - await _service.DeleteAsync(handle); - return true; - } -``` -#### WebApi:`localhost:5242/api/delete?handle={handle}` - -### 检查标识码是否存在 -```csharp -[HttpGet] - [Route("isExist")] - public async Task IsExist(string key) - { - return await _service.IsExistAsync(key); - } -``` -#### WebApi:`localhost:5242/api/isExist?key={key}` \ No newline at end of file +### 基本功能 +1. 去寻找`标识解析附件1 SNMS-API-1.2.6.docx`这份文档 +2. 按照`已支持的功能`去操作 +### 统计功能 +#### 查询当日解析的标识 +![Clip_20240429_230249.png](ReadMe%2FClip_20240429_230249.png) +`Get:`http://localhost:5242/api/query/today +#### 查询单个标识所有的解析次数 +![Clip_20240429_230509.png](ReadMe%2FClip_20240429_230509.png) +`Get:`http://localhost:5242/api/query/count?handle=88.101.6/xx004 diff --git a/ReadMe/Clip_20240429_230249.png b/ReadMe/Clip_20240429_230249.png new file mode 100644 index 0000000..addfb68 Binary files /dev/null and b/ReadMe/Clip_20240429_230249.png differ diff --git a/ReadMe/Clip_20240429_230509.png b/ReadMe/Clip_20240429_230509.png new file mode 100644 index 0000000..e268249 Binary files /dev/null and b/ReadMe/Clip_20240429_230509.png differ