diff --git a/OpenAuth.App/ServiceApp/AlgorithmsRepositoryApp.cs b/OpenAuth.App/ServiceApp/AlgorithmsRepositoryApp.cs new file mode 100644 index 0000000..51ab914 --- /dev/null +++ b/OpenAuth.App/ServiceApp/AlgorithmsRepositoryApp.cs @@ -0,0 +1,122 @@ +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 + } +} diff --git a/OpenAuth.Repository/Domain/LasaAlgorithmsRepository.cs b/OpenAuth.Repository/Domain/LasaAlgorithmsRepository.cs new file mode 100644 index 0000000..9e28a80 --- /dev/null +++ b/OpenAuth.Repository/Domain/LasaAlgorithmsRepository.cs @@ -0,0 +1,29 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.Repository.Domain +{ + [SugarTable("lasa_algorithmsrepository")] + public class LasaAlgorithmsRepository + { + [SugarColumn(IsPrimaryKey = true)] + public string Id { get; set; } + public string Name { get; set; } + public string Describe { get; set; } + public string Pic { get; set; } + public string Size { get; set; } + public int Type { get; set; } + public string Path { get; set; } + public DateTime? CreateTime { get; set; } + public string PushUrl { get; set; } + public string PullUrl { get; set; } + public string ServiceUrl { get; set; } + public string SecretKey { get; set; } + [Navigate(NavigateType.OneToMany, nameof(LasaModelLabel.PId))] + public List ModelLabels { get; set; } + } +} diff --git a/OpenAuth.Repository/Domain/LasaModelLabel.cs b/OpenAuth.Repository/Domain/LasaModelLabel.cs new file mode 100644 index 0000000..fd80aea --- /dev/null +++ b/OpenAuth.Repository/Domain/LasaModelLabel.cs @@ -0,0 +1,20 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.Repository.Domain +{ + [SugarTable("lasa_modellabel")] + public class LasaModelLabel + { + [SugarColumn(IsPrimaryKey = true)] + public string Id { get; set; } + public string Name { get; set; } + public int EnumValue { get; set; } + public double Reliability { get; set; } + public string PId { get; set; } + } +} diff --git a/OpenAuth.Repository/SugarDbContext.cs b/OpenAuth.Repository/SugarDbContext.cs index c8ff31b..72a8091 100644 --- a/OpenAuth.Repository/SugarDbContext.cs +++ b/OpenAuth.Repository/SugarDbContext.cs @@ -81,7 +81,8 @@ namespace OpenAuth.Repository public SugarRepositiry DroneDocktask { get; set; } public SugarRepositiry LasaMediaFile { get; set; } - + public SugarRepositiry LasaAlgorithmsRepository { get; set; } + public SugarRepositiry LasaModelLabel { get; set; } public SugarRepositiry DbfineInfo { get; set; } public SugarRepositiry SysOpenJob { get; set; } diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/AlgorithmsRepositoryController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/AlgorithmsRepositoryController.cs new file mode 100644 index 0000000..d2f6211 --- /dev/null +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/AlgorithmsRepositoryController.cs @@ -0,0 +1,111 @@ +using Infrastructure; +using Infrastructure.Cache; +using Infrastructure.CloudSdk.minio; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenAuth.App.ServiceApp; +using OpenAuth.Repository.Domain; +using System.Net.Http; + +namespace OpenAuth.WebApi.Controllers.ServiceControllers +{ + /// + /// 算法库 + /// + [Route("api/[controller]/[action]")] + [ApiController] + public class AlgorithmsRepositoryController : ControllerBase + { + private readonly AlgorithmsRepositoryApp _app; + public AlgorithmsRepositoryController(AlgorithmsRepositoryApp app) + { + _app = app; + } + /// + /// 添加算法 + /// + /// + /// + [HttpPost] + [AllowAnonymous] + public async Task> AddAlgorithmsRepository(LasaAlgorithmsRepository info) + { + var result = new Response(); + try + { + result = await _app.AddAlgorithmsRepository(info); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.Message; + } + return result; + } + /// + /// 修改算法 + /// + /// + /// + [HttpPost] + [AllowAnonymous] + public async Task> UpdateAlgorithmsRepository(LasaAlgorithmsRepository info) + { + var result = new Response(); + try + { + result = await _app.UpdateAlgorithmsRepository(info); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.Message; + } + return result; + } + /// + /// 删除算法 + /// + /// + /// + [HttpPost] + [AllowAnonymous] + public async Task> DeleteAlgorithmsRepository(string id) + { + var result = new Response(); + try + { + result = await _app.DeleteAlgorithmsRepository(id); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.Message; + } + return result; + } + /// + /// 获取算法列表 + /// + /// + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task>>> GetAlgorithmsRepositoryList(int page, int limit, string key) + { + var result = new Response>>(); + try + { + result = await _app.GetPageList(page, limit, key); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.Message; + } + + return result; + } + } +}