1. 雪花ID使用配置项

2. 使用自定义日志格式
3. 修复数据模型和新建流程的bug
This commit is contained in:
2023-03-14 20:36:51 +08:00
parent 1d73df3235
commit a4ed390e82
12 changed files with 445 additions and 397 deletions

View File

@@ -1,7 +1,7 @@
{
"AppSettings": {
"InjectMiniProfiler": true,
"SupportPackageNamePrefixs": ["Tnb"]
"SupportPackageNamePrefixs": [ "Tnb" ]
},
"Kestrel": {
"Endpoints": {
@@ -9,5 +9,13 @@
"Url": "http://localhost:9231"
}
}
},
"YitId": {
"WorkerId": 1, //必须 全局唯一,必须 程序设定,理论最大值 2^WorkerIdBitLength-1
"WorkerIdBitLength": 4, //机器码位长,决定 WorkerId 的最大值,默认值6,取值范围 [1, 16]
"SeqBitLength": 4 //序列数位长,默认值6,取值范围 [3, 21](建议不小于4),决定每毫秒基础生成的ID个数
},
"UnifyResultSettings": {
"ShowExceptionDetail": true
}
}

View File

@@ -1,7 +1,7 @@
{
"ConnectionStrings": {
"ConfigId": "default",
"DBName": "tnb",
"DBName": "tnb_bas",
"DBType": "PostgreSQL", //MySql;SqlServer;Oracle;PostgreSQL;Dm;Kdbndp;Sqlite;
"Host": "localhost",
"Port": "9202",
@@ -17,7 +17,7 @@
//"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"
//PostgreSQL
//"DefaultConnection": "PORT=5432;DATABASE=java_boot_dev_postgresql;HOST=192.168.0.103;PASSWORD=123456;USER ID=postgres"
"DefaultConnection": "server=localhost;port=9202;database=tnb;uid=totong;pwd=IPANyxGSKxIXg0dBM;pooling=true;"
"DefaultConnection": "server=localhost;port=9202;database=tnb_bas;uid=totong;pwd=IPANyxGSKxIXg0dBM;pooling=true;"
//MySql
//"DefaultConnection": "server=192.168.0.10;Database=netcore_test;Uid=netcore_test;Pwd=jhpGB3A88CF57fBC;AllowLoadLocalInfile=true"
}

View File

@@ -1,6 +1,8 @@
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using JNPF;
using JNPF.Logging;
using Spire.Xls;
using SqlSugar;
namespace Microsoft.Extensions.DependencyInjection;
@@ -39,33 +41,33 @@ public static class SqlSugarConfigureExtensions
services.AddSqlSugar(connectConfigList, client =>
{
//connectConfigList.ForEach(config =>
//{
// var db = ((SqlSugarScope)client).GetConnectionScope((string)config.ConfigId);
//connectConfigList.ForEach(config =>
//{
// var db = ((SqlSugarScope)client).GetConnectionScope((string)config.ConfigId);
// // 设置超时时间
// db.Ado.CommandTimeOut = 30;
// // 设置超时时间
// db.Ado.CommandTimeOut = 30;
// // 打印SQL语句
// db.Aop.OnLogExecuting = (sql, pars) =>
// {
// if (sql.StartsWith("SELECT", StringComparison.OrdinalIgnoreCase))
// Console.ForegroundColor = ConsoleColor.Green;
// if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase))
// Console.ForegroundColor = ConsoleColor.White;
// if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase))
// Console.ForegroundColor = ConsoleColor.Blue;
// Console.WriteLine("【" + DateTime.Now + "——执行SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, sql, pars) + "\r\n");
// App.PrintToMiniProfiler("SqlSugar", "Info", sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
// };
// db.Aop.OnError = (ex) =>
// {
// Console.ForegroundColor = ConsoleColor.Red;
// var pars = db.Utilities.SerializeObject(((SugarParameter[])ex.Parametres).ToDictionary(it => it.ParameterName, it => it.Value));
// Console.WriteLine("【" + DateTime.Now + "——错误SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n");
// App.PrintToMiniProfiler("SqlSugar", "Error", $"{ex.Message}{Environment.NewLine}{ex.Sql}{pars}{Environment.NewLine}");
// };
//});
// // 打印SQL语句
// db.Aop.OnLogExecuting = (sql, pars) =>
// {
// var oldColor = Console.ForegroundColor;
// Console.ForegroundColor = ConsoleColor.Green;
// var finalSql = UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, sql, pars);
// Console.WriteLine($"【{DateTime.Now.ToString("HH:mm:ss.fff")}——SQL执行完成】{db.Ado.SqlExecutionTime.TotalMilliseconds} ms");
// Console.WriteLine(finalSql);
// Console.ForegroundColor = oldColor;
// if (db.Ado.SqlExecutionTime.TotalMilliseconds > 3000)
// {
// Log.Warning($"慢查询: {db.Ado.SqlExecutionTime.TotalMilliseconds}ms, SQL: " + finalSql);
// }
// Console.WriteLine();
// };
// db.Aop.OnError = (ex) =>
// {
// Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
// };
//});
});
return services;

View File

@@ -1,3 +1,5 @@
using JNPF.Common.Security;
Serve.Run(RunOptions.Default
.AddWebComponent<WebComponent>().WithArgs(args));

View File

@@ -24,6 +24,7 @@ using System.Xml;
using System;
using System.Text;
using Top.Api;
using JNPF.Common.Security;
namespace JNPF.API.Entry;
@@ -207,6 +208,8 @@ public class Startup : AppStartup
endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
});
SnowflakeIdHelper.InitYitIdWorker();
serviceProvider.GetRequiredService<ITimeTaskService>().StartTimerJob();
}
@@ -226,7 +229,13 @@ public class Startup : AppStartup
}
private string LoggerFileFormat(LogMessage msg)
{
return $"{LoggerLevelName(msg.LogLevel)} {msg.LogDateTime.ToString(DATEFORMAT)} {msg.ThreadId}# {msg.Message}";
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)
{
@@ -236,7 +245,12 @@ public class Startup : AppStartup
LogLevel.Error => "\u001b[1m\u001b[31m",
_ => "\u001b[39m\u001b[22m"
};
return $"{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";
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;
}
}

View File

@@ -8,7 +8,7 @@
<SatelliteResourceLanguages>none</SatelliteResourceLanguages>
</PropertyGroup>
<ItemGroup>
<!--<ItemGroup>
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.dll" />
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.so" />
<None Remove="sensitive-words.txt" />
@@ -18,7 +18,7 @@
<EmbeddedResource Include="lib\regworkerid_lib_v1.3.1\yitidgengo.dll" />
<EmbeddedResource Include="lib\regworkerid_lib_v1.3.1\yitidgengo.so" />
<EmbeddedResource Include="sensitive-words.txt" />
</ItemGroup>
</ItemGroup>-->
<ItemGroup>
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.13" />
@@ -42,10 +42,4 @@
</Content>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@
@echo off
%1 %2
ver|find "5.">nul&&goto :Admin
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof
:Admin
cd /d %~dp0
echo --------------------------------
echo 1 --- install
echo 2 --- uninstall
echo --------------------------------
setlocal
set svcName=ToTong.TNB.Master
set binPath=Tnb.API.Entry.exe
set /p mode=input number to choise:
if %mode%==1 (
sc create %svcName% binpath=%~dp0%binPath% displayname=%svcName% start= auto
sc description %svcName% %svcName%
net start %svcName%
) else if %mode%==2 (
net stop %svcName%
sc delete %svcName%
)
endlocal
pause