feat: 完成web to code及code to web功能
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.DirectoryServices.ActiveDirectory;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -11,6 +12,7 @@ using Furion.DatabaseAccessor;
|
|||||||
using Furion.DependencyInjection;
|
using Furion.DependencyInjection;
|
||||||
using Mapster.Utils;
|
using Mapster.Utils;
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Org.BouncyCastle.Asn1.Ntt;
|
using Org.BouncyCastle.Asn1.Ntt;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
@@ -78,22 +80,56 @@ namespace Yi.Framework.Module.WebFirstManager.Domain
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private FieldEntity PropertyMapperToFiled(PropertyInfo propertyInfo)
|
private FieldEntity PropertyMapperToFiled(PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
var fieldEntity = new FieldEntity();
|
var fieldEntity = new FieldEntity();
|
||||||
fieldEntity.Name = propertyInfo.Name;
|
fieldEntity.Name = propertyInfo.Name;
|
||||||
var enumName = typeof(FieldTypeEnum).GetFields(BindingFlags.Static | BindingFlags.Public).Where(x => x.GetCustomAttribute<DisplayAttribute>()?.Name== propertyInfo.PropertyType.Name).FirstOrDefault()?.Name;
|
|
||||||
if (enumName is null)
|
|
||||||
|
//获取数据类型,包括可空类型
|
||||||
|
Type? fieldType = null;
|
||||||
|
// 如果字段类型是 Nullable<T> 泛型类型
|
||||||
|
if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||||
{
|
{
|
||||||
fieldEntity.FieldType = FieldTypeEnum.String;
|
Type nullableType = Nullable.GetUnderlyingType(propertyInfo.PropertyType)!;
|
||||||
Console.Out.WriteLine($"字段类型:{propertyInfo.PropertyType.Name},未定义");
|
fieldType = nullableType;
|
||||||
//throw new ApplicationException($"字段类型:{propertyInfo.PropertyType.Name},未定义");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fieldEntity.FieldType =EasyTool.EnumUtil.Parse<FieldTypeEnum>(enumName);
|
fieldType = propertyInfo.PropertyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//判断类型
|
||||||
|
var enumName = typeof(FieldTypeEnum).GetFields(BindingFlags.Static | BindingFlags.Public).Where(x => x.GetCustomAttribute<DisplayAttribute>()?.Description == fieldType.Name).FirstOrDefault()?.Name;
|
||||||
|
if (enumName is null)
|
||||||
|
{
|
||||||
|
fieldEntity.FieldType = FieldTypeEnum.String;
|
||||||
|
// App.GetRequiredService<ILogger<WebTemplateManager>>().LogError($"字段类型:{propertyInfo.PropertyType.Name},未定义");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fieldEntity.FieldType = EasyTool.EnumUtil.Parse<FieldTypeEnum>(enumName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否可空
|
||||||
|
if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||||
|
{
|
||||||
|
fieldEntity.IsRequired = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fieldEntity.IsRequired = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//判断是否主键
|
||||||
|
if (propertyInfo.GetCustomAttribute<SugarColumn>()?.IsPrimaryKey == true)
|
||||||
|
{
|
||||||
|
fieldEntity.IsKey = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断长度
|
||||||
var colum = propertyInfo.GetCustomAttribute<SugarColumn>();
|
var colum = propertyInfo.GetCustomAttribute<SugarColumn>();
|
||||||
if (colum is not null && colum.Length != 0)
|
if (colum is not null && colum.Length != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,5 +19,14 @@ namespace Yi.Framework.Module.WebFirstManager.Enums
|
|||||||
|
|
||||||
[Display(Name = "long", Description = "Int64")]
|
[Display(Name = "long", Description = "Int64")]
|
||||||
Long,
|
Long,
|
||||||
|
|
||||||
|
[Display(Name ="bool",Description = "Boolean")]
|
||||||
|
Bool,
|
||||||
|
|
||||||
|
[Display(Name = "decimal",Description = "Decimal")]
|
||||||
|
Decimal,
|
||||||
|
|
||||||
|
[Display(Name = "DateTime", Description = "DateTime")]
|
||||||
|
DateTime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,15 @@ namespace Yi.Framework.Module.WebFirstManager.Handler
|
|||||||
fieldStrs.AppendLine(lengthStr);
|
fieldStrs.AppendLine(lengthStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//添加可空类型
|
||||||
|
string nullStr ="";
|
||||||
|
if (field.IsRequired == false)
|
||||||
|
{
|
||||||
|
nullStr = "?";
|
||||||
|
}
|
||||||
|
|
||||||
//添加字段
|
//添加字段
|
||||||
var fieldStr = $"public {typeStr} {nameStr} {{ get; set; }}";
|
var fieldStr = $"public {typeStr}{nullStr} {nameStr} {{ get; set; }}";
|
||||||
|
|
||||||
fieldStrs.AppendLine(fieldStr);
|
fieldStrs.AppendLine(fieldStr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
v-hasPermi="['system:config:add']"
|
v-hasPermi="['system:config:add']"
|
||||||
>新增</el-button
|
>新增</el-button
|
||||||
>
|
>
|
||||||
|
<!-- :disabled="props.table.name==null" -->
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button
|
<el-button
|
||||||
@@ -94,7 +95,11 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column label="长度" align="center" prop="length" />
|
<el-table-column label="长度" align="center" prop="length" >
|
||||||
|
<template #default="scope">
|
||||||
|
{{ scope.row.length==0?'-':scope.row.length }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column label="是否必填" align="center" prop="isRequired" >
|
<el-table-column label="是否必填" align="center" prop="isRequired" >
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
|
|||||||
Reference in New Issue
Block a user