using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ZR.CodeGenerator;
using ZR.CodeGenerator.Service;
using ZR.Model;
using ZR.Model.CodeGenerator;
using ZR.Model.Vo;
using ZR.Service.IService;
using ZR.Service.System;
namespace ZR.Admin.WebApi.Controllers
{
///
/// 代码生成
///
[Route("codeGenerator")]
public class CodeGeneratorController : BaseController
{
//public ICodeGeneratorService CodeGeneratorService;
//public CodeGeneratorController(ICodeGeneratorService codeGeneratorService)
//{
// CodeGeneratorService = codeGeneratorService;
//}
private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
///
/// 获取所有数据库的信息
///
///
[HttpGet("GetListDataBase")]
//[YuebonAuthorize("GetListDataBase")]
//[NoPermissionRequired]
public IActionResult GetListDataBase()
{
return SUCCESS(_CodeGeneraterService.GetAllDataBases());
}
///
///获取所有表根据数据名
///
/// 数据库名
/// 表名
/// 分页信息
///
[HttpGet("FindListTable")]
public IActionResult FindListTable(string dbName, string tableName, PagerInfo pager)
{
if (string.IsNullOrEmpty(dbName))
{
dbName = "ZrAdmin";
}
List list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager);
var vm = new VMPageResult(list, pager);
return SUCCESS(vm);
}
///
/// 代码生成器
///
///
/// 要生成代码的表
/// 项目命名空间
/// 要删除表名的字符串用英文逗号","隔开
///
[HttpGet("Generate")]
[Log(Title = "代码生成", BusinessType = BusinessType.OTHER)]
public IActionResult Generate(string dbName, string baseSpace, string tables, string replaceTableNameStr)
{
if (string.IsNullOrEmpty(tables))
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
}
if (string.IsNullOrEmpty(baseSpace))
{
//baseSpace = "Zr";
}
DbTableInfo dbTableInfo = new() { Name = tables };
CodeGeneratorTool.Generate(dbName, baseSpace, dbTableInfo, replaceTableNameStr, true);
return SUCCESS(1);
}
}
}