Files
shanghaigangxiangtuzhuangMES/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs

98 lines
3.2 KiB
C#
Raw Normal View History

2021-09-06 18:35:36 +08:00
using Infrastructure;
2021-09-07 18:37:21 +08:00
using Infrastructure.Attribute;
using Infrastructure.Enums;
2021-09-06 18:35:36 +08:00
using Infrastructure.Model;
using Microsoft.AspNetCore.Mvc;
2021-09-07 21:52:44 +08:00
using SqlSugar;
2021-09-06 18:35:36 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2021-09-07 18:37:21 +08:00
using ZR.CodeGenerator;
2021-09-09 18:18:37 +08:00
using ZR.CodeGenerator.Model;
2021-09-07 18:37:21 +08:00
using ZR.CodeGenerator.Service;
2021-09-06 18:35:36 +08:00
using ZR.Model;
2021-09-06 21:37:32 +08:00
using ZR.Model.Vo;
2021-09-06 18:35:36 +08:00
using ZR.Service.IService;
using ZR.Service.System;
namespace ZR.Admin.WebApi.Controllers
{
/// <summary>
/// 代码生成
/// </summary>
2021-09-09 18:18:37 +08:00
[Route("tool/gen")]
2021-09-06 18:35:36 +08:00
public class CodeGeneratorController : BaseController
{
2021-09-07 18:37:21 +08:00
//public ICodeGeneratorService CodeGeneratorService;
//public CodeGeneratorController(ICodeGeneratorService codeGeneratorService)
//{
// CodeGeneratorService = codeGeneratorService;
//}
private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
2021-09-06 18:35:36 +08:00
/// <summary>
/// 获取所有数据库的信息
/// </summary>
/// <returns></returns>
2021-09-09 18:18:37 +08:00
[HttpGet("getDbList")]
2021-09-06 18:35:36 +08:00
//[YuebonAuthorize("GetListDataBase")]
public IActionResult GetListDataBase()
{
2021-09-09 18:18:37 +08:00
var dbList = _CodeGeneraterService.GetAllDataBases();
var defaultDb = dbList.Count > 0 ? dbList[0] : null;
return SUCCESS(new { dbList, defaultDb });
2021-09-06 18:35:36 +08:00
}
/// <summary>
///获取所有表根据数据名
/// </summary>
2021-09-07 18:37:21 +08:00
/// <param name="dbName">数据库名</param>
/// <param name="tableName">表名</param>
2021-09-06 21:37:32 +08:00
/// <param name="pager">分页信息</param>
2021-09-06 18:35:36 +08:00
/// <returns></returns>
[HttpGet("FindListTable")]
2021-09-07 18:37:21 +08:00
public IActionResult FindListTable(string dbName, string tableName, PagerInfo pager)
2021-09-06 18:35:36 +08:00
{
List<DbTableInfo> list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager);
var vm = new VMPageResult<DbTableInfo>(list, pager);
2021-09-06 18:35:36 +08:00
2021-09-06 21:37:32 +08:00
return SUCCESS(vm);
}
/// <summary>
2021-09-09 18:18:37 +08:00
/// 获取表格列
2021-09-06 21:37:32 +08:00
/// </summary>
2021-09-07 18:37:21 +08:00
/// <param name="dbName"></param>
2021-09-09 18:18:37 +08:00
/// <param name="tableName"></param>
/// <returns></returns>
[HttpGet("QueryColumnInfo")]
public IActionResult QueryColumnInfo(string dbName, string tableName)
{
if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName))
return ToRespose(ResultCode.PARAM_ERROR);
return SUCCESS(_CodeGeneraterService.GetColumnInfo(dbName, tableName));
}
/// <summary>
/// 代码生成器
/// </summary>
/// <param name="dto">数据传输对象</param>
2021-09-06 21:37:32 +08:00
/// <returns></returns>
[HttpGet("Generate")]
2021-09-07 18:37:21 +08:00
[Log(Title = "代码生成", BusinessType = BusinessType.OTHER)]
2021-09-09 18:18:37 +08:00
public IActionResult Generate([FromQuery] GenerateDto dto)
2021-09-06 21:37:32 +08:00
{
2021-09-09 18:18:37 +08:00
if (string.IsNullOrEmpty(dto.tables))
2021-09-07 18:37:21 +08:00
{
2021-09-07 21:52:44 +08:00
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
2021-09-07 18:37:21 +08:00
}
2021-09-09 18:18:37 +08:00
DbTableInfo dbTableInfo = new() { Name = dto.tables };
CodeGeneratorTool.Generate(dbTableInfo, dto);
2021-09-07 18:37:21 +08:00
2021-09-07 21:52:44 +08:00
return SUCCESS(1);
2021-09-06 18:35:36 +08:00
}
}
}