From c18ee4036da6020d66935f6f12f5063d5901fb76 Mon Sep 17 00:00:00 2001 From: lihanbo Date: Wed, 16 Oct 2024 15:22:58 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E7=A7=BB=E9=99=A4=E5=8F=82=E8=80=83?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=BC=95=E7=94=A8=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LFlow.Home/HomeModule.cs | 14 ++- LFlow.Home/Services/HomeService.cs | 27 +++++- .../Enums/UpgradeTargetType.cs | 12 +++ .../Enums/VersionChannel.cs | 12 +++ LFlow.VersionManagement/Enums/VersionType.cs | 14 +++ .../LFlow.VersionManagement.csproj | 21 ++++ LFlow.VersionManagement/Model/VersionDto.cs | 89 +++++++++++++++++ LFlow.VersionManagement/Model/VersionModel.cs | 97 +++++++++++++++++++ .../Repository/VersionManagementRepo.cs | 23 +++++ .../Service/IVersionManagementService.cs | 7 ++ .../Service/VersionManagementService.cs | 60 ++++++++++++ .../VersionManagementModule.cs | 22 +++++ LFlow.sln | 18 ++-- 13 files changed, 401 insertions(+), 15 deletions(-) create mode 100644 LFlow.VersionManagement/Enums/UpgradeTargetType.cs create mode 100644 LFlow.VersionManagement/Enums/VersionChannel.cs create mode 100644 LFlow.VersionManagement/Enums/VersionType.cs create mode 100644 LFlow.VersionManagement/LFlow.VersionManagement.csproj create mode 100644 LFlow.VersionManagement/Model/VersionDto.cs create mode 100644 LFlow.VersionManagement/Model/VersionModel.cs create mode 100644 LFlow.VersionManagement/Repository/VersionManagementRepo.cs create mode 100644 LFlow.VersionManagement/Service/IVersionManagementService.cs create mode 100644 LFlow.VersionManagement/Service/VersionManagementService.cs create mode 100644 LFlow.VersionManagement/VersionManagementModule.cs diff --git a/LFlow.Home/HomeModule.cs b/LFlow.Home/HomeModule.cs index a58a41b..0b08e1c 100644 --- a/LFlow.Home/HomeModule.cs +++ b/LFlow.Home/HomeModule.cs @@ -9,19 +9,29 @@ using LFlow.Home.Services; using Microsoft.Extensions.DependencyInjection; namespace LFlow.Home; - +/// +/// 首页模块 +/// public class HomeModule : IModule { + /// + /// 配置模块 + /// + /// 启动前的IServiceCollection public void ConfigureModule(IServiceCollection services) { // 将HomeModel注册到CodeFirst,将会在程序启动后自动创建表 CodeFirst.AddType(typeof(HomeModel)); + // 注册服务、仓储、模型 var assembly = Assembly.GetAssembly(typeof(HomeService))!; var types = assembly.GetTypes().ToList(); + RegisterModule.RegisterAllService(types, services); RegisterModule.RegisterAllRepo(types, services); - RegisterModule.RegisterAllModule(types, services); + RegisterModule.RegisterAllModel(types, services); + + // 添加控制器 services.AddControllers().AddApplicationPart(assembly); Console.WriteLine("HomeModule ConfigureModule"); diff --git a/LFlow.Home/Services/HomeService.cs b/LFlow.Home/Services/HomeService.cs index 756b78a..e4ccad0 100644 --- a/LFlow.Home/Services/HomeService.cs +++ b/LFlow.Home/Services/HomeService.cs @@ -10,15 +10,29 @@ using Serilog; using Microsoft.AspNetCore.Mvc; namespace LFlow.Home.Services; - +/// +/// 服务直接作为控制器 +/// +/// +/// public class HomeService(IRepo repo, ILogger logger) : BaseController, IHomeService { + /// + /// 删除 + /// + /// + /// [HttpGet] public HomeDto? DeleteById(string id) { var result = repo.Delete(id); return Mapper.Map(result); } + /// + /// 获取 + /// + /// + /// [HttpGet] public HomeDto? GetById(string id) { @@ -26,12 +40,23 @@ public class HomeService(IRepo repo, ILogger logger) : BaseCo var result = repo.Get(id); return Mapper.Map(result); } + /// + /// 保存 (修改或者新增,按主键判断) + /// + /// + /// [HttpPost] public HomeDto? Save(HomeDto entity) { var result = repo.SaveOrUpdate(Mapper.Map(entity), false); return Mapper.Map(result); } + /// + /// 搜索 + /// + /// + /// + /// [HttpGet] public List? Search(HomeDto whereObj) { diff --git a/LFlow.VersionManagement/Enums/UpgradeTargetType.cs b/LFlow.VersionManagement/Enums/UpgradeTargetType.cs new file mode 100644 index 0000000..b4ec7cf --- /dev/null +++ b/LFlow.VersionManagement/Enums/UpgradeTargetType.cs @@ -0,0 +1,12 @@ +namespace LFlow.VersionManagement.Enums; + +/// +/// 更新目标类型 +/// +public enum UpgradeTargetType +{ + // 鼎捷插件 + SWI = 1, + // XH工具箱 + XH_TOOL = 2, +} diff --git a/LFlow.VersionManagement/Enums/VersionChannel.cs b/LFlow.VersionManagement/Enums/VersionChannel.cs new file mode 100644 index 0000000..cb97296 --- /dev/null +++ b/LFlow.VersionManagement/Enums/VersionChannel.cs @@ -0,0 +1,12 @@ +namespace LFlow.VersionManagement.Enums; + +/// +/// 更新通道 +/// +public enum VersionChannel +{ + // 正式 + Official = 1, + // 预览 + Preview = 2 +} diff --git a/LFlow.VersionManagement/Enums/VersionType.cs b/LFlow.VersionManagement/Enums/VersionType.cs new file mode 100644 index 0000000..b369882 --- /dev/null +++ b/LFlow.VersionManagement/Enums/VersionType.cs @@ -0,0 +1,14 @@ +namespace LFlow.VersionManagement.Enums; + +/// +/// 更新类型 +/// +public enum VersionType +{ + // 优化 + Optimize = 1, + // 新增 + Add = 2, + // 修复 + Fix = 3 +} diff --git a/LFlow.VersionManagement/LFlow.VersionManagement.csproj b/LFlow.VersionManagement/LFlow.VersionManagement.csproj new file mode 100644 index 0000000..e1977d4 --- /dev/null +++ b/LFlow.VersionManagement/LFlow.VersionManagement.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + ../LFlow_Bin/Services/ + false + false + true + + + + + + + + + + + diff --git a/LFlow.VersionManagement/Model/VersionDto.cs b/LFlow.VersionManagement/Model/VersionDto.cs new file mode 100644 index 0000000..56b0ab4 --- /dev/null +++ b/LFlow.VersionManagement/Model/VersionDto.cs @@ -0,0 +1,89 @@ +using LFlow.Base.Interfaces; +using LFlow.VersionManagement.Enums; + +namespace LFlow.VersionManagement.Model; +public class VersionDto : IModel +{ + /// + /// ID + /// + public string? ID + { + get; + set; + } + /// + /// 版本号 eg:1.0.0.1 + /// + public string? CurrentVersion + { + get; set; + } + /// + /// 更新说明 + /// + public string? Description + { + get; set; + } + public DateTime LastPublishTime + { + get; set; + } + /// + /// 下载地址 + /// + public string? DownloadUrl + { + get; set; + } + /// + /// 文件名 + /// + public string? FileName + { + get; set; + } + /// + /// 文件大小 + /// + public string? FileSize + { + get; set; + } + /// + /// MD5 校验码 + /// + public string? Md5 + { + get; set; + } + /// + /// 是否强制更新 + /// + public bool IsRequired + { + get; set; + } + /// + /// 更新通道 + /// + public VersionChannel VersionChannel + { + get; set; + } + /// + /// 更新目标类型 + /// + public UpgradeTargetType UpgradeTargetType + { + get; set; + } + /// + /// 更新类型 + /// + public VersionType VersionType + { + get; set; + } +} diff --git a/LFlow.VersionManagement/Model/VersionModel.cs b/LFlow.VersionManagement/Model/VersionModel.cs new file mode 100644 index 0000000..06aa363 --- /dev/null +++ b/LFlow.VersionManagement/Model/VersionModel.cs @@ -0,0 +1,97 @@ +using LFlow.Base.Interfaces; +using LFlow.VersionManagement.Enums; +using SqlSugar; + +namespace LFlow.VersionManagement.Model; +/// +/// 版本信息 +/// +[SugarTable("T_P_VERSION")] +[Serializable] +public class VersionModel : IDataModel +{ + /// + /// ID + /// + [SugarColumn(IsPrimaryKey = true)] + public string ID + { + get; + set; + } + /// + /// 版本号 eg:1.0.0.1 + /// + public string? CurrentVersion + { + get; set; + } + /// + /// 更新说明 + /// + public string? Description + { + get; set; + } + public DateTime LastPublishTime + { + get; set; + } + /// + /// 下载地址 + /// + public string? DownloadUrl + { + get; set; + } + /// + /// 文件名 + /// + public string? FileName + { + get; set; + } + /// + /// 文件大小 + /// + public string? FileSize + { + get; set; + } + /// + /// MD5 校验码 + /// + public string? Md5 + { + get; set; + } + /// + /// 是否强制更新 + /// + public bool IsRequired + { + get; set; + } + /// + /// 更新通道 + /// + public VersionChannel VersionChannel + { + get; set; + } + /// + /// 更新目标类型 + /// + public UpgradeTargetType UpgradeTargetType + { + get; set; + } + /// + /// 更新类型 + /// + public VersionType VersionType + { + get; set; + } + +} diff --git a/LFlow.VersionManagement/Repository/VersionManagementRepo.cs b/LFlow.VersionManagement/Repository/VersionManagementRepo.cs new file mode 100644 index 0000000..818baad --- /dev/null +++ b/LFlow.VersionManagement/Repository/VersionManagementRepo.cs @@ -0,0 +1,23 @@ +using LFlow.Base.Default; +using LFlow.Base.Utils; +using LFlow.VersionManagement.Model; +using SqlSugar; + +namespace LFlow.VersionManagement.Repository; +public class VersionManagementRepo(ISqlSugarClient db) : DefaultCurdRepo(db) +{ + public override List Search(VersionModel whereObj) + { + return db.Queryable() + .Where(whereObj.ToWhereExp()) + .ToList(); + } + public override List WhereSearchId(VersionModel whereObj) + { + return db.Queryable() + .Where(whereObj.ToWhereExp()) + .Where(x => x.ID != null) + .Select(x => x.ID) + .ToList(); + } +} diff --git a/LFlow.VersionManagement/Service/IVersionManagementService.cs b/LFlow.VersionManagement/Service/IVersionManagementService.cs new file mode 100644 index 0000000..9b32023 --- /dev/null +++ b/LFlow.VersionManagement/Service/IVersionManagementService.cs @@ -0,0 +1,7 @@ +using LFlow.Base.Interfaces; +using LFlow.VersionManagement.Model; + +namespace LFlow.VersionManagement.Service; +public interface IVersionManagementService : IService +{ +} diff --git a/LFlow.VersionManagement/Service/VersionManagementService.cs b/LFlow.VersionManagement/Service/VersionManagementService.cs new file mode 100644 index 0000000..85445e7 --- /dev/null +++ b/LFlow.VersionManagement/Service/VersionManagementService.cs @@ -0,0 +1,60 @@ +using LFlow.Base.Interfaces; +using LFlow.Base.Utils; +using LFlow.VersionManagement.Model; +using Mapster; +using Microsoft.AspNetCore.Mvc; + +namespace LFlow.VersionManagement.Service; +/// +/// 版本管理服务 +/// +public class VersionManagementService : BaseController, 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 List Search(VersionDto whereObj) + { + return _repo.Search(whereObj.Adapt()).Adapt>(); + } + [HttpPost] + public List SearchAllId(VersionDto whereObj) + { + return _repo.WhereSearchId(whereObj.Adapt()); + } +} diff --git a/LFlow.VersionManagement/VersionManagementModule.cs b/LFlow.VersionManagement/VersionManagementModule.cs new file mode 100644 index 0000000..0a587f5 --- /dev/null +++ b/LFlow.VersionManagement/VersionManagementModule.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using LFlow.Base.Interfaces; +using LFlow.Base.Utils; +using LFlow.VersionManagement.Model; +using Microsoft.Extensions.DependencyInjection; + +namespace LFlow.User; + +public class VersionManagementModule : IModule +{ + public void ConfigureModule(IServiceCollection services) + { + CodeFirst.AddType(typeof(VersionModel)); + var assembly = Assembly.GetAssembly(typeof(VersionManagementModule))!; + var types = assembly.GetTypes().ToList(); + RegisterModule.RegisterAllService(types, services); + RegisterModule.RegisterAllRepo(types, services); + RegisterModule.RegisterAllModel(types, services); + services.AddControllers().AddApplicationPart(assembly); + Console.WriteLine("UserModule ConfigureModule"); + } +} diff --git a/LFlow.sln b/LFlow.sln index 46c79b8..9aeec19 100644 --- a/LFlow.sln +++ b/LFlow.sln @@ -3,11 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.5.002.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Base", "LFlow.Base\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LFlow.Base", "LFlow.Base\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Home", "LFlow.Home\LFlow.Home.csproj", "{1F607791-03F0-45EA-8F13-A085E2D49DD4}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.User", "LFlow.User\LFlow.User.csproj", "{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.VersionManagement", "LFlow.VersionManagement\LFlow.VersionManagement.csproj", "{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -19,14 +17,10 @@ Global {C581AFB2-50BA-4357-AD0A-AF287194837D}.Debug|Any CPU.Build.0 = Debug|Any CPU {C581AFB2-50BA-4357-AD0A-AF287194837D}.Release|Any CPU.ActiveCfg = Release|Any CPU {C581AFB2-50BA-4357-AD0A-AF287194837D}.Release|Any CPU.Build.0 = Release|Any CPU - {1F607791-03F0-45EA-8F13-A085E2D49DD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1F607791-03F0-45EA-8F13-A085E2D49DD4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1F607791-03F0-45EA-8F13-A085E2D49DD4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1F607791-03F0-45EA-8F13-A085E2D49DD4}.Release|Any CPU.Build.0 = Release|Any CPU - {AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Release|Any CPU.Build.0 = Release|Any CPU + {D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE