diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml
index f5967f1d..1b9e261b 100644
--- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml
+++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml
@@ -961,12 +961,12 @@
- 同步成功或者失败 null 就是未同步
+ 同步成功或者失败 默认是失败状态
- 同步失败的源订单号
+ 同步失败的源订单号(默认就包含所有来源单号)
@@ -986,13 +986,19 @@
- 创建
+ 创建(需要在明细都生成后最后调用)
-
+
- 同步金蝶
+ 同步金蝶(成功)
+
+
+
+
+
+ 同步金蝶(失败)
@@ -3334,6 +3340,13 @@
+
+
+ 下推
+
+
+
+
出库任务
diff --git a/src/WMS.Web.Domain/Entitys/OutStock.cs b/src/WMS.Web.Domain/Entitys/OutStock.cs
index 0a760543..445afe7b 100644
--- a/src/WMS.Web.Domain/Entitys/OutStock.cs
+++ b/src/WMS.Web.Domain/Entitys/OutStock.cs
@@ -62,12 +62,12 @@ namespace WMS.Web.Domain.Entitys
[Column("CreateTime")]
public DateTime CreateTime { get; set; } = DateTime.Now;
///
- /// 同步成功或者失败 null 就是未同步
+ /// 同步成功或者失败 默认是失败状态
///
[Column("SuccessSync")]
- public bool? SuccessSync { get; set; }
+ public bool SuccessSync { get; set; } = false;
///
- /// 同步失败的源订单号
+ /// 同步失败的源订单号(默认就包含所有来源单号)
///
[Column("SuccessSyncFail")]
public List SuccessSyncFail { get; set; }=new List();
@@ -86,7 +86,7 @@ namespace WMS.Web.Domain.Entitys
///
public List Details = new List();
///
- /// 创建
+ /// 创建(需要在明细都生成后最后调用)
///
///
public void Create(int creatorId, OutStockTask task)
@@ -97,16 +97,28 @@ namespace WMS.Web.Domain.Entitys
this.ReceiptCustomerId = task.ReceiptCustomerId;
this.CreatorId = creatorId;
this.CreateTime = DateTime.Now;
+ this.SuccessSync = false;
+ this.SuccessSyncFail = this.Details.SelectMany(s => s.ErpDetails).GroupBy(g => g.SourceBillNo).Select(s=>s.Key).ToList();
}
///
- /// 同步金蝶
+ /// 同步金蝶(成功)
///
///
- public void Sync(List sourcBilNos, bool isSuccess, int operateId, string remark)
+ public void SyncSuccess(string sourcNos, int operateId)
{
- SuccessSyncFail.AddRange(sourcBilNos);
- SuccessSyncFail.Distinct();
- this.SuccessSync = isSuccess;
+ this.SuccessSyncFail.Remove(sourcNos);
+ this.SuccessSync = true;
+ this.Remark = "";
+ this.OperateId = operateId;
+ this.SyncTime = DateTime.Now;
+ }
+ ///
+ /// 同步金蝶(失败)
+ ///
+ ///
+ public void SyncFail(string remark,int operateId)
+ {
+ this.SuccessSync = false;
this.Remark = remark;
this.OperateId = operateId;
this.SyncTime = DateTime.Now;
diff --git a/src/WMS.Web.Domain/Services/OutStockService.cs b/src/WMS.Web.Domain/Services/OutStockService.cs
index 6a5eee49..2b11645c 100644
--- a/src/WMS.Web.Domain/Services/OutStockService.cs
+++ b/src/WMS.Web.Domain/Services/OutStockService.cs
@@ -6,15 +6,18 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto;
+using WMS.Web.Core.Dto.Erp;
using WMS.Web.Core.Dto.Login;
using WMS.Web.Core.Dto.OutStock;
using WMS.Web.Core.Dto.TakeStock;
+using WMS.Web.Core.Help;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Values;
+using WMS.Web.Domain.Values.Erp;
namespace WMS.Web.Domain.Services
{
@@ -66,7 +69,6 @@ namespace WMS.Web.Domain.Services
var mIds = dto.Details.GroupBy(g => g.MaterialId).Select(s => s.Key).ToList();
OutStock entity = new OutStock();
- entity.Create(loginInfo.UserInfo.StaffId, outStockTask);
foreach (var mid in mIds)
{
//任务单明细
@@ -91,6 +93,8 @@ namespace WMS.Web.Domain.Services
outd.SerialNumbers.AddRange(dtoDetails.SelectMany(s => s.SerialNumbers));
entity.Details.Add(outd);
}
+ entity.Create(loginInfo.UserInfo.StaffId, outStockTask);
+
//需要填写序列号
//需要修改库存
@@ -123,13 +127,42 @@ namespace WMS.Web.Domain.Services
var list = await _outStockRepositories.GetEntityList(dto.Ids);
foreach (var entity in list)
{
- //下推金蝶
- var res = await _erpService.Push(new Core.Dto.Erp.ErpPushDto() { });
- entity.Sync(new List(), res.IsSuccess, loginInfo.UserInfo.StaffId, res.Message);
+ if (entity.SuccessSync) continue;
+ List failList = entity.SuccessSyncFail.Clone();//同步失败的来源单号
+ //找到单据里需要同步的单据
+ var sourcNos = entity.Details.SelectMany(s => s.ErpDetails).GroupBy(s => s.SourceBillNo).Select(s => s.Key);
+ foreach (var s in failList)
+ {
+ var erp_details = entity.Details.SelectMany(s => s.ErpDetails).Select(s => s.Erp_DetailId).ToList();
+ var erpDto = new ErpPushDto() {
+ FormId = FormIdParam.SAL_DELIVERYNOTICE.ToString(),
+ Numbers = new List() { s },
+ DetailsId = string.Join(",", erp_details)
+ };
+ //下推金蝶
+ var res = await this.Push(erpDto);
+ if (res.IsSuccess)
+ entity.SyncSuccess(s, loginInfo.UserInfo.StaffId);
+ else
+ entity.SyncFail(res.Message, loginInfo.UserInfo.StaffId);
+ }
+ entity.SuccessSync = entity.SuccessSyncFail.Count() > 0 ? false : true;
+ //最好一条一条执行,否则执行失败 但是金蝶那边又同步成功 就会造成数据比价乱
+ var isSuccess = await _outStockRepositories.Edit(entity, true);
+ if (entity == null) return Result.ReFailure(ResultCodes.DateWriteError);
}
- var isSuccess = await _outStockRepositories.EditEntityList(list, true);
- if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
+
+ return Result.ReSuccess();
+ }
+ ///
+ /// 下推
+ ///
+ ///
+ ///
+ private async Task Push(ErpPushDto dto)
+ {
+ var res = await _erpService.Push(dto);
return Result.ReSuccess();
}
}