添加重写VisualDev接口
This commit is contained in:
@@ -1,24 +1,23 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"ConfigId": "default",
|
||||
"DBName": "tnb_bas",
|
||||
"DBType": "PostgreSQL", //MySql;SqlServer;Oracle;PostgreSQL;Dm;Kdbndp;Sqlite;
|
||||
"Host": "localhost",
|
||||
"Port": "5432",
|
||||
"DBName": "tnb_bas",
|
||||
"UserName": "totong",
|
||||
"Password": "IPANyxGSKxIXg0dBM",
|
||||
//SqlServer
|
||||
//"DefaultConnection": "Data Source=192.168.0.214;Initial Catalog={0};User ID=sa;Password=kMaeMP8Yck6b6wA;MultipleActiveResultSets=true"
|
||||
//"DefaultConnection": "server={0},{1};database={2};uid={3};pwd={4};MultipleActiveResultSets=true"
|
||||
//Kdbndp
|
||||
//"DefaultConnection": "Server=192.168.0.103;Port=54321;UID=YANYU;PWD=123456;database=YANSOURCE"
|
||||
//"DefaultConnection": "server={0};port={1};database={2};uid={3};pwd={4};"
|
||||
//Dm
|
||||
//"DefaultConnection": "Server=192.168.0.50; User Id=JNPFTEST; PWD=I97eH!bRfy55qGzF;DATABASE=JNPFTEST"
|
||||
//"DefaultConnection": "server={0};port={1};database={2};uid={3};pwd={4};"
|
||||
//Oracle
|
||||
//"DefaultConnection": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.19)(PORT=1521))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME=JNPFCLOUD)));User Id=JNPFCLOUD;Password=JNPFCLOUD"
|
||||
//"DefaultConnection": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME={2})));User Id={3};Password={4}"
|
||||
//PostgreSQL
|
||||
//"DefaultConnection": "PORT=5432;DATABASE=java_boot_dev_postgresql;HOST=192.168.0.103;PASSWORD=123456;USER ID=postgres"
|
||||
"DefaultConnection": "server=localhost;port=5432;database=tnb_bas;uid=totong;pwd=IPANyxGSKxIXg0dBM;pooling=true;"
|
||||
"DefaultConnection": "server={0};port={1};database={2};uid={3};pwd={4};pooling=true;"
|
||||
//MySql
|
||||
//"DefaultConnection": "server=192.168.0.10;Database=netcore_test;Uid=netcore_test;Pwd=jhpGB3A88CF57fBC;AllowLoadLocalInfile=true"
|
||||
//"DefaultConnection": "server={0};port={1};database={2};uid={3};pwd={4};sslmode=none;pooling=true;charset=utf8mb4;allowLoadLocalInfile=true;allowPublicKeyRetrieval=true"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using JNPF;
|
||||
using JNPF.Logging;
|
||||
using Spire.Xls;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// SqlSugar配置拓展.
|
||||
/// </summary>
|
||||
public static class LoggingConfigureExtensions
|
||||
{
|
||||
const string DATEFORMAT = "HH:mm:ss.fff";
|
||||
|
||||
public static IServiceCollection LoggingConfigure(this IServiceCollection services)
|
||||
{
|
||||
services.AddConsoleFormatter(option =>
|
||||
{
|
||||
option.MessageFormat = LoggerConsoleFormat;
|
||||
}).AddFileLogging(options =>
|
||||
{
|
||||
options.MessageFormat = LoggerFileFormat;
|
||||
options.FileNameRule = fileName => string.Format(fileName, DateTime.Now); // 每天创建一个文件
|
||||
options.HandleWriteError = (writeError) => // 写入失败时启用备用文件
|
||||
{
|
||||
writeError.UseRollbackFileName(Path.GetFileNameWithoutExtension(writeError.CurrentFileName) + "-oops" + Path.GetExtension(writeError.CurrentFileName));
|
||||
};
|
||||
});
|
||||
return services;
|
||||
}
|
||||
private static string LoggerLevelName(LogLevel level)
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
LogLevel.Trace => "Trace",
|
||||
LogLevel.Debug => "Debug",
|
||||
LogLevel.Information => "Info",
|
||||
LogLevel.Warning => "Warn",
|
||||
LogLevel.Error => "Error",
|
||||
LogLevel.Critical => "Crit",
|
||||
_ => "None"
|
||||
};
|
||||
}
|
||||
private static string LoggerFileFormat(LogMessage msg)
|
||||
{
|
||||
var txt = $"{LoggerLevelName(msg.LogLevel)} {msg.LogDateTime.ToString(DATEFORMAT)} {msg.ThreadId}# {msg.Message}";
|
||||
if (msg.Exception != null)
|
||||
{
|
||||
//var EXCEPTION_SEPARATOR_WITHCOLOR = AppendWithColor(default, EXCEPTION_SEPARATOR, logLevelColors).ToString();
|
||||
txt += $"{Environment.NewLine}{msg.Exception}";
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
private static string LoggerConsoleFormat(LogMessage msg)
|
||||
{
|
||||
var fclr = msg.LogLevel switch
|
||||
{
|
||||
LogLevel.Warning => "\u001b[1m\u001b[33m",
|
||||
LogLevel.Error => "\u001b[1m\u001b[31m",
|
||||
_ => "\u001b[39m\u001b[22m"
|
||||
};
|
||||
var txt = $"{fclr}{LoggerLevelName(msg.LogLevel)}\u001b[49m \u001b[36m{msg.LogDateTime.ToString(DATEFORMAT)}\u001b[49m \u001b[39m\u001b[22m{msg.ThreadId}#\u001b[49m {fclr}{msg.Message}\u001b[49m";
|
||||
if (msg.Exception != null)
|
||||
{
|
||||
//var EXCEPTION_SEPARATOR_WITHCOLOR = AppendWithColor(default, EXCEPTION_SEPARATOR, logLevelColors).ToString();
|
||||
txt += $"{Environment.NewLine}{fclr}{msg.Exception}\u001b[49m";
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,23 +15,17 @@ public static class SqlSugarConfigureExtensions
|
||||
public static IServiceCollection SqlSugarConfigure(this IServiceCollection services)
|
||||
{
|
||||
// 获取选项
|
||||
ConnectionStringsOptions connectionStrings = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
ConnectionStringsOptions conn = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
|
||||
List<ConnectionConfig> connectConfigList = new List<ConnectionConfig>();
|
||||
|
||||
string? connectionStr = connectionStrings.DefaultConnection;
|
||||
var dataBase = connectionStrings.DBName;
|
||||
var DBType = (DbType)Enum.Parse(typeof(DbType), connectionStrings.DBType);
|
||||
var ConfigId = connectionStrings.ConfigId;
|
||||
var DBName = connectionStrings.DBName;
|
||||
|
||||
var DBType = (DbType)Enum.Parse(typeof(DbType), conn.DBType);
|
||||
// 默认数据库
|
||||
connectConfigList.Add(new ConnectionConfig
|
||||
{
|
||||
ConnectionString = string.Format(connectionStr, DBName),
|
||||
ConnectionString = string.Format(conn.DefaultConnection, conn.Host, conn.Port, conn.DBName, conn.UserName, conn.Password),
|
||||
DbType = DBType,
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigId = ConfigId,
|
||||
ConfigId = conn.ConfigId,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ using System;
|
||||
using System.Text;
|
||||
using Top.Api;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.VisualDev;
|
||||
|
||||
namespace JNPF.API.Entry;
|
||||
|
||||
@@ -32,11 +33,6 @@ public class Startup : AppStartup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddConsoleFormatter(option =>
|
||||
{
|
||||
option.MessageFormat = LoggerConsoleFormat;
|
||||
});
|
||||
|
||||
// SqlSugar
|
||||
services.SqlSugarConfigure();
|
||||
|
||||
@@ -140,6 +136,7 @@ public class Startup : AppStartup
|
||||
services.AddSession();
|
||||
services.AddMemoryCache(); // 使用本地缓存必须添加
|
||||
|
||||
services.LoggingConfigure();
|
||||
// 日志监听
|
||||
// services.AddMonitorLogging(options =>
|
||||
//{
|
||||
@@ -147,16 +144,6 @@ public class Startup : AppStartup
|
||||
// options.IgnorePropertyTypes = new[] { typeof(byte[]) };
|
||||
//});
|
||||
|
||||
services.AddFileLogging(options =>
|
||||
{
|
||||
options.MessageFormat = LoggerFileFormat;
|
||||
options.FileNameRule = fileName => string.Format(fileName, DateTime.Now); // 每天创建一个文件
|
||||
options.HandleWriteError = (writeError) => // 写入失败时启用备用文件
|
||||
{
|
||||
writeError.UseRollbackFileName(Path.GetFileNameWithoutExtension(writeError.CurrentFileName) + "-oops" + Path.GetExtension(writeError.CurrentFileName));
|
||||
};
|
||||
});
|
||||
|
||||
services.AddUnitOfWork<SqlSugarUnitOfWork>();
|
||||
|
||||
services.OSSServiceConfigure();
|
||||
@@ -164,6 +151,8 @@ public class Startup : AppStartup
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
services.AddSchedule();
|
||||
|
||||
services.AddOverideVisualDev();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
|
||||
@@ -201,7 +190,8 @@ public class Startup : AppStartup
|
||||
|
||||
app.UseInject(string.Empty);
|
||||
|
||||
app.MapWebSocketManager("/api/message/websocket", serviceProvider.GetService<IMHandler>());
|
||||
//app.MapWebSocketManager("/api/message/websocket", serviceProvider.GetService<IMHandler>());
|
||||
app.MapWebSocketManager("/websocket", serviceProvider.GetService<IMHandler>());
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
@@ -212,45 +202,4 @@ public class Startup : AppStartup
|
||||
|
||||
serviceProvider.GetRequiredService<ITimeTaskService>().StartTimerJob();
|
||||
}
|
||||
|
||||
const string DATEFORMAT = "HH:mm:ss.fff";
|
||||
private string LoggerLevelName(LogLevel level)
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
LogLevel.Trace => "Trace",
|
||||
LogLevel.Debug => "Debug",
|
||||
LogLevel.Information => "Info",
|
||||
LogLevel.Warning => "Warn",
|
||||
LogLevel.Error => "Error",
|
||||
LogLevel.Critical => "Crit",
|
||||
_ => "None"
|
||||
};
|
||||
}
|
||||
private string LoggerFileFormat(LogMessage msg)
|
||||
{
|
||||
var txt = $"{LoggerLevelName(msg.LogLevel)} {msg.LogDateTime.ToString(DATEFORMAT)} {msg.ThreadId}# {msg.Message}";
|
||||
if (msg.Exception != null)
|
||||
{
|
||||
//var EXCEPTION_SEPARATOR_WITHCOLOR = AppendWithColor(default, EXCEPTION_SEPARATOR, logLevelColors).ToString();
|
||||
txt += $"{Environment.NewLine}{msg.Exception}";
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
private string LoggerConsoleFormat(LogMessage msg)
|
||||
{
|
||||
var fclr = msg.LogLevel switch
|
||||
{
|
||||
LogLevel.Warning => "\u001b[1m\u001b[33m",
|
||||
LogLevel.Error => "\u001b[1m\u001b[31m",
|
||||
_ => "\u001b[39m\u001b[22m"
|
||||
};
|
||||
var txt = $"{fclr}{LoggerLevelName(msg.LogLevel)}\u001b[49m \u001b[36m{msg.LogDateTime.ToString(DATEFORMAT)}\u001b[49m \u001b[39m\u001b[22m{msg.ThreadId}#\u001b[49m {fclr}{msg.Message}\u001b[49m";
|
||||
if (msg.Exception != null)
|
||||
{
|
||||
//var EXCEPTION_SEPARATOR_WITHCOLOR = AppendWithColor(default, EXCEPTION_SEPARATOR, logLevelColors).ToString();
|
||||
txt += $"{Environment.NewLine}{fclr}{msg.Exception}\u001b[49m";
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
}
|
||||
@@ -1086,13 +1086,13 @@ public class SuperQueryHelper
|
||||
private static List<Dictionary<string, string>> GetUserRelationByUserId(string fieldValue)
|
||||
{
|
||||
// 获取数据库连接选项
|
||||
ConnectionStringsOptions connectionStrings = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
ConnectionStringsOptions conn = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig
|
||||
{
|
||||
ConnectionString = string.Format(connectionStrings.DefaultConnection, connectionStrings.DBName),
|
||||
DbType = (SqlSugar.DbType)Enum.Parse(typeof(SqlSugar.DbType), connectionStrings.DBType),
|
||||
ConnectionString = string.Format(conn.DefaultConnection, conn.Host, conn.Port, conn.DBName, conn.UserName, conn.Password),
|
||||
DbType = (DbType)Enum.Parse(typeof(DbType), conn.DBType),
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigId = connectionStrings.ConfigId,
|
||||
ConfigId = conn.ConfigId,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Tnb.SqlSugar" Version="2023.3.14.2031" />
|
||||
<PackageReference Include="Tnb.SqlSugar" Version="2023.3.23.1043" />
|
||||
<!--<ProjectReference Include="..\..\..\Tnb.Core\src\Tnb.SqlSugar\Tnb.SqlSugar.csproj" />-->
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace JNPF.VisualDev
|
||||
{
|
||||
public interface IVisualDevOverideActionManager : ISingleton
|
||||
{
|
||||
void Set(string modelId, IOverideVisualDevService overideVisualDev);
|
||||
|
||||
IOverideVisualDevService? GetOrDefault(string modelId);
|
||||
}
|
||||
|
||||
public interface IOverideVisualDevService
|
||||
{
|
||||
//string ModelId { get; set; }
|
||||
OverideVisualDevFunc OverideFuncs { get; }
|
||||
|
||||
//Task<dynamic>? GetList(VisualDevModelListQueryInput input);
|
||||
//Task<dynamic>? GetInfo(string id);
|
||||
//Task<dynamic>? GetDetails(string id, string modelId);
|
||||
//Task<dynamic>? Create(VisualDevModelDataCrInput visualdevModelDataCrForm);
|
||||
//Task<dynamic>? Update(string id, VisualDevModelDataUpInput visualdevModelDataUpForm);
|
||||
//Task? Delete(string id);
|
||||
//Task? BatchDelete(VisualDevModelDataBatchDelInput input);
|
||||
//Task<dynamic>? Export(VisualDevModelListQueryInput input);
|
||||
//Task<dynamic>? Import(IFormFile file);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace JNPF.VisualDev
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||
public class OverideVisualDevAttribute : Attribute
|
||||
{
|
||||
public string ModelId { get; set; }
|
||||
public OverideVisualDevAttribute(string modelId)
|
||||
{
|
||||
ModelId = modelId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace JNPF.VisualDev
|
||||
{
|
||||
public class OverideVisualDevFunc
|
||||
{
|
||||
public Func<VisualDevModelListQueryInput, Task<dynamic>>? GetListAsync { get; set; } = null;
|
||||
public Func<string, Task<dynamic>>? GetAsync { get; set; } = null;
|
||||
public Func<string, Task<dynamic>>? GetDetailsAsync { get; set; } = null;
|
||||
public Func<VisualDevModelDataCrInput, Task<dynamic>>? CreateAsync { get; set; } = null;
|
||||
public Func<string, VisualDevModelDataUpInput, Task<dynamic>>? UpdateAsync { get; set; } = null;
|
||||
public Func<string, Task>? DeleteAsync { get; set; } = null;
|
||||
public Func<VisualDevModelDataBatchDelInput, Task>? DeleteRangeAsync { get; set; } = null;
|
||||
public Func<VisualDevModelListQueryInput, Task<dynamic>>? ExportAsync { get; set; } = null;
|
||||
public Func<IFormFile, Task<dynamic>>? ImportAsync { get; set; } = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace JNPF.VisualDev
|
||||
{
|
||||
public class OverideVisualDevManager
|
||||
{
|
||||
private static ConcurrentDictionary<string, Type> actions = new ConcurrentDictionary<string, Type>();
|
||||
public OverideVisualDevManager()
|
||||
{
|
||||
}
|
||||
|
||||
public static IOverideVisualDevService? GetOrDefault(string modelId)
|
||||
{
|
||||
var tp = actions.GetOrDefault(modelId);
|
||||
if (tp != null) { return (IOverideVisualDevService)App.GetService(tp); }
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Add(string modelId, Type overideVisualDev)
|
||||
{
|
||||
if (!actions.ContainsKey(modelId))
|
||||
{
|
||||
actions.TryAdd(modelId, overideVisualDev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.Reflection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace JNPF.VisualDev
|
||||
{
|
||||
[SuppressSniffer]
|
||||
public static class OverideVisualDevServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加重写在线开发接口的服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddOverideVisualDev(this IServiceCollection services)
|
||||
{
|
||||
var actions = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IOverideVisualDevService).IsAssignableFrom(u)).ToList();
|
||||
foreach (var item in actions)
|
||||
{
|
||||
var attr = item.GetAttribute<OverideVisualDevAttribute>();
|
||||
if (attr != null)
|
||||
{
|
||||
OverideVisualDevManager.Add(attr.ModelId, item);
|
||||
}
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user