优化同步
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using WMS.Web.Core;
|
||||
using WMS.Web.Domain.Values;
|
||||
|
||||
namespace WMS.Web.Domain.Entitys
|
||||
@@ -12,12 +13,12 @@ namespace WMS.Web.Domain.Entitys
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[Table("t_wms_instock")]
|
||||
public class InStock
|
||||
public class InStock : EntityBase
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
public override int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单据编号
|
||||
@@ -95,10 +96,8 @@ namespace WMS.Web.Domain.Entitys
|
||||
this.CreateTime = DateTime.Now;
|
||||
if (this.Type == InstockType.Purchase)
|
||||
{
|
||||
//只有采购订单入库才需要同步金蝶:单据头为同步中默认
|
||||
this.SuccessSync = SyncStatus.SyncIng;
|
||||
//erp明细为失败默认,在处理同步时能找到该明细
|
||||
this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.Fail);
|
||||
this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.SyncIng);
|
||||
}
|
||||
else//非采购订单,这里就没有记录erpdetails的数据了
|
||||
this.SuccessSync = SyncStatus.Success;
|
||||
@@ -180,5 +179,23 @@ namespace WMS.Web.Domain.Entitys
|
||||
this.OperateId = operateId;
|
||||
this.SyncTime = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重传
|
||||
/// </summary>
|
||||
public void RepeatSync()
|
||||
{
|
||||
//只有完全失败的情况下才能重传
|
||||
if (this.SuccessSync != SyncStatus.Fail) return;
|
||||
this.SuccessSync = SyncStatus.SyncIng;
|
||||
var erpDetails = this.ErpDetails
|
||||
.Where(w => w.SuccessSync == SyncStatus.Fail)
|
||||
.ToList();
|
||||
foreach (var e in erpDetails)
|
||||
{
|
||||
e.SuccessSync = SyncStatus.SyncIng;
|
||||
}
|
||||
this.Remark = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace WMS.Web.Domain.IService
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo);
|
||||
Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo, bool isRepeatSync = true);
|
||||
|
||||
/// <summary>
|
||||
/// 收货
|
||||
|
||||
@@ -59,6 +59,14 @@ namespace WMS.Web.Domain.Infrastructure
|
||||
/// <returns></returns>
|
||||
Task<InStock> Update(InStock entity, bool isTransaction = true);
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateRange(List<InStock> entitys, bool isTransaction = true);
|
||||
|
||||
/// <summary>
|
||||
/// 根据单据头id获取数据
|
||||
/// </summary>
|
||||
|
||||
@@ -77,16 +77,21 @@ namespace WMS.Web.Domain.Services
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
public Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo)
|
||||
public Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo, bool isRepeatSync = true)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
var list = _inStockRepositories.GetList(dto.Ids).GetAwaiter().GetResult();
|
||||
var isSuccess = true;
|
||||
if (isRepeatSync)
|
||||
{
|
||||
var scope = _serviceScopeFactory.CreateScope();
|
||||
var sc_inStockRepositories = scope.ServiceProvider.GetRequiredService<IInStockRepositories>();
|
||||
var list = await sc_inStockRepositories.GetList(dto.Ids);
|
||||
list = list.Where(w => w.SuccessSync == SyncStatus.Fail).ToList();
|
||||
list.ForEach(f => f.RepeatSync());
|
||||
isSuccess = _inStockRepositories.UpdateRange(list, true).GetAwaiter().GetResult();
|
||||
}
|
||||
Task.Run(async () =>
|
||||
{
|
||||
foreach (var entity in list)
|
||||
{
|
||||
var res = await this.PurchaseInStock(entity, loginInfo, scope);
|
||||
var res = await this.PurchaseInStock(entity, loginInfo);
|
||||
if (!res.IsSuccess)
|
||||
_logger.LogError($"入库单同步失败:{res.Message}");
|
||||
}
|
||||
@@ -144,7 +149,7 @@ namespace WMS.Web.Domain.Services
|
||||
{
|
||||
OperateRequest oRequest = new OperateRequest();
|
||||
oRequest.Ids.Add(entity.Id);
|
||||
await Sync(oRequest, loginInfo);
|
||||
await Sync(oRequest, loginInfo,false);
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
@@ -732,13 +737,14 @@ namespace WMS.Web.Domain.Services
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Result> PurchaseInStock(InStock entity, LoginInDto loginInfo, IServiceScope scope)
|
||||
private async Task<Result> PurchaseInStock(InStock entity, LoginInDto loginInfo)
|
||||
{
|
||||
var scope = _serviceScopeFactory.CreateScope();
|
||||
var sc_InStockRepositories = scope.ServiceProvider.GetRequiredService<IInStockRepositories>();
|
||||
|
||||
if (entity.Type != InstockType.Purchase) return Result.ReSuccess();
|
||||
if (entity.SuccessSync == SyncStatus.Success) return Result.ReSuccess();
|
||||
var erpDetails = entity.ErpDetails.Where(w => w.SuccessSync == SyncStatus.Fail).ToList();
|
||||
var erpDetails = entity.ErpDetails.Where(w => w.SuccessSync == SyncStatus.SyncIng).ToList();
|
||||
foreach (var s in erpDetails)
|
||||
{
|
||||
var erp_details = entity.ErpDetails
|
||||
|
||||
Reference in New Issue
Block a user