哈嘍,又和大家見面了,雖然看文章的小伙伴不多,但是我相信總有一天,自己寫的這些文章或多或少會(huì)對(duì)其他人有些幫助,讓他們?cè)谙嚓P(guān)的業(yè)務(wù)開發(fā)下能少走些彎路,那我的目的就達(dá)到了,好了,今天就正式開始我們的系列了,今天要講的是金蝶系列的API,大家都知道,金蝶的產(chǎn)品是比較多的,那么我們這次要講解的就是金蝶云星空,或者叫K3Cloud。 首先,作為一名程序猿我們?cè)谀玫筋愃频慕涌趯?duì)接需求,第一件是肯定是看相關(guān)文檔,然后做接口分析,最后是封裝接口,運(yùn)用到我們的項(xiàng)目中去,所以對(duì)于我們來說,第一步就是尋找相關(guān)的開發(fā)文檔,在這方面不得不承認(rèn),金蝶社區(qū)是個(gè)好地方。里面有關(guān)于產(chǎn)品的所有知識(shí)點(diǎn)和大家遇到的各種問題。廢話不多說,文檔哪里找,請(qǐng)看下面的步驟 一.K3Cloud接口地址以及財(cái)務(wù)環(huán)境的登錄信息我們?cè)谧?netCore對(duì)接財(cái)務(wù)系統(tǒng)時(shí),要用到的幾個(gè)參數(shù)有:賬套號(hào),用戶名,密碼,財(cái)務(wù)環(huán)境地址(支持外網(wǎng)訪問) 這個(gè)信息你可以找你對(duì)接的客戶要,最好是能要到外網(wǎng)登錄的地址,因?yàn)檫@樣省去你遠(yuǎn)程登錄的麻煩,其次,賬號(hào)的權(quán)限也很重要,該賬號(hào)下必須能看到名為-- WebAPI的菜單,因?yàn)槲覀冃枰慕涌谛畔ê罄m(xù)的測(cè)試等都可以在這里處理。如下圖所示
二.對(duì)接要用到的接口列表既然將憑證API,那么我們需要用到的幾個(gè)菜單在財(cái)務(wù)會(huì)計(jì)--總賬下:主要有科目查詢接口、憑證字查詢接口、憑證新增接口 每個(gè)操作我們都可以通過在線測(cè)試WebAPI來驗(yàn)證我們的接口信息,查詢接口的請(qǐng)求參數(shù)說明詳見下圖
1.唯一碼的FormIdFormId為每個(gè)業(yè)務(wù)對(duì)象的表單Id,如科目對(duì)應(yīng)的就是BD_Account,這里建議我們?cè)陂_發(fā)時(shí),可以提前將這些用到的表單ID統(tǒng)一設(shè)置為常量。參考以下代碼片段,當(dāng)然實(shí)際開發(fā)中我們可能用不到這么多,大家根據(jù)自己的情況進(jìn)行合理的取舍。 public class BillKeyConst
{
#region 財(cái)務(wù)會(huì)計(jì) 總賬
? public const string 科目 = "BD_Account";
? public const string 帳薄 = "BD_AccountBook";
? public const string 會(huì)計(jì)日歷 = "BD_ACCOUNTCALENDAR";
? public const string 會(huì)計(jì)要素 = "BD_AccountGroup";
? public const string 幣別 = "BD_Currency";
? public const string 費(fèi)用項(xiàng)目 = "BD_Expense";
? public const string 匯率 = "BD_Rate";
? public const string 結(jié)算方式 = "BD_SETTLETYPE";
? public const string 憑證字 = "BD_VOUCHERGROUP";
? public const string 調(diào)整期間管理 = "GL_ADJUSTPERIOD";
? public const string 自動(dòng)轉(zhuǎn)賬 = "GL_AutoTransfer";
? public const string 現(xiàn)金流量項(xiàng)目 = "GL_CashFlow";
? public const string 附表項(xiàng)目指定 = "GL_CashIndirectItem";
? public const string 智能轉(zhuǎn)存 = "GL_DepositScheme";
? public const string 期末調(diào)匯 = "GL_ExchangeScheme";
? public const string 摘要庫(kù) = "GL_Explanation";
? public const string 附表項(xiàng)目調(diào)整 = "GL_INDIRECTITEMADJUST";
? public const string 帳薄隸屬關(guān)系 = "GL_MultiBookMergeScheme";
? public const string 結(jié)轉(zhuǎn)損益 = "GL_PLScheme";
? public const string T型賬 = "GL_TACCOUNT";
? public const string 憑證 = "GL_VOUCHER";
? public const string 憑證攤銷 = "GL_VoucherAmortize";
? public const string 模式憑證 = "GL_VoucherModel";
? public const string 憑證預(yù)提 = "GL_VoucherProvision";
? public const string 會(huì)計(jì)核算體系 = "Org_AccountSystem";
? #endregion
? #region 財(cái)務(wù)會(huì)計(jì) 智能會(huì)計(jì)平臺(tái)
? public const string 業(yè)務(wù)憑證 = "BAS_BusinessVoucher";
? public const string 憑證生成 = "Bas_MakeBizVchWizard";
? public const string 分錄類型 = "BAS_VchEntryType";
? public const string 憑證模板 = "BAS_VchTemplate";
? public const string 增值稅發(fā)票單據(jù) = "GL_AddedTaxBill";
? public const string 增值稅發(fā)票識(shí)別 = "GL_AddedTaxOcrResult";
? public const string 憑證自動(dòng)生成方案 = "GL_AutoBuildVoucherScheme";
? public const string 掃描識(shí)別模板管理 = "GL_BillOcrTemplate";
? public const string 對(duì)賬方案 = "GL_CHECKSCHEME";
? public const string 自定義單據(jù)識(shí)別 = "GL_OcrResultBase";
? public const string 掃描儀注冊(cè)登記 = "GL_ScannerSign";
? public const string 銀行回單_付款 = "GL_YHHDFK";
? public const string 銀行回單_收款 = "GL_YHHDSK";
? #endregion
? #region 供應(yīng)鏈 采購(gòu)單據(jù)
? public const string SCM_警示燈方案 = "SCM_WarnScheme";
? public const string BD_采購(gòu)條款 = "BD_PURCLAUSE";
? public const string BD_采購(gòu)折扣表 = "BD_PurDiscount";
? public const string PUR_評(píng)估等級(jí) = "PUR_Assessment";
? public const string PUR_采購(gòu)評(píng)估指標(biāo) = "PUR_AssessmentIndex";
? public const string PUR_采購(gòu)評(píng)估方案 = "PUR_AssessmentPlans";
? public const string PUR_貨源清單 = "PUR_CATALOG";
? public const string PUR_采購(gòu)合同 = "PUR_Contract";
? public const string PUR_采購(gòu)合同變更單 = "PUR_ContractChange";
? public const string PUR_期初采購(gòu)?fù)肆蠁?= "PUR_InitMRS";
? public const string PUR_退料申請(qǐng)單 = "PUR_MRAPP";
? public const string PUR_采購(gòu)?fù)肆蠁?= "PUR_MRB";
? public const string PUR_采購(gòu)調(diào)價(jià)表 = "PUR_PAT";
? public const string PUR_采購(gòu)定價(jià)變更單 = "PUR_POChange";
? public const string PUR_采購(gòu)定價(jià)新變更單 = "PUR_POXChange";
? public const string PUR_采購(gòu)價(jià)目表 = "PUR_PriceCategory";
? public const string PUR_物權(quán)轉(zhuǎn)移單 = "PUR_PropertyConvert";
? public const string PUR_采購(gòu)訂單 = "PUR_PurchaseOrder";
? public const string PUR_收料通知單 = "PUR_ReceiveBill";
? public const string PUR_采購(gòu)申請(qǐng)單 = "PUR_Requisition";
? public const string PUR_供應(yīng)商評(píng)分表 = "PUR_SupplierAsseementTb";
? public const string PUR_消耗匯總表 = "PUR_VMIConsumeSum";
? public const string STK_期初采購(gòu)入庫(kù)單 = "STK_InitInStock";
? public const string STK_采購(gòu)入庫(kù)單 = "STK_InStock";
? #endregion
? #region 供應(yīng)鏈 銷售管理
? public const string BD_云之家考勤設(shè)置 = "BD_AttendanceSetting";
? public const string BD_輕應(yīng)用自定義字段設(shè)置 = "BD_MobExtendFieldConfig";
? public const string BD_銷售折扣表 = "BD_SAL_DiscountList";
? public const string BD_銷售價(jià)目表 = "BD_SAL_PriceList";
? public const string BD_銷售條款 = "BD_SALCLAUSE";
? public const string SAL_銷售調(diào)價(jià)方案 = "SAL_ADJUSTPRICE";
? public const string SAL_可發(fā)量查詢 = "SAL_AvailableQuery";
? public const string SAL_批量調(diào)價(jià)單 = "SAL_BATCHADJUSTPRICE";
? public const string SAL_寄售結(jié)算單 = "SAL_ConsignmentSettle";
? public const string SAL_客戶物料對(duì)應(yīng)表 = "SAL_CustMatMapping";
? public const string SAL_發(fā)貨通知單 = "SAL_DELIVERYNOTICE";
? public const string SAL_期初銷售出庫(kù)單 = "SAL_INITOUTSTOCK";
? public const string SAL_電子面單 = "SAL_KuaidiBill";
? public const string SAL_銷售物流信息 = "SAL_LogisticsInfo";
? public const string SAL_銷售出庫(kù)單 = "SAL_OUTSTOCK";
? public const string SAL_銷售報(bào)價(jià)單 = "SAL_QUOTATION";
? public const string SAL_退貨通知單 = "SAL_RETURNNOTICE";
? public const string SAL_銷售退貨單 = "SAL_RETURNSTOCK";
? public const string SAL_銷售訂單 = "SAL_SaleOrder";
? public const string SAL_銷售訂單變更單 = "SAL_SaleOrderChange";
? public const string SAL_模擬報(bào)價(jià)單 = "Sal_SimulateQuotation";
? public const string SAL_標(biāo)準(zhǔn)費(fèi)率維護(hù) = "Sal_StdExchangeRate";
? public const string SAL_銷售訂單新變更單 = "SAL_XORDER";
? public const string SAL_銷售報(bào)價(jià)變更單 = "SAL_XQUOTATION";
? #endregion
? #region 供應(yīng)鏈 信用管理
? public const string CRE_信用檢查規(guī)則 = "CRE_CheckRule";
? public const string CRE_信用表更 = "CRE_CreditChange";
? public const string CRE_信用總額特批 = "CRE_CreditSumPermit";
? public const string CRE_信用檔案 = "CRE_CustArchives";
? public const string CRE_客戶物料信用檔案 = "CRE_CustMaterialArchive";
? public const string CRE_信用評(píng)估模型 = "CRE_EvalModel";
? public const string CRE_信用評(píng)估指標(biāo) = "CRE_EvaluateIndex";
? public const string CRE_信用等級(jí)方案 = "CRE_Gade";
? public const string CRE_信用評(píng)分表 = "CRE_ScoringTable";
? public const string CRE_信用特批權(quán)限 = "CRE_SpecPermission";
? public const string CRE_臨時(shí)信用檔案 = "CRE_TmpCustArchives";
? #endregion
? #region 供應(yīng)鏈 庫(kù)存管理
? public const string BD_歸檔序列號(hào) = "BD_ArchivedSerial";
? public const string BD_批號(hào)主檔 = "BD_BatchMainFile";
? public const string BD_批號(hào)_序列號(hào)屬性 = "BD_LotCodeItem";
? public const string BD_批號(hào)_序列號(hào)編碼規(guī)則 = "BD_LotCodeRule";
? public const string BD_生產(chǎn)追溯序列號(hào)主檔 = "BD_MTSerialMainFile";
? public const string BD_序列號(hào)主檔 = "BD_SerialMainFile";
? public const string BD_倉(cāng)庫(kù) = "BD_STOCK";
? public const string BD_倉(cāng)庫(kù)最大最小安全庫(kù)存 = "BD_StockAlert";
? public const string BD_庫(kù)存狀態(tài) = "BD_StockStatus";
? public const string SP_簡(jiǎn)單生成入庫(kù)單 = "SP_InStock";
? public const string SP_簡(jiǎn)單生成退庫(kù)單 = "SP_OUTSTOCK";
? public const string SP_簡(jiǎn)單生成領(lǐng)料單 = "SP_PickMtrl";
? public const string SP_簡(jiǎn)單生成退料單 = "SP_ReturnMtrl";
? public const string STK_組裝拆卸單 = "STK_AssembledApp";
? public const string STK_周期盤點(diǎn)計(jì)劃 = "STK_CycleCountPlan";
? public const string BD_物料周期盤點(diǎn)表 = "STK_CycleCountTable";
? public const string STK_即時(shí)庫(kù)存 = "STK_Inventory";
? public const string STK_初始庫(kù)存 = "STK_InvInit";
? public const string STK_庫(kù)存鎖庫(kù) = "STK_LockStock";
? public const string STK_鎖庫(kù)日志 = "STK_LOCKSTOCKLOG";
? public const string STK_批號(hào)調(diào)整單 = "STK_LOTADJUST";
? public const string STK_ABC分配組 = "STK_MaterialABCGroup";
? public const string STK_其他入庫(kù)單 = "STK_MISCELLANEOUS";
? public const string STK_其他出庫(kù)單 = "STK_MisDelivery";
? public const string STK_委托加工材料入庫(kù)單 = "STK_OEMInStock";
? public const string STK_委托加工材料退料單 = "STK_OEMInStockRETURN";
? public const string STK_委托加工材料收料單 = "STK_OEMReceive";
? public const string STK_出庫(kù)申請(qǐng)單 = "STK_OutStockApply";
? public const string STK_形態(tài)轉(zhuǎn)換單 = "STK_StatusConvert";
? public const string STK_庫(kù)存狀態(tài)轉(zhuǎn)換 = "STK_StockConvert";
? public const string STK_盤盈單 = "STK_StockCountGain";
? public const string STK_物料盤點(diǎn)作業(yè) = "STK_StockCountInput";
? public const string STK_盤虧單 = "STK_StockCountLoss";
? public const string STK_盤點(diǎn)方案 = "STK_StockCountScheme";
? public const string STK_調(diào)撥申請(qǐng)單 = "STK_TRANSFERAPPLY";
? public const string STK_直接調(diào)撥單 = "STK_TransferDirect";
? public const string STK_分布式調(diào)入單 = "STK_TRANSFERIN";
? public const string STK_分布式調(diào)出單 = "STK_TRANSFEROUT";
? #endregion
? #region 供應(yīng)鏈 組織間結(jié)算
? public const string IOS_應(yīng)付結(jié)算清單_物料 = "IOS_APSettlement";
? public const string IOS_應(yīng)付結(jié)算清單_費(fèi)用 = "IOS_APSettlementExp";
? public const string IOS_應(yīng)付結(jié)算清單_資產(chǎn) = "IOS_APSettlementFA";
? public const string IOS_應(yīng)收結(jié)算清單_物料 = "IOS_ARSettlement";
? public const string IOS_應(yīng)收結(jié)算清單_費(fèi)員 = "IOS_ARSettlementExp";
? public const string IOS_應(yīng)收結(jié)算清單_資產(chǎn) = "IOS_ARSettlementFA";
? public const string IOS_組織間結(jié)算價(jià)目表 = "IOS_PriceList";
? public const string IOS_定時(shí)結(jié)算 = "IOS_ScheduleSettle";
? public const string IOS_組織間結(jié)算關(guān)系 = "IOS_SettleRelation";
? public const string IOS_跨組織業(yè)務(wù)類型 = "IOS_TransferBizType";
? #endregion
? #region 供應(yīng)鏈 條碼管理
? public const string BD_異步生成數(shù)據(jù) = "BD_AsyncBillScanData";
? public const string BD_條碼盤點(diǎn)清單 = "BD_BarcodeInventoryData";
? public const string BD_條碼屬性 = "BD_BarCodeItem";
? public const string BD_條碼主檔 = "BD_BarCodeMainFile";
? public const string BD_條碼打印 = "BD_BarCodePrint";
? public const string BD_條碼規(guī)則 = "BD_BarCodeRule";
? public const string BD_條碼掃描 = "BD_BarCodeScan";
? public const string BD_條碼拆分 = "UN_BarCodeSplit";
? public const string BD_物料編碼解析對(duì)應(yīng)表 = "UN_MaterialMap";
? public const string BD_條碼拆箱表 = "UN_Packaging";
? public const string BD_掃描配置 = "UN_SCAN";
? public const string BD_掃描記錄 = "UN_SCANRecordSet";
? public const string BD_條碼掃描任務(wù) = "UN_SCANTASK";
? public const string BD_條碼掃描任務(wù)生成日志 = "UN_SCANTASKCREATELOG";
? public const string BD_條碼掃描任務(wù)方案 = "UN_SCANTASKSCHEME";
? #endregion
? #region 供應(yīng)鏈 供應(yīng)商管理
? public const string SVM_企業(yè)公告 = "SVM_BusinessBulletin";
? public const string SVM_比價(jià)單 = "SVM_ComparePrice";
? public const string SVM_詢價(jià)單 = "SVM_InquiryBill";
? public const string SVM_報(bào)價(jià)單 = "SVM_QuoteBill";
? public const string SVM_供應(yīng)商角色 = "SVM_Role";
? public const string SVM_供應(yīng)商用戶 = "SVM_SUPPLIERUSER";
? #endregion
? #region 供應(yīng)鏈 供應(yīng)商協(xié)同
? public const string SCP_供應(yīng)商協(xié)同條碼打印 = "SCP_BarCodePrint";
? public const string SCP_供應(yīng)商協(xié)同條碼掃描 = "SCP_BarCodeScan";
? public const string SCP_企業(yè)公告 = "SCP_BusinessBulletin";
? public const string SCP_詢價(jià)單 = "SCP_InquiryBill";
? public const string SCP_采購(gòu)入庫(kù)單 = "SCP_InStock";
? public const string SCP_退料通知單 = "SCP_MRAPP";
? public const string SCP_采購(gòu)?fù)肆蠁?= "SCP_MRB";
? public const string SCP_應(yīng)付單 = "SCP_Payable";
? public const string SCP_采購(gòu)訂單變更單 = "SCP_POChange";
? public const string SCP_采購(gòu)訂單 = "SCP_PurchaseOrder";
? public const string SCP_報(bào)價(jià)單 = "SCP_QuoteBill";
? public const string SCP_送貨通知單 = "SCP_ReceiveBill";
? public const string SCP_供應(yīng)商協(xié)同即時(shí)庫(kù)存查詢 = "SCP_STKInventory";
? public const string SCP_供應(yīng)商評(píng)估報(bào)告 = "SCP_SupplierAssResport";
? public const string SCP_供應(yīng)商注冊(cè)資料 = "SCP_SupReg";
? public const string SCP_供應(yīng)商協(xié)同VMI消耗匯總表 = "SCP_VMIConsumeSum";
? #endregion
? #region 基礎(chǔ)管理--基礎(chǔ)資料
? public const string 關(guān)鍵字_智能機(jī)器人 = "BAS_ROBOTKEYWORDS";
? public const string 消息任務(wù)_智能機(jī)器人 = "BAS_ROBOTMSGTASK";
? public const string 關(guān)鍵字服務(wù)_智能機(jī)器人 = "BAS_ROBOTSERVICE";
? public const string 會(huì)計(jì)政策 = "BD_ACCTPOLICY";
? public const string 輔助屬性值組合 = "BD_AuxPtyValCom";
? public const string 輔助屬性值 = "BD_AuxPtyValue";
? public const string 銀行 = "BD_BANK";
? public const string 聯(lián)系對(duì)象 = "BD_ContactObject";
? public const string 客戶 = "BD_Customer";
? public const string 客戶_包含非交易客戶 = "BD_Customer_All";
? public const string 部門 = "BD_Department";
? public const string 員工 = "BD_Empinfo";
? public const string 快遞100物流公司 = "BD_KD100LogisticsCom";
? public const string 物料 = "BD_MATERIAL";
? public const string 存貨類別 = "BD_MATERIALCATEGORY";
? public const string 存貨模板 = "BD_MATERIALTEMPLATE";
? public const string 物料單位換算 = "BD_MATERIALUNITCONVERT";
? public const string 員工任崗信息 = "BD_NEWSTAFF";
? public const string 業(yè)務(wù)員 = "BD_OPERATOR";
? public const string 業(yè)務(wù)組 = "BD_OPERATORGROUPBILL";
? public const string 付款條件 = "BD_PaymentCondition";
? public const string 崗位匯報(bào) = "BD_PostReport";
? public const string 收款條件 = "BD_RecCondition";
? public const string 供應(yīng)商 = "BD_Supplier";
? public const string 稅組合 = "BD_TAXMIX";
? public const string 稅率 = "BD_TaxRate";
? public const string 稅務(wù)規(guī)則 = "BD_TAXRULE";
? public const string 稅收制度 = "BD_TAXSYSTEM";
? public const string 稅種 = "BD_TAXTYPE";
? public const string 計(jì)量單位 = "BD_UNIT";
? public const string 銀行賬號(hào) = "CN_BANKACNT";
? public const string 現(xiàn)金賬號(hào) = "CN_CASHACCOUNT";
? public const string 內(nèi)部賬戶 = "CN_INNERACCOUNT";
? public const string 其他往來單位 = "FIN_OTHERS";
? public const string 崗位信息 = "HR_ORG_HRPOST";
? #endregion
? #region 基礎(chǔ)管理--組織管理
? public const string 組織隸屬關(guān)系 = "ORG_Affiliation";
? public const string 分配執(zhí)行情況 = "ORG_AutoAllocateLogInfo";
? public const string 基礎(chǔ)資料自動(dòng)分配計(jì)劃 = "ORG_AUTOALLOCATEPLAN";
? public const string 基礎(chǔ)資料控制策略 = "ORG_BaseDataControlPolicy";
? public const string 組織業(yè)務(wù)關(guān)系 = "ORG_BizRelation";
? public const string 組織變更檢查規(guī)則 = "ORG_ChangeChkRule";
? public const string 組織變更方案 = "ORG_ChangeSolution";
? public const string 組織機(jī)構(gòu) = "ORG_Organizations";
? public const string 組織形態(tài) = "ORG_OrgBodyForm";
? public const string 組織用戶維護(hù) = "Org_OrgUserRoleMap";
? #endregion
? }
2.查詢字段集合FieldKeys為要查詢的字段Key集合,如我需要查詢的字段有FName,FNumber等,詳細(xì)的字段說明可以通過保存接口查看 那么我們只需要傳入FName,FNumber即可。 3.返回結(jié)果的處理返回的結(jié)果是個(gè)數(shù)組類型,所以我們無(wú)法直接通過.net序列化為對(duì)象,所以建議是直接序列化為JArry數(shù)組,然后進(jìn)行取值。 三. .NetCore對(duì)接處理3.1登錄以及業(yè)務(wù)接口處理有了以上的對(duì)接參數(shù)和簡(jiǎn)單的接口信息了解之后,我們就可以開始我們的API接口對(duì)接工作了, 首先,在社區(qū)一位大佬封裝的WebAPI的基礎(chǔ)上,我們來處理.netCore環(huán)境下的WebAPI接口,非常感謝大佬,我們可以看到封裝的接口文件如下圖所示:
常用的有Query、BatchSave類,如下圖所示 Query操作 /// <summary>
/// 執(zhí)行查詢操作。
/// </summary>
public class Query : FormOperation
{
#region 公共覆蓋操作參數(shù)
/// <summary>
/// 操作的服務(wù)名稱定義。
/// </summary>
public override string ServiceName
{
get
{
return "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery";
}
}//end property
/// <summary>
/// 操作的請(qǐng)求參數(shù)。
/// </summary>
public override string RequestParameters
{
get
{
var parametersArray = new object[]
{
new
{
FormId = this.ObjectTypeId,
TopRowCount = this.TopRowCount,
Limit = this.PageRowCount == default(int) ? 2000 : this.PageRowCount,
StartRow = this.PageIndex,
FilterString = this.Filter,
OrderString = this.OrderBy,
FieldKeys = string.Join(",", this.FieldKeys)
}
};
return JsonConvert.SerializeObject(parametersArray);
}
}//end property
#endregion
#region 公共操作參數(shù)屬性
/// <summary>
/// 讀寫最多允許查詢的數(shù)量屬性值。
/// </summary>
/// <remarks>
/// 0或者不要此屬性表示不限制。
/// </remarks>
public virtual int TopRowCount { get; set; }//end property
/// <summary>
/// 讀寫分頁(yè)取數(shù)每頁(yè)允許獲取的數(shù)據(jù)屬性值。
/// </summary>
/// <remarks>
/// 最大不能超過2000。
/// </remarks>
public virtual int PageRowCount { get; set; }//end property
/// <summary>
/// 讀寫分頁(yè)取數(shù)開始行索引屬性值。
/// </summary>
/// <remarks>
/// 從0開始,例如每頁(yè)10行數(shù)據(jù),第2頁(yè)開始是10,第3頁(yè)開始是20,以此類推,當(dāng)不提供此屬性,表示僅查詢Limit中填寫的數(shù)據(jù)量。
/// </remarks>
public virtual int PageIndex { get; set; }//end property
/// <summary>
/// 讀寫過濾條件屬性值。
/// </summary>
public virtual string Filter { get; set; }//end property
/// <summary>
/// 讀寫排序條件屬性值。
/// </summary>
public virtual string OrderBy { get; set; }//end property
/// <summary>
/// 讀寫表單返回?cái)?shù)據(jù)字段的索引鍵屬性值。
/// </summary>
public virtual List<string> FieldKeys { get; set; }//end property
#endregion
#region 公共方法
/// <summary>
/// 設(shè)置讀寫動(dòng)態(tài)表單類型標(biāo)識(shí)。
/// </summary>
/// <param name="objectTypeId">動(dòng)態(tài)表單類型標(biāo)識(shí)。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual Query SetObjectTypeId(string objectTypeId)
{
return this.SetObjectTypeId<Query>(objectTypeId);
}//end method
/// <summary>
/// 設(shè)置最多允許查詢的單據(jù)數(shù)量。
/// </summary>
/// <param name="topRowCount">單據(jù)數(shù)量值。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual Query SetTopRowCount(int topRowCount)
{
this.TopRowCount = topRowCount;
return this;
}//end method
/// <summary>
/// 設(shè)置分頁(yè)取數(shù)每頁(yè)允許獲取的單據(jù)數(shù)量。
/// </summary>
/// <param name="pageRowCount">分頁(yè)數(shù)量值。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual Query SetPageRowCount(int pageRowCount)
{
this.PageRowCount = pageRowCount;
return this;
}//end method
/// <summary>
/// 設(shè)置分頁(yè)取數(shù)開始行索引。
/// </summary>
/// <param name="pageIndex">索引值。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual Query SetPageIndex(int pageIndex)
{
this.PageIndex = pageIndex;
return this;
}//end method
/// <summary>
/// 設(shè)置過濾條件。
/// </summary>
/// <param name="filter">過濾條件。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual Query SetFilter(string filter)
{
this.Filter = filter;
return this;
}//end method
/// <summary>
/// 設(shè)置排序條件。
/// </summary>
/// <param name="orderBy">排序條件。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual Query SetOrderBy(string orderBy)
{
this.OrderBy = orderBy;
return this;
}//end method
/// <summary>
/// 表單返回?cái)?shù)據(jù)字段。
/// </summary>
/// <param name="fieldKey">字段索引鍵。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual Query AddFieldKey(string fieldKey)
{
if (this.FieldKeys == null)
{
this.FieldKeys = new List<string>();
}//end if
this.FieldKeys.Add(fieldKey);
return this;
}//end method
#endregion
}//end class
BatchSave操作,主要用于憑證的批量保存 /// <summary>
/// 執(zhí)行批量保存操作。
/// </summary>
public class BatchSave : Save
{
#region 公共覆蓋操作參數(shù)
/// <summary>
/// 操作的服務(wù)名稱定義。
/// </summary>
public override string ServiceName
{
get
{
return "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave";
}
}//end property
/// <summary>
/// 待保存的數(shù)據(jù)對(duì)象。
/// </summary>
public override string RequestParameters
{
get
{
var parametersArray = new object[]{
this.ObjectTypeId,
new
{
Creator = string.IsNullOrEmpty(this.Creator) ? "IT" : this.Creator ,
NeedUpDateFields = this.NeedUpdateFieldKeys,
NeedReturnFieldKeys=this.NeedReturnFieldKeys,
Model = this.Models,
IsEntryBatchFill=this.IsEntryBatchFill,
IsDeleteEntry = this.IsDeleteEntry,
SubSystemId = this.SubSystemId,
IsAutoSubmitAndAudit=this.IsAutoSubmitAndAudit,
IsVerifyBaseDataField = this.IsVerifyBaseDataField,
NumberSearch = (this.BDSetter == BaseDataSetter.Number),
BatchCount=this.BatchCount
}
};
return JsonConvert.SerializeObject(parametersArray);
}
}//end property
#endregion
#region 公共操作參數(shù)屬性
/// <summary>
/// 讀寫待保存的數(shù)據(jù)對(duì)象。
/// </summary>
public override object Model
{
get
{
return this.Models == null ? null : this.Models.FirstOrDefault();
}
set
{
if (this.Models == null)
{
this.Models = new List<object>();
}//end if
this.Models.Add(value);
}
}//end property
/// <summary>
/// 讀寫待保存的多個(gè)數(shù)據(jù)對(duì)象。
/// </summary>
public virtual List<object> Models { get; set; }//end property
/// <summary>
/// 是否批量填充分錄。
/// </summary>
public virtual bool IsEntryBatchFill { get; set; }//end property
public virtual bool IsAutoSubmitAndAudit { get; set; }
public virtual int BatchCount { get; set; }
#endregion
#region 公共方法
/// <summary>
/// 添加待保存的數(shù)據(jù)對(duì)象。
/// </summary>
/// <param name="model">待保存的數(shù)據(jù)對(duì)象。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
public virtual BatchSave AddModel(object model)
{
if (this.Models == null)
{
this.Models = new List<object>();
}//end if
this.Models.Add(model);
return this;
}//end method
/// <summary>
/// 設(shè)置待保存的數(shù)據(jù)對(duì)象,但無(wú)論執(zhí)行多少次只會(huì)保留最后一次設(shè)置的數(shù)據(jù)對(duì)象。
/// </summary>
/// <param name="model">待保存的數(shù)據(jù)對(duì)象。</param>
/// <returns>返回類本身實(shí)例對(duì)象。</returns>
new public virtual BatchSave SetModel(object model)
{
return this.SetModel<BatchSave>(model);
}//end method
#endregion
}//end class
然后我們來看APIException類,可以看到該異常處理類統(tǒng)一繼承自Kingdee.BOS.WebAPi.Client.ServiceException.
所以我們要引用 Kingdee.BOS.WebApi.Client.dll 另外這里官網(wǎng)給的代碼示例中有句話很值得重視:// 使用webapi引用組件Kingdee.BOS.WebApi.Client.dll 這個(gè)組件我們可以在金蝶的安裝目錄下找到,當(dāng)你興致勃勃的找到這個(gè)dll,并將它引用到你的.netCore的項(xiàng)目中時(shí),編譯運(yùn)行你會(huì)發(fā)現(xiàn)有個(gè)ServiceException類在.netCore環(huán)境下不支持,因?yàn)樗鼉H在.net Framework支持。 所以呢,我們的第一反應(yīng)是這可咋辦,別著急,我們總有辦法解決,反編譯應(yīng)該是我們?cè)陂_發(fā)過程中比較常見的解決問題的辦法,所以當(dāng)我們將上述的dll進(jìn)行反編譯以后,我們可以得到如下一堆文件
接著我們就可以來處理我們的接口了,按照示例代碼中的一樣,我們來實(shí)現(xiàn)登錄接口 /// <summary>
/// 實(shí)現(xiàn)登錄。
/// </summary>
/// <returns>返回API結(jié)果。</returns>
public virtual APIResponse<LoginResult> Login()
{
var result = APIClient.CreateAPIOperation<LoginByUserPassword>(_Config.URL)
.SetDBId(_Config.DBId)
.SetUserName(_Config.UserName)
.SetPassword(_Config.Password)
.ToKdAPIRequest()
.ToAPIResponse<LoginResult>();
return result;
}
_config.Url---對(duì)應(yīng)我們的金蝶財(cái)務(wù)環(huán)境的登錄地址 _config.DBid--對(duì)應(yīng)我們要操作的賬套號(hào)---怎么查看到這個(gè)賬套號(hào)是多少呢?還記得我們上面說的那個(gè)WebAPI菜單嘛,沒錯(cuò)就是那里。我們隨便點(diǎn)開一個(gè)菜單,比如我這里以科目為例,我們選中科目后,點(diǎn)擊在線測(cè)試WebAPI按鈕,就能找到我們所需的各自參數(shù)了。
_config.UserName --登錄的用戶名
這四個(gè)參數(shù)就對(duì)應(yīng)我們登錄接口的四個(gè)參數(shù)。 要注意的一點(diǎn)是我們?cè)谡{(diào)用我們的業(yè)務(wù)接口時(shí),必須先調(diào)用登錄接口以實(shí)現(xiàn)登錄操作。不然無(wú)法操作我們的業(yè)務(wù)接口。 /// <summary>
/// 查詢?nèi)嗣駧艓艅e編碼
/// </summary>
/// <returns></returns>
public string QueryCurrency()
{
this.Login();
var result = APIClient.CreateAPIOperation<Query>(_Config.URL)
.SetObjectTypeId(BillKeyConst.幣別)
.AddFieldKey("FNumber")
.AddFieldKey("FName")
.SetFilter("FName like '%人民幣%'")
.ToAPIRequest<KdAPIRequest>().Execute<JArray>();
if (result.Count > 0)
{
return result[0][0].ToString();
}
else
{
return "";
}
}
如我們上圖所示的查詢?nèi)嗣駧诺拿Q和編碼。當(dāng)然這只是查詢單個(gè)實(shí)體,當(dāng)我們查詢所有的數(shù)據(jù)時(shí),就可能會(huì)用到分頁(yè)查詢,因?yàn)榻鸬牟樵兘涌谀J(rèn)一次查詢2000條數(shù)據(jù),所以當(dāng)總數(shù)量超過2000時(shí),我們就需要用到分頁(yè)查詢了。 public string QueryBasicInfoByPageList(string typeId, string FieldName, string Filter, int pageIndex)
{
this.Login();
var result = APIClient.CreateAPIOperation<Query>(_Config.URL)
.SetObjectTypeId(typeId)
.AddFieldKey(FieldName)
.SetFilter(Filter)
.SetPageIndex(pageIndex)
.ToAPIRequest<KdAPIRequest>().Execute<string>();
return result;
}
只需要在原有的基礎(chǔ)上,增加pageIndex-頁(yè)碼參數(shù)即可,不過要注意的是每次查詢的起始頁(yè)碼是不一樣的,這樣才能通過循環(huán)來得到我們需要的列表數(shù)據(jù)。 3.2 憑證保存接口 /// <summary>
/// 批量保存單據(jù)實(shí)體
/// </summary>
/// <param name="typeId"></param>
/// <param name="models"></param>
/// <returns></returns>
public string BatchSave(string typeId, List<object> models)
{
this.Login();
var client = APIClient.CreateAPIOperation<BatchSave>(_Config.URL);
client.SetObjectTypeId(typeId);
client.Models = models;
return client.ToAPIRequest<KdAPIRequest>().Execute<string>();
}
憑證批量保存接口,所以當(dāng)我們?cè)谕獠繕?gòu)造好憑證實(shí)體后,就可直接通過該接口來處理憑證的保存工作。憑證保存實(shí)體如下CloudSaveVoucherModel public class CloudSaveVoucherModel
{
public string FVoucherID { get; set; }
public FVoucherNumber FAccountBookID { get; set; }
public string FDate { get; set; }
public FVoucherNumber FVoucherGroupID { get; set; }
public string FVoucherGroupNo { get; set; }
public string FIsAdjustVoucher { get; set; }
public string FDocumentStatus { get; set; }
public string FYear { get; set; }
public FVoucherNumber FSourceBillKey { get; set; }
public string FPeriod { get; set; }
public string FImportVersion { get; set; }
public Fentity[] FEntity { get; set; }
}
public class FVoucherNumber
{
public string FNumber { get; set; }
}
public class Fentity
{
public string FEntryID { get; set; }
public string FExplanation { get; set; }
public FVoucherNumber FAccountID { get; set; }
public Fdetailid FDetailID { get; set; }
public FVoucherNumber FCurrencyID { get; set; }
public FVoucherNumber FExchangerateType { get; set; }
public string FExchangeRate { get; set; }
public FVoucherNumber FUnitId { get; set; }
public string FPrice { get; set; }
public string FQty { get; set; }
public decimal FAmountFor { get; set; }
public decimal FDebit { get; set; }
public decimal FCredit { get; set; }
public FVoucherNumber FSettleTypeID { get; set; }
public string FSettleNo { get; set; }
public string FExportentryID { get; set; }
}
public class Fdetailid
{
/// <summary>
/// 費(fèi)用項(xiàng)目
/// </summary>
public FVoucherNumber FDetailID__Fflex9 { get; set; }
/// <summary>
/// 供應(yīng)商
/// </summary>
public FVoucherNumber FDetailID__Fflex4 { get; set; }
public FVoucherNumber FDetailID__Fflex5 { get; set; }
/// <summary>
/// 客戶
/// </summary>
public FVoucherNumber FDetailID__Fflex6 { get; set; }
/// <summary>
/// 員工
/// </summary>
public FVoucherNumber FDetailID__Fflex7 { get; set; }
/// <summary>
/// 物料
/// </summary>
public FVoucherNumber FDetailID__Fflex8 { get; set; }
/// <summary>
/// 資產(chǎn)類別
/// </summary>
public FVoucherNumber FDetailID__Fflex10 { get; set; }
/// <summary>
/// 組織機(jī)構(gòu)
/// </summary>
public FVoucherNumber FDetailID__Fflex11 { get; set; }
/// <summary>
/// 物料分組
/// </summary>
public FVoucherNumber FDETAILID__FF100005 { get; set; }
public FVoucherNumber FDetailID__Fflex12 { get; set; }
public FVoucherNumber FDetailID__Fflex13 { get; set; }
}
通過前面的BatchSave類,我們可以看到有個(gè)屬性叫做NeedReturnFieldKeys -- 意為需要返回的字段,等于是在執(zhí)行成功保存操作后,金蝶可以直接將我們需要返回的字段返回回來,傳遞形式還是和查詢的FieldsKey格式一樣,但是在實(shí)際的開發(fā)過程中我發(fā)現(xiàn)其實(shí)即便你傳了NeedReturnFieldKeys,但是在返回值中并沒有正常返回。我曾經(jīng)在論壇里找個(gè)該問題,發(fā)現(xiàn)有小伙伴也遇到同樣的問題。但是都沒有得到解決,因?yàn)槲以趯?shí)際的邏輯中還需要得到類似總金額,憑證日期,憑證號(hào)等字段,所以沒辦法只能通過查詢接口再執(zhí)行一次查詢操作了,當(dāng)然不涉及后續(xù)的業(yè)務(wù)處理的話,可以不用執(zhí)行該步驟的。 ps:當(dāng)你執(zhí)行批量保存操作時(shí),如果一次操作的JSon數(shù)據(jù)量過大時(shí),接口提示操作超時(shí),所以在實(shí)際開發(fā)中建議可以分批次進(jìn)行保存操作。 四.結(jié)語(yǔ)相對(duì)來說,K3Cloud的接口文檔還是比較全面的,所以當(dāng)時(shí)在實(shí)際開發(fā)的時(shí)候,并沒有遇到很多坑,只是在API封裝的過程中,如上述說到的.netCore環(huán)境不支持的情況,這樣的話通過反編譯來處理問題也是一個(gè)不錯(cuò)的辦法。后續(xù)我們還會(huì)在處理用友的一個(gè)產(chǎn)品時(shí)同樣使用反編譯來處理問題。 以上就是自己在實(shí)際生產(chǎn)過程中處理K3CloudAPI接口時(shí)的一些想法和思路。比如金蝶社區(qū),論壇是不錯(cuò)的選擇。同樣QQ群也是一個(gè)溝通交流的途徑。比如上面說到的批量保存時(shí)JSon串過大導(dǎo)致接口操作超時(shí)的問題,就是通過群里一個(gè)小伙伴的提醒,改變了思路通過分批傳遞的方法來解決問題的。我想說的是在開發(fā)過程中我們會(huì)遇到各種各樣的問題,但是通過解決這些問題我們就能得到鍛煉和成長(zhǎng),這就是我們的財(cái)富。說實(shí)話在之前我從沒接觸過這些知識(shí)點(diǎn)和業(yè)務(wù)范圍,但是這不是也是一種成長(zhǎng)的方式嘛。希望可以給在開發(fā)對(duì)接此產(chǎn)品的小伙伴一點(diǎn)幫助,一點(diǎn)支持就夠了。 附上本文中的示例代碼:K3Cloud接口 或者微信搜索【程序員貝塔】回復(fù) "金蝶"即可獲取文章中的源代碼 |
|