From 360bcd6bfef8ece7e6dbe316bc204c0e9c8889ca Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 9 Sep 2024 18:05:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=B5=8B=E8=AF=95=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Common/DictionaryService.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 ///