自定义webapi 实现对物料清单反查结果查询原创
金蝶云社区-亦木丶
亦木丶
9人赞赏了该文章 996次浏览 未经作者许可,禁止转载编辑于2022年08月15日 17:05:45

1,构建webapi参数类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
    public class BomOption
    {
        /// <summary>
        /// 使用组织
        /// </summary>
        public long BomUseOrgId { get; set; }
        /// <summary>
        /// 跨组织查询
        /// </summary>
        public bool IsMultiOrg { get; set; }
        /// <summary>
        /// 反查结果包含已禁用BOM
        /// </summary>
        public bool ContainForbiddenBom { get; set; }
        /// <summary>
        /// FIsAuxpropFilter
        /// </summary>
        public bool isAuxpropFilter { get; set; }
        /// <summary>
        /// 需求日期
        /// </summary>
        public DateTime ValidDate { get; set; }
        /// <summary>
        /// 展开层级
        /// </summary>
        public int ExpandLevelTo { get; set; }
        /// <summary>
        /// 子项物料ID
        /// </summary>
        public List<long> BillMaterialIds { get; set; }
    }
}

2,物料反查逻辑调用,继承于AbstractWebApiBusinessService,构建一个工程,将生成的DLL放在服务器website/bin目录

具体代码如下

using Kingdee.BOS;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceFacade.KDServiceFx;
using Kingdee.BOS.Util;
using Kingdee.BOS.WebApi.ServicesStub;
using Kingdee.K3.Core.MFG;
using Kingdee.K3.Core.MFG.ENG.BomExpand;
using Kingdee.K3.Core.MFG.ENG.ParamOption;
using Kingdee.K3.MFG.ServiceHelper.ENG;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
    public class GetBomQueryBackwardDatas: AbstractWebApiBusinessService
    {

        public GetBomQueryBackwardDatas(KDServiceContext context) : base(context)
        {

        }
        public JObject ExecuteService(string info)
        {
            JObject result = new JObject();
            var param = JsonConvert.DeserializeObject<BomOption>(info);
            FormMetadata bomMetadata = Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.GetFormMetaData(this.KDContext.Session.AppContext, MFGFormIdConst.SubSys_ENG.BomBill);
            BomQueryOption newBomQueryOption = new BomQueryOption(bomMetadata);
            newBomQueryOption.ExpandLevelTo = param.ExpandLevelTo;
            newBomQueryOption.ValidDate = param.ValidDate;
            newBomQueryOption.isAuxpropFilter = param.isAuxpropFilter;
            if (newBomQueryOption.ExpandLevelTo == 0)
            {
                newBomQueryOption.ExpandLevelTo = newBomQueryOption.BomMaxLevel;
            }
            newBomQueryOption.isAuxpropFilter = param.isAuxpropFilter == false ? true : false; //如果不勾上辅助属性过滤,辅助属性参与SQL语句 旧逻辑,反之走新逻辑
            //展开选项带上使用组织
            newBomQueryOption.Option.SetVariableValue("BomUseOrgId", param.BomUseOrgId);
            //跨组织查询参数
            newBomQueryOption.Option.SetVariableValue("IsMultiOrg", param.IsMultiOrg);
            newBomQueryOption.Option.SetVariableValue("ContainForbiddenBom", param.ContainForbiddenBom);
List<DynamicObject> lstExpandSource = this.BuildBomExpandSourceData(param);
            if (lstExpandSource == null || lstExpandSource.Count <= 0)
            {
                result.Add("Status", "False");
                result.Add("Message", "当前子项物料为空,请重新选,请确认!");
                return result;
                
            }
             List <DynamicObject> queryDatas = BomQueryServiceHelper.GetBomQueryBackwardResult(this.KDContext.Session.AppContext, lstExpandSource, newBomQueryOption); 
            result.Add("Status", "Success");
            result.Add("Data", queryDatas.IsEmpty() ? "" : JsonConvert.SerializeObject(queryDatas));
            result.Add("Message", "查询成功");
            return result;
        }


        private List<DynamicObject> BuildBomExpandSourceData(BomOption option)
        {
            List<DynamicObject> lstExpandSource = new List<DynamicObject>();

            if (!option.BillMaterialIds.IsEmpty())
            {
                foreach (var baseId in option.BillMaterialIds)
                {
                    if (baseId == 0)
                    {
                        continue;
                    }
                    BomBackwardSourceDynamicRow bomExpandSourceRowView = BomBackwardSourceDynamicRow.CreateInstance();
                    
                    bomExpandSourceRowView.MaterialId_Id = baseId;
                    bomExpandSourceRowView.AuxPropId = 0;
                    lstExpandSource.Add(bomExpandSourceRowView.DataEntity);
                }
            }
            return lstExpandSource;
        }
    }
}

3,客户端调用逻辑实现

using ClassLibrary1;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.WebApi.Client;
using Kingdee.K3.Core.MFG.ENG.ParamOption;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                K3CloudApiClient client = new K3CloudApiClient("http://localhost:1702/k3cloud/");
                //ValidateLogin(金蝶webapi界面中有此登录信息,数据库)
                var loginResult = client.ValidateLogin("62a0339474f6a3", "demo", "******", 2052);
                var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
                  
                if (resultType == 1)
                {
                    BomOption bomExpandParam = new BomOption() {
                        BomUseOrgId=1,
                        ValidDate = DateTime.Now,
                        BillMaterialIds =new List<long>() { 188524 }
                    };
                        
                    string serviceName = "ClassLibrary1.GetBomQueryBackwardDatas.ExecuteService,ClassLibrary1";
                    var info = client.Execute<JObject>(serviceName, new object[] { JsonConvert.SerializeObject(bomExpandParam) });
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            
        }
        public class ValidModelEntity
        {
            public string Acctid { get; set; }

            public string userName { get; set; }

            public string password { get; set; }

            public int lcid { get; set; }
        }
    }
}

4,调用结果image.png


备注:

测试工程目录

image.png

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