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) }; } }