优化同步
This commit is contained in:
@@ -592,6 +592,11 @@
|
|||||||
<param name="operateId"></param>
|
<param name="operateId"></param>
|
||||||
<param name="syncStatus"></param>
|
<param name="syncStatus"></param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:WMS.Web.Domain.Entitys.InStock.RepeatSync">
|
||||||
|
<summary>
|
||||||
|
重传
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:WMS.Web.Domain.Entitys.InStockDetails">
|
<member name="T:WMS.Web.Domain.Entitys.InStockDetails">
|
||||||
<summary>
|
<summary>
|
||||||
wms入库单明细
|
wms入库单明细
|
||||||
@@ -2129,6 +2134,14 @@
|
|||||||
<param name="isTransaction"></param>
|
<param name="isTransaction"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:WMS.Web.Domain.Infrastructure.IInStockRepositories.UpdateRange(System.Collections.Generic.List{WMS.Web.Domain.Entitys.InStock},System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
批量修改
|
||||||
|
</summary>
|
||||||
|
<param name="entitys"></param>
|
||||||
|
<param name="isTransaction"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:WMS.Web.Domain.Infrastructure.IInStockRepositories.GetList(System.Collections.Generic.List{System.Int32})">
|
<member name="M:WMS.Web.Domain.Infrastructure.IInStockRepositories.GetList(System.Collections.Generic.List{System.Int32})">
|
||||||
<summary>
|
<summary>
|
||||||
根据单据头id获取数据
|
根据单据头id获取数据
|
||||||
@@ -2570,7 +2583,7 @@
|
|||||||
入库单服务接口
|
入库单服务接口
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:WMS.Web.Domain.IService.IInStockService.Sync(WMS.Web.Core.Dto.OperateRequest,WMS.Web.Core.Dto.Login.LoginInDto)">
|
<member name="M:WMS.Web.Domain.IService.IInStockService.Sync(WMS.Web.Core.Dto.OperateRequest,WMS.Web.Core.Dto.Login.LoginInDto,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
同步金蝶
|
同步金蝶
|
||||||
</summary>
|
</summary>
|
||||||
@@ -3867,7 +3880,7 @@
|
|||||||
入库单服务
|
入库单服务
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:WMS.Web.Domain.Services.InStockService.Sync(WMS.Web.Core.Dto.OperateRequest,WMS.Web.Core.Dto.Login.LoginInDto)">
|
<member name="M:WMS.Web.Domain.Services.InStockService.Sync(WMS.Web.Core.Dto.OperateRequest,WMS.Web.Core.Dto.Login.LoginInDto,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
同步-金蝶
|
同步-金蝶
|
||||||
</summary>
|
</summary>
|
||||||
@@ -3951,7 +3964,7 @@
|
|||||||
<param name="dto"></param>
|
<param name="dto"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:WMS.Web.Domain.Services.InStockService.PurchaseInStock(WMS.Web.Domain.Entitys.InStock,WMS.Web.Core.Dto.Login.LoginInDto,Microsoft.Extensions.DependencyInjection.IServiceScope)">
|
<member name="M:WMS.Web.Domain.Services.InStockService.PurchaseInStock(WMS.Web.Domain.Entitys.InStock,WMS.Web.Core.Dto.Login.LoginInDto)">
|
||||||
<summary>
|
<summary>
|
||||||
采购:同步金蝶
|
采购:同步金蝶
|
||||||
</summary>
|
</summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using WMS.Web.Core;
|
||||||
using WMS.Web.Domain.Values;
|
using WMS.Web.Domain.Values;
|
||||||
|
|
||||||
namespace WMS.Web.Domain.Entitys
|
namespace WMS.Web.Domain.Entitys
|
||||||
@@ -12,12 +13,12 @@ namespace WMS.Web.Domain.Entitys
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[Table("t_wms_instock")]
|
[Table("t_wms_instock")]
|
||||||
public class InStock
|
public class InStock : EntityBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ID
|
/// ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Id { get; set; }
|
public override int Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单据编号
|
/// 单据编号
|
||||||
@@ -95,10 +96,8 @@ namespace WMS.Web.Domain.Entitys
|
|||||||
this.CreateTime = DateTime.Now;
|
this.CreateTime = DateTime.Now;
|
||||||
if (this.Type == InstockType.Purchase)
|
if (this.Type == InstockType.Purchase)
|
||||||
{
|
{
|
||||||
//只有采购订单入库才需要同步金蝶:单据头为同步中默认
|
|
||||||
this.SuccessSync = SyncStatus.SyncIng;
|
this.SuccessSync = SyncStatus.SyncIng;
|
||||||
//erp明细为失败默认,在处理同步时能找到该明细
|
this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.SyncIng);
|
||||||
this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.Fail);
|
|
||||||
}
|
}
|
||||||
else//非采购订单,这里就没有记录erpdetails的数据了
|
else//非采购订单,这里就没有记录erpdetails的数据了
|
||||||
this.SuccessSync = SyncStatus.Success;
|
this.SuccessSync = SyncStatus.Success;
|
||||||
@@ -180,5 +179,23 @@ namespace WMS.Web.Domain.Entitys
|
|||||||
this.OperateId = operateId;
|
this.OperateId = operateId;
|
||||||
this.SyncTime = DateTime.Now;
|
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="dto"></param>
|
||||||
/// <param name="loginInfo"></param>
|
/// <param name="loginInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo);
|
Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo, bool isRepeatSync = true);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 收货
|
/// 收货
|
||||||
|
|||||||
@@ -59,6 +59,14 @@ namespace WMS.Web.Domain.Infrastructure
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<InStock> Update(InStock entity, bool isTransaction = true);
|
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>
|
/// <summary>
|
||||||
/// 根据单据头id获取数据
|
/// 根据单据头id获取数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -77,16 +77,21 @@ namespace WMS.Web.Domain.Services
|
|||||||
/// <param name="dto"></param>
|
/// <param name="dto"></param>
|
||||||
/// <param name="loginInfo"></param>
|
/// <param name="loginInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo)
|
public Task<Result> Sync(OperateRequest dto, LoginInDto loginInfo, bool isRepeatSync = true)
|
||||||
{
|
{
|
||||||
|
var list = _inStockRepositories.GetList(dto.Ids).GetAwaiter().GetResult();
|
||||||
|
var isSuccess = true;
|
||||||
|
if (isRepeatSync)
|
||||||
|
{
|
||||||
|
list = list.Where(w => w.SuccessSync == SyncStatus.Fail).ToList();
|
||||||
|
list.ForEach(f => f.RepeatSync());
|
||||||
|
isSuccess = _inStockRepositories.UpdateRange(list, true).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var scope = _serviceScopeFactory.CreateScope();
|
|
||||||
var sc_inStockRepositories = scope.ServiceProvider.GetRequiredService<IInStockRepositories>();
|
|
||||||
var list = await sc_inStockRepositories.GetList(dto.Ids);
|
|
||||||
foreach (var entity in list)
|
foreach (var entity in list)
|
||||||
{
|
{
|
||||||
var res = await this.PurchaseInStock(entity, loginInfo, scope);
|
var res = await this.PurchaseInStock(entity, loginInfo);
|
||||||
if (!res.IsSuccess)
|
if (!res.IsSuccess)
|
||||||
_logger.LogError($"入库单同步失败:{res.Message}");
|
_logger.LogError($"入库单同步失败:{res.Message}");
|
||||||
}
|
}
|
||||||
@@ -144,7 +149,7 @@ namespace WMS.Web.Domain.Services
|
|||||||
{
|
{
|
||||||
OperateRequest oRequest = new OperateRequest();
|
OperateRequest oRequest = new OperateRequest();
|
||||||
oRequest.Ids.Add(entity.Id);
|
oRequest.Ids.Add(entity.Id);
|
||||||
await Sync(oRequest, loginInfo);
|
await Sync(oRequest, loginInfo,false);
|
||||||
}
|
}
|
||||||
return Result.ReSuccess();
|
return Result.ReSuccess();
|
||||||
}
|
}
|
||||||
@@ -732,13 +737,14 @@ namespace WMS.Web.Domain.Services
|
|||||||
/// <param name="entity"></param>
|
/// <param name="entity"></param>
|
||||||
/// <param name="loginInfo"></param>
|
/// <param name="loginInfo"></param>
|
||||||
/// <returns></returns>
|
/// <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>();
|
var sc_InStockRepositories = scope.ServiceProvider.GetRequiredService<IInStockRepositories>();
|
||||||
|
|
||||||
if (entity.Type != InstockType.Purchase) return Result.ReSuccess();
|
if (entity.Type != InstockType.Purchase) return Result.ReSuccess();
|
||||||
if (entity.SuccessSync == SyncStatus.Success) 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)
|
foreach (var s in erpDetails)
|
||||||
{
|
{
|
||||||
var erp_details = entity.ErpDetails
|
var erp_details = entity.ErpDetails
|
||||||
|
|||||||
@@ -196,6 +196,43 @@ namespace WMS.Web.Repositories
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 批量修改
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entitys"></param>
|
||||||
|
/// <param name="isTransaction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> UpdateRange(List<InStock> entitys, bool isTransaction = true)
|
||||||
|
{
|
||||||
|
IDbContextTransaction _transaction = null;
|
||||||
|
if (isTransaction)
|
||||||
|
_transaction = _context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<int> list = entitys.Select(s => s.Id).ToList();
|
||||||
|
|
||||||
|
var res = await _context.Instock
|
||||||
|
.Include(s => s.Details)
|
||||||
|
.Include(s => s.ErpDetails)
|
||||||
|
.Where(f => list.Contains(f.Id)).ToListAsync();
|
||||||
|
|
||||||
|
_mapper.ToMapList(entitys, res);
|
||||||
|
_mapper.ToMapList(entitys.SelectMany(s => s.Details).ToList(), res.SelectMany(s => s.Details).ToList());
|
||||||
|
_mapper.ToMapList(entitys.SelectMany(s => s.ErpDetails).ToList(), res.SelectMany(s => s.ErpDetails).ToList());
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
if (_transaction != null)
|
||||||
|
_transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (_transaction != null)
|
||||||
|
_transaction.Rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据单据头id获取数据
|
/// 根据单据头id获取数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user