From 760321f8facacb2c3d82c275e6a29892ec8b483c Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 7 Nov 2024 18:09:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_ServiceExtensions/SwaggerSetup.cs | 1 - .../IRaCIS.Core.Application.csproj | 4 + .../IRaCIS.Core.Application.xml | 274 +++++++++--------- .../Service/Common/DevelopService.cs | 25 -- .../Service/Common/DictionaryService.cs | 31 -- .../CodeTemplate/CodeTemplateModel.cs | 46 +++ .../CodeTemplate/CodeTemplateService.cs | 119 ++++++++ .../CodeTemplates/EFCore/EntityType.t4 | 4 +- 8 files changed, 306 insertions(+), 198 deletions(-) delete mode 100644 IRaCIS.Core.Application/Service/Common/DevelopService.cs create mode 100644 IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateModel.cs create mode 100644 IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateService.cs diff --git a/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs index d2f85d734..a430b2709 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs @@ -109,7 +109,6 @@ public static class SwaggerSetup //路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件, //注意localhost:8001/swagger是访问不到的,去launchSettings.json把launchUrl去掉,如果你想换一个路径,直接写名字即可,比如直接写c.Route = "doc"; options.RoutePrefix = string.Empty; - options.RoutePrefix = string.Empty; //DocExpansion设置为none可折叠所有方法 options.DocExpansion(DocExpansion.None); diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 1cf3fd0b9..cee4a0855 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -70,4 +70,8 @@ + + + + diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 75af1b317..ec6925b59 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -549,23 +549,134 @@ 系统模板文档配置表 - + - 开始时候一些帮助 比如根据配置的字典生成枚举 + 数据字典-基础数据维护 - - + - 开始时候一些帮助 比如根据配置的字典生成枚举 + 数据字典-基础数据维护 - - + - 根据配置的字典名生成后端枚举 + 添加bool - + + + + + + 获取所有字典的Key + + + + + + 添加字典 的同时 一起添加子项 --New + + + + + + + New 查询条件 + + + + + + + 添加和编辑 + + + + + + + 获取子项数组 + + + + + + 删除字典数据 + + + + 传递父亲 code 字符串 数组 返回多个下拉框数据 + + + + + + + 根据父亲Code 获取单个下拉框数据 + + + + + + + 根据父亲字典分组 获取子项 + + + + + + + 获取标准字典 + + + + + + 获取标准字典 + + + + + + 获取标准指定字典 + + + + + + + 获取所有下拉框 枚举 bool 数据 + + + + + + 获取是和否 + + + + + + + 获取审核状态 + + + + + + + + + 邮件事件消息列表 + + + + + + + 重新发布失败的事件消息 + + @@ -833,136 +944,6 @@ - - - 数据字典-基础数据维护 - - - - - 数据字典-基础数据维护 - - - - - 添加bool - - - - - - - 获取所有字典的Key - - - - - - 添加字典 的同时 一起添加子项 --New - - - - - - - New 查询条件 - - - - - - - 添加和编辑 - - - - - - - 获取子项数组 - - - - - - 删除字典数据 - - - - 传递父亲 code 字符串 数组 返回多个下拉框数据 - - - - - - - 根据父亲Code 获取单个下拉框数据 - - - - - - - 根据父亲字典分组 获取子项 - - - - - - - 获取标准字典 - - - - - - 获取标准字典 - - - - - - 获取标准指定字典 - - - - - - - 获取所有下拉框 枚举 bool 数据 - - - - - - 获取是和否 - - - - - - - 获取审核状态 - - - - - - - - - 邮件事件消息列表 - - - - - - - 重新发布失败的事件消息 - - - - ExploreRecommendService @@ -2316,6 +2297,21 @@ + + + 获取数据库的表信息 以及字段信息 + + + + + + + + 根据字典名 code 生成枚举定义 + + + + 上传文件转PDF 或者给url 这边下载然后转PDF diff --git a/IRaCIS.Core.Application/Service/Common/DevelopService.cs b/IRaCIS.Core.Application/Service/Common/DevelopService.cs deleted file mode 100644 index 77eda0273..000000000 --- a/IRaCIS.Core.Application/Service/Common/DevelopService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace IRaCIS.Core.Application.Service.Common -{ - - /// - /// 开始时候一些帮助 比如根据配置的字典生成枚举 - /// - /// - [ApiExplorerSettings(GroupName = "Common")] - public class DevelopService(IRepository _dictionaryRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService - { - /// - /// 根据配置的字典名生成后端枚举 - /// - /// - /// - [HttpPost] - public async Task BackDicGenerateEnum(string dicName) - { - - return ResponseOutput.Ok(); - } - } -} diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index 1f957a530..e3a8e2b9f 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -26,37 +26,6 @@ namespace IRaCIS.Core.Application.Service IRepository _readingQuestionCriterionTrial, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IDictionaryService { - 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) - { - // 添加 XML 注释作为枚举描述 - enumCode.AppendLine($" /// "); - enumCode.AppendLine($" /// {item.ValueCN}"); // 假设你有一个描述字段 - enumCode.AppendLine($" /// "); - // 每个枚举值生成 - enumCode.AppendLine($" {item.Value.Trim().Replace(" ", "")} = {item.Code},"); - - } - - enumCode.AppendLine("}"); - - // 返回生成的枚举代码 - var enumStr = enumCode.ToString(); - - return ResponseOutput.Ok(enumStr); - - } - /// /// 添加bool /// diff --git a/IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateModel.cs b/IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateModel.cs new file mode 100644 index 000000000..8d833d3ca --- /dev/null +++ b/IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateModel.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Application.Service.DTO; + +public class TemplateTable +{ + public string TableName { get; set; } + + public string Comment { get; set; } + + + + public List AddOrEditPropertyList => TablePropertyList.Where(t => !AddOrUpdateExcludeNameList.Contains(t.PropertyName)).ToList(); + + [JsonIgnore] + public List TablePropertyList { get; set; } + + [JsonIgnore] + public List AddOrUpdateExcludeNameList = new List() { "CreateUserId", "UpdateUserId", "CreateTime", "UpdateTime", "DeleteUserId", "IsDeleted", "DeletedTime" }; + +} + +public class TemplateTableProperty +{ + public string ColumnName { get; set; } + + public string PropertyName { get; set; } + + public string CSharpType { get; set; } + + public bool IsNullable { get; set; } + + public int? MaxLength { get; set; } + + public bool IsPrimarykey { get; set; } + + + public string Comment { get; set; } + + +} \ No newline at end of file diff --git a/IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateService.cs b/IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateService.cs new file mode 100644 index 000000000..65e6b4e48 --- /dev/null +++ b/IRaCIS.Core.Application/Service/MinimalApiService/CodeTemplate/CodeTemplateService.cs @@ -0,0 +1,119 @@ +using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing; +using IRaCIS.Application.Contracts; +using IRaCIS.Core.Application.Service.DTO; +using Microsoft.AspNetCore.Builder; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.Extensions.Configuration; +using NPOI.HPSF; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Application.Service +{ + + public class CodeTemplateService(IRepository _dicRepository,IMapper _mapper, IConfiguration _configuration) : ServiceBase + { + + static string GetCSharpType(Type type) + { + if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) + { + var underlyingType = Nullable.GetUnderlyingType(type); + return $"{GetCSharpType(underlyingType)}?"; + } + + return type switch + { + _ when type == typeof(int) => "int", + _ when type == typeof(long) => "long", + _ when type == typeof(short) => "short", + _ when type == typeof(byte) => "byte", + _ when type == typeof(bool) => "bool", + _ when type == typeof(decimal) => "decimal", + _ when type == typeof(double) => "double", + _ when type == typeof(float) => "float", + _ when type == typeof(Guid) => "Guid", + _ when type == typeof(DateTime) => "DateTime", + _ when type == typeof(string) => "string", + _ => type.Name // 非常见类型,返回 .NET 类型名称 + }; + } + + /// + /// 获取数据库的表信息 以及字段信息 + /// + /// + /// + /// + public List GetDataBaseTableList(string tableName, string comment) + { + var contextOptions = new DbContextOptionsBuilder().UseSqlServer(_configuration.GetSection("ConnectionStrings:RemoteNew").Value).Options; + + using var dbContext = new IRaCISDBContext(contextOptions); + var dbModel = dbContext.Model; + + var list = dbModel.GetEntityTypes().Where(t => t.GetTableName().IsNotNullOrEmpty()) + .WhereIf(tableName.IsNotNullOrEmpty(), t => t.GetTableName()!.Contains(tableName)) + .WhereIf(comment.IsNotNullOrEmpty(), t => t.GetComment().Contains(comment)) + .Select(t => new TemplateTable() + { + TableName = t.GetTableName()!, + TablePropertyList = t.GetProperties().Select(property => new TemplateTableProperty() + { + PropertyName = property.Name, + ColumnName = property.GetColumnName(), + IsNullable = property.IsNullable, + IsPrimarykey = property.IsKey(), + CSharpType = GetCSharpType(property.ClrType), + Comment = property.GetComment() ?? string.Empty + }).ToList() + }).ToList(); + + + return list; + } + + /// + /// 根据字典名 code 生成枚举定义 + /// + /// + /// + 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) + { + // 添加 XML 注释作为枚举描述 + enumCode.AppendLine($" /// "); + enumCode.AppendLine($" /// {item.ValueCN}"); // 假设你有一个描述字段 + enumCode.AppendLine($" /// "); + // 每个枚举值生成 + enumCode.AppendLine($" {item.Value.Trim().Replace(" ", "")} = {item.Code},"); + + } + + enumCode.AppendLine("}"); + + // 返回生成的枚举代码 + var enumStr = enumCode.ToString(); + + return ResponseOutput.Ok(enumStr); + + } + + + + } +} diff --git a/IRaCIS.Core.Test/CodeTemplates/EFCore/EntityType.t4 b/IRaCIS.Core.Test/CodeTemplates/EFCore/EntityType.t4 index 1ad870103..6d75acc32 100644 --- a/IRaCIS.Core.Test/CodeTemplates/EFCore/EntityType.t4 +++ b/IRaCIS.Core.Test/CodeTemplates/EFCore/EntityType.t4 @@ -87,13 +87,13 @@ public partial class <#= EntityType.Name #>: BaseFullAuditEntity { var maxLength = property.GetMaxLength(); - if (maxLength.HasValue && maxLength != 200) // ȲΪ200ʱ[StringLength] + if (maxLength.HasValue && maxLength != 400) // ȲΪ200ʱ[StringLength] { #> [StringLength(<#= maxLength.Value #>)] <# } - else if(maxLength.HasValue && maxLength == 200){} + else if(maxLength.HasValue && maxLength == 400){} else { #>