实现动态下拉框获取

This commit is contained in:
ChenYi 2025-07-09 11:58:18 +08:00
parent 652d8dcb47
commit 7f42ee56d3
7 changed files with 86 additions and 12 deletions

View File

@ -14,9 +14,6 @@ namespace JiShe.IoT.CommonServices.Dto
{
/// <summary>
/// 类型名称
/// MalignantLoadLevelEnum 恶性负载等级
/// DurationOfAutomaticClosingEnum 自动合闸时长类型
/// MalignLoadTypeEnum 恶性负载类型
/// </summary>
[Required]
public string TypeName { get; set; }

View File

@ -14,20 +14,17 @@ namespace JiShe.IoT.CommonServices
/// </summary>
public interface ICommonService
{
#region
/// <summary>
/// 初始化所有固定的枚举下拉框字典
/// </summary>
/// <returns></returns>
Task InitSelectTypetList();
void InitSelectTypetList();
/// <summary>
/// 根据type名称获取下拉框数据主要是枚举等
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<List<SelectResult>> GetSelectResultList(SelectResultListInput input);
#endregion
List<SelectResult> GetSelectResultList(SelectResultListInput input);
}
}

View File

@ -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<string, List<SelectResult>> _selectListType = new();
/// <summary>
/// 初始化所有固定的枚举下拉框字典
/// </summary>
/// <returns></returns>
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));
}
}
/// <summary>
/// 根据type名称获取下拉框数据主要是枚举等
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public List<SelectResult> GetSelectResultList(SelectResultListInput input)
{
List<SelectResult> selectResults = _selectListType.TryGetValue(input.TypeName, out var list) ? list : new List<SelectResult>();
return selectResults;
}
}
}

View File

@ -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<CacheDeviceDataToRedisJob>();
context.Services.AddHostedService<CacheFocusDataToRedisJob>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var commonService = context.ServiceProvider.GetRequiredService<ICommonService>();
commonService.InitSelectTypetList();
}
}
}

View File

@ -45,9 +45,5 @@
<ProjectReference Include="..\JiShe.IoT.Application.Contracts\JiShe.IoT.Application.Contracts.csproj" />
<ProjectReference Include="..\JiShe.IoT.Domain\JiShe.IoT.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="CommonServices\" />
</ItemGroup>
</Project>

View File

@ -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;
}
/// <summary>
/// 根据type名称获取下拉框数据
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("get-select-list")]
[SwaggerOperation(summary: "根据type名称获取下拉框数据", Tags = new[] { "Common" })]
public List<SelectResult> GetSelectResultList(SelectResultListInput input)
{
return _commonService.GetSelectResultList(input);
}
}
}

View File

@ -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()