Files
SystemX.Web/Projects/WebApi/WebApi.Project.UniqueKeyApi/Controllers/CPMetaController.cs

84 lines
3.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SystemX.Core.Controller;
using WebApi.Project.UniqueKeyApi.Models;
using WebApi.Project.UniqueKeyApi.Services;
namespace WebApi.Project.UniqueKeyApi.Controllers
{
[ApiController]
[Route("[controller]/[action]")]
public class CPMetaController : CommonController<UniqueKeyApiConfig>
{
private readonly CPMetaService _cpMetaService;
public CPMetaController(IServiceProvider serviceProvider, IHttpContextAccessor httpContextAccessor, CPMetaService cpMetaService)
: base(serviceProvider, httpContextAccessor)
{
_cpMetaService = cpMetaService;
}
[HttpGet("health")]
public async Task<IResult> Health()
{
LogXnet.WriteLine($"[{GetRequestMethod()}:{GetMethodName()}] [Client IP:{GetClientIP()}] [RequestUrl:{GetRequestUrl()}]{Environment.NewLine}", LogXLabel.CONTROLLER);
await Task.CompletedTask;
return Results.Ok("Healthy");
}
[HttpPost]
public async Task<IResult> SetWbmsMeta([FromBody]Request_SetWbmsMeta request)
{
Guid guid = Guid.NewGuid();
LogXnet.WriteLine($"[Request][{GetRequestMethod()}:{GetMethodName()}][Client IP:{GetClientIP()}][RequestUrl:{GetRequestUrl()}]::({guid}){Environment.NewLine} {request.ToJson()}", LogXLabel.CONTROLLER);
Response_SetWbmsMeta response = await _cpMetaService.SetWbmsMeta(request, guid.ToString());
LogXnet.WriteLine($"[Response]::({guid}){Environment.NewLine} {response.ToJson()}", LogXLabel.CONTROLLER);
return Results.Ok(response);
}
[HttpGet]
public async Task<IResult> GetWbmsMeta([FromQuery] DateOnly? startDate, DateOnly? endDate, int? ShardID = 1)
{
Guid guid = Guid.NewGuid();
LogXnet.WriteLine($"[Request][{GetRequestMethod()}:{GetMethodName()}][Client IP:{GetClientIP()}][RequestUrl:{GetRequestUrl()}]::({guid}){Environment.NewLine} key:{startDate}~{endDate}", LogXLabel.CONTROLLER);
Response_GetWbms response = await _cpMetaService.GetWbmsMeta(new Request_GetWbmsMeta() { StartDateTime = startDate, EndDateTime = endDate, ShardID = (int)ShardID }, guid.ToString());
LogXnet.WriteLine($"[Response]::({guid}){Environment.NewLine} {response.ToJson()}", LogXLabel.CONTROLLER);
return Results.Ok(response);
}
[HttpGet]
public async Task<IResult> GetWbmsMetaByProductID([FromQuery] string ProductID, int? ShardID = 1)
{
Guid guid = Guid.NewGuid();
LogXnet.WriteLine($"[Request][{GetRequestMethod()}:{GetMethodName()}][Client IP:{GetClientIP()}][RequestUrl:{GetRequestUrl()}]::({guid}){Environment.NewLine} key:{ProductID}", LogXLabel.CONTROLLER);
Response_GetWbms response = await _cpMetaService.GetWbmsMeta(new Request_GetWbmsMetaByProductID() { ProductID = ProductID, ShardID = (int)ShardID }, guid.ToString());
LogXnet.WriteLine($"[Response]::({guid}){Environment.NewLine} {response.ToJson()}", LogXLabel.CONTROLLER);
return Results.Ok(response);
}
[HttpGet]
public async Task<IResult> GetWbmsMetaByMacAddress([FromQuery] string MacAddress, int? ShardID = 1)
{
Guid guid = Guid.NewGuid();
LogXnet.WriteLine($"[Request][{GetRequestMethod()}:{GetMethodName()}][Client IP:{GetClientIP()}][RequestUrl:{GetRequestUrl()}]::({guid}){Environment.NewLine} key:{MacAddress}", LogXLabel.CONTROLLER);
Response_GetWbms response = await _cpMetaService.GetWbmsMeta(new Request_GetWbmsMetaByMacAddress() { MacAddress = MacAddress, ShardID = (int)ShardID }, guid.ToString());
LogXnet.WriteLine($"[Response]::({guid}){Environment.NewLine} {response.ToJson()}", LogXLabel.CONTROLLER);
return Results.Ok(response);
}
}
}