namespace MiaoYu.Api.Admin.Controllers.DevelopmentTools;
///
/// 代码生成器控制器
///
[ControllerDescriptor(MenuId = "31")]
public class CodeGenerationController : AdminControllerBase
{
public CodeGenerationController(ICodeGenerationService defaultService) : base(defaultService)
{
}
///
/// 获取所有数据库列表
///
///
[ActionDescriptor(DisplayName = "获取数据库列表")]
[HttpGet]
public List GetDatabasesAsync()
{
return _defaultService.GetAllDataSources();
}
///
/// 获取列表
///
///
///
///
///
[ActionDescriptor(DisplayName = "查询列表")]
[HttpPost("{size}/{page}")]
public PagingView FindListAsync([FromRoute] int size, [FromRoute] int page, [FromBody] GenFormDto search)
{
return _defaultService.GetGenContextDtos(page, size, search);
}
///
/// 获取代码 根据 表名 和 类型
///
///
///
[ActionDescriptor(DisplayName = "获取代码")]
[HttpPost]
public async Task GetCodeAsync([FromBody] GenFormDto genFormDto)
{
var code = await _defaultService.GetCodeByTypeAndTableNameAsync(genFormDto);
//var lowCodeTableInfos = new List();
if (!string.IsNullOrWhiteSpace(genFormDto.TableName))
{
var table = _defaultService.GetGenContextDtoByTableName(
genFormDto.TableName,
genFormDto.DataBase);
//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 _defaultService.DownloadAsync(genFormDto);
HttpContext.DownLoadFile(codeBytes, contentType, fileName);
}
///
/// 创建代码文件
///
///
///
[ActionDescriptor(DisplayName = "创建代码文件")]
[HttpPost]
public async Task DownloadAllAsync([FromBody] GenFormDto genFormDto)
{
var (codeBytes, contentType, fileName) = await _defaultService.DownloadAllAsync(genFormDto);
HttpContext.DownLoadFile(codeBytes, contentType, fileName);
}
///
/// 数据库字典文件
///
///
[ActionDescriptor(DisplayName = "生成数据库字典文件")]
[HttpPost]
public void CreateDataDictionary()
{
var data = _defaultService.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 _defaultService.AutoImprotProjectAsync(genFormDto);
return true;
}
}