案例:

Cloud的采购订单同步到第三方系统,第三方系统入库后同步生成Cloud采购入库单。

解决方案:调用采购订单的下推API,先生成保存状态的采购入库单(采购入库单中的仓库是必填项,可以在采购订单中默认一个仓库通过单据转换关系携带,或者通过单据转换插件默认一个仓库),然后根据第三方的系统传过来的数据,调用这个采购入库单的保存API(JSON中的FID和FEntryID需要给定值,这个定值就是这个采购入库单的FID和FEntryID),将数量等信息按照第三方系统传过来的数据进行修改。

示例代码,仅供参考。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Contracts;
using Kingdee.BOS;
using Kingdee.BOS.Core;
using System.IO;
using System.Configuration;
using Newtonsoft.Json.Linq;
using Kingdee.BOS.WebApi.Client;
using Kingdee.BOS.Core.Msg;
using Kingdee.BOS.Util;
using System.Dynamic;
using Kingdee.BOS.Orm.Drivers;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.DataEntity;
using Newtonsoft.Json;

namespace K3CloudPlugIn
{
    public class GetInstockDataInfo : IScheduleService
    {
        K3CloudApiClient client = new K3CloudApiClient(Common.url);
        /// <summary>
        /// 实际运行的Run 方法
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="schedule"></param>
        public void Run(Context ctx, Schedule schedule)
        {
            //获取入库单中间表数据,并生成相应的采购入库单,委外入库单,生产入库单
            K3JSTService.XZGTCBS InstockService = new K3JSTService.XZGTCBS();
            string FDate = DateTime.Now.ToShortDateString();
            //调用WebService,将数据插入中间表
            //FDate = "2019-12-11";
            InstockService.GetCaiGouRuKuInfo(FDate);
            string ReturnInfo = "";
            string JsonInfo = "";
            string BillSql = "";
            string EntrySql = "";
            string result = "";
            int TotalRows = 0;
            string io_id = "";//聚水潭入库单ID
            string po_id = "";//聚水潭入库单关联的采购单ID
            DataSet ds_BillSql = new DataSet();
            DataSet ds_EntrySql = new DataSet();
            string OrderSql = "";
            DataSet ds_OrderSql = new DataSet();
            string FBillNo = "";
            string FBillID = "";
            JObject jsonRoot;
            JArray Numbers;
            JObject CustomParams;
            var loginResult = "";
            var resultType = 0;
            string autrjson;
            JObject joAudit;
            JObject joAuditIsSucess;
            JArray Fields;
            string AlterSql = "";
            DataSet ds_AlterSql = new DataSet();
            JObject basedata;
            string SaveResult = "";
            string FOrgId = "";
            BillSql = @"/*dialect*/select distinct a.* from MyOrderHouse a left join MyOrderHouseEntry b on a.io_id = b.io_id ";
            BillSql = BillSql + "left join T_BD_MATERIAL c on c.F_RFGW_TEXT = b.sku_id where ISNULL(c.FMATERIALID,0) > 0 and ISNULL(a.WinBillID,0) = 0 ";
            ds_BillSql = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(ctx, BillSql);
            TotalRows = ds_BillSql.Tables[0].Rows.Count;
            if (TotalRows > 0)
            {
                for (int i = 0; i < TotalRows; i++)
                {
                    io_id = ds_BillSql.Tables[0].Rows[i]["io_id"].ToString();
                    po_id = ds_BillSql.Tables[0].Rows[i]["po_id"].ToString();

#region 第一种情况:该入库单对应的采购订单是由Cloud的采购订单同步过去的
                    //第一种情况:该入库单对应的采购订单是由Cloud的采购订单同步过去的
                    OrderSql = @"/*dialect*/select * from t_PUR_POOrder where FJSTORDERNO = '" + po_id + "'";
                    ds_OrderSql = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(ctx,OrderSql);
                    if (ds_OrderSql.Tables[0].Rows.Count > 0)
                    {
                        FOrgId = ds_OrderSql.Tables[0].Rows[0]["FPURCHASEORGID"].ToString();
                        //获取入库单的物料编码和数量,以及对应采购订单的分录内码
                        EntrySql = @"/*dialect*/select distinct e.FENTRYID as 'EntryID',b.qty as 'Qty',c.FNUMBER as 'MatNO' from MyOrderHouse a left join MyOrderHouseEntry b on a.io_id = b.io_id ";
                        EntrySql = EntrySql + "left join T_BD_MATERIAL c on b.sku_id = c.F_RFGW_TEXT left join t_PUR_POOrder d on a.po_id = d.FJSTORDERNO ";
                        EntrySql = EntrySql + "left join t_PUR_POOrderEntry e on d.FID = e.FID and c.FMATERIALID = e.FMATERIALID ";
                        EntrySql = EntrySql + "where a.io_id = '" + io_id + "' and ISNULL(e.FENTRYID,0) > 0 and ISNULL(c.FMATERIALID,0) > 0 and c.FUSEORGID = '" + FOrgId + "'";
                        ds_EntrySql = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(ctx,EntrySql);
                        if (ds_EntrySql.Tables[0].Rows.Count > 0)
                        {
                            Common.STKEntryIds = new string[ds_EntrySql.Tables[0].Rows.Count];
                            Common.STKMats = new string[ds_EntrySql.Tables[0].Rows.Count];
                            Common.STKMatIds = new int[ds_EntrySql.Tables[0].Rows.Count];
                            Common.STKqty = new decimal[ds_EntrySql.Tables[0].Rows.Count];
                            Common.STKprice = new decimal[ds_EntrySql.Tables[0].Rows.Count];
                            for (int j = 0; j < ds_EntrySql.Tables[0].Rows.Count; j++)
                            {
                                Common.STKMats[j] = ds_EntrySql.Tables[0].Rows[j]["MatNO"].ToString();
                                Common.STKEntryIds[j] = ds_EntrySql.Tables[0].Rows[j]["EntryID"].ToString();
                                Common.STKqty[j] = Convert.ToDecimal(ds_EntrySql.Tables[0].Rows[j]["Qty"].ToString());
                            }
                        }
                        //调用采购订单的下推API
                        // 开始构建Web API参数对象
                        // using Newtonsoft.Json.Linq;  // (需引用Newtonsoft.Json.dll)
                        jsonRoot = new JObject();
                        jsonRoot.Add("Ids", "");//单据内码集合,字符串类型,格式:"Id1,Id2,..."(使用内码时必录)
                        Numbers = new JArray();
                        jsonRoot.Add("Numbers", Numbers);//单据编码集合,数组类型,格式:[No1,No2,...](使用编码时必录)
                        jsonRoot.Add("EntryIds", string.Join(",", Common.STKEntryIds));//分录内码集合,逗号分隔(分录下推时必录),注(按分录下推时,单据内码和编码不需要填,否则按整单下推)
                        jsonRoot.Add("RuleId", "44789b6e-ef2e-44a3-bcb9-dd38b8f13eae");//转换规则内码,字符串类型(未启用默认转换规则时,则必录)
                        jsonRoot.Add("TargetBillTypeId", "");//目标单据类型内码,字符串类型(非必录)
                        jsonRoot.Add("TargetOrgId", 0);//目标组织内码,整型(非必录)
                        jsonRoot.Add("TargetFormId", "STK_InStock");//目标单据FormId,字符串类型,(启用默认转换规则时,则必录)
                        jsonRoot.Add("IsEnableDefaultRule", "true"); //是否启用默认转换规则,布尔类型,默认false(非必录)
                        jsonRoot.Add("IsDraftWhenSaveFail", "false");
                        CustomParams = new JObject();//自定义参数,字典类型,格式:"{key1:value1,key2:value2,...}"(非必录) ,注(传到转换插件的操作选项中,平台不会解析里面的值)
                        jsonRoot.Add("CustomParams", CustomParams);
                        JsonInfo = jsonRoot.ToString();
                        loginResult = client.ValidateLogin(Common.dbid, Common.username,Common.password, 2052);
                        resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
                        //登录结果类型等于1,代表登录成功
                        if (resultType == 1)
                        {
                            ReturnInfo = client.Push("PUR_PurchaseOrder", JsonInfo);
                            try
                            {
                                JObject jo = (JObject)JsonConvert.DeserializeObject(ReturnInfo);
                                JObject JoResult = (JObject)JsonConvert.DeserializeObject(jo["Result"]["ResponseStatus"].ToString());
                                JArray array = (JArray)JsonConvert.DeserializeObject(JoResult["SuccessEntitys"].ToString());
                                FBillNo = array[0]["Number"].ToString();
                                FBillID = array[0]["Id"].ToString();

if (FBillNo != "")
                                {
                                    //调用采购入库单的保存API,修改实收数量和仓库
                                    jsonRoot = new JObject();
                                    jsonRoot.Add("Creator", "");
                                    Fields = new JArray();
                                    Fields.Add("FInStockEntry");
                                    Fields.Add("FRealQty");

jsonRoot.Add("NeedUpDateFields", Fields);
                                    jsonRoot.Add("NeedReturnFields", new JArray());
                                    jsonRoot.Add("IsDeleteEntry", "false");
                                    jsonRoot.Add("SubSystemId", "");
                                    jsonRoot.Add("IsVerifyBaseDataField", "false");
                                    jsonRoot.Add("IsEntryBatchFill", "True");
                                    jsonRoot.Add("ValidateFlag", "True");
                                    jsonRoot.Add("NumberSearch", "True");
                                    jsonRoot.Add("InterationFlags", "STK_InvCheckResult");
                                    // Model: 单据详细数据参数
                                    JObject model = new JObject();
                                    jsonRoot.Add("Model", model);
                                    // 单据主键:必须填写,系统据此判断是新增还是修改单据;新增单据,填0
                                    model.Add("FID", FBillID.ToString());

JArray entryRows = new JArray();
                                    // 把单据体行集合,添加到model中,以单据体Key为标识
                                    string entityKey = "FInStockEntry";
                                    model.Add(entityKey, entryRows);

AlterSql = @"/*dialect*/select b.FSEQ,b.FENTRYID,c.FNUMBER,b.FREALQTY from t_STK_InStock a left join T_STK_INSTOCKENTRY b on a.fid = b.fid ";
                                    AlterSql = AlterSql + "left join T_BD_MATERIAL c on b.FMATERIALID = c.FMATERIALID where a.fbillno = '" + FBillNo + "'";
                                    ds_AlterSql = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(ctx, AlterSql);
                                    for (int j = 0; j < ds_AlterSql.Tables[0].Rows.Count; j++)
                                    {
                                        for (int k = 0; k < Common.STKEntryIds.Length; k++)
                                        {
                                            //if (ds_AlterSql.Tables[0].Rows[j]["FSEQ"].ToString().Equals(Common.Seqs[k].ToString()) && ds_AlterSql.Tables[0].Rows[j]["FMATERIALID"].ToString().Equals(Common.TarMatIds[k].ToString()))
                                            if (ds_AlterSql.Tables[0].Rows[j]["FNUMBER"].ToString().Equals(Common.STKMats[k].ToString()))
                                            {
                                                // 添加新行,把新行加入到单据体行集合
                                                JObject entryRow = new JObject();
                                                entryRows.Add(entryRow);
                                                // 给新行,设置关键字段值
                                                // 单据体主键:必须填写,系统据此判断是新增还是修改行
                                                entryRow.Add("FEntryID", ds_AlterSql.Tables[0].Rows[j]["FENTRYID"].ToString());
                                                entryRow.Add("FRealQty", Convert.ToDecimal(Common.STKqty[k].ToString()));
                                            }
                                        }
                                    }
                                    SaveResult = Save("STK_InStock", jsonRoot.ToString());
                                    try
                                    {
                                        JObject josave = (JObject)JsonConvert.DeserializeObject(SaveResult);
                                        string number = josave["Result"]["Number"].ToString();
                                        string id = josave["Result"]["Id"].ToString();
                                        if (number != "")
                                        {
                                            autrjson = "{\"CreateOrgId\":0,\"Numbers\":[\"" + FBillNo + "\"],\"InterationFlags\":\"STK_InvCheckResult\"}";
                                            result = Audit("STK_InStock", autrjson);
                                            joAudit = (JObject)JsonConvert.DeserializeObject(result);
                                            joAuditIsSucess = (JObject)JsonConvert.DeserializeObject(joAudit["Result"]["ResponseStatus"].ToString());
                                            string IsSucess = joAuditIsSucess["IsSuccess"].ToString();
                                            if (IsSucess.Equals("True"))
                                            {
                                                Kingdee.BOS.ServiceHelper.DBServiceHelper.Execute(ctx, @"/*dialect*/update MyOrderHouse set WinBillID = '" + FBillID + "',WinBillNO = '" + FBillNo + "' where io_id = '" + io_id + "'");
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {                                       
                                        throw;
                                    }                                   
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    #endregion
                }
            }

}

/// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        public bool Login()
        {
            string dbid = Common.dbid;
            string username = Common.username;
            string password = Common.password;
            var loginResult = client.Login(
                               dbid,
                               username,
                               password,
                               2052);
            return loginResult;
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="formid"></param>
        /// <param name="jsonstr"></param>
        /// <returns></returns>
        public string Save(string formid, string jsonstr)
        {
            string result = "登录失败,请检查与站点地址、数据中心Id,用户名及密码!";
            //string result = "";
            if (Login())
            {
                result = client.Execute<string>(
                                               "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save",
                                               new object[] { formid, jsonstr });
            }
            return result;
        }
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="formid"></param>
        /// <param name="jsonstr"></param>
        /// <returns></returns>
        public string Audit(string formid, string jsonstr)
        {
            string result = "登录失败,请检查与站点地址、数据中心Id,用户名及密码!";
            result = client.Execute<string>("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit", new object[] { formid, jsonstr });
            result = client.Execute<string>("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit", new object[] { formid, jsonstr });
            return result;
        }
    }
}

与第三方系统对接,生成Cloud出入库单据的更多相关文章

  1. 安卓智能POS终端手持机PDA应用仓库出入库,移库,盘点,销售开单系统

    随着移动互联网的兴起,目前仓储管理所面临的的问题可以迎刃而解,WMS仓库系统解决方案通过智能终端扫描条码技术应用解决了工作量大导致工作效率不高,以及数据实时传输等问题,该方案主要提供仓库出入库,移库, ...

  2. PDA手持终端在ERP系统仓库管理出入库盘点环节的应用

    PDA手持终端在ERP系统仓库管理出入库盘点环节的应用 传统库存管理的数据录入过程,常采用PC机录入数据,或在电脑上结合条码枪扫描条码进行管理(非实时),造成管理上的不便.因而,采用无线(WIFI)手 ...

  3. 腾讯EC .net API对接第三方系统

    最近公司销售部门用到了腾讯EC,实现公司内部OA系统与腾讯ec的数据同步,要求如下: 1.OA内部系统账号与腾讯ec登陆账号同步 2.首先做义工客户端工具用来把现有客户导入到EC,销售人员的客户信息与 ...

  4. PDA应用在WMS仓储管理系统 实现无线扫描出入库作业

    WMS系统是根据仓储物流管理的建设实施经验而推出的一款专业化仓储管理软件.与传统进销存软件相比优势在于,其不但包含了正常的出入库.盘点等库存管理基本功能,重点在于可以实现仓库作业过程的管理,通过条码及 ...

  5. 第三方系统打开EAFC的实现

    前言:EAFC是我们公司的一个框架,一个项目上,客户的OA系统要调用我们推送过去的代办任务,希望能打开我们的代办处理界面,我们的代办处理界面是winform的.引出给出了以下的一个方案.在此备存. - ...

  6. U811.1接口EAI系列之二--生成销售出库单调用U8的EAI通用处理方法--PowerBuilder语言

    1.销售系统销售出库,更新U811.1材料库存的EAI的XML生成. 2.主要根据U8配置会生成出库单和同时是否更新库存量,还是更新现存量等等. 3.具体参考代码如下: 作者:王春天 2013-11- ...

  7. 第三方API对接如何设计接口认证?

    一.前言 在与第三方系统做接口对接时,往往需要考虑接口的安全性问题,本文主要分享几个常见的系统之间做接口对接时的认证方案. 二.认证方案 例如订单下单后通过 延时任务 对接 物流系统 这种 异步 的场 ...

  8. 基于IdentityServer的系统对接微信公众号

    业务需求 公司有两个业务系统,A和B,AB用户之间属于多对一的关系,数据库里面也就是两张表,A表有个外键指向B.现在需要实现以下几个功能. A用户扫描B的二维码,填写相关的注册信息,注册完成之后自动属 ...

  9. 应用SAP PI实现SAP BW数据仓库对于第三方系统数据完美集成以及DELTA加载的分析

    注明:本篇的技术性细节参考了SAP SCN上的一篇SAP PI 和BW集成的文章,本篇文章并不打算过多探讨实现的技术细节,因为在SCN上的这篇英文文章已经完全涵盖了技术细节和配置步骤 大家可以通过搜索 ...

随机推荐

  1. Apache 相关 mod_rewrite ,RewriteCond,{HTTP_HOST}

    1.给子域名加www标记  RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC] RewriteCond %{HTTP_HOST} !^www\ ...

  2. php面试笔记(3)-php基础知识-运算符

    本文是根据慕课网Jason老师的课程进行的PHP面试知识点总结和升华,如有侵权请联系我进行删除,email:guoyugygy@163.com 在面试中,考官往往喜欢基础扎实的面试者,而运算符相关的考 ...

  3. HTML,Css,JavaScript之间的关系

    简述HTML,Css,JavaScript 网页设计思路是把网页分成三个层次,即:结构层(HTML).表示层(CSS).行为层(Javascript). 1.HTML(超文本标记语言 Hyper Te ...

  4. 自己用C语言写NXP S32K116 serial bootloader

    了解更多关于bootloader 的C语言实现,请加我QQ: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). 每次我有了新的EVA ...

  5. typescript 点滴

    1 extend的用法 const x = extend({ a: 'hello' }, { b: 42 }); 2只有在d.ts,你才可以使用  export as 这样子的语法.而且必须有name ...

  6. telnet命令连接服务器端

    win7: (1).使用telnet命令: 控制面板--->程序--->打开或关闭Windows功能--->Telnet客户端[勾选] (2)连接(cmd) eg:telnet ww ...

  7. K8S ? K3S !

    K8S ? K3S ! K3S 踩坑开始 歪比歪比(奇怪的服务器) 服务器选择我熟悉的 Centos K3S内置 Containerd 但是!作为一个服务器使用自然是要用常见的一点的容器 Docker ...

  8. git中常混淆的操作

    1, git fetch 和 git pull 参考链接: https://stackoverflow.com/questions/292357/what-is-the-difference-betw ...

  9. Centos7 使用Docker 部署mssql 2017

    mssql是.NET的标配,一般使用.NET的人基本都用mssql. 以前mssql只能支持windows平台,从微软打出 拥抱开源 的口号开始,mssql的2017 版本,开始支持linux系统. ...

  10. WPF 原生绑定和命令功能使用指南

    WPF 原生绑定和命令功能使用指南 魏刘宏 2020 年 2 月 21 日 如今,当谈到 WPF 时,我们言必称 MVVM.框架(如 Prism)等,似乎已经忘了不用这些的话该怎么使用 WPF 了.当 ...