哈嘍拐叉,又和大家見面了岩遗,雖然看文章的小伙伴不多,但是我相信總有一天凤瘦,自己寫的這些文章或多或少會對其他人有些幫助宿礁,讓他們在相關(guān)的業(yè)務(wù)開發(fā)下能少走些彎路,那我的目的就達(dá)到了蔬芥,好了梆靖,今天就正式開始我們的系列了控汉,今天要講的是金蝶系列的API,大家都知道返吻,金蝶的產(chǎn)品是比較多的姑子,那么我們這次要講解的就是金蝶云星空,或者叫K3Cloud思喊。
首先壁酬,作為一名程序猿我們在拿到類似的接口對接需求,第一件是肯定是看相關(guān)文檔恨课,然后做接口分析舆乔,最后是封裝接口,運用到我們的項目中去剂公,所以對于我們來說希俩,第一步就是尋找相關(guān)的開發(fā)文檔,在這方面不得不承認(rèn)纲辽,金蝶社區(qū)是個好地方颜武。里面有關(guān)于產(chǎn)品的所有知識點和大家遇到的各種問題。廢話不多說拖吼,文檔哪里找鳞上,請看下面的步驟
一.K3Cloud接口地址以及財務(wù)環(huán)境的登錄信息
我們在做.netCore對接財務(wù)系統(tǒng)時,要用到的幾個參數(shù)有:賬套號吊档,用戶名篙议,密碼,財務(wù)環(huán)境地址(支持外網(wǎng)訪問)
這個信息你可以找你對接的客戶要怠硼,最好是能要到外網(wǎng)登錄的地址鬼贱,因為這樣省去你遠(yuǎn)程登錄的麻煩,其次香璃,賬號的權(quán)限也很重要巩梢,該賬號下必須能看到名為-- WebAPI的菜單螟蝙,因為我們需要的接口信息包括后續(xù)的測試等都可以在這里處理顺囊。如下圖所示
二.對接要用到的接口列表
既然將憑證API晰搀,那么我們需要用到的幾個菜單在財務(wù)會計--總賬下:主要有科目查詢接口、憑證字查詢接口同云、憑證新增接口
每個操作我們都可以通過在線測試WebAPI來驗證我們的接口信息糖权,查詢接口的請求參數(shù)說明詳見下圖
要注意的地方有幾點:
1.唯一碼的FormId
FormId為每個業(yè)務(wù)對象的表單Id,如科目對應(yīng)的就是BD_Account,這里建議我們在開發(fā)時炸站,可以提前將這些用到的表單ID統(tǒng)一設(shè)置為常量星澳。參考以下代碼片段,當(dāng)然實際開發(fā)中我們可能用不到這么多旱易,大家根據(jù)自己的情況進(jìn)行合理的取舍禁偎。
publicclassBillKeyConst
?? {
#region財務(wù)會計總賬
?
?publicconststring科目="BD_Account";
?
?publicconststring帳薄="BD_AccountBook";
?
?publicconststring會計日歷="BD_ACCOUNTCALENDAR";
?
?publicconststring會計要素="BD_AccountGroup";
?
?publicconststring幣別="BD_Currency";
?
?publicconststring費用項目="BD_Expense";
?
?publicconststring匯率="BD_Rate";
?
?publicconststring結(jié)算方式="BD_SETTLETYPE";
?
?publicconststring憑證字="BD_VOUCHERGROUP";
?
?publicconststring調(diào)整期間管理="GL_ADJUSTPERIOD";
?
?publicconststring自動轉(zhuǎn)賬="GL_AutoTransfer";
?
?publicconststring現(xiàn)金流量項目="GL_CashFlow";
?
?publicconststring附表項目指定="GL_CashIndirectItem";
?
?publicconststring智能轉(zhuǎn)存="GL_DepositScheme";
?
?publicconststring期末調(diào)匯="GL_ExchangeScheme";
?
?publicconststring摘要庫="GL_Explanation";
?
?publicconststring附表項目調(diào)整="GL_INDIRECTITEMADJUST";
?
?publicconststring帳薄隸屬關(guān)系="GL_MultiBookMergeScheme";
?
?publicconststring結(jié)轉(zhuǎn)損益="GL_PLScheme";
?
?publicconststringT型賬="GL_TACCOUNT";
?
?publicconststring憑證="GL_VOUCHER";
?
?publicconststring憑證攤銷="GL_VoucherAmortize";
?
?publicconststring模式憑證="GL_VoucherModel";
?
?publicconststring憑證預(yù)提="GL_VoucherProvision";
?
?publicconststring會計核算體系="Org_AccountSystem";
?
?#endregion
?
?#region財務(wù)會計智能會計平臺
?
?publicconststring業(yè)務(wù)憑證="BAS_BusinessVoucher";
?
?publicconststring憑證生成="Bas_MakeBizVchWizard";
?
?publicconststring分錄類型="BAS_VchEntryType";
?
?publicconststring憑證模板="BAS_VchTemplate";
?
?publicconststring增值稅發(fā)票單據(jù)="GL_AddedTaxBill";
?
?publicconststring增值稅發(fā)票識別="GL_AddedTaxOcrResult";
?
?publicconststring憑證自動生成方案="GL_AutoBuildVoucherScheme";
?
?publicconststring掃描識別模板管理="GL_BillOcrTemplate";
?
?publicconststring對賬方案="GL_CHECKSCHEME";
?
?publicconststring自定義單據(jù)識別="GL_OcrResultBase";
?
?publicconststring掃描儀注冊登記="GL_ScannerSign";
?
?publicconststring銀行回單_付款="GL_YHHDFK";
?
?publicconststring銀行回單_收款="GL_YHHDSK";
?
?#endregion
?
?#region供應(yīng)鏈采購單據(jù)
?
?publicconststringSCM_警示燈方案="SCM_WarnScheme";
?
?publicconststringBD_采購條款="BD_PURCLAUSE";
?
?publicconststringBD_采購折扣表="BD_PurDiscount";
?
?publicconststringPUR_評估等級="PUR_Assessment";
?
?publicconststringPUR_采購評估指標(biāo)="PUR_AssessmentIndex";
?
?publicconststringPUR_采購評估方案="PUR_AssessmentPlans";
?
?publicconststringPUR_貨源清單="PUR_CATALOG";
?
?publicconststringPUR_采購合同="PUR_Contract";
?
?publicconststringPUR_采購合同變更單="PUR_ContractChange";
?
?publicconststringPUR_期初采購?fù)肆蠁?"PUR_InitMRS";
?
?publicconststringPUR_退料申請單="PUR_MRAPP";
?
?publicconststringPUR_采購?fù)肆蠁?"PUR_MRB";
?
?publicconststringPUR_采購調(diào)價表="PUR_PAT";
?
?publicconststringPUR_采購定價變更單="PUR_POChange";
?
?publicconststringPUR_采購定價新變更單="PUR_POXChange";
?
?publicconststringPUR_采購價目表="PUR_PriceCategory";
?
?publicconststringPUR_物權(quán)轉(zhuǎn)移單="PUR_PropertyConvert";
?
?publicconststringPUR_采購訂單="PUR_PurchaseOrder";
?
?publicconststringPUR_收料通知單="PUR_ReceiveBill";
?
?publicconststringPUR_采購申請單="PUR_Requisition";
?
?publicconststringPUR_供應(yīng)商評分表="PUR_SupplierAsseementTb";
?
?publicconststringPUR_消耗匯總表="PUR_VMIConsumeSum";
?
?publicconststringSTK_期初采購入庫單="STK_InitInStock";
?
?publicconststringSTK_采購入庫單="STK_InStock";
?
?#endregion
?
?#region供應(yīng)鏈銷售管理
?
?publicconststringBD_云之家考勤設(shè)置="BD_AttendanceSetting";
?
?publicconststringBD_輕應(yīng)用自定義字段設(shè)置="BD_MobExtendFieldConfig";
?
?publicconststringBD_銷售折扣表="BD_SAL_DiscountList";
?
?publicconststringBD_銷售價目表="BD_SAL_PriceList";
?
?publicconststringBD_銷售條款="BD_SALCLAUSE";
?
?publicconststringSAL_銷售調(diào)價方案="SAL_ADJUSTPRICE";
?
?publicconststringSAL_可發(fā)量查詢="SAL_AvailableQuery";
?
?publicconststringSAL_批量調(diào)價單="SAL_BATCHADJUSTPRICE";
?
?publicconststringSAL_寄售結(jié)算單="SAL_ConsignmentSettle";
?
?publicconststringSAL_客戶物料對應(yīng)表="SAL_CustMatMapping";
?
?publicconststringSAL_發(fā)貨通知單="SAL_DELIVERYNOTICE";
?
?publicconststringSAL_期初銷售出庫單="SAL_INITOUTSTOCK";
?
?publicconststringSAL_電子面單="SAL_KuaidiBill";
?
?publicconststringSAL_銷售物流信息="SAL_LogisticsInfo";
?
?publicconststringSAL_銷售出庫單="SAL_OUTSTOCK";
?
?publicconststringSAL_銷售報價單="SAL_QUOTATION";
?
?publicconststringSAL_退貨通知單="SAL_RETURNNOTICE";
?
?publicconststringSAL_銷售退貨單="SAL_RETURNSTOCK";
?
?publicconststringSAL_銷售訂單="SAL_SaleOrder";
?
?publicconststringSAL_銷售訂單變更單="SAL_SaleOrderChange";
?
?publicconststringSAL_模擬報價單="Sal_SimulateQuotation";
?
?publicconststringSAL_標(biāo)準(zhǔn)費率維護(hù)="Sal_StdExchangeRate";
?
?publicconststringSAL_銷售訂單新變更單="SAL_XORDER";
?
?publicconststringSAL_銷售報價變更單="SAL_XQUOTATION";
?
?#endregion
?
?#region供應(yīng)鏈信用管理
?
?publicconststringCRE_信用檢查規(guī)則="CRE_CheckRule";
?
?publicconststringCRE_信用表更="CRE_CreditChange";
?
?publicconststringCRE_信用總額特批="CRE_CreditSumPermit";
?
?publicconststringCRE_信用檔案="CRE_CustArchives";
?
?publicconststringCRE_客戶物料信用檔案="CRE_CustMaterialArchive";
?
?publicconststringCRE_信用評估模型="CRE_EvalModel";
?
?publicconststringCRE_信用評估指標(biāo)="CRE_EvaluateIndex";
?
?publicconststringCRE_信用等級方案="CRE_Gade";
?
?publicconststringCRE_信用評分表="CRE_ScoringTable";
?
?publicconststringCRE_信用特批權(quán)限="CRE_SpecPermission";
?
?publicconststringCRE_臨時信用檔案="CRE_TmpCustArchives";
?
?
?#endregion
?
?#region供應(yīng)鏈庫存管理
?
?publicconststringBD_歸檔序列號="BD_ArchivedSerial";
?
?publicconststringBD_批號主檔="BD_BatchMainFile";
?
?publicconststringBD_批號_序列號屬性="BD_LotCodeItem";
?
?publicconststringBD_批號_序列號編碼規(guī)則="BD_LotCodeRule";
?
?publicconststringBD_生產(chǎn)追溯序列號主檔="BD_MTSerialMainFile";
?
?publicconststringBD_序列號主檔="BD_SerialMainFile";
?
?publicconststringBD_倉庫="BD_STOCK";
?
?publicconststringBD_倉庫最大最小安全庫存="BD_StockAlert";
?
?publicconststringBD_庫存狀態(tài)="BD_StockStatus";
?
?publicconststringSP_簡單生成入庫單="SP_InStock";
?
?publicconststringSP_簡單生成退庫單="SP_OUTSTOCK";
?
?publicconststringSP_簡單生成領(lǐng)料單="SP_PickMtrl";
?
?publicconststringSP_簡單生成退料單="SP_ReturnMtrl";
?
?publicconststringSTK_組裝拆卸單="STK_AssembledApp";
?
?publicconststringSTK_周期盤點計劃="STK_CycleCountPlan";
?
?publicconststringBD_物料周期盤點表="STK_CycleCountTable";
?
?publicconststringSTK_即時庫存="STK_Inventory";
?
?publicconststringSTK_初始庫存="STK_InvInit";
?
?publicconststringSTK_庫存鎖庫="STK_LockStock";
?
?publicconststringSTK_鎖庫日志="STK_LOCKSTOCKLOG";
?
?publicconststringSTK_批號調(diào)整單="STK_LOTADJUST";
?
?publicconststringSTK_ABC分配組="STK_MaterialABCGroup";
?
?publicconststringSTK_其他入庫單="STK_MISCELLANEOUS";
?
?publicconststringSTK_其他出庫單="STK_MisDelivery";
?
?publicconststringSTK_委托加工材料入庫單="STK_OEMInStock";
?
?publicconststringSTK_委托加工材料退料單="STK_OEMInStockRETURN";
?
?publicconststringSTK_委托加工材料收料單="STK_OEMReceive";
?
?publicconststringSTK_出庫申請單="STK_OutStockApply";
?
?publicconststringSTK_形態(tài)轉(zhuǎn)換單="STK_StatusConvert";
?
?publicconststringSTK_庫存狀態(tài)轉(zhuǎn)換="STK_StockConvert";
?
?publicconststringSTK_盤盈單="STK_StockCountGain";
?
?publicconststringSTK_物料盤點作業(yè)="STK_StockCountInput";
?
?publicconststringSTK_盤虧單="STK_StockCountLoss";
?
?publicconststringSTK_盤點方案="STK_StockCountScheme";
?
?publicconststringSTK_調(diào)撥申請單="STK_TRANSFERAPPLY";
?
?publicconststringSTK_直接調(diào)撥單="STK_TransferDirect";
?
?publicconststringSTK_分布式調(diào)入單="STK_TRANSFERIN";
?
?publicconststringSTK_分布式調(diào)出單="STK_TRANSFEROUT";
?
?#endregion
?
?#region供應(yīng)鏈組織間結(jié)算
?
?publicconststringIOS_應(yīng)付結(jié)算清單_物料="IOS_APSettlement";
?
?publicconststringIOS_應(yīng)付結(jié)算清單_費用="IOS_APSettlementExp";
?
?publicconststringIOS_應(yīng)付結(jié)算清單_資產(chǎn)="IOS_APSettlementFA";
?
?publicconststringIOS_應(yīng)收結(jié)算清單_物料="IOS_ARSettlement";
?
?publicconststringIOS_應(yīng)收結(jié)算清單_費員="IOS_ARSettlementExp";
?
?publicconststringIOS_應(yīng)收結(jié)算清單_資產(chǎn)="IOS_ARSettlementFA";
?
?publicconststringIOS_組織間結(jié)算價目表="IOS_PriceList";
?
?publicconststringIOS_定時結(jié)算="IOS_ScheduleSettle";
?
?publicconststringIOS_組織間結(jié)算關(guān)系="IOS_SettleRelation";
?
?publicconststringIOS_跨組織業(yè)務(wù)類型="IOS_TransferBizType";
?
?#endregion
?
?#region供應(yīng)鏈條碼管理
?
?publicconststringBD_異步生成數(shù)據(jù)="BD_AsyncBillScanData";
?
?publicconststringBD_條碼盤點清單="BD_BarcodeInventoryData";
?
?publicconststringBD_條碼屬性="BD_BarCodeItem";
?
?publicconststringBD_條碼主檔="BD_BarCodeMainFile";
?
?publicconststringBD_條碼打印="BD_BarCodePrint";
?
?publicconststringBD_條碼規(guī)則="BD_BarCodeRule";
?
?publicconststringBD_條碼掃描="BD_BarCodeScan";
?
?publicconststringBD_條碼拆分="UN_BarCodeSplit";
?
?publicconststringBD_物料編碼解析對應(yīng)表="UN_MaterialMap";
?
?publicconststringBD_條碼拆箱表="UN_Packaging";
?
?publicconststringBD_掃描配置="UN_SCAN";
?
?publicconststringBD_掃描記錄="UN_SCANRecordSet";
?
?publicconststringBD_條碼掃描任務(wù)="UN_SCANTASK";
?
?publicconststringBD_條碼掃描任務(wù)生成日志="UN_SCANTASKCREATELOG";
?
?publicconststringBD_條碼掃描任務(wù)方案="UN_SCANTASKSCHEME";
?
?#endregion
?
?#region供應(yīng)鏈供應(yīng)商管理
?
?publicconststringSVM_企業(yè)公告="SVM_BusinessBulletin";
?
?publicconststringSVM_比價單="SVM_ComparePrice";
?
?publicconststringSVM_詢價單="SVM_InquiryBill";
?
?publicconststringSVM_報價單="SVM_QuoteBill";
?
?publicconststringSVM_供應(yīng)商角色="SVM_Role";
?
?publicconststringSVM_供應(yīng)商用戶="SVM_SUPPLIERUSER";
?
?#endregion
?
?#region供應(yīng)鏈供應(yīng)商協(xié)同
?
?publicconststringSCP_供應(yīng)商協(xié)同條碼打印="SCP_BarCodePrint";
?
?publicconststringSCP_供應(yīng)商協(xié)同條碼掃描="SCP_BarCodeScan";
?
?publicconststringSCP_企業(yè)公告="SCP_BusinessBulletin";
?
?publicconststringSCP_詢價單="SCP_InquiryBill";
?
?publicconststringSCP_采購入庫單="SCP_InStock";
?
?publicconststringSCP_退料通知單="SCP_MRAPP";
?
?publicconststringSCP_采購?fù)肆蠁?"SCP_MRB";
?
?publicconststringSCP_應(yīng)付單="SCP_Payable";
?
?publicconststringSCP_采購訂單變更單="SCP_POChange";
?
?publicconststringSCP_采購訂單="SCP_PurchaseOrder";
?
?publicconststringSCP_報價單="SCP_QuoteBill";
?
?publicconststringSCP_送貨通知單="SCP_ReceiveBill";
?
?publicconststringSCP_供應(yīng)商協(xié)同即時庫存查詢="SCP_STKInventory";
?
?publicconststringSCP_供應(yīng)商評估報告="SCP_SupplierAssResport";
?
?publicconststringSCP_供應(yīng)商注冊資料="SCP_SupReg";
?
?publicconststringSCP_供應(yīng)商協(xié)同VMI消耗匯總表="SCP_VMIConsumeSum";
?
?#endregion
?
?#region基礎(chǔ)管理--基礎(chǔ)資料
?
?publicconststring關(guān)鍵字_智能機器人="BAS_ROBOTKEYWORDS";
?
?publicconststring消息任務(wù)_智能機器人="BAS_ROBOTMSGTASK";
?
?publicconststring關(guān)鍵字服務(wù)_智能機器人="BAS_ROBOTSERVICE";
?
?publicconststring會計政策="BD_ACCTPOLICY";
?
?publicconststring輔助屬性值組合="BD_AuxPtyValCom";
?
?publicconststring輔助屬性值="BD_AuxPtyValue";
?
?publicconststring銀行="BD_BANK";
?
?publicconststring聯(lián)系對象="BD_ContactObject";
?
?publicconststring客戶="BD_Customer";
?
?publicconststring客戶_包含非交易客戶="BD_Customer_All";
?
?publicconststring部門="BD_Department";
?
?publicconststring員工="BD_Empinfo";
?
?publicconststring快遞100物流公司="BD_KD100LogisticsCom";
?
?publicconststring物料="BD_MATERIAL";
?
?publicconststring存貨類別="BD_MATERIALCATEGORY";
?
?publicconststring存貨模板="BD_MATERIALTEMPLATE";
?
?publicconststring物料單位換算="BD_MATERIALUNITCONVERT";
?
?publicconststring員工任崗信息="BD_NEWSTAFF";
?
?publicconststring業(yè)務(wù)員="BD_OPERATOR";
?
?publicconststring業(yè)務(wù)組="BD_OPERATORGROUPBILL";
?
?publicconststring付款條件="BD_PaymentCondition";
?
?publicconststring崗位匯報="BD_PostReport";
?
?publicconststring收款條件="BD_RecCondition";
?
?publicconststring供應(yīng)商="BD_Supplier";
?
?publicconststring稅組合="BD_TAXMIX";
?
?publicconststring稅率="BD_TaxRate";
?
?publicconststring稅務(wù)規(guī)則="BD_TAXRULE";
?
?publicconststring稅收制度="BD_TAXSYSTEM";
?
?publicconststring稅種="BD_TAXTYPE";
?
?publicconststring計量單位="BD_UNIT";
?
?publicconststring銀行賬號="CN_BANKACNT";
?
?publicconststring現(xiàn)金賬號="CN_CASHACCOUNT";
?
?publicconststring內(nèi)部賬戶="CN_INNERACCOUNT";
?
?publicconststring其他往來單位="FIN_OTHERS";
?
?publicconststring崗位信息="HR_ORG_HRPOST";
?
?#endregion
?
?#region基礎(chǔ)管理--組織管理
?
?publicconststring組織隸屬關(guān)系="ORG_Affiliation";
?
?publicconststring分配執(zhí)行情況="ORG_AutoAllocateLogInfo";
?
?publicconststring基礎(chǔ)資料自動分配計劃="ORG_AUTOALLOCATEPLAN";
?
?publicconststring基礎(chǔ)資料控制策略="ORG_BaseDataControlPolicy";
?
?publicconststring組織業(yè)務(wù)關(guān)系="ORG_BizRelation";
?
?publicconststring組織變更檢查規(guī)則="ORG_ChangeChkRule";
?
?publicconststring組織變更方案="ORG_ChangeSolution";
?
?publicconststring組織機構(gòu)="ORG_Organizations";
?
?publicconststring組織形態(tài)="ORG_OrgBodyForm";
?
?publicconststring組織用戶維護(hù)="Org_OrgUserRoleMap";
?
?#endregion
?}
2.查詢字段集合
FieldKeys為要查詢的字段Key集合腿堤,如我需要查詢的字段有FName,FNumber等,詳細(xì)的字段說明可以通過保存接口查看
那么我們只需要傳入FName,FNumber即可如暖。
3.返回結(jié)果的處理
返回的結(jié)果是個數(shù)組類型笆檀,所以我們無法直接通過.net序列化為對象,所以建議是直接序列化為JArry數(shù)組盒至,然后進(jìn)行取值酗洒。
三. .NetCore對接處理
3.1登錄以及業(yè)務(wù)接口處理
有了以上的對接參數(shù)和簡單的接口信息了解之后,我們就可以開始我們的API接口對接工作了枷遂,
首先樱衷,在社區(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>
? ? ?? /// 操作的請求參數(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>
? ? ?? /// 讀寫分頁取數(shù)每頁允許獲取的數(shù)據(jù)屬性值辉哥。
? ? ?? /// </summary>
? ? ?? /// <remarks>
? ? ?? /// 最大不能超過2000涣达。
? ? ?? /// </remarks>
? ? ?? public virtual int PageRowCount { get; set; }//end property
?
? ? ?? /// <summary>
? ? ?? /// 讀寫分頁取數(shù)開始行索引屬性值。
? ? ?? /// </summary>
? ? ?? /// <remarks>
? ? ?? /// 從0開始证薇,例如每頁10行數(shù)據(jù),第2頁開始是10匆篓,第3頁開始是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>
? ? ?? /// 讀寫表單返回數(shù)據(jù)字段的索引鍵屬性值先慷。
? ? ?? /// </summary>
? ? ?? public virtual List<string> FieldKeys { get; set; }//end property
?
? ? ?? #endregion
?
? ? ?? #region 公共方法
?
? ? ?? /// <summary>
? ? ?? /// 設(shè)置讀寫動態(tài)表單類型標(biāo)識。
? ? ?? /// </summary>
? ? ?? /// <param name="objectTypeId">動態(tài)表單類型標(biāo)識咨察。</param>
? ? ?? /// <returns>返回類本身實例對象论熙。</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>返回類本身實例對象脓诡。</returns>
? ? ?? public virtual Query SetTopRowCount(int topRowCount)
? ? ?? {
? ? ? ? ?? this.TopRowCount = topRowCount;
? ? ? ? ?? return this;
? ? ?? }//end method
?
? ? ?? /// <summary>
? ? ?? /// 設(shè)置分頁取數(shù)每頁允許獲取的單據(jù)數(shù)量无午。
? ? ?? /// </summary>
? ? ?? /// <param name="pageRowCount">分頁數(shù)量值。</param>
? ? ?? /// <returns>返回類本身實例對象祝谚。</returns>
? ? ?? public virtual Query SetPageRowCount(int pageRowCount)
? ? ?? {
? ? ? ? ?? this.PageRowCount = pageRowCount;
? ? ? ? ?? return this;
? ? ?? }//end method
?
? ? ?? /// <summary>
? ? ?? /// 設(shè)置分頁取數(shù)開始行索引宪迟。
? ? ?? /// </summary>
? ? ?? /// <param name="pageIndex">索引值。</param>
? ? ?? /// <returns>返回類本身實例對象交惯。</returns>
? ? ?? public virtual Query SetPageIndex(int pageIndex)
? ? ?? {
? ? ? ? ?? this.PageIndex = pageIndex;
? ? ? ? ?? return this;
? ? ?? }//end method
?
? ? ?? /// <summary>
? ? ?? /// 設(shè)置過濾條件次泽。
? ? ?? /// </summary>
? ? ?? /// <param name="filter">過濾條件。</param>
? ? ?? /// <returns>返回類本身實例對象席爽。</returns>
? ? ?? public virtual Query SetFilter(string filter)
? ? ?? {
? ? ? ? ?? this.Filter = filter;
? ? ? ? ?? return this;
? ? ?? }//end method
?
? ? ?? /// <summary>
? ? ?? /// 設(shè)置排序條件意荤。
? ? ?? /// </summary>
? ? ?? /// <param name="orderBy">排序條件。</param>
? ? ?? /// <returns>返回類本身實例對象拳昌。</returns>
? ? ?? public virtual Query SetOrderBy(string orderBy)
? ? ?? {
? ? ? ? ?? this.OrderBy = orderBy;
? ? ? ? ?? return this;
? ? ?? }//end method
?
? ? ?? /// <summary>
? ? ?? /// 表單返回數(shù)據(jù)字段袭异。
? ? ?? /// </summary>
? ? ?? /// <param name="fieldKey">字段索引鍵。</param>
? ? ?? /// <returns>返回類本身實例對象炬藤。</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ù)對象上真。
? ? ?? /// </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ù)對象。
? ? ?? /// </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>
? ? ?? /// 讀寫待保存的多個數(shù)據(jù)對象羹膳。
? ? ?? /// </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ù)對象。
? ? ?? /// </summary>
? ? ?? /// <param name="model">待保存的數(shù)據(jù)對象陵像。</param>
? ? ?? /// <returns>返回類本身實例對象就珠。</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ù)對象,但無論執(zhí)行多少次只會保留最后一次設(shè)置的數(shù)據(jù)對象醒颖。
? ? ?? /// </summary>
? ? ?? /// <param name="model">待保存的數(shù)據(jù)對象妻怎。</param>
? ? ?? /// <returns>返回類本身實例對象。</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
這個組件我們可以在金蝶的安裝目錄下找到逼侦,當(dāng)你興致勃勃的找到這個dll,并將它引用到你的.netCore的項目中時腰耙,編譯運行你會發(fā)現(xiàn)有個ServiceException類在.netCore環(huán)境下不支持榛丢,因為它僅在.net Framework支持。
所以呢挺庞,我們的第一反應(yīng)是這可咋辦晰赞,別著急,我們總有辦法解決,反編譯應(yīng)該是我們在開發(fā)過程中比較常見的解決問題的辦法宾肺,所以當(dāng)我們將上述的dll進(jìn)行反編譯以后溯饵,我們可以得到如下一堆文件
接著我們就可以來處理我們的接口了,按照示例代碼中的一樣锨用,我們來實現(xiàn)登錄接口
/// <summary>
/// 實現(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---對應(yīng)我們的金蝶財務(wù)環(huán)境的登錄地址
_config.DBid--對應(yīng)我們要操作的賬套號---怎么查看到這個賬套號是多少呢增拥?還記得我們上面說的那個WebAPI菜單嘛啄巧,沒錯就是那里。我們隨便點開一個菜單掌栅,比如我這里以科目為例秩仆,我們選中科目后,點擊在線測試WebAPI按鈕猾封,就能找到我們所需的各自參數(shù)了澄耍。
_config.UserName --登錄的用戶名
_config.Password -- 登錄的用戶名的密碼
這四個參數(shù)就對應(yīng)我們登錄接口的四個參數(shù)。
要注意的一點是我們在調(diào)用我們的業(yè)務(wù)接口時晌缘,必須先調(diào)用登錄接口以實現(xiàn)登錄操作齐莲。不然無法操作我們的業(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)然這只是查詢單個實體选酗,當(dāng)我們查詢所有的數(shù)據(jù)時,就可能會用到分頁查詢岳枷,因為金蝶的查詢接口默認(rèn)一次查詢2000條數(shù)據(jù)芒填,所以當(dāng)總數(shù)量超過2000時,我們就需要用到分頁查詢了空繁。
? ? ? 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-頁碼參數(shù)即可,不過要注意的是每次查詢的起始頁碼是不一樣的盛泡,這樣才能通過循環(huán)來得到我們需要的列表數(shù)據(jù)播玖。
3.2 憑證保存接口
? /// <summary>
? ? ?? /// 批量保存單據(jù)實體
? ? ?? /// </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)我們在外部構(gòu)造好憑證實體后饭于,就可直接通過該接口來處理憑證的保存工作。憑證保存實體如下CloudSaveVoucherModel
publicclass CloudSaveVoucherModel
? ? {
? ? ? ? publicstringFVoucherID {get;set; }
? ? ? ? publicFVoucherNumber FAccountBookID {get;set; }
? ? ? ? publicstringFDate {get;set; }
? ? ? ? publicFVoucherNumber FVoucherGroupID {get;set; }
? ? ? ? publicstringFVoucherGroupNo {get;set; }
? ? ? ? publicstringFIsAdjustVoucher {get;set; }
? ? ? ? publicstringFDocumentStatus {get;set; }
? ? ? ? publicstringFYear {get;set; }
? ? ? ? publicFVoucherNumber FSourceBillKey {get;set; }
? ? ? ? publicstringFPeriod {get;set; }
? ? ? ? publicstringFImportVersion {get;set; }
? ? ? ? publicFentity[] FEntity {get;set; }
? ? }
? ? publicclass FVoucherNumber
? ? {
? ? ? ? publicstringFNumber {get;set; }
? ? }
? ? publicclass Fentity
? ? {
? ? ? ? publicstringFEntryID {get;set; }
? ? ? ? publicstringFExplanation {get;set; }
? ? ? ? publicFVoucherNumber FAccountID {get;set; }
? ? ? ? publicFdetailid FDetailID {get;set; }
? ? ? ? publicFVoucherNumber FCurrencyID {get;set; }
? ? ? ? publicFVoucherNumber FExchangerateType {get;set; }
? ? ? ? publicstringFExchangeRate {get;set; }
? ? ? ? publicFVoucherNumber FUnitId {get;set; }
? ? ? ? publicstringFPrice {get;set; }
? ? ? ? publicstringFQty {get;set; }
? ? ? ? publicdecimalFAmountFor {get;set; }
? ? ? ? publicdecimalFDebit {get;set; }
? ? ? ? publicdecimalFCredit {get;set; }
? ? ? ? publicFVoucherNumber FSettleTypeID {get;set; }
? ? ? ? publicstringFSettleNo {get;set; }
? ? ? ? publicstringFExportentryID {get;set; }
? ? }
? ? publicclass Fdetailid
? ? {
? ? ? ? ///<summary>/// 費用項目
? ? ? ? ///</summary>publicFVoucherNumber FDetailID__Fflex9 {get;set; }
? ? ? ? ///<summary>/// 供應(yīng)商
? ? ? ? ///</summary>publicFVoucherNumber FDetailID__Fflex4 {get;set; }
? ? ? ? publicFVoucherNumber FDetailID__Fflex5 {get;set; }
? ? ? ? ///<summary>/// 客戶
? ? ? ? ///</summary>publicFVoucherNumber FDetailID__Fflex6 {get;set; }
? ? ? ? ///<summary>/// 員工
? ? ? ? ///</summary>publicFVoucherNumber FDetailID__Fflex7 {get;set; }
? ? ? ? ///<summary>/// 物料
? ? ? ? ///</summary>publicFVoucherNumber FDetailID__Fflex8 {get;set; }
? ? ? ? ///<summary>/// 資產(chǎn)類別
? ? ? ? ///</summary>publicFVoucherNumber FDetailID__Fflex10 {get;set; }
? ? ? ? ///<summary>/// 組織機構(gòu)
? ? ? ? ///</summary>publicFVoucherNumber FDetailID__Fflex11 {get;set; }
? ? ? ? ///<summary>/// 物料分組
? ? ? ? ///</summary>publicFVoucherNumber FDETAILID__FF100005 {get;set; }
? ? ? ? publicFVoucherNumber FDetailID__Fflex12 {get;set; }
? ? ? ? publicFVoucherNumber FDetailID__Fflex13 {get;set; }
? ? }
通過前面的BatchSave類维蒙,我們可以看到有個屬性叫做NeedReturnFieldKeys -- 意為需要返回的字段掰吕,等于是在執(zhí)行成功保存操作后,金蝶可以直接將我們需要返回的字段返回回來颅痊,傳遞形式還是和查詢的FieldsKey格式一樣殖熟,但是在實際的開發(fā)過程中我發(fā)現(xiàn)其實即便你傳了NeedReturnFieldKeys,但是在返回值中并沒有正常返回斑响。我曾經(jīng)在論壇里找個該問題菱属,發(fā)現(xiàn)有小伙伴也遇到同樣的問題钳榨。但是都沒有得到解決,因為我在實際的邏輯中還需要得到類似總金額纽门,憑證日期薛耻,憑證號等字段,所以沒辦法只能通過查詢接口再執(zhí)行一次查詢操作了赏陵,當(dāng)然不涉及后續(xù)的業(yè)務(wù)處理的話饼齿,可以不用執(zhí)行該步驟的。
ps:當(dāng)你執(zhí)行批量保存操作時蝙搔,如果一次操作的JSon數(shù)據(jù)量過大時缕溉,接口提示操作超時,所以在實際開發(fā)中建議可以分批次進(jìn)行保存操作吃型。
四.結(jié)語
相對來說证鸥,K3Cloud的接口文檔還是比較全面的,所以當(dāng)時在實際開發(fā)的時候勤晚,并沒有遇到很多坑枉层,只是在API封裝的過程中,如上述說到的.netCore環(huán)境不支持的情況运翼,這樣的話通過反編譯來處理問題也是一個不錯的辦法返干。后續(xù)我們還會在處理用友的一個產(chǎn)品時同樣使用反編譯來處理問題。
以上就是自己在實際生產(chǎn)過程中處理K3CloudAPI接口時的一些想法和思路血淌。比如金蝶社區(qū)矩欠,論壇是不錯的選擇。同樣QQ群也是一個溝通交流的途徑悠夯。比如上面說到的批量保存時JSon串過大導(dǎo)致接口操作超時的問題癌淮,就是通過群里一個小伙伴的提醒,改變了思路通過分批傳遞的方法來解決問題的沦补。我想說的是在開發(fā)過程中我們會遇到各種各樣的問題乳蓄,但是通過解決這些問題我們就能得到鍛煉和成長,這就是我們的財富夕膀。說實話在之前我從沒接觸過這些知識點和業(yè)務(wù)范圍虚倒,但是這不是也是一種成長的方式嘛。希望可以給在開發(fā)對接此產(chǎn)品的小伙伴一點幫助产舞,一點支持就夠了魂奥。