同步入库单-方法优化
This commit is contained in:
@@ -143,67 +143,7 @@ namespace WMS.Web.Domain.Services
|
||||
return Result.ReFailure(erp_result.Message, erp_result.Status);
|
||||
var erp_list = erp_result.Data;
|
||||
|
||||
//2.通过单据编号找到wms系统现有的任务单;并修改
|
||||
var erp_removeList = new List<ErpPurchaseInStockResultDto>();
|
||||
var SourceBillNo_list = erp_list.GroupBy(x => x.FBillNo).Select(x => x.Key).ToList();
|
||||
var data_list = await _inStockTaskRepositories.GetListBy(SourceBillNo_list);
|
||||
if (data_list.Count != 0)
|
||||
{
|
||||
//2.1提取出wms任务单明细信息
|
||||
var data_list_details = data_list.SelectMany(x => x.Details).ToList();
|
||||
foreach (var item in data_list_details)
|
||||
{
|
||||
var data = data_list.Where(x => x.Id == item.Fid).FirstOrDefault();
|
||||
|
||||
//2.1.1对比erp的物料信息
|
||||
var erp_data = erp_list.Where(x => x.FBillNo == data.SourceBillNo && x.FMaterialId == item.MaterialId).FirstOrDefault();
|
||||
if (erp_data != null)
|
||||
{
|
||||
//2.1.2修改数量
|
||||
item.AccruedQty = erp_data.FQty;
|
||||
item.DeliveredQty = erp_data.FStockInQty;
|
||||
erp_removeList.Add(erp_data);
|
||||
}
|
||||
}
|
||||
|
||||
//2.2.提交修改
|
||||
var isSuccess = await _inStockTaskRepositories.UpdateRange(data_list, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
//2.3剔除:已修改的单据
|
||||
foreach (var item in erp_removeList)
|
||||
{
|
||||
erp_list.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
//3.wms任务单的来源单据编号不存在于erp中,那么就新增
|
||||
if (erp_list.Count != 0)
|
||||
{
|
||||
var add_entitys = new List<InStockTask>();
|
||||
//var current_billNos = erp_list.GroupBy(x => x.FBillNo).Select(x => x.Key).ToList();
|
||||
var current_billNos = erp_list.GroupBy(x => new { x.FBillNo, x.FCreateDate }).Select(x => new { x.Key.FBillNo, x.Key.FCreateDate }).ToList();
|
||||
foreach (var item in current_billNos)
|
||||
{
|
||||
var dto = new InStockTask();
|
||||
dto.SourceBillNo = item.FBillNo;
|
||||
dto.CreateTime = item.FCreateDate;
|
||||
dto.Create(InstockType.Purchase);
|
||||
|
||||
//找到当前对应来源单据编号的集合数据
|
||||
var current_erp_details = erp_list.Where(x => x.FBillNo == item.FBillNo).ToList();
|
||||
//给到dto的实体明细中
|
||||
dto.Details = _mapper.Map<List<InStockTaskDetails>>(current_erp_details);
|
||||
add_entitys.Add(dto);
|
||||
}
|
||||
//3.1提交新增
|
||||
var isSuccess = await _inStockTaskRepositories.AddRange(add_entitys, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
|
||||
return Result.ReSuccess();
|
||||
return await this.SysnData(erp_list.ToList(), isTransaction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -220,65 +160,7 @@ namespace WMS.Web.Domain.Services
|
||||
return Result.ReFailure(erp_result.Message, erp_result.Status);
|
||||
var erp_list = erp_result.Data;
|
||||
|
||||
//2.通过单据编号找到wms系统现有的任务单;并修改
|
||||
var erp_removeList = new List<ErpMiscellaneousDto>();
|
||||
var SourceBillNo_list = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList();
|
||||
var data_list = await _inStockTaskRepositories.GetListBy(SourceBillNo_list);
|
||||
if (data_list.Count != 0)
|
||||
{
|
||||
//2.1提取出wms任务单明细信息
|
||||
var data_list_details = data_list.SelectMany(x => x.Details).ToList();
|
||||
foreach (var item in data_list_details)
|
||||
{
|
||||
var data = data_list.Where(x => x.Id == item.Fid).FirstOrDefault();
|
||||
|
||||
//2.1.1对比erp的物料信息
|
||||
var erp_data = erp_list.Where(x => x.BillNo == data.SourceBillNo && x.MaterialId == item.MaterialId).FirstOrDefault();
|
||||
if (erp_data != null)
|
||||
{
|
||||
//2.1.2修改数量
|
||||
item.AccruedQty = erp_data.Qty;
|
||||
erp_removeList.Add(erp_data);
|
||||
}
|
||||
}
|
||||
|
||||
//2.2.提交修改
|
||||
var isSuccess = await _inStockTaskRepositories.UpdateRange(data_list, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
//2.3剔除:已修改的单据
|
||||
foreach (var item in erp_removeList)
|
||||
{
|
||||
erp_list.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
//3.wms任务单的来源单据编号不存在于erp中,那么就新增
|
||||
if (erp_list.Count != 0)
|
||||
{
|
||||
var add_entitys = new List<InStockTask>();
|
||||
var current_billNos = erp_list.GroupBy(x => new { x.BillNo,x.CreateTime }).Select(x => new {x.Key.BillNo,x.Key.CreateTime }).ToList();
|
||||
foreach (var item in current_billNos)
|
||||
{
|
||||
var dto = new InStockTask();
|
||||
dto.SourceBillNo = item.BillNo;
|
||||
dto.CreateTime = item.CreateTime;
|
||||
dto.Create(InstockType.Miscellaneous);
|
||||
|
||||
//找到当前对应来源单据编号的集合数据
|
||||
var current_erp_details = erp_list.Where(x => x.BillNo == item.BillNo).ToList();
|
||||
//给到dto的实体明细中
|
||||
dto.Details = _mapper.Map<List<InStockTaskDetails>>(current_erp_details);
|
||||
add_entitys.Add(dto);
|
||||
}
|
||||
//3.1提交新增
|
||||
var isSuccess = await _inStockTaskRepositories.AddRange(add_entitys, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
|
||||
return Result.ReSuccess();
|
||||
return await this.SysnData(erp_list.ToList(), isTransaction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -295,65 +177,7 @@ namespace WMS.Web.Domain.Services
|
||||
return Result.ReFailure(erp_result.Message, erp_result.Status);
|
||||
var erp_list = erp_result.Data;
|
||||
|
||||
//2.通过单据编号找到wms系统现有的任务单;并修改
|
||||
var erp_removeList = new List<ErpTransferDirectDto>();
|
||||
var SourceBillNo_list = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList();
|
||||
var data_list = await _inStockTaskRepositories.GetListBy(SourceBillNo_list);
|
||||
if (data_list.Count != 0)
|
||||
{
|
||||
//2.1提取出wms任务单明细信息
|
||||
var data_list_details = data_list.SelectMany(x => x.Details).ToList();
|
||||
foreach (var item in data_list_details)
|
||||
{
|
||||
var data = data_list.Where(x => x.Id == item.Fid).FirstOrDefault();
|
||||
|
||||
//2.1.1对比erp的物料信息
|
||||
var erp_data = erp_list.Where(x => x.BillNo == data.SourceBillNo && x.MaterialId == item.MaterialId).FirstOrDefault();
|
||||
if (erp_data != null)
|
||||
{
|
||||
//2.1.2修改数量
|
||||
item.AccruedQty = erp_data.Qty;
|
||||
erp_removeList.Add(erp_data);
|
||||
}
|
||||
}
|
||||
|
||||
//2.2.提交修改
|
||||
var isSuccess = await _inStockTaskRepositories.UpdateRange(data_list, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
//2.3剔除:已修改的单据
|
||||
foreach (var item in erp_removeList)
|
||||
{
|
||||
erp_list.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
//3.wms任务单的来源单据编号不存在于erp中,那么就新增
|
||||
if (erp_list.Count != 0)
|
||||
{
|
||||
var add_entitys = new List<InStockTask>();
|
||||
var current_billNos = erp_list.GroupBy(x => new { x.BillNo, x.CreateTime }).Select(x => new { x.Key.BillNo, x.Key.CreateTime }).ToList();
|
||||
foreach (var item in current_billNos)
|
||||
{
|
||||
var dto = new InStockTask();
|
||||
dto.SourceBillNo = item.BillNo;
|
||||
dto.CreateTime = item.CreateTime;
|
||||
dto.Create(InstockType.Stkdirecttransfers);
|
||||
|
||||
//找到当前对应来源单据编号的集合数据
|
||||
var current_erp_details = erp_list.Where(x => x.BillNo == item.BillNo).ToList();
|
||||
//给到dto的实体明细中
|
||||
dto.Details = _mapper.Map<List<InStockTaskDetails>>(current_erp_details);
|
||||
add_entitys.Add(dto);
|
||||
}
|
||||
//3.1提交新增
|
||||
var isSuccess = await _inStockTaskRepositories.AddRange(add_entitys, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
|
||||
return Result.ReSuccess();
|
||||
return await this.SysnData(erp_list.ToList(), isTransaction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -370,65 +194,7 @@ namespace WMS.Web.Domain.Services
|
||||
return Result.ReFailure(erp_result.Message, erp_result.Status);
|
||||
var erp_list = erp_result.Data;
|
||||
|
||||
//2.通过单据编号找到wms系统现有的任务单;并修改
|
||||
var erp_removeList = new List<ErpTransferinDto>();
|
||||
var SourceBillNo_list = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList();
|
||||
var data_list = await _inStockTaskRepositories.GetListBy(SourceBillNo_list);
|
||||
if (data_list.Count != 0)
|
||||
{
|
||||
//2.1提取出wms任务单明细信息
|
||||
var data_list_details = data_list.SelectMany(x => x.Details).ToList();
|
||||
foreach (var item in data_list_details)
|
||||
{
|
||||
var data = data_list.Where(x => x.Id == item.Fid).FirstOrDefault();
|
||||
|
||||
//2.1.1对比erp的物料信息
|
||||
var erp_data = erp_list.Where(x => x.BillNo == data.SourceBillNo && x.MaterialId == item.MaterialId).FirstOrDefault();
|
||||
if (erp_data != null)
|
||||
{
|
||||
//2.1.2修改数量
|
||||
item.AccruedQty = erp_data.Qty;
|
||||
erp_removeList.Add(erp_data);
|
||||
}
|
||||
}
|
||||
|
||||
//2.2.提交修改
|
||||
var isSuccess = await _inStockTaskRepositories.UpdateRange(data_list, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
//2.3剔除:已修改的单据
|
||||
foreach (var item in erp_removeList)
|
||||
{
|
||||
erp_list.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
//3.wms任务单的来源单据编号不存在于erp中,那么就新增
|
||||
if (erp_list.Count != 0)
|
||||
{
|
||||
var add_entitys = new List<InStockTask>();
|
||||
var current_billNos = erp_list.GroupBy(x => new { x.BillNo, x.CreateTime }).Select(x => new { x.Key.BillNo, x.Key.CreateTime }).ToList();
|
||||
foreach (var item in current_billNos)
|
||||
{
|
||||
var dto = new InStockTask();
|
||||
dto.SourceBillNo = item.BillNo;
|
||||
dto.CreateTime = item.CreateTime;
|
||||
dto.Create(InstockType.StktransferInst);
|
||||
|
||||
//找到当前对应来源单据编号的集合数据
|
||||
var current_erp_details = erp_list.Where(x => x.BillNo == item.BillNo).ToList();
|
||||
//给到dto的实体明细中
|
||||
dto.Details = _mapper.Map<List<InStockTaskDetails>>(current_erp_details);
|
||||
add_entitys.Add(dto);
|
||||
}
|
||||
//3.1提交新增
|
||||
var isSuccess = await _inStockTaskRepositories.AddRange(add_entitys, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
|
||||
return Result.ReSuccess();
|
||||
return await this.SysnData(erp_list.ToList(), isTransaction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -439,7 +205,7 @@ namespace WMS.Web.Domain.Services
|
||||
/// <returns></returns>
|
||||
public async Task<Result> SysnAssembledApp(List<string> billNos = null, bool isTransaction = true)
|
||||
{
|
||||
var erp_list = new List<ErpAssembledAppDto>();
|
||||
var erp_list = new List<ErpInStockResultDto>();
|
||||
|
||||
//1.获取金蝶数据:组装成品入库订单数据
|
||||
var erp_result_ass = await _erpService.BillQueryForAssembledApp_Assembly(billNos);
|
||||
@@ -456,8 +222,79 @@ namespace WMS.Web.Domain.Services
|
||||
erp_list.AddRange(erp_list_disass);
|
||||
|
||||
|
||||
//2.通过单据编号找到wms系统现有的任务单;并修改
|
||||
var erp_removeList = new List<ErpAssembledAppDto>();
|
||||
return await this.SysnData(erp_list, isTransaction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步
|
||||
/// </summary>
|
||||
/// <param name="billNos"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Sysn(List<string> billNos = null)
|
||||
{
|
||||
//1.事务
|
||||
IDbContextTransaction _transaction = _basicsRepositories.GetTransaction();
|
||||
bool isRollback = false;
|
||||
bool isTransaction = false;
|
||||
|
||||
//3.同步数据
|
||||
var result = await this.InStock(billNos, isTransaction);
|
||||
if (!result.IsSuccess) isRollback = true;
|
||||
|
||||
//3.提交事务
|
||||
var isSuccess = _basicsRepositories.CommitTransaction(isRollback, _transaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步:入库单类型的数据
|
||||
/// </summary>
|
||||
/// <param name="billNos"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> InStock(List<string> billNos,bool isTransaction)
|
||||
{
|
||||
//1.同步数据:采购订单
|
||||
var purchase_result = await this.SsynPurchaseInStock(billNos, isTransaction);
|
||||
if (!purchase_result.IsSuccess)
|
||||
return Result.ReFailure(purchase_result.Message, purchase_result.Status);
|
||||
|
||||
//2.同步数据:其他入库单
|
||||
var miscellaneou_result = await this.SysnMiscellaneous(billNos, isTransaction);
|
||||
if (!miscellaneou_result.IsSuccess)
|
||||
return Result.ReFailure(miscellaneou_result.Message, miscellaneou_result.Status);
|
||||
|
||||
//3.同步数据:直接调拨入库单
|
||||
var TransferDirect_result = await this.SysnTransferDirect(billNos, isTransaction);
|
||||
if (!TransferDirect_result.IsSuccess)
|
||||
return Result.ReFailure(TransferDirect_result.Message, TransferDirect_result.Status);
|
||||
|
||||
//4.同步数据:分步式入库单
|
||||
var Transferin_result = await this.SysnTransferin(billNos, isTransaction);
|
||||
if (!Transferin_result.IsSuccess)
|
||||
return Result.ReFailure(Transferin_result.Message, Transferin_result.Status);
|
||||
|
||||
//5.同步数据:组装拆卸单
|
||||
var AssembledApp_result = await this.SysnAssembledApp(billNos, isTransaction);
|
||||
if (!AssembledApp_result.IsSuccess)
|
||||
return Result.ReFailure(AssembledApp_result.Message, AssembledApp_result.Status);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ERP数据同步到WMS数据库
|
||||
/// </summary>
|
||||
/// <param name="erp_list"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> SysnData(List<ErpInStockResultDto> erp_list, bool isTransaction)
|
||||
{
|
||||
//1.通过单据编号找到wms系统现有的任务单;并修改
|
||||
var erp_removeList = new List<ErpInStockResultDto>();
|
||||
var SourceBillNo_list = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList();
|
||||
var data_list = await _inStockTaskRepositories.GetListBy(SourceBillNo_list);
|
||||
if (data_list.Count != 0)
|
||||
@@ -474,6 +311,7 @@ namespace WMS.Web.Domain.Services
|
||||
{
|
||||
//2.1.2修改数量
|
||||
item.AccruedQty = erp_data.Qty;
|
||||
item.DeliveredQty = erp_data.DeliveredQty;
|
||||
erp_removeList.Add(erp_data);
|
||||
}
|
||||
}
|
||||
@@ -494,16 +332,16 @@ namespace WMS.Web.Domain.Services
|
||||
if (erp_list.Count != 0)
|
||||
{
|
||||
var add_entitys = new List<InStockTask>();
|
||||
var current_billNos = erp_list.GroupBy(x => new { x.BillNo, x.CreateTime }).Select(x => new { x.Key.BillNo, x.Key.CreateTime }).ToList();
|
||||
var current_billNos = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList();
|
||||
|
||||
foreach (var item in current_billNos)
|
||||
{
|
||||
var current_order= erp_list.Where(x => x.BillNo == item).FirstOrDefault();
|
||||
var dto = new InStockTask();
|
||||
dto.SourceBillNo = item.BillNo;
|
||||
dto.CreateTime = item.CreateTime;
|
||||
dto.Create(InstockType.Assembled);
|
||||
dto.Create((InstockType)current_order.Type, current_order.BillNo, current_order.CreateTime);
|
||||
|
||||
//找到当前对应来源单据编号的集合数据
|
||||
var current_erp_details = erp_list.Where(x => x.BillNo == item.BillNo).ToList();
|
||||
var current_erp_details = erp_list.Where(x => x.BillNo == item).ToList();
|
||||
//给到dto的实体明细中
|
||||
dto.Details = _mapper.Map<List<InStockTaskDetails>>(current_erp_details);
|
||||
add_entitys.Add(dto);
|
||||
|
||||
Reference in New Issue
Block a user