using OpenAuth.App.BaseApp.Base; using OpenAuth.Repository.Domain; using OpenAuth.Repository; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Infrastructure.CloudSdk.minio; using OpenAuth.App.Interface; using SqlSugar; using Infrastructure; using Microsoft.AspNetCore.Http; using DocumentFormat.OpenXml.EMMA; namespace OpenAuth.App.ServiceApp { public class AlgorithmsRepositoryApp : SqlSugarBaseApp { public AlgorithmsRepositoryApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth) : base(unitWork, repository, auth) { } #region 算法库管理 //添加算法库 public async Task> AddAlgorithmsRepository(LasaAlgorithmsRepository info) { using (var db = UnitWork.CreateContext()) { info.Id = Guid.NewGuid().ToString(); await db.LasaAlgorithmsRepository.InsertAsync(info); foreach (var item in info.ModelLabels) { item.Id = Guid.NewGuid().ToString(); item.PId = info.Id; } await db.LasaModelLabel.InsertRangeAsync(info.ModelLabels); if (db.Commit()) return new Response { Result = true, Message = "添加成功" }; else return new Response { Result = false, Message = "添加失败" }; } } //修改算法库 public async Task> UpdateAlgorithmsRepository(LasaAlgorithmsRepository info) { using (var db = UnitWork.CreateContext()) { await db.LasaAlgorithmsRepository.UpdateAsync(info); await db.LasaModelLabel.DeleteAsync(r => r.PId == info.Id); foreach (var item in info.ModelLabels) { item.Id = Guid.NewGuid().ToString(); item.PId = info.Id; } await db.LasaModelLabel.InsertRangeAsync(info.ModelLabels); if (db.Commit()) return new Response { Result = true, Message = "修改成功" }; else return new Response { Result = false, Message = "修改失败" }; } } //删除算法库 public async Task> DeleteAlgorithmsRepository(string id) { using (var db = UnitWork.CreateContext()) { await db.LasaAlgorithmsRepository.DeleteByIdAsync(id); await db.LasaModelLabel.DeleteAsync(r => r.PId == id); if (db.Commit()) return new Response { Result = true, Message = "删除成功" }; else return new Response { Result = false, Message = "删除失败" }; } } /// /// 分页获取所有数据 /// /// /// /// /// public async Task>>> GetPageList(int page, int limit, string key) { RefAsync totalCount = 0; using (var db = UnitWork.CreateContext()) { var list = await db.LasaAlgorithmsRepository.AsQueryable().Includes(a => a.ModelLabels) .WhereIF(!string.IsNullOrEmpty(key), a => a.Name.Contains(key)) .ToPageListAsync(page, limit, totalCount); return new Response>> { Result = new PageInfo> { Items = list, Total = totalCount } }; } } #endregion } }