diff --git a/OpenAuth.App/DbExtension.cs b/OpenAuth.App/DbExtension.cs
index b09212bc..559869e4 100644
--- a/OpenAuth.App/DbExtension.cs
+++ b/OpenAuth.App/DbExtension.cs
@@ -85,6 +85,11 @@ namespace OpenAuth.App
///
public IList GetDbTableStructure(string tableName)
{
+ if(string.IsNullOrEmpty(tableName))
+ {
+ return new List();
+ }
+
//如果是空,说明没有通过ProcessExternalDb设置过,直接从本地读取
if(string.IsNullOrEmpty(_dbTypeStr)){
_dbTypeStr = _appConfiguration.Value.DbTypes[_httpContextAccessor.GetTenantId()];
@@ -414,6 +419,22 @@ namespace OpenAuth.App
return new List();
}
+ ///
+ /// 通过表名和外部数据源ID获取表结构
+ ///
+ /// 表名
+ /// 外部数据源ID
+ ///
+ public IList GetDbTableStructure(string tableName, string externalDataSourceId){
+ var connection = SugarClient.Queryable().First(u => u.Id == externalDataSourceId);
+ if (connection != null)
+ {
+ var dbType = connection.Dbtype;
+ SetConnection(connection.Connectionstring, dbType);
+ }
+ return GetDbTableStructure(tableName);
+ }
+
///
/// 处理外部数据库
///
diff --git a/OpenAuth.WebApi/Controllers/SysConfController.cs b/OpenAuth.WebApi/Controllers/SysConfController.cs
index 1e35cb67..f6daeb4c 100644
--- a/OpenAuth.WebApi/Controllers/SysConfController.cs
+++ b/OpenAuth.WebApi/Controllers/SysConfController.cs
@@ -1,8 +1,13 @@
-using Infrastructure;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using OpenAuth.App;
+using OpenAuth.App.Response;
+using OpenAuth.Repository.QueryObj;
namespace OpenAuth.WebApi.Controllers
{
@@ -12,13 +17,15 @@ namespace OpenAuth.WebApi.Controllers
[Route("api/[controller]/[action]")]
[ApiController]
[ApiExplorerSettings(GroupName = "系统配置_SysConf")]
- public class SysConfController :ControllerBase
+ public class SysConfController : ControllerBase
{
private IOptions _appConfiguration;
+ private DbExtension _dbExtension;
- public SysConfController(IOptions appConfiguration)
+ public SysConfController(IOptions appConfiguration, DbExtension dbExtension)
{
_appConfiguration = appConfiguration;
+ _dbExtension = dbExtension;
}
///
@@ -34,5 +41,53 @@ namespace OpenAuth.WebApi.Controllers
Result = _appConfiguration.Value.IsIdentityAuth
};
}
+
+ ///
+ /// 获取数据库表结构
+ ///
+ /// 表名
+ /// 外部数据源ID
+ ///
+ [HttpGet]
+ public Response> GetDbTableStructure(string tableName, string externalDataSourceId)
+ {
+ var result = new Response>();
+ try
+ {
+ result.Result = _dbExtension.GetDbTableStructure(tableName, externalDataSourceId).ToList();
+ }
+ catch (Exception ex)
+ {
+ result.Code = 500;
+ result.Message = ex.Message;
+ }
+ return result;
+ }
+
+ ///
+ /// 获取数据库表结构(用于下拉框)
+ ///
+ /// 表名
+ /// 外部数据源ID
+ ///
+ [HttpGet]
+ public TableData GetDbTableStructureForSelect(string tableName, string externalDataSourceId)
+ {
+ var result = new TableData();
+ try
+ {
+ result.data = _dbExtension.GetDbTableStructure(tableName, externalDataSourceId).Select(u => new
+ {
+ Id = u.ColumnName,
+ Name = u.ColumnName
+ });
+ }
+ catch (Exception ex)
+ {
+ result.code = 500;
+ result.msg = ex.Message;
+ }
+ return result;
+ }
}
}
diff --git a/newdocs/docs/notes/pro/devnew.md b/newdocs/docs/notes/pro/devnew.md
index f63780bc..6fb65f8d 100644
--- a/newdocs/docs/notes/pro/devnew.md
+++ b/newdocs/docs/notes/pro/devnew.md
@@ -129,7 +129,7 @@ create table stock
选中刚刚添加的`Stock`表,依次点击【生成实体】【生成业务代码】【生成vue页面】;
-如果存在子表,也进行相同的操作。即选中刚刚添加的`StockDetail`表,依次点击【生成实体】【生成业务代码】,子表不需要生成vue页面;
+如果存在子表,也进行相同的操作。即选中刚刚添加的`StockDetail`表,依次点击【生成实体】【生成业务代码】【生成vue页面】,子表虽然不需要生成vue页面,但需要生成前端js api;
成功后生成的后端.Net代码位置如下:
@@ -139,11 +139,13 @@ OpenAuth.App\StockApp\Request\AddOrUpdateStockReq.cs
OpenAuth.App\StockApp\Request\QueryStockListReq.cs
OpenAuth.WebApi\Controllers\StocksController.cs
-并且会在OpenAuth.Repository\OpenAuthDBContext.cs中自动添加:
-
+::: warning 注意
+以前代码生成器生成基于EF的代码时,会在OpenAuth.Repository\OpenAuthDBContext.cs中自动添加:
```
public virtual DbSet Stocks { get; set; }
```
+现在基于SqlSugar的代码生成器,已不需要。如果有其他开发方面需要,可自行手动添加。
+:::
前端Vue代码: