pan
2025-11-05 b2c6ce78c7c95c37f9c3e9ea11e86a7af7b0d3fd
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_BasicService/ErpApiService.cs
@@ -1,4 +1,5 @@
锘縰sing NetTaste;
锘縰sing Microsoft.Extensions.Logging;
using NetTaste;
using Newtonsoft.Json;
using Org.BouncyCastle.Ocsp;
using SqlSugar.Extensions;
@@ -21,13 +22,15 @@
        private readonly ISupplierInfoService _supplierInfoService;
        private readonly IMaterialUnitService _materialUnitService;
        private readonly IMaterielInfoService _materielInfoService;
        private readonly ILogger<ErpApiService> _logger;
        public ErpApiService(IHttpClientFactory httpClientFactory, ISupplierInfoService supplierInfoService, IMaterialUnitService materialUnitService, IMaterielInfoService materielInfoService)
        public ErpApiService(IHttpClientFactory httpClientFactory, ISupplierInfoService supplierInfoService, IMaterialUnitService materialUnitService, IMaterielInfoService materielInfoService, ILogger<ErpApiService> logger)
        {
            _httpClientFactory = httpClientFactory;
            _supplierInfoService = supplierInfoService;
            _materialUnitService = materialUnitService;
            _materielInfoService = materielInfoService;
            _logger = logger;
        }
        /// <summary>
@@ -36,10 +39,19 @@
        /// <returns></returns>
        public async Task<string> GetTokenAsync()
        {
            try
            {
            var request = new TokenRequest { appId = "BG_SYSTEM", secretKey = "7e9239c1e132462a9cf03bfa342a044aMTcxODE5MzgxODI4Mw" };
            var response = await PostAsync<TokenRequest, TokenResponse>("auth/getAccessToken", request, includeToken: false);
            var _token = response?.data?.access_token;
            return _token ?? "";
            }
            catch (Exception ex)
            {
                _logger.LogInformation("ErpApiService GetTokenAsync澶辫触:  " + ex.Message);
                return "";
            }
        }
@@ -49,6 +61,8 @@
        /// <param name="vendorCode"></param>
        /// <returns></returns>
        public async Task GetSuppliersAsync(string vendorCode = null)
        {
            try
        {
            var req = new SupplierRequest { vendorCode = vendorCode };
            var result = await PostAsync<SupplierRequest, SupplierResponse>("erp/getVendorInfo", req, includeToken: true);
@@ -94,6 +108,12 @@
                    }
                }
            }
            }
            catch (Exception ex)
            {
                _logger.LogInformation("ErpApiService GetSuppliersAsync澶辫触:  " + ex.Message);
            }
        }
@@ -103,6 +123,8 @@
        /// <param name="vendorCode"></param>
        /// <returns></returns>
        public async Task GetMaterialUnitAsync(string itemNo = null)
        {
            try
        {
            var req = new MaterialUnitRequest { itemNo = itemNo };
            var result = await PostAsync<MaterialUnitRequest, MaterialUnitResponse>("erp/getMaterialUnit", req, true);
@@ -152,9 +174,17 @@
                    }
                }
            }
            }
            catch (Exception ex)
            {
                _logger.LogInformation("ErpApiService GetMaterialUnitAsync 澶辫触:  " + ex.Message);
            }
        }
        public async Task GetMaterialInfoAsync(MaterialRequest materialRequest)
        {
            try
        {
            var first = WIDESEA_Core.Helper.AppSettings.GetValue("FirstMaterialSync").ObjToBool();
            if (first)
@@ -257,8 +287,13 @@
                }
            }
            }
            catch (Exception ex)
            {
                _logger.LogInformation("ErpApiService GetMaterialInfoAsync 澶辫触:  " + ex.Message);
        }
        }
        private async Task<TResponse> PostAsync<TRequest, TResponse>(string url, TRequest request, string _token, bool isNullSerialize = false)
        {