From 0fe060899b6b0ee62e1dcdeeeec2c784d83cb8ac Mon Sep 17 00:00:00 2001 From: wintel Date: Sun, 17 Sep 2023 17:14:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=EF=BC=9B=E5=A2=9E=E5=8A=A0=E6=89=93=E5=8D=B0=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAuth.App/Base/TableData.cs | 2 - .../SysPrinterPlanApp/Request/QueryReq.cs | 18 ++++++ .../SysPrinterPlanApp/SysPrinterPlanApp.cs | 10 ++++ OpenAuth.App/Test/TestBase.cs | 19 ++++++- OpenAuth.App/Test/TestSysPrinterPlan.cs | 56 +++++++++++++++++++ OpenAuth.Repository/Test/TestBase.cs | 49 +++------------- .../Controllers/SysPrinterPlansController.cs | 9 +++ 7 files changed, 120 insertions(+), 43 deletions(-) create mode 100644 OpenAuth.App/SysPrinterPlanApp/Request/QueryReq.cs create mode 100644 OpenAuth.App/Test/TestSysPrinterPlan.cs diff --git a/OpenAuth.App/Base/TableData.cs b/OpenAuth.App/Base/TableData.cs index 65da368c..c61b534d 100644 --- a/OpenAuth.App/Base/TableData.cs +++ b/OpenAuth.App/Base/TableData.cs @@ -12,9 +12,7 @@ // layui datatable数据返回 // *********************************************************************** -using System; using System.Collections.Generic; -using Infrastructure; using OpenAuth.Repository.Domain; namespace OpenAuth.App.Response diff --git a/OpenAuth.App/SysPrinterPlanApp/Request/QueryReq.cs b/OpenAuth.App/SysPrinterPlanApp/Request/QueryReq.cs new file mode 100644 index 00000000..5c716e4e --- /dev/null +++ b/OpenAuth.App/SysPrinterPlanApp/Request/QueryReq.cs @@ -0,0 +1,18 @@ +namespace OpenAuth.App.Request +{ + /// + /// 打印方案数据源请求参数 + /// + public class QueryReq : PageReq + { + /// + ///数据源;打印方案对应的数据来源SQL + /// + public string SourceSql { get; set; } + + /// + /// 入口参数JSON字符串 + /// + public string ParamJsonStr { get; set; } + } +} diff --git a/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs b/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs index c2a44d0c..2f18d15b 100644 --- a/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs +++ b/OpenAuth.App/SysPrinterPlanApp/SysPrinterPlanApp.cs @@ -74,5 +74,15 @@ namespace OpenAuth.App { } + 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 13c9f81e..a353e9f0 100644 --- a/OpenAuth.App/Test/TestBase.cs +++ b/OpenAuth.App/Test/TestBase.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using OpenAuth.Repository; +using SqlSugar; namespace OpenAuth.App.Test { @@ -66,8 +67,24 @@ namespace OpenAuth.App.Test var dbtypes = config.GetSection("AppSetting:DbTypes").GetChildren() .ToDictionary(x => x.Key, x => x.Value); - Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{config.GetSection("ConnectionStrings")["OpenAuthDBContext"]}"); + var connectionString = config.GetSection("ConnectionStrings")["OpenAuthDBContext"]; + + Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{connectionString}"); + var sqlsugarTypes = UtilMethods.EnumToDictionary(); + var dbType = sqlsugarTypes.FirstOrDefault(it => + dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key)); + + serviceCollection.AddScoped(s => + { + var sqlSugar = new SqlSugarClient(new ConnectionConfig() + { + DbType = dbType.Value, + ConnectionString = connectionString, + IsAutoCloseConnection = true, + }); + return sqlSugar; + }); } /// diff --git a/OpenAuth.App/Test/TestSysPrinterPlan.cs b/OpenAuth.App/Test/TestSysPrinterPlan.cs new file mode 100644 index 00000000..119d03b7 --- /dev/null +++ b/OpenAuth.App/Test/TestSysPrinterPlan.cs @@ -0,0 +1,56 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Infrastructure; +using Infrastructure.Cache; +using Infrastructure.Extensions; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Moq; +using NUnit.Framework; +using OpenAuth.App.Request; +using OpenAuth.App.SSO; +using OpenAuth.Repository; +using OpenAuth.Repository.Domain; +using OpenAuth.Repository.Interface; + +namespace OpenAuth.App.Test +{ + public class TestSysPrinterPlan : TestBase + { + public override ServiceCollection GetService() + { + var services = new ServiceCollection(); + + var cachemock = new Mock(); + cachemock.Setup(x => x.Get("tokentest")) + .Returns(new UserAuthSession { Account = Define.SYSTEM_USERNAME }); + services.AddScoped(x => cachemock.Object); + + var httpContextAccessorMock = new Mock(); + httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]) + .Returns("tokentest"); + + services.AddScoped(x => httpContextAccessorMock.Object); + + return services; + } + + [Test] + public async Task Query() + { + var app = _autofacServiceProvider.GetService(); + + var result = await app.Query(new QueryReq() + { + SourceSql = "select * from user" + }); + + Console.WriteLine(JsonHelper.Instance.Serialize(result)); + + //延长主线程,防止程序退出 + Thread.Sleep(3000); + } + + } +} diff --git a/OpenAuth.Repository/Test/TestBase.cs b/OpenAuth.Repository/Test/TestBase.cs index 4fc337cb..17dcc306 100644 --- a/OpenAuth.Repository/Test/TestBase.cs +++ b/OpenAuth.Repository/Test/TestBase.cs @@ -73,51 +73,20 @@ namespace OpenAuth.Repository.Test var connectionString = config.GetSection("ConnectionStrings")["OpenAuthDBContext"]; Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{connectionString}"); + var sqlsugarTypes = UtilMethods.EnumToDictionary(); + var dbType = sqlsugarTypes.FirstOrDefault(it => + dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key)); + serviceCollection.AddScoped(s => { - - SqlSugarClient sqlSugar; - if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER)) + var sqlSugar = new SqlSugarClient(new ConnectionConfig() { - sqlSugar = new SqlSugarClient (new ConnectionConfig() - { - DbType = SqlSugar.DbType.SqlServer, - ConnectionString = connectionString, - IsAutoCloseConnection = true, - }); - } - else if(dbtypes.ContainsValue(Define.DBTYPE_MYSQL)) //mysql - { - sqlSugar = new SqlSugarClient (new ConnectionConfig() - { - DbType = SqlSugar.DbType.MySql, - ConnectionString = connectionString, - IsAutoCloseConnection = true, - }); - } - else if(dbtypes.ContainsValue(Define.DBTYPE_PostgreSQL)) //PostgreSQL - { - sqlSugar = new SqlSugarClient (new ConnectionConfig() - { - DbType = SqlSugar.DbType.PostgreSQL, - ConnectionString = connectionString, - IsAutoCloseConnection = true, - }); - } - else - { - sqlSugar = new SqlSugarClient (new ConnectionConfig() - { - DbType = SqlSugar.DbType.Oracle, - ConnectionString = connectionString, - IsAutoCloseConnection = true, - }); - } - + DbType = dbType.Value, + ConnectionString = connectionString, + IsAutoCloseConnection = true, + }); return sqlSugar; }); - - var builder = new ContainerBuilder(); diff --git a/OpenAuth.WebApi/Controllers/SysPrinterPlansController.cs b/OpenAuth.WebApi/Controllers/SysPrinterPlansController.cs index 7a17e768..e7307060 100644 --- a/OpenAuth.WebApi/Controllers/SysPrinterPlansController.cs +++ b/OpenAuth.WebApi/Controllers/SysPrinterPlansController.cs @@ -83,6 +83,15 @@ namespace OpenAuth.WebApi.Controllers { return await _app.Load(request); } + + /// + /// 打印方案根据数据源获取打印数据 + /// + [HttpGet] + public async Task Query(QueryReq request) + { + return await _app.Query(request); + } /// /// 批量删除