namespace CloudGaming.Api.Admin.Controllers.DevelopmentTools;
///
/// 代码生成器控制器
///
[ControllerDescriptor(MenuId = "31")]
public class CodeGenerationController(IServiceProvider serviceProvider)
: AdminControllerBase(serviceProvider)
{
///
/// 获取列表
///
///
///
///
///
[ActionDescriptor(DisplayName = "查询列表")]
[HttpPost("{size}/{page}")]
public PagingView FindListAsync([FromRoute] int size, [FromRoute] int page, [FromBody] GenFormDto search)
{
return Service.GetGenContextDtos(page, size, search);
}
///
/// 获取代码 根据 表名 和 类型
///
///
///
[ActionDescriptor(DisplayName = "获取代码")]
[HttpPost]
public async Task GetCodeAsync([FromBody] GenFormDto genFormDto)
{
var code = await Service.GetCodeByTypeAndTableNameAsync(genFormDto);
//var lowCodeTableInfos = new List();
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()
};
}
///
/// 下载当前代码
///
///
///
[ActionDescriptor(DisplayName = "下载当前代码")]
[HttpPost]
public async Task DownloadAsync([FromBody] GenFormDto genFormDto)
{
var (codeBytes, contentType, fileName) = await Service.DownloadAsync(genFormDto);
HttpContext.DownLoadFile(codeBytes, contentType, fileName);
}
///
/// 创建代码文件
///
///
///
[ActionDescriptor(DisplayName = "创建代码文件")]
[HttpPost]
public async Task DownloadAllAsync([FromBody] GenFormDto genFormDto)
{
var (codeBytes, contentType, fileName) = await Service.DownloadAllAsync(genFormDto);
HttpContext.DownLoadFile(codeBytes, contentType, fileName);
}
///
/// 数据库字典文件
///
///
[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);
}
///
/// 生成代码并自动导入项目
///
///
///
[ActionDescriptor(DisplayName = "生成代码并自动导入项目")]
[HttpPost]
public async Task AutoImprotProjectAsync([FromBody] GenFormDto genFormDto)
{
await Service.AutoImprotProjectAsync(genFormDto);
return true;
}
}