mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
fix #I8206M 打印方案增加数据源设置
This commit is contained in:
parent
0fe060899b
commit
c5e735b2e8
@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using OpenAuth.App.Interface;
|
using OpenAuth.App.Interface;
|
||||||
@ -47,6 +49,28 @@ namespace OpenAuth.App
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<TableData> Query(QueryReq request)
|
||||||
|
{
|
||||||
|
var result = new TableData();
|
||||||
|
|
||||||
|
var sugarParams = new List<SugarParameter>();
|
||||||
|
if (!string.IsNullOrEmpty(request.ParamJsonStr))
|
||||||
|
{
|
||||||
|
var param = JsonHelper.Instance.Deserialize<Dictionary<string, string>>(request.ParamJsonStr);
|
||||||
|
foreach (var p in param)
|
||||||
|
{
|
||||||
|
sugarParams.Add(new SugarParameter($"@{p.Key}", p.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var objs = await SugarClient.Ado.SqlQueryAsync<dynamic>(request.SourceSql,sugarParams);
|
||||||
|
result.count = SugarClient.Ado.SqlQuery<dynamic>(request.SourceSql, sugarParams).Count;
|
||||||
|
result.data = objs.Skip((request.page - 1) * request.limit)
|
||||||
|
.Take(request.limit).ToList();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void Add(AddOrUpdateSysPrinterPlanReq obj)
|
public void Add(AddOrUpdateSysPrinterPlanReq obj)
|
||||||
{
|
{
|
||||||
//程序类型取入口应用的名称,可以根据自己需要调整
|
//程序类型取入口应用的名称,可以根据自己需要调整
|
||||||
@ -73,16 +97,5 @@ namespace OpenAuth.App
|
|||||||
public SysPrinterPlanApp(ISqlSugarClient client, IAuth auth) : base(client, auth)
|
public SysPrinterPlanApp(ISqlSugarClient client, IAuth auth) : base(client, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TableData> Query(QueryReq request)
|
|
||||||
{
|
|
||||||
var result = new TableData();
|
|
||||||
|
|
||||||
var objs = await SugarClient.Ado.SqlQueryAsync<dynamic>(request.SourceSql);
|
|
||||||
result.data = objs.Skip((request.page - 1) * request.limit)
|
|
||||||
.Take(request.limit).ToList();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,10 +60,6 @@ namespace OpenAuth.App.Test
|
|||||||
|
|
||||||
serviceCollection.AddDbContext<OpenAuthDBContext>();
|
serviceCollection.AddDbContext<OpenAuthDBContext>();
|
||||||
|
|
||||||
var container = AutofacExt.InitForTest(serviceCollection);
|
|
||||||
_autofacServiceProvider = new AutofacServiceProvider(container);
|
|
||||||
AutofacContainerModule.ConfigServiceProvider(_autofacServiceProvider);
|
|
||||||
|
|
||||||
var dbtypes = config.GetSection("AppSetting:DbTypes").GetChildren()
|
var dbtypes = config.GetSection("AppSetting:DbTypes").GetChildren()
|
||||||
.ToDictionary(x => x.Key, x => x.Value);
|
.ToDictionary(x => x.Key, x => x.Value);
|
||||||
|
|
||||||
@ -85,6 +81,10 @@ namespace OpenAuth.App.Test
|
|||||||
});
|
});
|
||||||
return sqlSugar;
|
return sqlSugar;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var container = AutofacExt.InitForTest(serviceCollection);
|
||||||
|
_autofacServiceProvider = new AutofacServiceProvider(container);
|
||||||
|
AutofacContainerModule.ConfigServiceProvider(_autofacServiceProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -37,19 +37,40 @@ namespace OpenAuth.App.Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Query()
|
public async Task QueryWithParam()
|
||||||
{
|
{
|
||||||
var app = _autofacServiceProvider.GetService<SysPrinterPlanApp>();
|
var app = _autofacServiceProvider.GetService<SysPrinterPlanApp>();
|
||||||
|
|
||||||
var result = await app.Query(new QueryReq()
|
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));
|
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||||
|
|
||||||
//延长主线程,防止程序退出
|
//异步测试,延长主线程,防止程序退出
|
||||||
Thread.Sleep(3000);
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task QueryNoParam()
|
||||||
|
{
|
||||||
|
var app = _autofacServiceProvider.GetService<SysPrinterPlanApp>();
|
||||||
|
|
||||||
|
var result = await app.Query(new QueryReq()
|
||||||
|
{
|
||||||
|
SourceSql = "select * from user ",
|
||||||
|
page = 1,
|
||||||
|
limit = 2
|
||||||
|
});
|
||||||
|
|
||||||
|
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||||
|
|
||||||
|
//异步测试,延长主线程,防止程序退出
|
||||||
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user