优化代码生成数据库连接

This commit is contained in:
不做码农
2023-06-12 21:24:15 +08:00
parent 5185a8c4d3
commit b5f8034b26
7 changed files with 34 additions and 32 deletions

View File

@@ -2,6 +2,7 @@
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Extensions;
using IP2Region.Ex.Models;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
@@ -230,8 +231,9 @@ namespace ZR.Admin.WebApi.Controllers
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
}
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
var dbConfig = AppSettings.Get<List<DbConfigs>>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb);
dto.DbType = AppSettings.GetAppConfig("gen:dbType", 0);
dto.DbType = dbConfig.DbType;
dto.GenTable = genTableInfo;
dto.IsPreview = true;
//生成代码
@@ -255,8 +257,9 @@ namespace ZR.Admin.WebApi.Controllers
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
}
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
var dbConfig = AppSettings.Get<List<DbConfigs>>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb);
dto.DbType = AppSettings.GetAppConfig("gen:dbType", 0);
dto.DbType = dbConfig.DbType;
dto.GenTable = genTableInfo;
//自定义路径
if (genTableInfo.GenType == "1")

View File

@@ -35,7 +35,7 @@ namespace ZR.Admin.WebApi.Extensions
List<DbConfigs> dbConfigs = Configuration.GetSection("DbConfigs").Get<List<DbConfigs>>();
var iocList = new List<IocConfig>();
foreach (var item in dbConfigs)
foreach (var item in dbConfigs.FindAll(f => !f.IsGenerateDb))
{
iocList.Add(new IocConfig()
{

View File

@@ -12,6 +12,14 @@
"DbType": 1, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3PgSql = 4
"ConfigId": "0", //多租户唯一标识
"IsAutoCloseConnection": true
},
{
"Conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog={dbName};",
"DbType": 1,
"ConfigId": "0",
"IsAutoCloseConnection": true,
"DbName": "ZrAdmin",//代码生成默认连接数据库
"IsGenerateDb": true //是否代码生成使用库,不要改动
}
//...下面添加更多的数据库源
],
@@ -50,13 +58,10 @@
},
//代码生成配置
"gen": {
"conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog=ZrAdmin;",
"dbType": 1, //MySql = 0, SqlServer = 1
"autoPre": true, //自动去除表前缀
"author": "admin",
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "", //前端代码存储路径egD:\Work\ZRAdmin-Vue3
"oracle_db": ""
"vuePath": "" //前端代码存储路径egD:\Work\ZRAdmin-Vue3
},
//邮箱配置信息
"MailOptions": {