diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index 0174ee41d..57fe7ac1c 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -5,6 +5,9 @@ using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Infra.EFCore.Common; +using IP2Region.Net.XDB; +using System.Collections; +using System.Text; namespace IRaCIS.Application.Services { @@ -29,6 +32,32 @@ namespace IRaCIS.Application.Services { + public async Task GenerateEnumDefine(string code) + { + var searchList = await _dicRepository.Where(t => t.Parent.Code == code && t.ParentId != null && t.IsEnable).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + + // StringBuilder 用于构建枚举代码字符串 + var enumCode = new StringBuilder(); + + // 生成枚举定义 + enumCode.AppendLine($"public enum {code}"); + enumCode.AppendLine("{"); + + foreach (var item in searchList) + { + // 每个枚举值生成 + enumCode.AppendLine($" {item.Code} = {item.ValueCN},"); + } + + enumCode.AppendLine("}"); + + // 返回生成的枚举代码 + var enumStr= enumCode.ToString(); + + return ResponseOutput.Ok(enumStr); + + } + /// /// 添加bool ///