K3Cloud.WebApi.Core.IoC
2024.7.25.1803
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package K3Cloud.WebApi.Core.IoC --version 2024.7.25.1803
NuGet\Install-Package K3Cloud.WebApi.Core.IoC -Version 2024.7.25.1803
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="K3Cloud.WebApi.Core.IoC" Version="2024.7.25.1803" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add K3Cloud.WebApi.Core.IoC --version 2024.7.25.1803
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: K3Cloud.WebApi.Core.IoC, 2024.7.25.1803"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install K3Cloud.WebApi.Core.IoC as a Cake Addin #addin nuget:?package=K3Cloud.WebApi.Core.IoC&version=2024.7.25.1803 // Install K3Cloud.WebApi.Core.IoC as a Cake Tool #tool nuget:?package=K3Cloud.WebApi.Core.IoC&version=2024.7.25.1803
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
k3cloud_webapi_sample
项目特色:
1、支持多账套切换
2、支持自定义缓存(默认内存缓存),缓存故障切换回内存缓存
3、表单实体类生成(C#、Java)
4、表单查询链式调用(支持分页、排序、缓存、汇总、计数)
5、集成json转Lambda表达式进行表单查询
6、支持金蝶云星空所有WebApi接口
7、附公有云代理SQL操作示例
2023-08-10新增自定义缓存
2023-07-21链式查询支持Select,只输出需要查询的字段
2023-06-09新增 完成@GTGuang的Issues#I7BSGM星空账套切换
需要实现多账套切换请appsettings.json配置修改为:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"K3CLOUDCONFIG": {
"config1": { // 键值自己随便命名都可以
"ServerHost": "http://localhost:1200/k3cloud",
"AcctId": "61271b176f110c",
"UserName": "宋小康",
"Password": "123456",
"AppID": "",
"AppSecret": "",
"LCID": 2052,
"ConnectionValidTime": 10
},
"config2": {
"ServerHost": "https://yyds.test.ik3cloud.com/k3cloud",
"AcctId": "20186311217100",
"UserName": "宋小康",
"AppID": "204614_12cVu21XNUbC0YDoyuG/TZTJ6Lx9RoOF",
"AppSecret": "b4f16e8a797b85326fc5b86407190772",
"LCID": 2052,
"ConnectionValidTime": 10
}
}
}
使用方法:
// 在Program.cs注入
services.AddK3Sugar();
// Controller使用
var jsonDocument = JsonDocument.Parse(jsonStr);
var u = ExpressionBuilder.ParseExpressionOf<SAL_SaleOrder>(jsonDocument);
// 默认第一个配置(config1)
Refasync<int> total = 0;
var res = await K3Scoped.Client.Queryable(u)
.OrderBy(u => new { u.FId, u.FQty }, new[] { OrderType.Descending, OrderType.Ascending })
//.WithCache()
.ToPageListAsync(page, limit, t => t.FMaterialId_FNumber, total);
var sumData = await K3Scoped.Client.Queryable(u).SumAsync(t => new { t.FQty, t.FStockOutQty, t.FRemainOutQty });
// 切换配置
var res = await K3Scoped.GetClient("config2").Queryable(u) // 重点在这里
.OrderBy(u => new { u.FId, u.FQty }, new[] { OrderType.Descending, OrderType.Ascending })
//.WithCache() //同样的参数去除缓存才能看到效果
.ToPageListAsync(page, limit, t => t.FMaterialId_FNumber, total);
var sumData = await K3Scoped.GetClient("config2").Queryable(u).SumAsync(t => new { t.FQty, t.FStockOutQty, t.FRemainOutQty });
完整使用示例请查看HomeController.cs文件
2022-9-22新增
1、数字类型字段的IN NotIN支持 如:FQty In(1,2)
2、过滤字符中 大括号包裹 如:FQty greater_than {{fStockOutQty}} 转换为sql语句 FQty>FStockOutQty
介绍
金蝶云星空webapi C# Demo
一个基于 金蝶K3Cloud(星空云) webapi 封装库
测试环境
- Visual Studio Community 2022
- .net 7.0
配置
控制台配置使用
using K3Cloud.WebApi.Core.IoC;
using K3Cloud.WebApi.Core.IoC.Types;
K3Services.AddK3Sugar(new K3Config
{
ServerHost = "http://192.168.0.19/k3cloud",
AcctId = "6115be3f79b045",
UserName = "宋小康",
Password = "123456",
LCID = "2052"
});
Refasync<int> total = 0;
var res = await K3Scoped.Client.Queryable(u).WithCache(60).ToPageListAsync(1, 10, total);
var sumData = await K3Scoped.Client.Queryable(u).WithCache(60).SumAsync(t => t.FBaseQty);
return Json(new
{
code = 0,
count = total.Value,
totalRow = sumData,
data = res
});
WebMvc 或 WebApi 配置使用
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"K3CLOUDCONFIG": {
"ServerHost": "http://192.168.0.19/k3cloud",
"AcctId": "6115be3f79b045",
"UserName": "宋小康",
"Password": "123456",
"AppID": "",
"AppSecret": "",
"LCID": 2052
}
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
var options = Configuration.GetValue<K3Config>("K3CLOUDCONFIG");
services.AddK3Sugar(options);
}
}
public class HomeController : Controller
{
public async Task<IActionResult> IndexAsync()
{
Expression<Func<SAL_SaleOrder2, bool>> u = null;// u => u.FBillNo == "TM2205";
Refasync<int> totalNum = 0;
var res = await K3Scoped.Client.Queryable(u).Where(t => t.FBillNo == "TM2205").OrderBy(u => u.FId, new[] { OrderType.Descending }).WithCache().ToPageListAsync(1, 10, totalNum);
var sumData = await K3Scoped.Client.Queryable(u).WithCache().SumAsync(u => new { u.FQty, u.FRemainOutQty, u.FStockOutQty });
return Json(new
{
code = 0,
totalRow = sumData,
count = totalNum.Value,
data = res
});
}
}
演示单据保存
private async Task<decimal> HuilvAsync()
{
// 从某Api获取当月第一个美元汇率
return 6.3012;
}
DateTime fDate = DateTime.Now;
var begDate = new DateTime(fDate.Year, fDate.Month, 1);
var endDate = begDate.AddMonths(1).AddDays(-1);
var rateList = await K3Scoped.Client.ExecuteBillQueryAsync<BD_Rate>(t => t.FBegDate == begDate && t.FEndDate == endDate);
// 查询当月美元固定汇率 无则创建 有则更新
if (rateList.Any())
{
var fid = rateList.First().FRateID;
await K3Scoped.Client.UnAuditAsync("BD_Rate", fid);
var curRate = await HuilvAsync();
var bill = new K3SaveParam<BD_RateModel>
{
NeedUpDateFields = new string[] { "FExchangeRate", "FBegDate", "FEndDate" },
Model = new BD_RateModel
{
FRateID = fid,
FRATETYPEID = K3Number.Parse("HLTX01_SYS"),
FCyForID = K3Number.Parse("PRE007"),
FCyToID = K3Number.Parse("PRE001"),
FExchangeRate = curRate,
FBegDate = begDate,
FEndDate = endDate,
FUseOrgId = K3Number.Parse("100"),
FCreateOrgId = K3Number.Parse("100"),
}
};
_ = await K3Scoped.Client.SaveAsync(bill, true);
}
else
{
var curRate = await HuilvAsync();
if (curRate == 0) return;
var bill = new K3SaveParam<BD_RateModel>
{
Model = new BD_RateModel
{
FRateID = 0,
FRATETYPEID = K3Number.Parse("HLTX01_SYS"),
FCyForID = K3Number.Parse("PRE007"),
FCyToID = K3Number.Parse("PRE001"),
FExchangeRate = curRate,
FBegDate = begDate,
FEndDate = endDate,
FUseOrgId = K3Number.Parse("100"),
FCreateOrgId = K3Number.Parse("100"),
}
};
_ = await K3Scoped.Client.SaveAsync(bill, true);
}
实现方法
- 建一个与业务表单对象ID(FormId)同名的class(如:销售订单类 SAL_SaleOrder.cs)
- 在SAL_SaleOrder.cs创建 Field的对应属性(如:单据编号 FBillNo)
- __ (双横线)替代 . 返回解析数组后 . 再替代 __
- 利用 SQLBuilder 生成 SQL
前端提交查询条件:
[{"logicalOperator": "and",
"conditionFieldVal": "FMaterialId__FNumber",
"conditionOptionVal": "in",
"conditionValueVal": {"value": "CH4441,CH4443","text": "CH4441,CH4443"}, "conditionValueLeftVal": {"value": "", "text": ""},
"conditionValueRightVal": {"value": "", "text": ""}
}]
后端生成json发送至webapi
[{"FormId":"STK_Inventory","FieldKeys":"FOwnerId.FNumber,FOwnerId.FName,FKeeperId.FNumber,FKeeperId.FName,FMaterialId.FNumber,FMaterialName,FModel,FLot.FNumber,FStockId.FNumber,FStockName,FStockStatusId.FNumber,FStockStatusId.FName,FStockUnitId.FNumber,FStockUnitId.FName,FBaseQty",
"FilterString":"FMaterialId.FNumber IN ('CH4441','CH4443')",
"OrderString":"",
"TopRowCount":0,
"StartRow":0,
"Limit":10
}]
webapi服务器返回数组
[["100","测试账套","100","测试账套","CH4441","测试物料1"," ",null,"CK001","配件仓","KCZT01_SYS","可用","Pcs","Pcs",1280.0000000000],
["100","测试账套","100","测试账套","CH4443","子项物料1"," ",null,"CK003","赠品仓","KCZT002","不参与核算","Pcs","Pcs",98.0000000000],
["100","测试账套","100","测试账套","CH4443","子项物料1"," ",null,"CK001","配件仓","KCZT01_SYS","可用","Pcs","Pcs",10.0000000000],
["100","测试账套","100","测试账套","CH4443","子项物料1"," ",null,"CK002","成品仓","KCZT01_SYS","可用","Pcs","Pcs",0.0],
["100","测试账套","100","测试账套","CH4441","测试物料1"," ",null,"CK002","成品仓","KCZT01_SYS","可用","Pcs","Pcs",0.0]]
再将数组翻译成Json
[
{"FOwnerId__FNumber":"100","FOwnerId__FName":"测试账套","FKeeperId__FNumber":"100","FKeeperId__FName":"测试账套","FMaterialId__FNumber":"CH4441","FMaterialName":"测试物料1","FModel":" ","FStockId__FNumber":"CK001","FStockName":"配件仓","FStockStatusId__FNumber":"KCZT01_SYS","FStockStatusId__FName":"可用","FStockUnitId__FNumber":"Pcs","FStockUnitId__FName":"Pcs","FBaseQty":1280.0},
{"FOwnerId__FNumber":"100","FOwnerId__FName":"测试账套","FKeeperId__FNumber":"100","FKeeperId__FName":"测试账套","FMaterialId__FNumber":"CH4443","FMaterialName":"子项物料1","FModel":" ","FStockId__FNumber":"CK003","FStockName":"赠品仓","FStockStatusId__FNumber":"KCZT002","FStockStatusId__FName":"不参与核算","FStockUnitId__FNumber":"Pcs","FStockUnitId__FName":"Pcs","FBaseQty":98.0},
{"FOwnerId__FNumber":"100","FOwnerId__FName":"测试账套","FKeeperId__FNumber":"100","FKeeperId__FName":"测试账套","FMaterialId__FNumber":"CH4443","FMaterialName":"子项物料1","FModel":" ","FStockId__FNumber":"CK001","FStockName":"配件仓","FStockStatusId__FNumber":"KCZT01_SYS","FStockStatusId__FName":"可用","FStockUnitId__FNumber":"Pcs","FStockUnitId__FName":"Pcs","FBaseQty":10.0},
{"FOwnerId__FNumber":"100","FOwnerId__FName":"测试账套","FKeeperId__FNumber":"100","FKeeperId__FName":"测试账套","FMaterialId__FNumber":"CH4443","FMaterialName":"子项物料1","FModel":" ","FStockId__FNumber":"CK002","FStockName":"成品仓","FStockStatusId__FNumber":"KCZT01_SYS","FStockStatusId__FName":"可用","FStockUnitId__FNumber":"Pcs","FStockUnitId__FName":"Pcs","FBaseQty":0.0},
{"FOwnerId__FNumber":"100","FOwnerId__FName":"测试账套","FKeeperId__FNumber":"100","FKeeperId__FName":"测试账套","FMaterialId__FNumber":"CH4441","FMaterialName":"测试物料1","FModel":" ","FStockId__FNumber":"CK002","FStockName":"成品仓","FStockStatusId__FNumber":"KCZT01_SYS","FStockStatusId__FName":"可用","FStockUnitId__FNumber":"Pcs","FStockUnitId__FName":"Pcs","FBaseQty":0.0}
]
截图
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Http.Polly (>= 8.0.7)
- Newtonsoft.Json (>= 13.0.3)
- SQLBuilder.Lite (>= 1.0.1)
-
.NETStandard 2.1
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Http.Polly (>= 8.0.7)
- Newtonsoft.Json (>= 13.0.3)
- SQLBuilder.Lite (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2024.7.27.1552 | 58 | 7/27/2024 |
2024.7.25.1803 | 60 | 7/25/2024 |
2024.7.19.2043 | 84 | 7/19/2024 |
2024.7.17.929 | 62 | 7/17/2024 |
2024.7.11.1746 | 56 | 7/11/2024 |
2024.5.23.1126 | 90 | 5/23/2024 |
2024.5.22.1553 | 92 | 5/22/2024 |
2024.5.17.1803 | 95 | 5/17/2024 |
2024.2.23.1423 | 93 | 2/23/2024 |
2024.1.29.1437 | 106 | 1/29/2024 |
2024.1.29.1246 | 78 | 1/29/2024 |
2023.12.2.1043 | 180 | 12/2/2023 |
2023.11.15.1252 | 101 | 11/15/2023 |
2023.10.25.1011 | 124 | 10/25/2023 |
2023.10.16.1520 | 126 | 10/16/2023 |
2023.8.26.1015 | 135 | 8/26/2023 |
2023.8.22.1556 | 128 | 8/22/2023 |
2023.8.20.1509 | 127 | 8/20/2023 |
2023.8.19.1807 | 130 | 8/19/2023 |
2023.8.11.1059 | 132 | 8/11/2023 |
2023.8.10.1641 | 144 | 8/10/2023 |
2023.8.6.1010 | 146 | 8/6/2023 |
2023.7.30.1449 | 138 | 7/30/2023 |