代码生成增加预览功能、其他功能优化

This commit is contained in:
izory
2021-09-24 18:37:51 +08:00
parent 3a418df47f
commit a4a6f673b2
21 changed files with 516 additions and 622 deletions

View File

@@ -94,7 +94,7 @@ namespace ZR.Admin.WebApi.Controllers
//生成代码
CodeGeneratorTool.Generate(genTableInfo, dto);
//下载文件
CodeGeneratorTool.ZipGenCode(dto);
FileHelper.ZipGenCode(dto);
//HttpContext.Response.Headers.Add("Content-disposition", $"attachment; filename={zipFileName}");
return SUCCESS(new { zipPath = "/Generatecode/" + dto.ZipFileName, fileName = dto.ZipFileName });
@@ -145,7 +145,7 @@ namespace ZR.Admin.WebApi.Controllers
}
/// <summary>
/// 导入表
/// 导入表结构(保存)
/// </summary>
/// <param name="tables"></param>
/// <param name="dbName"></param>
@@ -218,5 +218,32 @@ namespace ZR.Admin.WebApi.Controllers
}
return SUCCESS(rows);
}
/// <summary>
/// 预览代码
/// </summary>
/// <param name="tableId"></param>
/// <returns></returns>
[HttpGet("preview/{tableId}")]
[ActionPermissionFilter(Permission = "tool:gen:preview")]
public IActionResult Preview(long tableId)
{
if (tableId <= 0)
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
}
var genTableInfo = GenTableService.GetGenTableInfo(tableId);
genTableInfo.Columns = GenTableColumnService.GenTableColumns(tableId);
GenerateDto dto = new();
dto.GenTable = genTableInfo;
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
dto.IsPreview = 1;
dto.GenCodeFiles = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
//生成代码
CodeGeneratorTool.Generate(genTableInfo, dto);
return SUCCESS(dto.GenCodes);
}
}
}