style: 修改codegen命名

This commit is contained in:
橙子
2024-02-16 21:06:34 +08:00
parent 6675376241
commit 3f1f76b2e8
50 changed files with 141 additions and 143 deletions

View File

@@ -0,0 +1,99 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
using Volo.Abp.Uow;
using Yi.Framework.CodeGen.Application.Contracts.IServices;
using Yi.Framework.CodeGen.Domain.Entities;
using Yi.Framework.CodeGen.Domain.Managers;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.CodeGen.Application.Services
{
/// <summary>
/// CodeGen
/// </summary>
public class CodeGenService : ApplicationService, ICodeGenService
{
private ISqlSugarRepository<TableAggregateRoot, Guid> _tableRepository;
private CodeFileManager _codeFileManager;
private WebTemplateManager _webTemplateManager;
public CodeGenService(ISqlSugarRepository<TableAggregateRoot, Guid> tableRepository, CodeFileManager codeFileManager, WebTemplateManager webTemplateManager)
{
_tableRepository = tableRepository;
_codeFileManager = codeFileManager;
_webTemplateManager = webTemplateManager;
}
/// <summary>
/// Web To Code
/// </summary>
/// <returns></returns>
public async Task PostWebBuildCodeAsync(List<Guid> ids)
{
//获取全部表
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);
}
}
/// <summary>
/// Web To Db
/// </summary>
/// <returns></returns>
public async Task PostWebBuildDbAsync()
{
throw new NotImplementedException();
}
/// <summary>
/// Code To Web
/// </summary>
/// <returns></returns>
[UnitOfWork]
public async Task PostCodeBuildWebAsync()
{
var tableAggregateRoots = await _webTemplateManager.BuildCodeToWebAsync();
//覆盖数据库,将聚合根保存到数据库
_tableRepository._Db.DbMaintenance.TruncateTable<TableAggregateRoot>();
_tableRepository._Db.DbMaintenance.TruncateTable<FieldEntity>();
//导航插入即可
await _tableRepository._Db.InsertNav(tableAggregateRoots).Include(x => x.Fields).ExecuteCommandAsync();
}
/// <summary>
/// Code To Db
/// </summary>
/// <returns></returns>
public async Task PostCodeBuildDbAsync()
{
throw new NotImplementedException();
}
/// <summary>
/// 打开目录
/// </summary>
/// <returns></returns>
[HttpPost("code-gen/dir/{**path}")]
public async Task PostDir([FromRoute] string path)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
path = Uri.UnescapeDataString(path);
//去除包含@的目录
path = string.Join("\\", path.Split("\\").Where(x => !x.Contains("@")).ToList());
Process.Start("explorer.exe", path);
}
else
{
throw new UserFriendlyException("当前操作系统不支持打开目录");
}
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Reflection;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;
using Yi.Framework.CodeGen.Application.Contracts.Dtos.Field;
using Yi.Framework.CodeGen.Application.Contracts.IServices;
using Yi.Framework.CodeGen.Domain.Entities;
using Yi.Framework.CodeGen.Domain.Shared.Enums;
using Yi.Framework.Ddd.Application;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.CodeGen.Application.Services
{
/// <summary>
/// 字段管理
/// </summary>
public class FieldService : YiCrudAppService<FieldEntity, FieldDto, Guid, FieldGetListInput>, IFieldService
{
private ISqlSugarRepository<FieldEntity, Guid> _repository;
public FieldService(ISqlSugarRepository<FieldEntity, Guid> repository) : base(repository)
{
_repository = repository;
}
public async override Task<PagedResultDto<FieldDto>> GetListAsync([FromQuery] FieldGetListInput input)
{
RefAsync<int> total = 0;
var entities = await _repository._DbQueryable.WhereIF(input.TableId is not null, x => x.TableId.Equals(input.TableId!))
.WhereIF(input.Name is not null, x => x.Name!.Contains(input.Name!))
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<FieldDto>
{
TotalCount = total,
Items = await MapToGetListOutputDtosAsync(entities)
};
}
/// <summary>
/// 获取类型枚举
/// </summary>
/// <returns></returns>
[Route("field/type")]
public object GetFieldTypeEnum()
{
return typeof(FieldTypeEnum).GetFields(BindingFlags.Static | BindingFlags.Public).Select(x => new { lable = x.Name, value = (int)Enum.Parse(typeof(FieldTypeEnum), x.Name) }).ToList();
}
}
}

View File

@@ -0,0 +1,21 @@
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;
using Yi.Framework.CodeGen.Application.Contracts.Dtos.Table;
using Yi.Framework.CodeGen.Application.Contracts.IServices;
using Yi.Framework.CodeGen.Domain.Entities;
using Yi.Framework.Ddd.Application;
namespace Yi.Framework.CodeGen.Application.Services
{
public class TableService : YiCrudAppService<TableAggregateRoot, TableDto, Guid, TableGetListInput>, ITableService
{
public TableService(IRepository<TableAggregateRoot, Guid> repository) : base(repository)
{
}
public override Task<PagedResultDto<TableDto>> GetListAsync(TableGetListInput input)
{
return base.GetListAsync(input);
}
}
}

View File

@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Yi.Framework.CodeGen.Application.Contracts.Dtos.Template;
using Yi.Framework.CodeGen.Application.Contracts.IServices;
using Yi.Framework.CodeGen.Domain.Entities;
using Yi.Framework.Ddd.Application;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.CodeGen.Application.Services;
public class TemplateService : YiCrudAppService<TemplateEntity, TemplateDto, Guid, TemplateGetListInput>, ITemplateService
{
private ISqlSugarRepository<TemplateEntity, Guid> _repository;
public TemplateService(ISqlSugarRepository<TemplateEntity, Guid> repository) : base(repository)
{
_repository = repository;
}
public async override Task<PagedResultDto<TemplateDto>> GetListAsync([FromQuery] TemplateGetListInput input)
{
RefAsync<int> total = 0;
var entities = await _repository._DbQueryable.WhereIF(input.Name is not null, x => x.Name.Equals(input.Name!))
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<TemplateDto>
{
TotalCount = total,
Items = await MapToGetListOutputDtosAsync(entities)
};
}
}