From 7f42ee56d367a1bcf54418ee8666be6ba3f823c4 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Wed, 9 Jul 2025 11:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8A=A8=E6=80=81=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E6=A1=86=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/SelectResultListInput.cs | 3 -- .../CommonServices/ICommonService.cs | 7 +--- .../CommonServices/CommonService.cs | 41 +++++++++++++++++++ .../IoTApplicationModule.cs | 8 ++++ .../JiShe.IoT.Application.csproj | 4 -- .../Controllers/CommonController.cs | 32 +++++++++++++++ .../{Controllers => }/IoTController.cs | 3 ++ 7 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 src/JiShe.IoT.Application/CommonServices/CommonService.cs create mode 100644 src/JiShe.IoT.HttpApi/Controllers/CommonController.cs rename src/JiShe.IoT.HttpApi/{Controllers => }/IoTController.cs (70%) diff --git a/src/JiShe.IoT.Application.Contracts/CommonServices/Dto/SelectResultListInput.cs b/src/JiShe.IoT.Application.Contracts/CommonServices/Dto/SelectResultListInput.cs index 18a6b0c..352dc4e 100644 --- a/src/JiShe.IoT.Application.Contracts/CommonServices/Dto/SelectResultListInput.cs +++ b/src/JiShe.IoT.Application.Contracts/CommonServices/Dto/SelectResultListInput.cs @@ -14,9 +14,6 @@ namespace JiShe.IoT.CommonServices.Dto { /// /// 类型名称 - /// MalignantLoadLevelEnum 恶性负载等级 - /// DurationOfAutomaticClosingEnum 自动合闸时长类型 - /// MalignLoadTypeEnum 恶性负载类型 /// [Required] public string TypeName { get; set; } diff --git a/src/JiShe.IoT.Application.Contracts/CommonServices/ICommonService.cs b/src/JiShe.IoT.Application.Contracts/CommonServices/ICommonService.cs index 5b3f1d4..24ba65a 100644 --- a/src/JiShe.IoT.Application.Contracts/CommonServices/ICommonService.cs +++ b/src/JiShe.IoT.Application.Contracts/CommonServices/ICommonService.cs @@ -14,20 +14,17 @@ namespace JiShe.IoT.CommonServices /// public interface ICommonService { - #region 公共依赖接口 - /// /// 初始化所有固定的枚举下拉框字典 /// /// - Task InitSelectTypetList(); + void InitSelectTypetList(); /// /// 根据type名称获取下拉框数据,主要是枚举等 /// /// /// - Task> GetSelectResultList(SelectResultListInput input); - #endregion + List GetSelectResultList(SelectResultListInput input); } } diff --git a/src/JiShe.IoT.Application/CommonServices/CommonService.cs b/src/JiShe.IoT.Application/CommonServices/CommonService.cs new file mode 100644 index 0000000..eb06cbd --- /dev/null +++ b/src/JiShe.IoT.Application/CommonServices/CommonService.cs @@ -0,0 +1,41 @@ +using JiShe.IoT.CommonServices.Dto; +using JiShe.ServicePro.Commons; +using JiShe.ServicePro.Core; +using System.Collections.Concurrent; +using System.Collections.Generic; + +namespace JiShe.IoT.CommonServices +{ + public class CommonService : IoTAppService, ICommonService + { + private static ConcurrentDictionary> _selectListType = new(); + + /// + /// 初始化所有固定的枚举下拉框字典 + /// + /// + public void InitSelectTypetList() + { + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + var typeList = assemblies.SelectMany(x => x.GetTypes()).Where(x => x.IsDefined(typeof(SelectResultAttribute), false)); + + foreach (var typeInfoItem in typeList) + { + + _selectListType.TryAdd(typeInfoItem.Name, CommonHelper.GetEnumAttributeList(typeInfoItem)); + } + } + + /// + /// 根据type名称获取下拉框数据,主要是枚举等 + /// + /// + /// + public List GetSelectResultList(SelectResultListInput input) + { + List selectResults = _selectListType.TryGetValue(input.TypeName, out var list) ? list : new List(); + + return selectResults; + } + } +} diff --git a/src/JiShe.IoT.Application/IoTApplicationModule.cs b/src/JiShe.IoT.Application/IoTApplicationModule.cs index 36fe466..6ef5bf5 100644 --- a/src/JiShe.IoT.Application/IoTApplicationModule.cs +++ b/src/JiShe.IoT.Application/IoTApplicationModule.cs @@ -1,3 +1,4 @@ +using JiShe.IoT.CommonServices; using JiShe.IoT.Jobs.ToMysql; using JiShe.IoT.Jobs.ToRedis; using JiShe.ServicePro.CTWingManagement; @@ -10,6 +11,7 @@ using JiShe.ServicePro.IoTDBManagement; using JiShe.ServicePro.OneNETManagement; using JiShe.ServicePro.TemplateManagement; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; namespace JiShe.IoT { @@ -56,5 +58,11 @@ namespace JiShe.IoT context.Services.AddHostedService(); context.Services.AddHostedService(); } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var commonService = context.ServiceProvider.GetRequiredService(); + commonService.InitSelectTypetList(); + } } } diff --git a/src/JiShe.IoT.Application/JiShe.IoT.Application.csproj b/src/JiShe.IoT.Application/JiShe.IoT.Application.csproj index 9a126a9..9e39949 100644 --- a/src/JiShe.IoT.Application/JiShe.IoT.Application.csproj +++ b/src/JiShe.IoT.Application/JiShe.IoT.Application.csproj @@ -45,9 +45,5 @@ - - - - diff --git a/src/JiShe.IoT.HttpApi/Controllers/CommonController.cs b/src/JiShe.IoT.HttpApi/Controllers/CommonController.cs new file mode 100644 index 0000000..f0eedf9 --- /dev/null +++ b/src/JiShe.IoT.HttpApi/Controllers/CommonController.cs @@ -0,0 +1,32 @@ +using JiShe.IoT.CommonServices; +using JiShe.IoT.CommonServices.Dto; +using JiShe.ServicePro.Commons; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.IoT.Controllers +{ + public class CommonController:IoTController + { + private readonly ICommonService _commonService; + public CommonController(ICommonService commonService) + { + _commonService = commonService; + } + + /// + /// 根据type名称获取下拉框数据 + /// + /// + /// + [HttpGet("get-select-list")] + [SwaggerOperation(summary: "根据type名称获取下拉框数据", Tags = new[] { "Common" })] + public List GetSelectResultList(SelectResultListInput input) + { + return _commonService.GetSelectResultList(input); + } + } +} diff --git a/src/JiShe.IoT.HttpApi/Controllers/IoTController.cs b/src/JiShe.IoT.HttpApi/IoTController.cs similarity index 70% rename from src/JiShe.IoT.HttpApi/Controllers/IoTController.cs rename to src/JiShe.IoT.HttpApi/IoTController.cs index a1785ea..5e83575 100644 --- a/src/JiShe.IoT.HttpApi/Controllers/IoTController.cs +++ b/src/JiShe.IoT.HttpApi/IoTController.cs @@ -1,7 +1,10 @@ +using JiShe.ServicePro.SwaggerConfigs; + namespace JiShe.IoT.Controllers { /* Inherit your controllers from this class. */ + [ApiExplorerSettings(GroupName = nameof(SwaggerGroupEnum.IoTAdmin))] public abstract class IoTController : AbpController { protected IoTController()