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.

109 lines
3.8 KiB
C#

1 year ago
using Admin.Core.Common;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Admin.Core.Api
{
/// <summary>
/// Controller代码生成
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
[AllowAnonymous]
public class SeedController : ControllerBase
{
private readonly SqlSugarClient _sqlSugarClient;
private readonly IWebHostEnvironment Env;
/// <summary>
/// 构造方法
/// </summary>
/// <param name="sqlSugarClient"></param>
/// <param name="env"></param>
public SeedController(ISqlSugarClient sqlSugarClient, IWebHostEnvironment env)
{
_sqlSugarClient = sqlSugarClient as SqlSugarClient;
Env = env;
}
/// <summary>
/// 获取控制器(需指定表名和数据库)
/// </summary>
/// <param name="ConnID">数据库链接名称</param>
/// <param name="tableNames">需要生成的表名</param>
/// <returns></returns>
[HttpPost]
public string GetFrameFilesByTableNamesForController([FromBody] string[] tableNames, [FromQuery] string ConnID = null)
{
ConnID = ConnID == null ? MainDb.CurrentDbConnId.ToLower() : ConnID;
var isMuti = Appsettings.app(new string[] { "MutiDBEnabled" }).ObjToBool();
var seed = FrameSeed.CreateControllers(_sqlSugarClient, ConnID, isMuti, tableNames);
var data = $"库{ConnID}-Controllers层生成{seed}";
return data;
}
/// <summary>
/// 获取实体(需指定表名和数据库)
/// </summary>
/// <param name="ConnID">数据库链接名称</param>
/// <param name="tableNames">需要生成的表名</param>
/// <returns></returns>
[HttpPost]
public string GetFrameFilesByTableNamesForEntity([FromBody] string[] tableNames, [FromQuery] string ConnID = null)
{
ConnID = ConnID == null ? MainDb.CurrentDbConnId.ToLower() : ConnID;
var isMuti = Appsettings.app(new string[] { "MutiDBEnabled" }).ObjToBool();
var data = $"库{ConnID}-Models层生成{FrameSeed.CreateModels(_sqlSugarClient, ConnID, isMuti, tableNames)}";
return data;
}
/// <summary>
/// 获取控制器、服务、仓储、实体(需指定表名和数据库)
/// </summary>
/// <param name="ConnID">数据库链接名称</param>
/// <param name="tableNames">需要生成的表名</param>
/// <returns></returns>
[HttpPost]
public string GetFrameFilesByTableNames([FromBody] string[] tableNames, [FromQuery] string ConnID = null)
{
try
{
ConnID = ConnID == null ? MainDb.CurrentDbConnId.ToLower() : ConnID;
var isMuti = Appsettings.app(new string[] { "MutiDBEnabled" }).ObjToBool();
FrameSeed.CreateControllers(_sqlSugarClient, ConnID, isMuti, tableNames);
FrameSeed.CreateIServices(_sqlSugarClient, ConnID, isMuti, tableNames);
FrameSeed.CreateServices(_sqlSugarClient, ConnID, isMuti, tableNames);
FrameSeed.CreateIRepositorys(_sqlSugarClient, ConnID, isMuti, tableNames);
FrameSeed.CreateRepository(_sqlSugarClient, ConnID, isMuti, tableNames);
FrameSeed.CreateModels(_sqlSugarClient, ConnID, isMuti, tableNames);
var data = $"库{ConnID}-控制器、服务、仓储、实体层生成";
return data;
}
catch (Exception)
{
throw;
}
}
}
}