案例:

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缓存相关配置

    小编今天来总结下 apache的缓存模块相关信息 硬盘缓存:mod_disk_cache,依赖 mod_cache 模块 内存缓存:mod_mem_cache,依赖 mod_cache 模块 文件缓存 ...

  2. javascript canvas全部API

    HTMLCanvasElement//canvas elem对象 属性 height//高 width//宽 方法 getContext()//获取<canvas>相关的可绘制的上下文 t ...

  3. 开源堡垒机jumpserver的配置和使用

    开源跳板机jumpserver配置和使用 http://docs.jumpserver.org/zh/docs/quick_start.html#id9 系统设置 基本设置 # 修改url 的&quo ...

  4. apache/tomcat安装过程略

    apache/tomcat安装过程略 一些变量 apache安装目录 APACHE_PREFIX=/Data/app/apache apache配置文件 APACHE_CONF=/etc/httpd/ ...

  5. 大数据运维尖刀班 | 集群_监控_CDH_Docker_K8S_两项目_腾讯云服务器

    说明:大数据时代,传统运维向大数据运维升级换代很常见,也是个不错的机会.如果想系统学习大数据运维,个人比较推荐通信巨头运维大咖的分享课:https://url.cn/5HIqOOr,主要是实战强.含金 ...

  6. css position absolute相对于父元素的设置方式

    手机赚钱怎么赚,给大家推荐一个手机赚钱APP汇总平台:手指乐(http://www.szhile.com/),辛苦搬砖之余用闲余时间动动手指,就可以日赚数百元 大家知道css的position abs ...

  7. MySQL中的索引、左连接、右连接、join、sql执行顺序

    逻辑架构: 1.连接层 2.服务层 3.引擎层(插拔式) 4.存储层 存储引擎: 常用的有:MyISAM.InnoDB 查看命令:show variables like '%storage_engin ...

  8. sed命令简介

    sed处理时,有2个缓冲区:[pattern space]和[hold space] sed执行过程: 先读入一行,去掉尾部换行符,存入[pattern space],执行编辑命令. 处理完毕,除非加 ...

  9. IDEA 修改编码

    IDEA: 一. 文件编码修改 IntelliJ IDEA可以在菜单中的File -> Settings -> Editor -> File Encoding下修改项目文件的编码 1 ...

  10. C#_.net core 3.0自定义读取.csv文件数据_解决首行不是标题的问题_Linqtocsv改进

    linqtocsv文件有不太好的地方就是:无法设置标题的行数,默认首行就是标题,这不是很尴尬吗?   并不是所有的csv文件严格写的首行是标题,下面全是数据,我接受的任务就是读取很多.csv报表数据, ...