From c5e735b2e852b6a3d5312178be40784cded98b65 Mon Sep 17 00:00:00 2001 From: wintel Date: Sun, 17 Sep 2023 18:15:22 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#I8206M=20=E6=89=93=E5=8D=B0=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=BA=90=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SysPrinterPlanApp/SysPrinterPlanApp.cs | 35 +++++++++++++------ OpenAuth.App/Test/TestBase.cs | 8 ++--- OpenAuth.App/Test/TestSysPrinterPlan.cs | 29 ++++++++++++--- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs b/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs index 2f18d15b..d37e92b3 100644 --- a/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs +++ b/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Infrastructure; using OpenAuth.App.Interface; @@ -46,6 +48,28 @@ namespace OpenAuth.App result.count = await objs.CountAsync(); return result; } + + public async Task Query(QueryReq request) + { + var result = new TableData(); + + var sugarParams = new List(); + if (!string.IsNullOrEmpty(request.ParamJsonStr)) + { + var param = JsonHelper.Instance.Deserialize>(request.ParamJsonStr); + foreach (var p in param) + { + sugarParams.Add(new SugarParameter($"@{p.Key}", p.Value)); + } + } + + var objs = await SugarClient.Ado.SqlQueryAsync(request.SourceSql,sugarParams); + result.count = SugarClient.Ado.SqlQuery(request.SourceSql, sugarParams).Count; + result.data = objs.Skip((request.page - 1) * request.limit) + .Take(request.limit).ToList(); + + return result; + } public void Add(AddOrUpdateSysPrinterPlanReq obj) { @@ -73,16 +97,5 @@ namespace OpenAuth.App public SysPrinterPlanApp(ISqlSugarClient client, IAuth auth) : base(client, auth) { } - - public async Task Query(QueryReq request) - { - var result = new TableData(); - - var objs = await SugarClient.Ado.SqlQueryAsync(request.SourceSql); - result.data = objs.Skip((request.page - 1) * request.limit) - .Take(request.limit).ToList(); - - return result; - } } } \ No newline at end of file diff --git a/OpenAuth.App/Test/TestBase.cs b/OpenAuth.App/Test/TestBase.cs index a353e9f0..6eca7b38 100644 --- a/OpenAuth.App/Test/TestBase.cs +++ b/OpenAuth.App/Test/TestBase.cs @@ -60,10 +60,6 @@ namespace OpenAuth.App.Test serviceCollection.AddDbContext(); - var container = AutofacExt.InitForTest(serviceCollection); - _autofacServiceProvider = new AutofacServiceProvider(container); - AutofacContainerModule.ConfigServiceProvider(_autofacServiceProvider); - var dbtypes = config.GetSection("AppSetting:DbTypes").GetChildren() .ToDictionary(x => x.Key, x => x.Value); @@ -85,6 +81,10 @@ namespace OpenAuth.App.Test }); return sqlSugar; }); + + var container = AutofacExt.InitForTest(serviceCollection); + _autofacServiceProvider = new AutofacServiceProvider(container); + AutofacContainerModule.ConfigServiceProvider(_autofacServiceProvider); } /// diff --git a/OpenAuth.App/Test/TestSysPrinterPlan.cs b/OpenAuth.App/Test/TestSysPrinterPlan.cs index 119d03b7..d4bc0f09 100644 --- a/OpenAuth.App/Test/TestSysPrinterPlan.cs +++ b/OpenAuth.App/Test/TestSysPrinterPlan.cs @@ -37,19 +37,40 @@ namespace OpenAuth.App.Test } [Test] - public async Task Query() + public async Task QueryWithParam() { var app = _autofacServiceProvider.GetService(); var result = await app.Query(new QueryReq() { - SourceSql = "select * from user" + SourceSql = "select * from user where account like @account", + ParamJsonStr = "{\"account\":\"test%\"}", + page = 1, + limit = 2 }); Console.WriteLine(JsonHelper.Instance.Serialize(result)); - //延长主线程,防止程序退出 - Thread.Sleep(3000); + //异步测试,延长主线程,防止程序退出 + Thread.Sleep(1000); + } + + [Test] + public async Task QueryNoParam() + { + var app = _autofacServiceProvider.GetService(); + + var result = await app.Query(new QueryReq() + { + SourceSql = "select * from user ", + page = 1, + limit = 2 + }); + + Console.WriteLine(JsonHelper.Instance.Serialize(result)); + + //异步测试,延长主线程,防止程序退出 + Thread.Sleep(1000); } }