erp客户同步
This commit is contained in:
Binary file not shown.
27
src/WMS.Web.Core/Dto/Erp/Customer/ErpCustomerDto.cs
Normal file
27
src/WMS.Web.Core/Dto/Erp/Customer/ErpCustomerDto.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.Erp.Customer
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户
|
||||
/// </summary>
|
||||
public class ErpCustomerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
public string Number { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
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.Supplier;
|
||||
|
||||
@@ -58,7 +59,14 @@ namespace WMS.Web.Domain.IService.Public
|
||||
/// <param name="supplierId"></param>
|
||||
/// <returns></returns>
|
||||
string GetSupplierName(List<ErpSupplierDto> erpSuppliers, int supplierId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取客户名称
|
||||
/// </summary>
|
||||
/// <param name="erpCustomers"></param>
|
||||
/// <param name="customerId"></param>
|
||||
/// <returns></returns>
|
||||
string GetCustomerName(List<ErpCustomerDto> erpCustomers, int customerId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取仓库名称
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
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;
|
||||
@@ -66,7 +67,11 @@ namespace WMS.Web.Domain.IService.Public
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<ResultList<ErpSupplierDto>> BillQueryForSupplier();
|
||||
|
||||
/// <summary>
|
||||
/// 客户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<ResultList<ErpCustomerDto>> BillQueryForCustomer();
|
||||
/// <summary>
|
||||
/// 获取仓库信息
|
||||
/// </summary>
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
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.Supplier;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
@@ -100,6 +101,17 @@ namespace WMS.Web.Domain.Services.Public
|
||||
var supplier = erpSuppliers.Where(x => x.Id == supplierId).FirstOrDefault();
|
||||
return supplier == null ? "" : supplier.Name;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取客户名称
|
||||
/// </summary>
|
||||
/// <param name="erpCustomers"></param>
|
||||
/// <param name="customerId"></param>
|
||||
/// <returns></returns>
|
||||
public string GetCustomerName(List<ErpCustomerDto> erpCustomers, int customerId)
|
||||
{
|
||||
var supplier = erpCustomers.Where(x => x.Id == customerId).FirstOrDefault();
|
||||
return supplier == null ? "" : supplier.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取仓库名称
|
||||
@@ -136,5 +148,7 @@ namespace WMS.Web.Domain.Services.Public
|
||||
var stock = erpStocks.Where(x => x.Id == stockId).FirstOrDefault();
|
||||
return stock == null ? "" : stock.Code;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,10 @@ namespace WMS.Web.Domain.Values.Erp
|
||||
/// <summary>
|
||||
/// 分布式调出单
|
||||
/// </summary>
|
||||
STK_TRANSFEROUT=15
|
||||
STK_TRANSFEROUT=15,
|
||||
/// <summary>
|
||||
/// 客户
|
||||
/// </summary>
|
||||
BD_Customer=16
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace WMS.Web.Repositories
|
||||
var staffList = await _basicsRepositories.GetStaffListAsync(_loginRepositories.CompanyId);
|
||||
ids = staffList.Where(w => EF.Functions.Like(w.Name, "%" + dto.Creator + "%")).Select(s => s.Id).ToList();
|
||||
}
|
||||
|
||||
#region erp基础资料
|
||||
List<int> mIds = new List<int>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
if (!materials_result.IsSuccess)
|
||||
@@ -100,6 +100,24 @@ namespace WMS.Web.Repositories
|
||||
mIds = materials.Where(w => EF.Functions.Like(w.MaterialNumber, "%" + dto.MaterialNumber + "%")).Select(s => s.MaterialId).ToList();
|
||||
}
|
||||
|
||||
//取组织
|
||||
var org_result = await _erpService.BillQueryForOrg();
|
||||
if (!org_result.IsSuccess)
|
||||
return (new List<OutStockQueryInfoResponse>(), 0);
|
||||
var orgs = org_result.Data.ToList();
|
||||
|
||||
List<int> cIds = new List<int>();
|
||||
var customer_result = await _erpService.BillQueryForCustomer();
|
||||
if (!customer_result.IsSuccess)
|
||||
return (new List<OutStockQueryInfoResponse>(), 0);
|
||||
var customers = customer_result.Data.ToList();
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.ReceiptCustomer))
|
||||
{
|
||||
cIds = customers.Where(w => EF.Functions.Like(w.Name, "%" + dto.ReceiptCustomer + "%")).Select(s => s.MaterialId).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
var query = _context.OutStockDetails
|
||||
.GroupJoin(_context.OutStock, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
|
||||
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
||||
@@ -139,8 +157,10 @@ namespace WMS.Web.Repositories
|
||||
Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.detail.StockId),
|
||||
SourceBillNo = s.order.SourceBillNo,
|
||||
SaleBillNo = s.detail.SaleBillNo,
|
||||
DeliveryOrg = "",
|
||||
ReceiptCustomer = "",
|
||||
DeliveryOrg = _erpBasicDataExtendService.GetOrgName(orgs, s.order.DeliveryOrgId),
|
||||
ReceiptCustomer = s.order.Type == OutStockType.Sal
|
||||
? _erpBasicDataExtendService.GetCustomerName(customers, s.order.ReceiptCustomerId)
|
||||
: _erpBasicDataExtendService.GetOrgName(orgs, s.order.DeliveryOrgId),
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.detail.MaterialId),
|
||||
MaterialNumber = _erpBasicDataExtendService.GetMaterialNumber(materials, s.detail.MaterialId),
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.detail.MaterialId),
|
||||
|
||||
@@ -214,6 +214,7 @@ namespace WMS.Web.Repositories
|
||||
/// <returns></returns>
|
||||
public async Task<(List<OutStockTaskQueryInfoResponse> list, int total)> GetListAsync(OutStockTaskQueryRequest dto)
|
||||
{
|
||||
#region erp基础资料
|
||||
List<int> mIds = new List<int>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
if (!materials_result.IsSuccess)
|
||||
@@ -224,14 +225,34 @@ namespace WMS.Web.Repositories
|
||||
{
|
||||
mIds = materials.Where(w => EF.Functions.Like(w.MaterialNumber, "%" + dto.MaterialNumber + "%")).Select(s => s.MaterialId).ToList();
|
||||
}
|
||||
|
||||
//取组织
|
||||
var org_result = await _erpService.BillQueryForOrg();
|
||||
if (!org_result.IsSuccess)
|
||||
return (new List<OutStockTaskQueryInfoResponse>(), 0);
|
||||
var orgs = org_result.Data.ToList();
|
||||
|
||||
List<int> cIds = new List<int>();
|
||||
var customer_result = await _erpService.BillQueryForCustomer();
|
||||
if (!customer_result.IsSuccess)
|
||||
return (new List<OutStockTaskQueryInfoResponse>(), 0);
|
||||
var customers = customer_result.Data.ToList();
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.ReceiptCustomer))
|
||||
{
|
||||
cIds = customers.Where(w => EF.Functions.Like(w.Name, "%" + dto.ReceiptCustomer + "%")).Select(s => s.MaterialId).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
var query = _context.OutStockTaskDetails
|
||||
.GroupJoin(_context.OutStockTask, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
|
||||
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
||||
.OrderByDescending(o => o.order.Id)
|
||||
.Where(adv => 1 == 1);
|
||||
|
||||
//if (!string.IsNullOrEmpty(dto.ReceiptCustomer))
|
||||
if (mIds.Count()!=0)
|
||||
if (cIds.Count() != 0)
|
||||
query = query.Where(w => cIds.Contains(w.order.ReceiptCustomerId));
|
||||
if (mIds.Count() != 0)
|
||||
query = query.Where(w => mIds.Contains(w.detail.MaterialId));
|
||||
if (dto.Ids.Count() > 0)
|
||||
query = query.Where(w => dto.Ids.Contains(w.detail.Id));
|
||||
@@ -255,18 +276,20 @@ namespace WMS.Web.Repositories
|
||||
{
|
||||
#region dto组装
|
||||
Id = s.order.Id,
|
||||
DetailId=s.detail.Id,
|
||||
BillNo =s.order.BillNo,
|
||||
DetailId = s.detail.Id,
|
||||
BillNo = s.order.BillNo,
|
||||
Status = s.order.Status.GetRemark(),
|
||||
Type = s.order.Type.GetRemark(),
|
||||
CreateTime = s.order.OperateTime.DateToStringSeconds(),
|
||||
OutStockBeginTime= s.detail.OutStockBeginTime.DateToStringSeconds(),
|
||||
OutStockBeginTime = s.detail.OutStockBeginTime.DateToStringSeconds(),
|
||||
OutStockEndTime = s.detail.OutStockEndTime.DateToStringSeconds(),
|
||||
Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.detail.StockId),
|
||||
SourceBillNo = s.order.SourceBillNo,
|
||||
SaleBillNo = s.detail.SaleBillNo,
|
||||
DeliveryOrg = "",
|
||||
ReceiptCustomer = "",
|
||||
DeliveryOrg = _erpBasicDataExtendService.GetOrgName(orgs, s.order.DeliveryOrgId),
|
||||
ReceiptCustomer = s.order.Type == OutStockType.Sal
|
||||
? _erpBasicDataExtendService.GetCustomerName(customers, s.order.ReceiptCustomerId)
|
||||
: _erpBasicDataExtendService.GetOrgName(orgs, s.order.DeliveryOrgId),
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.detail.MaterialId),
|
||||
MaterialNumber = _erpBasicDataExtendService.GetMaterialNumber(materials, s.detail.MaterialId),
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.detail.MaterialId),
|
||||
|
||||
Reference in New Issue
Block a user