| | |
| | | 锘縰sing NetTaste; |
| | | 锘縰sing Microsoft.Extensions.Logging; |
| | | using NetTaste; |
| | | using Newtonsoft.Json; |
| | | using Org.BouncyCastle.Ocsp; |
| | | using SqlSugar.Extensions; |
| | |
| | | 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> |
| | |
| | | /// <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 ""; |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | /// <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); |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogInformation("ErpApiService GetSuppliersAsync澶辫触: " + ex.Message); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | /// <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); |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | 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) |
| | |
| | | } |
| | | } |
| | | |
| | | } |
| | | 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) |
| | | { |