From 055c24186c9acbba0ee693d566b4a7c53915492a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E6=A2=A6=E5=8D=83=E5=B9=B4?= <421281095@qq.com> Date: Wed, 24 Sep 2025 17:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=A7=E9=A3=9E=E6=9C=BA?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServiceApp/LasaAircraftServiceApp.cs | 105 ++++++++++++++++++ .../LasaAircraftController.cs | 79 +++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 OpenAuth.App/ServiceApp/LasaAircraftServiceApp.cs create mode 100644 OpenAuth.WebApi/Controllers/ServiceControllers/LasaAircraftController.cs diff --git a/OpenAuth.App/ServiceApp/LasaAircraftServiceApp.cs b/OpenAuth.App/ServiceApp/LasaAircraftServiceApp.cs new file mode 100644 index 0000000..21fc85f --- /dev/null +++ b/OpenAuth.App/ServiceApp/LasaAircraftServiceApp.cs @@ -0,0 +1,105 @@ +using Infrastructure; +using OpenAuth.App.BaseApp.Base; +using OpenAuth.App.Interface; +using OpenAuth.Repository; +using OpenAuth.Repository.Domain; +using SqlSugar; + +namespace OpenAuth.App.ServiceApp; + +public class LasaAircraftServiceApp : SqlSugarBaseApp +{ + public LasaAircraftServiceApp(ISugarUnitOfWork unitWork, + ISimpleClient repository, IAuth auth) : base(unitWork, repository, auth) + { + } + + public async Task> AddLasaAircraft(LasaAircraft info) + { + info.Id = Guid.NewGuid().ToString(); + info.CreateTime = DateTime.Now; + if (await Repository.InsertAsync(info)) + { + return new Response + { + Result = true, + Message = "添加成功" + }; + } + + return new Response + { + Result = false, + Message = "添加失败" + }; + } + + public async Task> DeleteLasaAircraft(string id) + { + if (await Repository.DeleteByIdAsync(id)) + { + return new Response + { + Result = true, + Message = "删除成功" + }; + } + + return new Response + { + Result = false, + Message = "删除失败" + }; + } + + public async Task> UpdateLasaAircraft(LasaAircraft info) + { + info.UpdateTime = DateTime.Now; + // 使用Updateable方法来避免空值更新问题 + using (var db = Repository.AsSugarClient()) + { + var result = await Repository.AsSugarClient().Updateable(info).IgnoreNullColumns().ExecuteCommandAsync(); + if (result > 0) + { + return new Response + { + Result = true, + Message = "修改成功" + }; + } + } + + + return new Response + { + Result = false, + Message = "修改失败" + }; + } + + public async Task>>> GetLasaAircraftList(string key, int page, + int limit) + { + RefAsync totalCount = 0; + var pageList = await Repository.AsQueryable() + .WhereIF(!string.IsNullOrEmpty(key), x => x.Name.Contains(key) || x.Sn.Contains(key)) + .ToPageListAsync(page, limit, totalCount); + + return new Response>> + { + Result = new PageInfo> + { + Items = pageList, + Total = totalCount + } + }; + } + + public async Task> GetLasaAircraft(string id) + { + return new Response + { + Result = await Repository.GetByIdAsync(id) + }; + } +} \ No newline at end of file diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/LasaAircraftController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/LasaAircraftController.cs new file mode 100644 index 0000000..39b0d7d --- /dev/null +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/LasaAircraftController.cs @@ -0,0 +1,79 @@ +using Infrastructure; +using Microsoft.AspNetCore.Mvc; +using OpenAuth.App.ServiceApp; +using OpenAuth.Repository.Domain; + +namespace OpenAuth.WebApi.Controllers.ServiceControllers; + +/// +/// 大飞机信息 +/// +[Route("api/[controller]/[action]")] +[ApiController] +public class LasaAircraftController : ControllerBase +{ + private readonly LasaAircraftServiceApp _app; + + public LasaAircraftController(LasaAircraftServiceApp app) + { + _app = app; + } + + /// + /// 添加大飞机信息 + /// + /// + /// + [HttpPost] + public async Task> AddLasaAircraft(LasaAircraft info) + { + return await _app.AddLasaAircraft(info); + } + + /// + /// 删除大飞机信息 + /// + /// + /// + [HttpPost] + public async Task> DeleteLasaAircraft(string id) + { + return await _app.DeleteLasaAircraft(id); + } + + /// + /// 修改大飞机信息 + /// + /// + /// + [HttpPost] + public async Task> UpdateLasaAircraft(LasaAircraft info) + { + return await _app.UpdateLasaAircraft(info); + } + + /// + /// 获取大飞机信息列表 + /// + /// + /// + /// + /// + [HttpGet] + public async Task>>> GetLasaAircraftList( + [FromQuery] string key, [FromQuery] int page = 1, [FromQuery] int limit = 10) + { + return await _app.GetLasaAircraftList(key, page, limit); + } + + /// + /// 获取大飞机信息详情 + /// + /// + /// + [HttpGet] + public async Task> GetLasaAircraft(string id) + { + return await _app.GetLasaAircraft(id); + } +} \ No newline at end of file