feat: webfrist基本流程已完成
This commit is contained in:
@@ -22,25 +22,29 @@ namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
public async Task BuildWebToCodeAsync(TableAggregateRoot tableEntity)
|
||||
{
|
||||
var templates = await _repository.GetListAsync();
|
||||
var fields = await _fieldRepository.GetListAsync();
|
||||
foreach (var template in templates)
|
||||
{
|
||||
string templateStr = template.TemplateStr;
|
||||
var handledTempalte = new HandledTemplate();
|
||||
handledTempalte.TemplateStr= template.TemplateStr;
|
||||
handledTempalte.BuildPath = template.BuildPath;
|
||||
foreach (var templateHandler in _templateHandlers)
|
||||
{
|
||||
templateHandler.SetTable(tableEntity);
|
||||
templateStr = templateHandler.Invoker(templateStr);
|
||||
handledTempalte = templateHandler.Invoker(handledTempalte.TemplateStr, handledTempalte.BuildPath);
|
||||
}
|
||||
await BuildToFileAsync(handledTempalte);
|
||||
|
||||
await BuildToFileAsync(templateStr, template);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task BuildToFileAsync(string str, TemplateEntity templateEntity)
|
||||
private async Task BuildToFileAsync(HandledTemplate handledTemplate)
|
||||
{
|
||||
|
||||
//await File.WriteAllTextAsync(str, templateEntity.BuildPath);
|
||||
if (!Directory.Exists(Path.GetDirectoryName(handledTemplate.BuildPath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(handledTemplate.BuildPath));
|
||||
}
|
||||
await File.WriteAllTextAsync(handledTemplate.BuildPath,handledTemplate.TemplateStr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EasyTool;
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
@@ -82,7 +82,7 @@ namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
{
|
||||
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;
|
||||
var enumName = typeof(FieldTypeEnum).GetFields(BindingFlags.Static | BindingFlags.Public).Where(x => x.GetCustomAttribute<DisplayAttribute>()?.Name== propertyInfo.PropertyType.Name).FirstOrDefault()?.Name;
|
||||
if (enumName is null)
|
||||
{
|
||||
fieldEntity.FieldType = FieldTypeEnum.String;
|
||||
@@ -91,7 +91,7 @@ namespace Yi.Framework.Module.WebFirstManager.Domain
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldEntity.FieldType = EnumUtil.Parse<FieldTypeEnum>(enumName);
|
||||
fieldEntity.FieldType =EasyTool.EnumUtil.Parse<FieldTypeEnum>(enumName);
|
||||
}
|
||||
|
||||
var colum = propertyInfo.GetCustomAttribute<SugarColumn>();
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Infrastructure.Ddd.Dtos.Abstract;
|
||||
using Yi.Framework.Infrastructure.Ddd.Dtos.Abstract;
|
||||
|
||||
namespace Yi.Framework.Module.WebFirstManager.Dtos.Template
|
||||
{
|
||||
@@ -20,5 +15,16 @@ namespace Yi.Framework.Module.WebFirstManager.Dtos.Template
|
||||
/// 生成路径
|
||||
/// </summary>
|
||||
public string BuildPath { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 模板名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? Remarks { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,11 @@ namespace Yi.Framework.Module.WebFirstManager.Dtos.Template
|
||||
{
|
||||
public class TemplateGetListInput : PagedAndSortedResultRequestDto
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 模板名称
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,22 @@ namespace Yi.Framework.Module.WebFirstManager.Entities
|
||||
/// <summary>
|
||||
/// 模板字符串
|
||||
/// </summary>
|
||||
[SugarColumn(Length =99999)]
|
||||
public string TemplateStr { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 生成路径
|
||||
/// </summary>
|
||||
public string BuildPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? Remarks { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,13 +11,13 @@ namespace Yi.Framework.Module.WebFirstManager.Enums
|
||||
{
|
||||
public enum FieldTypeEnum
|
||||
{
|
||||
[Description("String")]
|
||||
[Display(Name ="string",Description = "String")]
|
||||
String,
|
||||
|
||||
[Description("Int32")]
|
||||
[Display(Name = "int", Description = "Int32")]
|
||||
Int,
|
||||
|
||||
[Description("Int64")]
|
||||
[Display(Name = "long", Description = "Int64")]
|
||||
Long,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
using System.Text;
|
||||
using EasyTool;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Furion.DependencyInjection;
|
||||
using Yi.Framework.Module.WebFirstManager.Enums;
|
||||
|
||||
namespace Yi.Framework.Module.WebFirstManager.Handler
|
||||
{
|
||||
public class FieldTemplateHandler : TemplateHandlerBase, ITemplateHandler, ISingleton
|
||||
{
|
||||
public string Invoker(string str)
|
||||
public HandledTemplate Invoker(string str,string path)
|
||||
{
|
||||
return str.Replace("@field", BuildFields());
|
||||
var output= new HandledTemplate();
|
||||
output.TemplateStr = str.Replace("@field", BuildFields());
|
||||
output.BuildPath = path;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +29,20 @@ namespace Yi.Framework.Module.WebFirstManager.Handler
|
||||
|
||||
foreach (var field in Table.Fields)
|
||||
{
|
||||
var typeStr = EnumUtil.GetDescriptionByValue(field.FieldType);
|
||||
var typeStr = typeof(FieldTypeEnum).GetFields().Where(x=> x.Name== field.FieldType.ToString())?.FirstOrDefault().GetCustomAttribute<DisplayAttribute>().Name;
|
||||
|
||||
if (typeStr is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var nameStr = field.Name;
|
||||
|
||||
//添加备注
|
||||
if (string.IsNullOrEmpty(field.Description))
|
||||
if (!string.IsNullOrEmpty(field.Description))
|
||||
{
|
||||
var desStr = "/// <summary>" +
|
||||
@$"///{field.Description}" +
|
||||
"/// </summary>";
|
||||
var desStr = "/// <summary>\n" +
|
||||
$"///{field.Description}\n" +
|
||||
"/// </summary>\n";
|
||||
fieldStrs.AppendLine(desStr);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Module.WebFirstManager.Handler
|
||||
{
|
||||
public class HandledTemplate
|
||||
{
|
||||
public string TemplateStr { get; set; }
|
||||
|
||||
public string BuildPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,6 @@ namespace Yi.Framework.Module.WebFirstManager.Handler
|
||||
public interface ITemplateHandler
|
||||
{
|
||||
void SetTable(TableAggregateRoot table);
|
||||
string Invoker(string str);
|
||||
HandledTemplate Invoker(string str, string path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,12 @@ namespace Yi.Framework.Module.WebFirstManager.Handler
|
||||
{
|
||||
public class ModelTemplateHandler : TemplateHandlerBase, ITemplateHandler, ISingleton
|
||||
{
|
||||
public string Invoker(string str)
|
||||
public HandledTemplate Invoker(string str, string path)
|
||||
{
|
||||
return str.Replace("@model", StrUtil.ToFirstLetterLowerCase(Table.Name)).Replace("@Model", StrUtil.ToFirstLetterUpperCase(Table.Name));
|
||||
var output = new HandledTemplate();
|
||||
output.TemplateStr= str.Replace("@model", StrUtil.ToFirstLetterLowerCase(Table.Name)).Replace("@Model", StrUtil.ToFirstLetterUpperCase(Table.Name));
|
||||
output.BuildPath = path.Replace("@model", StrUtil.ToFirstLetterLowerCase(Table.Name)).Replace("@Model", StrUtil.ToFirstLetterUpperCase(Table.Name));
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@ namespace Yi.Framework.Module.WebFirstManager.Handler
|
||||
{
|
||||
public class NameSpaceTemplateHandler : TemplateHandlerBase, ITemplateHandler, ISingleton
|
||||
{
|
||||
public string Invoker(string str)
|
||||
public HandledTemplate Invoker(string str, string path)
|
||||
{
|
||||
return str.Replace("@namespace", "");
|
||||
var output = new HandledTemplate();
|
||||
output.TemplateStr = str.Replace("@namespace", "");
|
||||
output.BuildPath = path;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Module.WebFirstManager.Dtos.Table;
|
||||
using Yi.Framework.Module.WebFirstManager.Dtos.Template;
|
||||
using Yi.Framework.Module.WebFirstManager.Entities;
|
||||
|
||||
namespace Yi.Framework.Module.WebFirstManager.Impl
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Module.WebFirstManager.Dtos.Template;
|
||||
using Yi.Framework.Module.WebFirstManager.Entities;
|
||||
@@ -15,5 +12,17 @@ namespace Yi.Framework.Module.WebFirstManager.Impl
|
||||
[ApiDescriptionSettings("WebFirstManager")]
|
||||
public class TemplateService : CrudAppService<TemplateEntity, TemplateDto, long, TemplateGetListInput>, ITemplateService, IDynamicApiController, ITransient
|
||||
{
|
||||
public async override Task<PagedResultDto<TemplateDto>> GetListAsync([FromQuery] TemplateGetListInput input)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
var entities = await _DbQueryable.WhereIF(input.Name is not null, x => x.Name.Equals(input.Name!))
|
||||
.ToPageListAsync(input.PageNum, input.PageSize, total);
|
||||
|
||||
return new PagedResultDto<TemplateDto>
|
||||
{
|
||||
Total = total,
|
||||
Items = await MapToGetListOutputDtosAsync(entities)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -27,17 +28,17 @@ namespace Yi.Framework.Module.WebFirstManager.Impl
|
||||
{
|
||||
_tableRepository = tableRepository;
|
||||
_codeFileManager = codeFileManager;
|
||||
_webTemplateManager= webTemplateManager;
|
||||
_webTemplateManager = webTemplateManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Web To Code
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task PostWebBuildCodeAsync()
|
||||
public async Task PostWebBuildCodeAsync(List<long> ids)
|
||||
{
|
||||
//获取全部表
|
||||
var tables = await _tableRepository.GetListAsync();
|
||||
var tables = await _tableRepository._DbQueryable.Where(x => ids.Contains(x.Id)).Includes(x => x.Fields).ToListAsync();
|
||||
foreach (var table in tables)
|
||||
{
|
||||
await _codeFileManager.BuildWebToCodeAsync(table);
|
||||
@@ -61,7 +62,7 @@ namespace Yi.Framework.Module.WebFirstManager.Impl
|
||||
[UnitOfWork]
|
||||
public async Task PostCodeBuildWebAsync()
|
||||
{
|
||||
var tableAggregateRoots =await _webTemplateManager.BuildCodeToWebAsync();
|
||||
var tableAggregateRoots = await _webTemplateManager.BuildCodeToWebAsync();
|
||||
//覆盖数据库,将聚合根保存到数据库
|
||||
_tableRepository._Db.DbMaintenance.TruncateTable<TableAggregateRoot>();
|
||||
_tableRepository._Db.DbMaintenance.TruncateTable<FieldEntity>();
|
||||
@@ -69,7 +70,7 @@ namespace Yi.Framework.Module.WebFirstManager.Impl
|
||||
//导航插入即可
|
||||
await _tableRepository._Db.InsertNav(tableAggregateRoots).Include(x => x.Fields).ExecuteCommandAsync();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -80,5 +81,17 @@ namespace Yi.Framework.Module.WebFirstManager.Impl
|
||||
public async Task PostCodeBuildDbAsync()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task PostDir(string path)
|
||||
{
|
||||
path = Uri.UnescapeDataString(path);
|
||||
//去除包含@的目录
|
||||
path = string.Join("\\", path.Split("\\").Where(x => !x.Contains("@")).ToList());
|
||||
Process.Start("explorer.exe", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user