erp客户同步

This commit is contained in:
18942506660
2023-11-09 10:06:36 +08:00
parent b51f09542c
commit 0bd21a0329
9 changed files with 184 additions and 13 deletions

View File

@@ -12,6 +12,7 @@ using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto.Erp;
using WMS.Web.Core.Dto.Erp.Customer;
using WMS.Web.Core.Dto.Erp.Org;
using WMS.Web.Core.Dto.Erp.OutStock;
using WMS.Web.Core.Dto.Erp.Purchase;
@@ -397,7 +398,74 @@ namespace WMS.Web.Domain.Services.Public
return ResultList<ErpSupplierDto>.ReFailure(ResultCodes.ErpSupplierError);
}
}
/// <summary>
/// 客户
/// </summary>
/// <returns></returns>
public async Task<ResultList<ErpCustomerDto>> BillQueryForCustomer()
{
try
{
//1.获取缓存中的供应商数据;
var cache_key = "erp_customer_list";
var customers = _memoryCache.Get<List<ErpCustomerDto>>(cache_key);
if (customers == null || customers.Count == 0)
{
//2.先登录金蝶-拿到token
var token_result = await this.Init();
if (!token_result.IsSuccess)
return ResultList<ErpCustomerDto>.ReFailure(token_result);
//3.获取金蝶供应商:拼接参数和条件
var query = new ErpBillQueryDto(token_result.Data);
var param = new ErpBillQueryParamDto(FormIdParam.BD_Customer.ToString());
param.FieldKeys = "FCUSTID,FNumber,FName";
param.Limit = 10000;
//查询条件:备注其中的条件值以金蝶的值为准!!!
param.FilterString = "";
//备注因为供应商数据不是很多就不能和获取物料一样循环获取组织这里就获取10000条数据就行了
var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
_logger.LogInformation($"供应商拉取-开始时间:{beginTime}");
//4.参数json化
query.Data = JsonConvert.SerializeObject(param);
var json = JsonConvert.SerializeObject(query);
//5.请求查询接口并返回数据
var result_json = await _client.ExecuteBillQueryAsync(json);
var result = JsonConvert.DeserializeObject<List<List<string>>>(result_json);
var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
_logger.LogInformation($"供应商拉取-结束时间:{endTime}");
//6.拼装
var list = new List<ErpCustomerDto>();
foreach (var item in result)
{
var lis = new ErpCustomerDto();
lis.Id = int.Parse(item[0]);
lis.Number = item[1];
lis.Name = item[2];
list.Add(lis);
}
//5.供应商集合进行缓存
_memoryCache.Set(cache_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12)));
_logger.LogInformation($"供应商拉取-总条数:{list.Count}");
return ResultList<ErpCustomerDto>.ReSuccess(list);
}
else
{
return ResultList<ErpCustomerDto>.ReSuccess(customers);
}
}
catch (Exception)
{
return ResultList<ErpCustomerDto>.ReFailure(ResultCodes.ErpSupplierError);
}
}
/// <summary>
/// erp:仓库
/// </summary>
@@ -1006,6 +1074,8 @@ namespace WMS.Web.Domain.Services.Public
}
}
#endregion
}
}