From 93e6a8bf1c1d3586528978f614b17c9aa1f9734e Mon Sep 17 00:00:00 2001 From: hao <1836460075@qq.com> Date: 星期五, 13 六月 2025 16:04:41 +0800 Subject: [PATCH] Merge branch 'master' of http://43.142.96.171:8080/r/~yhj/HM_JK --- StandardInterface/MES.Service/service/Kingdee/ErpKcManager.cs | 145 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 145 insertions(+), 0 deletions(-) diff --git a/StandardInterface/MES.Service/service/Kingdee/ErpKcManager.cs b/StandardInterface/MES.Service/service/Kingdee/ErpKcManager.cs new file mode 100644 index 0000000..4d87a6f --- /dev/null +++ b/StandardInterface/MES.Service/service/Kingdee/ErpKcManager.cs @@ -0,0 +1,145 @@ +锘� +using Kingdee.CDP.WebApi.SDK; +using MES.Service.DB; +using MES.Service.Dto.webApi; +using MES.Service.Modes; +using SqlSugar; +using System.Text; + +namespace MES.Service.service.Kingdee; + +public class ErpKcManager : Repository<ErpMesKc> +{ + public bool QueryStocks(Inventory inventory) + { + List<ErpKc> erpKc = GetErpInventory(inventory); + + // 妫�鏌ヨ繑鍥炵粨鏋滄槸鍚︿负绌� + if (erpKc == null || erpKc.Count == 0) + { + throw new NotImplementedException("杩斿洖缁撴灉涓虹┖"); + } + else + { + var baseObjects = MapErpCABtoWomcab(erpKc); + + return UseTransaction(db => + { + return SaveData(db, baseObjects) ? 1 : 0; + }) > 0; + } + } + + #region 1.鑾峰彇鍗虫椂搴撳瓨 + public List<ErpKc> GetErpInventory(Inventory inventory) + { + //娉ㄦ剰 1锛氭澶勪笉鍐嶄娇鐢ㄥ弬鏁板舰寮忎紶鍏ョ敤鎴峰悕鍙婂瘑鐮佺瓑鏁忔劅淇℃伅锛屾敼涓哄湪鐧诲綍閰嶇疆鏂囦欢涓缃�� + //娉ㄦ剰 2锛氬繀椤诲厛閰嶇疆绗笁鏂圭郴缁熺櫥褰曟巿鏉冧俊鎭悗锛屽啀杩涜涓氬姟鎿嶄綔锛岃鎯呭弬鑰冨悇璇█鐗堟湰SDK浠嬬粛涓殑鐧诲綍閰嶇疆鏂囦欢璇存槑銆� + //璇诲彇閰嶇疆锛屽垵濮嬪寲SDK + K3CloudApi client = new K3CloudApi(); + //鐢ㄤ簬璁板綍缁撴灉 + StringBuilder Info = new StringBuilder(); + //涓氬姟瀵硅薄鏍囪瘑 + string formId = "STK_Inventory"; + DateTime dt = DateTime.Now; + //鏌ヨ瀛楁闆嗗悎锛屽嵆杩斿洖鍝簺鏁版嵁锛屼笉鑳戒负绌猴紝鏍规嵁涓嶅悓涓氬姟鍗曟嵁濉啓涓嶅悓鐨勫瓧娈靛悕锛屼互涓嬩粎涓虹ず渚� + //string fieldKeys = "FCode,FFileId,FRelevantObject"; + //string FilterString = "FID='-2146304'"; + string fieldKeys = "FMaterialId.FNumber,FMtoNo,FStockId.FNumber,FLot.FNumber,FStockUnitId.FNumber,FBaseUnitId.FNumber,FStockStatusId.FName,FBASEQTY,FMaterialid.FSTOREURNOM,FMaterialid.FSTOREURNUM,FStockOrgId.FNumber"; + string FilterString = string.Format(@"FMaterialId.FNumber like '%{0}%' and FStockId.FNumber like '%{1}%' and FBaseQty>0 and FStockOrgId.FNumber like'%{2}%'", inventory.ItemNo,inventory.DepotCode, inventory.StockOrgNumber); + string OrderString = ""; + int TopRowCount = 0; + int StartRow = 0; + int Limit = 0; + + var param = new QueryParam() + { + FormId = formId, + FieldKeys = fieldKeys, + FilterString = FilterString, + OrderString = OrderString, + TopRowCount = TopRowCount, + StartRow = StartRow, + Limit = Limit + }; + //璋冪敤鎺ュ彛 + var result = client.ExecuteBillQuery(param.ToJson()); + + return result.Select(s => + { + var entity = new ErpKc + { + FMaterialId = s[0]?.ToString(), + FMtoNo = s[1]?.ToString(), + FStockId = s[2]?.ToString(), + FLot = s[3]?.ToString(), + FStockUnitId = s[4]?.ToString(), + FBaseUnitId = s[5]?.ToString(), + FStockStatusId = s[6]?.ToString(), + FBASEQTY = s[7]?.ToString() , + FSTOREURNOM = s[8]?.ToString(), + FSTOREURNUM = s[9]?.ToString(), + // FOwnerId = s[10]?.ToString() + FStockOrgId = s[10]?.ToString() + }; + return entity; + }).ToList(); + } + #endregion + + + private List<ErpMesKc> MapErpCABtoWomcab(List<ErpKc> dtoList) + { + var ErpMesKcList = new List<ErpMesKc>(); + + foreach (var dto in dtoList) + { + var kc = new ErpMesKc + { + FNumber = dto.FMaterialId, + // FQty = Convert.ToDecimal(dto.FBASEQTY), + FQty = SafeParseDecimal(dto.FBASEQTY), + FBaseUnit=dto.FBaseUnitId, + FStockUnit=dto.FStockUnitId, + FStockNumber=dto.FStockId, + CreateDate=DateTime.Now, + FBatchno=dto.FLot, + FMtono=dto.FMtoNo, + FStockStatus=dto.FStockStatusId, + FStoreUrnom= Convert.ToDecimal(dto.FSTOREURNOM), + FStoreUrnum= Convert.ToDecimal(dto.FSTOREURNUM), + //FOwnerId=dto.FOwnerId, + FStockOrgId = dto.FStockOrgId, + + }; + + ErpMesKcList.Add(kc); + } + + return ErpMesKcList; + } + + + private decimal SafeParseDecimal(string? input) + { + if (string.IsNullOrWhiteSpace(input)) return 0; + + if (decimal.TryParse( + input, + System.Globalization.NumberStyles.Float, + System.Globalization.CultureInfo.InvariantCulture, + out var result)) + return result; + + return 0; // 璺宠繃閿欒瀛楁锛岀粰榛樿鍊� + } + + // 鎻掑叆鎴栨洿鏂版暟鎹殑鏂规硶 + private bool SaveData(SqlSugarScope db, List<ErpMesKc> kcc) + { + var save = base.InsertRange(kcc); + if (save) return true; + throw new NotImplementedException("鎻掑叆澶辫触"); + } + +} -- Gitblit v1.9.3