二开案例.webapi.根据formid得到表单的entry信息(主键、单据状态字段、单据编号字段、单据类型字段)原创
金蝶云社区-zfyadd
zfyadd
35人赞赏了该文章 313次浏览 未经作者许可,禁止转载编辑于2024年06月14日 10:26:10

该功能可以通过接口的方式获得表单的关键信息,十分有用。

废话不多说直接上代码

using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.ServiceFacade.KDServiceFx;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.BOS.WebApi.ServicesStub;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;

namespace scjr.extend.plugin.ly.lyproject
{
    [Kingdee.BOS.Util.HotUpdate]
    class fdatatowebapidatatable : AbstractWebApiBusinessService
    {
        public fdatatowebapidatatable(KDServiceContext context)
            : base(context)
        { }
        private string _formId = string.Empty;

        private FormMetadata _formMetadata;

        private JObject _json_info;

        public object getWebApiData(string param)
        {

            try
            {
                _json_info = JObject.Parse(param);
                var ctx = KDContext.Session.AppContext;
                if (ctx == null)
                {
                    // 会话超时,需重新登录
                    return new
                    {
                        isSuccess = false,
                        message = "会话超时,请重新登录"
                    };
                }
                this._formId = String.Format("{0}", _json_info["formid"]);
                _formMetadata = FormMetaDataCache.GetCachedFormMetaData(ctx, _formId);
                List<Entity> entrys = _formMetadata.BusinessInfo.Entrys;
                List<object> results = new List<object>();
                var bus = _formMetadata.BusinessInfo;
                foreach (Entity ent in entrys)
                {
                    if (ent.GetType().Name.EqualsIgnoreCase("HeadEntity"))
                    {
                        results.Add(new
                        {
                            pkname = ent.EntryPkFieldName,
                            tablename = ent.TableName,
                            entryname = ent.EntryName,
                            entrytype = ent.GetType().Name,
                            billnoname = bus.GetBillNoField().Name[2052],
                            billnofieldname = bus.GetBillNoField().FieldName,
                            billstatusname = bus.GetBillStatusField().Name[2052],
                            billstatusfieldname = bus.GetBillStatusField().FieldName,
                            billtypename = bus.GetBillTypeField().Name[2052],
                            billtypefieldname = bus.GetBillTypeField().FieldName
                        });
                        continue;
                    }
                    results.Add(new
                    {
                        pkname = ent.EntryPkFieldName,
                        tablename = ent.TableName,
                        entryname = ent.EntryName,
                        entrytype = ent.GetType().Name,
                        entrytypeid = ent.EntityType
                    });
                }
                return new
                    {
                        isSuccess = true,
                        message = "",
                        data = results

                    };

            }
            catch (Exception e)
            {
                return new
                {
                    isSuccess = false,
                    message = e.Message
                };
            }


        }



    }
}

效果如下图:

image.png

响应结果:

{
"isSuccess": true,
"message": "",
"data": [
{
"pkname": "FID",
"tablename": "T_STK_STKTRANSFERIN",
"entryname": "STK_STKTRANSFERIN",
"entrytype": "HeadEntity",
"billnoname": "单据编号",
"billnofieldname": "FBILLNO",
"billstatusname": "单据状态",
"billstatusfieldname": "FDOCUMENTSTATUS",
"billtypename": "单据类型",
"billtypefieldname": "FBILLTYPEID"
},
{
"pkname": "FEntryID",
"tablename": "T_STK_STKTRANSFERINENTRY",
"entryname": "STK_STKTRANSFERINENTRY",
"entrytype": "EntryEntity",
"entrytypeid": 1
},
{
"pkname": "FDetailID",
"tablename": "T_STK_STKTRANSFERINSERIAL",
"entryname": "STK_STKTRANSFERINSERIAL",
"entrytype": "SNSubEntryEntity",
"entrytypeid": 1
},
{
"pkname": "FLinkId",
"tablename": "T_STK_STKTRANSFERINENTRY_LK",
"entryname": "FSTKTSTKRANSFERINENTRY_Link",
"entrytype": "SubEntryEntity",
"entrytypeid": 2
}
]
}

制作不易,谢谢大家收藏、点赞、关注

图标赞 35
35人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!