From 2ddef0d1b587c3d0375a7ee87d1f56622f36b175 Mon Sep 17 00:00:00 2001 From: lihanbo Date: Fri, 18 Oct 2024 11:32:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91=E8=BD=AC=E4=B8=BA?= =?UTF-8?q?=E8=87=AA=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/VersionManagementController.cs | 75 +++++++++++++++++++ .../Service/IVersionManagementService.cs | 12 ++- .../Service/VersionManagementService.cs | 59 +++++---------- 3 files changed, 104 insertions(+), 42 deletions(-) create mode 100644 LFlow.VersionManagement/Controller/VersionManagementController.cs diff --git a/LFlow.VersionManagement/Controller/VersionManagementController.cs b/LFlow.VersionManagement/Controller/VersionManagementController.cs new file mode 100644 index 0000000..3eadeea --- /dev/null +++ b/LFlow.VersionManagement/Controller/VersionManagementController.cs @@ -0,0 +1,75 @@ +using LFlow.Base.Interfaces; +using LFlow.Base.Utils; +using LFlow.VersionManagement.Enums; +using LFlow.VersionManagement.Model; +using LFlow.VersionManagement.Service; +using Mapster; +using Microsoft.AspNetCore.Mvc; + +namespace LFlow.VersionManagement.Controller; +public class VersionManagementController(IVersionManagementService service) : BaseController +{ + [HttpDelete] + public int DeleteById(string id) + { + return service.DeleteById(id); + } + + [HttpGet] + public PagedApiResult> GetAll(int pageIndex, int pageSize) + { + var total = 0; + var result = service.GetAll(pageIndex, pageSize, ref total); + return PagedApiResult>.SuccessResult( + data: Mapper.Map>(result) ?? [], + total, + pageIndex, + pageSize + ); + //return new PagedApiResult> + //{ + // Data = Mapper.Map>(result), + // PageIndex = pageIndex, + // PageSize = pageSize, + // Message = "获取成功", + // Code = 200, + // Success = true, + // TotalCount = total + //}; + } + + [HttpGet] + public ApiResult GetById(string id) + { + var result = service.GetById(id).Adapt(); + return ApiResult.SuccessResult(result); + } + [HttpPost] + public ApiResult Save(VersionDto entity, bool isUpdate) + { + if (!isUpdate) + { + entity.ID = Guid.NewGuid().ToString(); + entity.DownloadUrl = "/"; + } + var result = service.Save(entity, isUpdate).Adapt(); + return ApiResult.SuccessResult(result); + } + + [HttpPost] + public List Search(VersionDto whereObj) + { + return service.Search(whereObj).Adapt>(); + } + + //[HttpPost] + //public ApiResult CheckUpdate(VersionDto current) + //{ + + //} + [HttpGet] + public ApiResult GetLastUpdate(VersionType type, VersionChannel channel, UpgradeTargetType targetType) + { + return ApiResult.SuccessResult(service.GetLastVersion(type, channel, targetType)); + } +} diff --git a/LFlow.VersionManagement/Service/IVersionManagementService.cs b/LFlow.VersionManagement/Service/IVersionManagementService.cs index 9b32023..6016cd1 100644 --- a/LFlow.VersionManagement/Service/IVersionManagementService.cs +++ b/LFlow.VersionManagement/Service/IVersionManagementService.cs @@ -1,7 +1,17 @@ using LFlow.Base.Interfaces; +using LFlow.VersionManagement.Enums; using LFlow.VersionManagement.Model; namespace LFlow.VersionManagement.Service; -public interface IVersionManagementService : IService +public interface IVersionManagementService : IService// { + VersionDto GetById(string id); + List Search(VersionDto whereObj); + + int DeleteById(string id); + VersionDto Save(VersionDto entity, bool isUpdate); + + List GetAll(int pageIndex, int pageSize, ref int total); + + VersionDto? GetLastVersion(VersionType type, VersionChannel channel, UpgradeTargetType targetType); } diff --git a/LFlow.VersionManagement/Service/VersionManagementService.cs b/LFlow.VersionManagement/Service/VersionManagementService.cs index 85445e7..2a99773 100644 --- a/LFlow.VersionManagement/Service/VersionManagementService.cs +++ b/LFlow.VersionManagement/Service/VersionManagementService.cs @@ -1,60 +1,37 @@ using LFlow.Base.Interfaces; -using LFlow.Base.Utils; +using LFlow.VersionManagement.Enums; using LFlow.VersionManagement.Model; +using LFlow.VersionManagement.Repository; using Mapster; -using Microsoft.AspNetCore.Mvc; namespace LFlow.VersionManagement.Service; /// /// 版本管理服务 /// -public class VersionManagementService : BaseController, IVersionManagementService +public class VersionManagementService : IVersionManagementService { private readonly IRepo _repo; public VersionManagementService(IRepo repo) { _repo = repo; } - [HttpDelete] - public int DeleteById(string id) - { - return _repo.DeleteById(id); - } - [HttpGet] - public PagedApiResult> GetAll(int pageIndex, int pageSize) - { - var total = 0; - var result = _repo.GetAll(pageIndex, pageSize, ref total); - return new PagedApiResult> - { - Data = Mapper.Map>(result), - PageIndex = pageIndex, - PageSize = pageSize, - Message = "获取成功", - Success = true, - TotalCount = total - }; - } - - [HttpGet] - public VersionDto GetById(string id) - { - return _repo.Get(id).Adapt(); - } - [HttpPost] - public VersionDto Save(VersionDto entity, bool isUpdate) - { - return _repo.SaveOrUpdate(entity.Adapt(), isUpdate).Adapt(); - } - [HttpPost] + public int DeleteById(string id) => _repo.DeleteById(id); + public List GetAll(int pageIndex, int pageSize, ref int total) => _repo.GetAll(pageIndex, pageSize, ref total).Adapt>(); + public VersionDto GetById(string id) => _repo.Get(id).Adapt(); + public VersionDto Save(VersionDto entity, bool isUpdate) => _repo.SaveOrUpdate(entity.Adapt(), isUpdate).Adapt(); + // 搜索需要增加分页 public List Search(VersionDto whereObj) + => _repo.Search(whereObj.Adapt()).Adapt>(); + public VersionDto? GetLastVersion(VersionType type, VersionChannel channel, UpgradeTargetType targetType) { - return _repo.Search(whereObj.Adapt()).Adapt>(); - } - [HttpPost] - public List SearchAllId(VersionDto whereObj) - { - return _repo.WhereSearchId(whereObj.Adapt()); + if (_repo is VersionManagementRepo versionRepo) + { + return versionRepo.GetLatestVersion(type, channel, targetType).Adapt(); + } + else + { + return default; + } } }