From a863d3772c7cc6d2702c6a8de771b7471394f9a0 Mon Sep 17 00:00:00 2001 From: yanghongwei Date: Fri, 28 Mar 2025 23:20:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=88=97=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/DeviceController.cs | 2 +- Controllers/LogController.cs | 34 +++++++++++++++++++++++++++++++++ LY.App.csproj | 2 +- Program.cs | 11 ++++++----- Service/DeviceService.cs | 15 +++++++++------ Service/LogService.cs | 23 ++++++++++++++++++++++ 6 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 Controllers/LogController.cs diff --git a/Controllers/DeviceController.cs b/Controllers/DeviceController.cs index ed45feb..b8bfae2 100644 --- a/Controllers/DeviceController.cs +++ b/Controllers/DeviceController.cs @@ -49,7 +49,7 @@ namespace LY.App.Controllers [HttpPost("updata")] public async Task Updata(UpdateDevice input) { - var result = _deviceService.updata(input); + var result = await _deviceService.updata(input); return Ok(result); } [HttpDelete("delete")] diff --git a/Controllers/LogController.cs b/Controllers/LogController.cs new file mode 100644 index 0000000..7211979 --- /dev/null +++ b/Controllers/LogController.cs @@ -0,0 +1,34 @@ +using LY.App.Service; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace LY.App.Controllers +{ + /// + /// 日志控制器 + /// + [Route("api/[controller]")] + [ApiController] + public class LogController : ControllerBase + { + private readonly LogService _logService; + public LogController(LogService logService) + { + _logService = logService; + } + + /// + /// 获取日志列表 + /// + /// 页码 + /// 页大小 + /// 页大小 + /// + [HttpGet("list")] + public async Task GetLogs(int pageNum = 1, int pageSize = 10, string key = null) + { + var result = await _logService.List(pageNum, pageSize, key); + return Ok(result); + } + } +} diff --git a/LY.App.csproj b/LY.App.csproj index c5e7e00..277bc7a 100644 --- a/LY.App.csproj +++ b/LY.App.csproj @@ -3,7 +3,7 @@ net6.0 - en + disable enable Linux diff --git a/Program.cs b/Program.cs index d25099a..f720b88 100644 --- a/Program.cs +++ b/Program.cs @@ -102,11 +102,12 @@ app.UseStaticFiles(new StaticFileOptions() RequestPath = "/upload" }); // Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} +//if (app.Environment.IsDevelopment()) +//{ + +//} +app.UseSwagger(); +app.UseSwaggerUI(); //·ƥ app.UseRouting(); app.UseAuthorization(); diff --git a/Service/DeviceService.cs b/Service/DeviceService.cs index 094927c..1f63cff 100644 --- a/Service/DeviceService.cs +++ b/Service/DeviceService.cs @@ -32,7 +32,7 @@ namespace LY.App.Service /// /// /// - public async Task List(int pageNum, int pageSize, string key) + public async Task List(int pageNum, int pageSize, string key) { RefAsync total = 0; var items = await _db.Queryable() @@ -40,10 +40,13 @@ namespace LY.App.Service .WhereIF(!string.IsNullOrEmpty(key), s => s.Name.Contains(key) || s.DeviceSN.Contains(key)) .OrderByDescending(s => s.Id) .ToPageListAsync(pageNum, pageSize, total); - return new + return new ApiResult() { - total = total.Value, - items + data = new + { + total = total.Value, + items + } }; } /// @@ -137,7 +140,7 @@ namespace LY.App.Service try { var input = JsonConvert.DeserializeObject(data); - // Console.WriteLine($"rev data:{data}"); + // Console.WriteLine($"rev data:{data}"); await _alarmService.AddAlarm(input); } catch (Exception ex) @@ -165,7 +168,7 @@ namespace LY.App.Service } // 加载阵地信息 var position = await _db.Queryable() - .Where(s=>s.IsDeleted==false).ToListAsync(); + .Where(s => s.IsDeleted == false).ToListAsync(); foreach (var item in position) { var key = RedisKeyList.PositioinRegion(item.Id); diff --git a/Service/LogService.cs b/Service/LogService.cs index 8f84f82..918ed42 100644 --- a/Service/LogService.cs +++ b/Service/LogService.cs @@ -20,5 +20,28 @@ namespace LY.App.Service var entity = input.Adapt(); await _db.Insertable(entity).ExecuteReturnSnowflakeIdAsync(); } + /// + /// 分页查询 + /// + /// + /// + /// + /// + public async Task List(int pageNum, int pageSize, string key) + { + RefAsync total = 0; + var items = await _db.Queryable() + .WhereIF(!string.IsNullOrEmpty(key), s => s.Message.Contains(key)) + .OrderByDescending(s => s.Id) + .ToPageListAsync(pageNum, pageSize, total); + return new ApiResult() + { + data = new + { + total = total.Value, + items + } + }; + } } }