You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using Estsh.Core.CodeGenerate;
|
|
using Estsh.Core.Controllers;
|
|
using Estsh.Core.Dapper;
|
|
using Estsh.Core.Model.Result;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Estsh.Core.Web.Controllers
|
|
{
|
|
[Route("[controller]")]
|
|
[ApiController]
|
|
public class CodeGeneratorController : Controller
|
|
{
|
|
[HttpGet("Index")]
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpGet("GetGenerate")]
|
|
public IActionResult GetGenerate(string tables, string baseSpace)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(baseSpace))
|
|
{
|
|
result.message = "项目命名空间不能为空";
|
|
result.ErrCode = "错误代码:入参为空";
|
|
}
|
|
else
|
|
{
|
|
DapperDbContext dbContext = HttpContext?.RequestServices.GetService(typeof(DapperDbContext)) as DapperDbContext;
|
|
CodeGenerator codeGenerator = new CodeGenerator();
|
|
codeGenerator.Generate(baseSpace, tables, dbContext);
|
|
result.message = "生成成功";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//Log4NetHelper.Error("代码生成异常", ex);
|
|
result.message = "代码生成异常:" + ex.Message;
|
|
result.ErrCode = "错误代码:代码异常";
|
|
}
|
|
|
|
return Json(result);;
|
|
}
|
|
}
|
|
}
|