🐛 修复多库数据库偶先bug
This commit is contained in:
parent
dea937033e
commit
a9547257e6
@ -2,6 +2,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
|
||||
@ -9,6 +10,11 @@ namespace Infrastructure
|
||||
{
|
||||
public static class App
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局配置文件
|
||||
/// </summary>
|
||||
public static OptionsSetting OptionsSetting => CatchOrDefault(() => ServiceProvider?.GetService<IOptions<OptionsSetting>>()?.Value);
|
||||
|
||||
/// <summary>
|
||||
/// 服务提供器
|
||||
/// </summary>
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Infrastructure
|
||||
namespace Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局静态常量
|
||||
/// </summary>
|
||||
public class GlobalConstant
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成常量
|
||||
/// </summary>
|
||||
public static readonly string CodeGenDbConfig;
|
||||
|
||||
/// <summary>
|
||||
/// 管理员权限
|
||||
/// </summary>
|
||||
|
||||
@ -19,6 +19,7 @@ namespace Infrastructure
|
||||
public JwtSettings JwtSettings { get; set; }
|
||||
public Gen Gen { get; set; }
|
||||
public List<DbConfigs> DbConfigs { get; set; }
|
||||
public DbConfigs CodeGenDbConfig { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送邮件数据配置
|
||||
@ -94,10 +95,6 @@ namespace Infrastructure
|
||||
public int DbType { get; set; }
|
||||
public string ConfigId { get; set; }
|
||||
public bool IsAutoCloseConnection { get; set; }
|
||||
/// <summary>
|
||||
/// 是否代码生成使用库
|
||||
/// </summary>
|
||||
public bool IsGenerateDb { get; set; }
|
||||
public string DbName { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Extensions;
|
||||
using IP2Region.Ex.Models;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
@ -13,7 +12,6 @@ using ZR.CodeGenerator.Model;
|
||||
using ZR.CodeGenerator.Service;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System.Generate;
|
||||
using ZR.Service.System.IService;
|
||||
@ -153,7 +151,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
throw new CustomException("表不能为空");
|
||||
}
|
||||
var dbConfig = AppSettings.Get<List<DbConfigs>>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb);
|
||||
DbConfigs dbConfig = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
|
||||
string[] tableNames = tables.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
int result = 0;
|
||||
foreach (var tableName in tableNames)
|
||||
@ -218,29 +216,25 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <summary>
|
||||
/// 预览代码
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="tableId"></param>
|
||||
/// <param name="VueVersion"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("preview/{tableId}")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:preview")]
|
||||
public IActionResult Preview(long tableId = 0, int VueVersion = 0)
|
||||
public IActionResult Preview([FromQuery] GenerateDto dto, [FromRoute] int tableId = 0)
|
||||
{
|
||||
GenerateDto dto = new()
|
||||
{
|
||||
TableId = tableId,
|
||||
VueVersion = VueVersion
|
||||
};
|
||||
dto.TableId = tableId;
|
||||
if (dto == null || dto.TableId <= 0)
|
||||
{
|
||||
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||
}
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
|
||||
var dbConfig = AppSettings.Get<List<DbConfigs>>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb);
|
||||
var dbConfig = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
|
||||
|
||||
dto.DbType = dbConfig.DbType;
|
||||
dto.GenTable = genTableInfo;
|
||||
dto.IsPreview = true;
|
||||
//生成代码
|
||||
|
||||
CodeGeneratorTool.Generate(dto);
|
||||
|
||||
return SUCCESS(dto.GenCodes);
|
||||
@ -261,7 +255,7 @@ 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);
|
||||
var dbConfig = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
|
||||
|
||||
dto.DbType = dbConfig.DbType;
|
||||
dto.GenTable = genTableInfo;
|
||||
|
||||
@ -36,7 +36,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.FindAll(f => !f.IsGenerateDb))
|
||||
foreach (var item in dbConfigs)
|
||||
{
|
||||
iocList.Add(new IocConfig()
|
||||
{
|
||||
|
||||
@ -62,7 +62,6 @@ builder.Services.AddAuthentication(options =>
|
||||
};
|
||||
});
|
||||
|
||||
//InternalApp.InternalServices = builder.Services;
|
||||
builder.Services.AddSingleton(new AppSettings(builder.Configuration));
|
||||
builder.Services.AddAppService();
|
||||
//开启计划任务
|
||||
|
||||
@ -12,18 +12,17 @@
|
||||
"DbType": 1, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4
|
||||
"ConfigId": "0", //多租户唯一标识
|
||||
"IsAutoCloseConnection": true
|
||||
},
|
||||
{
|
||||
//代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名
|
||||
"Conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog={dbName};",
|
||||
"DbType": 1,
|
||||
"ConfigId": "0",
|
||||
"IsAutoCloseConnection": true,
|
||||
"DbName": "ZrAdmin", //代码生成默认连接数据库
|
||||
"IsGenerateDb": true //是否代码生成使用库,不要改动
|
||||
}
|
||||
//...下面添加更多的数据库源
|
||||
],
|
||||
//代码生成数据库配置
|
||||
"CodeGenDbConfig": {
|
||||
//代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名
|
||||
"Conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog={dbName};",
|
||||
"DbType": 1,
|
||||
"IsAutoCloseConnection": true,
|
||||
"DbName": "ZrAdmin" //代码生成默认连接数据库
|
||||
},
|
||||
"urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
|
||||
"corsUrls": "http://localhost:8887", //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
|
||||
"JwtSettings": {
|
||||
|
||||
@ -414,9 +414,9 @@ namespace ZR.CodeGenerator
|
||||
OptionsSetting optionsSetting = new();
|
||||
|
||||
var gen = AppSettings.Get<Gen>("gen");
|
||||
var dbConfigs = AppSettings.Get<List<DbConfigs>>("dbConfigs");
|
||||
var dbConfig = dbConfigs.FirstOrDefault(f => f.IsGenerateDb);
|
||||
optionsSetting.DbConfigs = dbConfigs;
|
||||
var dbConfig = AppSettings.Get<DbConfigs>("CodeGenDbConfig");
|
||||
|
||||
optionsSetting.CodeGenDbConfig = dbConfig;
|
||||
optionsSetting.Gen = gen ?? throw new CustomException("代码生成节点配置异常");
|
||||
optionsSetting.Gen.GenDbConfig = dbConfig ?? throw new CustomException("代码生成节点数据配置异常");
|
||||
List<GenTableColumn> genTableColumns = new();
|
||||
|
||||
@ -20,9 +20,8 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
public SqlSugarClient GetSugarDbContext(string dbName = "")
|
||||
{
|
||||
List<DbConfigs> dbConfigs = AppSettings.Get<List<DbConfigs>>("dbConfigs");
|
||||
DbConfigs configs = AppSettings.Get<DbConfigs>("CodeGenDbConfig");
|
||||
|
||||
DbConfigs configs = dbConfigs.Find(f => f.IsGenerateDb == true);
|
||||
string connStr = configs.Conn;
|
||||
|
||||
if (!string.IsNullOrEmpty(dbName))
|
||||
|
||||
@ -17,8 +17,7 @@ namespace ZR.CodeGenerator.Service
|
||||
{
|
||||
var db = GetSugarDbContext();
|
||||
//Oracle库特殊处理
|
||||
List<DbConfigs> dbConfigs = AppSettings.Get<List<DbConfigs>>("dbConfigs");
|
||||
DbConfigs configs = dbConfigs.Find(f => f.IsGenerateDb == true);
|
||||
DbConfigs configs = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
|
||||
if (configs.DbType == 3)
|
||||
{
|
||||
return new List<string>() { configs?.DbName };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user