feat: 完成code to web模块
This commit is contained in:
@@ -6,20 +6,20 @@ using Yi.Framework.Module.WebFirstManager.Handler;
|
||||
namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 模板领域服务
|
||||
/// 代码文件领域服务,与代码文件生成相关,web to code
|
||||
/// </summary>
|
||||
public class TemplateManager : ITransient
|
||||
public class CodeFileManager : ITransient
|
||||
{
|
||||
private IEnumerable<ITemplateHandler> _templateHandlers;
|
||||
private IRepository<TemplateEntity> _repository;
|
||||
private IRepository<FieldEntity> _fieldRepository;
|
||||
public TemplateManager(IEnumerable<ITemplateHandler> templateHandlers, IRepository<FieldEntity> fieldRepository, IRepository<TemplateEntity> repository)
|
||||
public CodeFileManager(IEnumerable<ITemplateHandler> templateHandlers, IRepository<FieldEntity> fieldRepository, IRepository<TemplateEntity> repository)
|
||||
{
|
||||
_templateHandlers = templateHandlers;
|
||||
_repository = repository;
|
||||
_fieldRepository = fieldRepository;
|
||||
}
|
||||
public async Task HandlerAsync(TableEntity tableEntity)
|
||||
public async Task BuildWebToCodeAsync(TableAggregateRoot tableEntity)
|
||||
{
|
||||
var templates = await _repository.GetListAsync();
|
||||
var fields = await _fieldRepository.GetListAsync();
|
||||
@@ -29,7 +29,6 @@ namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
foreach (var templateHandler in _templateHandlers)
|
||||
{
|
||||
templateHandler.SetTable(tableEntity);
|
||||
templateHandler.SetFields(fields);
|
||||
templateStr = templateHandler.Invoker(templateStr);
|
||||
}
|
||||
|
||||
@@ -43,6 +42,8 @@ namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
|
||||
//await File.WriteAllTextAsync(str, templateEntity.BuildPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,14 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Furion.DependencyInjection;
|
||||
|
||||
namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
{
|
||||
internal class DataBaseManger
|
||||
/// <summary>
|
||||
/// 数据库领域服务,与数据库相关,同步到数据库,web to db ,code to db
|
||||
/// </summary>
|
||||
public class DataBaseManger : ITransient
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EasyTool;
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using Mapster.Utils;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Org.BouncyCastle.Asn1.Ntt;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Helper;
|
||||
using Yi.Framework.Module.WebFirstManager.Entities;
|
||||
using Yi.Framework.Module.WebFirstManager.Enums;
|
||||
using DescriptionAttribute = System.ComponentModel.DescriptionAttribute;
|
||||
|
||||
namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 与webfrist相关,同步到web,code to web
|
||||
/// </summary>
|
||||
public class WebTemplateManager : ITransient
|
||||
{
|
||||
private IRepository<TableAggregateRoot> _repository;
|
||||
public WebTemplateManager(IRepository<TableAggregateRoot> repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过当前的实体代码获取表存储
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public Task<List<TableAggregateRoot>> BuildCodeToWebAsync()
|
||||
{
|
||||
var entityTypes = new List<Type>();
|
||||
foreach (var assembly in App.Assemblies)
|
||||
{
|
||||
foreach (var t in assembly.GetTypes())
|
||||
{
|
||||
if (t.GetCustomAttributes(false).Any(a => a.GetType().Equals(typeof(SugarTable))
|
||||
&& !t.GetCustomAttributes(false).Any(a => a.GetType().Equals(typeof(SplitTableAttribute)))))
|
||||
{
|
||||
entityTypes.Add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var tableAggregateRoots = new List<TableAggregateRoot>();
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
tableAggregateRoots.Add(EntityTypeMapperToTable(entityType));
|
||||
}
|
||||
|
||||
return Task.FromResult(tableAggregateRoots);
|
||||
}
|
||||
|
||||
private TableAggregateRoot EntityTypeMapperToTable(Type entityType)
|
||||
{
|
||||
var tableAggregateRoot = new TableAggregateRoot();
|
||||
tableAggregateRoot.Fields = new List<FieldEntity>();
|
||||
var table = entityType.GetCustomAttribute<SugarTable>();
|
||||
|
||||
tableAggregateRoot.Name = table.TableName;
|
||||
|
||||
foreach (var p in entityType.GetProperties())
|
||||
{
|
||||
tableAggregateRoot.Fields.Add(PropertyMapperToFiled(p));
|
||||
}
|
||||
tableAggregateRoot.Fields.ForEach(x => x.TableId = tableAggregateRoot.Id);
|
||||
return tableAggregateRoot;
|
||||
}
|
||||
|
||||
|
||||
private FieldEntity PropertyMapperToFiled(PropertyInfo propertyInfo)
|
||||
{
|
||||
var fieldEntity = new FieldEntity();
|
||||
fieldEntity.Name = propertyInfo.Name;
|
||||
var enumName = typeof(FieldTypeEnum).GetFields(BindingFlags.Static | BindingFlags.Public).Where(x => x.GetCustomAttribute<DescriptionAttribute>()?.Description == propertyInfo.PropertyType.Name).FirstOrDefault()?.Name;
|
||||
if (enumName is null)
|
||||
{
|
||||
fieldEntity.FieldType = FieldTypeEnum.String;
|
||||
Console.Out.WriteLine($"字段类型:{propertyInfo.PropertyType.Name},未定义");
|
||||
//throw new ApplicationException($"字段类型:{propertyInfo.PropertyType.Name},未定义");
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldEntity.FieldType = EnumUtil.Parse<FieldTypeEnum>(enumName);
|
||||
}
|
||||
|
||||
var colum = propertyInfo.GetCustomAttribute<SugarColumn>();
|
||||
if (colum is not null && colum.Length != 0)
|
||||
{
|
||||
fieldEntity.Length = colum.Length;
|
||||
}
|
||||
return fieldEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user