二开案例.WebApi.查询枚举类型数据
【应用场景】通过WebApi获取下拉列表字段绑定的枚举类型的枚举项集合。
【案例演示】采购订单,单据头上有一个下拉列表字段【验收方式】,其绑定的枚举类型为【采购验收方式】,本文演示使用WebApi的方式获取该枚举类型的枚举项集合。
【实现步骤】
<1>编写WebApi调用代码,代码如下。
using Kingdee.BOS.WebApi.Client;
using Kingdee.BOS.WebApi.FormService;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
namespace Jac.XkDemo.BOS.WebApi
{
/// <summary>
/// 【WebApi调用】查询枚举类型数据
/// </summary>
[TestClass]
public class QueryEnumTypeDataWebApiService : AbstractWebApiTests
{
/// <summary>
/// 通过枚举单据直接查询枚举类型数据
/// </summary>
[TestMethod]
public void QueryEnumTypeDataTest()
{
// Init
var apiClient = new K3CloudApiClient(url);
var isLoginOk = apiClient.Login(dbid, userName, password, lcid);
Assert.IsTrue(isLoginOk);
// Action
// 查找枚举类型【采购验收方式】及其枚举项
//var data = "{"FormId":"","FieldKeys":"","FilterString":"","OrderString":"","TopRowCount":0,"StartRow":0,"Limit":0}";
var data = new
{
FormId = "BOS_EnumBill",
FieldKeys = "FName,FCategory,FValue,FCaption",
FilterString = "FID='9a9bcf8e-053a-4ca9-b525-6c4e62fbcbd5'",
OrderString = "FSEQ",
TopRowCount = 0,
StartRow = 0,
Limit = 0
};
var requestData = JsonConvert.SerializeObject(data);
var responseData = apiClient.ExecuteBillQuery(requestData);
var enumItems = JsonConvert.SerializeObject(responseData);
// Assert
Assert.IsTrue(responseData != null && responseData.Count > 0);
}
/// <summary>
/// 通过业务对象的元数据,间接从下拉列表字段上获取枚举类型数据
/// </summary>
[TestMethod]
public void QueryEnumTypeDataTest2()
{
// Init
var apiClient = new K3CloudApiClient(url);
var isLoginOk = apiClient.Login(dbid, userName, password, lcid);
Assert.IsTrue(isLoginOk);
List<List<object>> ojs = null;
// Action
// 获取采购订单的元数据
var data = new
{
FormId = "PUR_PurchaseOrder"
};
var requestData = JsonConvert.SerializeObject(data);
var responseData = apiClient.QueryBusinessInfo(requestData);
var responseObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseData);
var resultObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseObj["Result"].ToString());
var metadata = JsonConvert.DeserializeObject<FormMetaDataCosmic>(resultObj["NeedReturnData"].ToString());
// 从采购订单元数据中定位下拉列表字段,从该字段的属性中获取枚举类型【采购验收方式】的枚举项
var entry = metadata.Entrys.FirstOrDefault(o => o.Key == "FBillHead");
Assert.IsTrue(entry != null);
var field = entry.Fields.FirstOrDefault(o => o.Key == "FACCTYPE");
Assert.IsTrue(field != null);
var enumItems = field.Extends.ToString();
// Assert
Assert.IsTrue(ojs != null && ojs.Count > 0);
}
}
/// <summary>
/// WebApi测试基类
/// </summary>
public abstract class AbstractWebApiTests
{
#region 测试参数
/// <summary>
/// 应用站点地址
/// </summary>
protected string url = "http://localhost/k3cloud/";
/// <summary>
/// 数据中心内码(账套ID)
/// </summary>
protected string dbid = "5f3a43d65be160";
/// <summary>
/// 登录账号
/// </summary>
protected string userName = "demo";
/// <summary>
/// 登录密码
/// </summary>
protected string password = "888888";
/// <summary>
/// 登录语言内码(2052:中文;1033:英文)
/// </summary>
protected int lcid = 2052;
#endregion
}
}
<2>执行以上代码,可观察WebApi的调用结果如下。
【知识点】
<1>枚举类型对应单据:【枚举单据[BOS_EnumBill]】
<2>枚举类型查询常用SQL:
-- 查询枚举类型
SELECT a.FID AS 枚举类型内码,b.FNAME AS 枚举类型名称,* FROM T_META_FORMENUM a
LEFT JOIN T_META_FORMENUM_L b ON a.FID=b.FID AND b.FLOCALEID=2052
WHERE b.FNAME='采购验收方式'
-- 查询枚举值
SELECT a.FVALUE AS 枚举值,b.FCAPTION AS 枚举名,* FROM T_META_FORMENUMITEM a
LEFT JOIN T_META_FORMENUMITEM_L b ON a.FENUMID=b.FENUMID AND b.FLOCALEID=2052
WHERE a.FID='9a9bcf8e-053a-4ca9-b525-6c4e62fbcbd5'
ORDER BY a.FSEQ
<3>下拉列表字段对应的元数据如下,其中EnumType为下拉列表字段绑定的枚举类型的内码,通过该内码就可以查询到枚举类型定义及其枚举项。
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.WebApi.查询枚举类型数据
本文2024-09-23 04:20:53发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164720.html