116 lines
3.7 KiB
C#
116 lines
3.7 KiB
C#
namespace CloudGaming.Api.Admin.Controllers.DevelopmentTools;
|
|
|
|
/// <summary>
|
|
/// 代码生成器控制器
|
|
/// </summary>
|
|
[ControllerDescriptor(MenuId = "31")]
|
|
public class CodeGenerationController(IServiceProvider serviceProvider)
|
|
: AdminControllerBase<ICodeGenerationService>(serviceProvider)
|
|
{
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="size"></param>
|
|
/// <param name="page"></param>
|
|
/// <param name="search"></param>
|
|
/// <returns></returns>
|
|
[ActionDescriptor(DisplayName = "查询列表")]
|
|
[HttpPost("{size}/{page}")]
|
|
public PagingView FindListAsync([FromRoute] int size, [FromRoute] int page, [FromBody] GenFormDto search)
|
|
{
|
|
return Service.GetGenContextDtos(page, size, search);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取代码 根据 表名 和 类型
|
|
/// </summary>
|
|
/// <param name="genFormDto"></param>
|
|
/// <returns></returns>
|
|
[ActionDescriptor(DisplayName = "获取代码")]
|
|
[HttpPost]
|
|
public async Task<dynamic> GetCodeAsync([FromBody] GenFormDto genFormDto)
|
|
{
|
|
var code = await Service.GetCodeByTypeAndTableNameAsync(genFormDto);
|
|
|
|
//var lowCodeTableInfos = new List<LowCodeTableInfo>();
|
|
|
|
if (!string.IsNullOrWhiteSpace(genFormDto.TableName))
|
|
{
|
|
var table = Service.GetGenContextDtoByTableName(genFormDto.TableName);
|
|
|
|
//lowCodeTableInfos = table.TableInfos;
|
|
}
|
|
|
|
return new
|
|
{
|
|
code,
|
|
//appTableInfos = lowCodeTableInfos.Select(w => new
|
|
//{
|
|
// w.Name=,
|
|
// w.DefaultValue,
|
|
// w.MaxLength,
|
|
// w.Position,
|
|
// w.DbTypeTextFull,
|
|
// w.Comment,
|
|
// CsTypeName = w.CsType.Name,
|
|
// w.IsPrimary,
|
|
// w.IsIdentity,
|
|
// w.IsNullable
|
|
//}).ToList()
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下载当前代码
|
|
/// </summary>
|
|
/// <param name="genFormDto"></param>
|
|
/// <returns></returns>
|
|
[ActionDescriptor(DisplayName = "下载当前代码")]
|
|
[HttpPost]
|
|
public async Task DownloadAsync([FromBody] GenFormDto genFormDto)
|
|
{
|
|
var (codeBytes, contentType, fileName) = await Service.DownloadAsync(genFormDto);
|
|
HttpContext.DownLoadFile(codeBytes, contentType, fileName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建代码文件
|
|
/// </summary>
|
|
/// <param name="genFormDto"></param>
|
|
/// <returns></returns>
|
|
[ActionDescriptor(DisplayName = "创建代码文件")]
|
|
[HttpPost]
|
|
public async Task DownloadAllAsync([FromBody] GenFormDto genFormDto)
|
|
{
|
|
var (codeBytes, contentType, fileName) = await Service.DownloadAllAsync(genFormDto);
|
|
HttpContext.DownLoadFile(codeBytes, contentType, fileName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据库字典文件
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[ActionDescriptor(DisplayName = "生成数据库字典文件")]
|
|
[HttpPost]
|
|
public void CreateDataDictionary()
|
|
{
|
|
var data = Service.CreateDataDictionary();
|
|
var fileName =
|
|
$"{(string.IsNullOrWhiteSpace(data.dataBase) ? "" : data.dataBase + "_")}数据库设计{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
|
|
|
|
HttpContext.DownLoadFile(data.excel, Tools.GetFileContentType[".xlsx"], fileName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成代码并自动导入项目
|
|
/// </summary>
|
|
/// <param name="genFormDto"></param>
|
|
/// <returns></returns>
|
|
[ActionDescriptor(DisplayName = "生成代码并自动导入项目")]
|
|
[HttpPost]
|
|
public async Task<bool> AutoImprotProjectAsync([FromBody] GenFormDto genFormDto)
|
|
{
|
|
await Service.AutoImprotProjectAsync(genFormDto);
|
|
return true;
|
|
}
|
|
} |