diff --git a/src/WMS.Web.Api/Controllers/OutStockController.cs b/src/WMS.Web.Api/Controllers/OutStockController.cs
index 0fba0703..b438b379 100644
--- a/src/WMS.Web.Api/Controllers/OutStockController.cs
+++ b/src/WMS.Web.Api/Controllers/OutStockController.cs
@@ -53,13 +53,13 @@ namespace WMS.Web.Api.Controllers
}
///
- /// 保存
+ /// 保存(出库)
///
///
///
[HttpPost]
[Route("Save")]
- public async Task Save(List dto)
+ public async Task Save(SaveOutStockRequest dto)
{
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
if (loginInfo == null || loginInfo.UserInfo == null)
diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml
index 22b95af7..eeeb8478 100644
--- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml
+++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml
@@ -190,7 +190,7 @@
-
+
保存
diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml
index eeb7e5bc..2e61c0e7 100644
--- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml
+++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml
@@ -2305,42 +2305,17 @@
出库单保存
-
+
- 来源单号
+ 出库任务单Id
-
-
- 销售订单号
-
-
-
-
- 发货组织
-
-
-
-
- 收货客户
-
-
-
+
物料Id
-
-
- 仓库ID
-
-
-
-
- 仓位ID
-
-
-
+
出库数量
diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml
index 34602b8a..81c8250c 100644
--- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml
+++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml
@@ -655,6 +655,11 @@
主键 订单编号
+
+
+ 任务单ID
+
+
单据编号
@@ -690,7 +695,7 @@
明细
-
+
创建
@@ -924,11 +929,6 @@
物料ID
-
-
- 单位ID
-
-
仓库ID
@@ -1983,7 +1983,7 @@
出库服务
-
+
出库单
diff --git a/src/WMS.Web.Core/Dto/OutStock/SaveOutStockRequest.cs b/src/WMS.Web.Core/Dto/OutStock/SaveOutStockRequest.cs
index 5519ffc2..77e22436 100644
--- a/src/WMS.Web.Core/Dto/OutStock/SaveOutStockRequest.cs
+++ b/src/WMS.Web.Core/Dto/OutStock/SaveOutStockRequest.cs
@@ -11,40 +11,21 @@ namespace WMS.Web.Core.Dto.OutStock
public class SaveOutStockRequest
{
///
- /// 来源单号
+ /// 出库任务单Id
///
- [Required(ErrorMessage = "来源单号不能为空")]
- public string SourceBillNo { get; set; }
- ///
- /// 销售订单号
- ///
- [Required(ErrorMessage = "销售订单号不能为空")]
- public string SaleBillNo { get; set; }
- ///
- /// 发货组织
- ///
- [Required(ErrorMessage = "发货组织不能为空")]
- public int DeliveryOrgId { get; set; }
- ///
- /// 收货客户
- ///
- [Required(ErrorMessage = "收货客户不能为空")]
- public int ReceiptCustomerId { get; set; }
+ [Required(ErrorMessage = "出库单不能为空")]
+ public int TaskId { get; set; }
+ public List Details { get; set; } = new List();
+
+ }
+ public class SaveOutStockDetailsRequest
+ {
///
/// 物料Id
///
[Required(ErrorMessage = "物料不能为空")]
public int MaterialId { get; set; }
///
- /// 仓库ID
- ///
- [Required(ErrorMessage = "仓库不能为空")]
- public int StockId { get; set; }
- ///
- /// 仓位ID
- ///
- public int? SubStockId { get; set; }
- ///
/// 出库数量
///
[Required(ErrorMessage = "出库数量不能为空")]
diff --git a/src/WMS.Web.Domain/Entitys/OutStock.cs b/src/WMS.Web.Domain/Entitys/OutStock.cs
index 36a133d6..89c8edb3 100644
--- a/src/WMS.Web.Domain/Entitys/OutStock.cs
+++ b/src/WMS.Web.Domain/Entitys/OutStock.cs
@@ -21,6 +21,11 @@ namespace WMS.Web.Domain.Entitys
[Column("Id")]
public override int Id { get; set; }
///
+ /// 任务单ID
+ ///
+ [Column("TaskId")]
+ public int TaskId { get; set; }
+ ///
/// 单据编号
///
[Column("BillNo")]
@@ -59,11 +64,14 @@ namespace WMS.Web.Domain.Entitys
/// 创建
///
///
- public void Create(int creatorId)
+ public void Create(int creatorId,int taskId, OrderType type)
{
+ this.TaskId = taskId;
+ this.Type = type;
this.CreatorId = creatorId;
this.CreateTime = DateTime.Now;
}
+
///
/// 生成单据号
diff --git a/src/WMS.Web.Domain/IService/IOutStockService.cs b/src/WMS.Web.Domain/IService/IOutStockService.cs
index 244d4b0a..1ebcbe0f 100644
--- a/src/WMS.Web.Domain/IService/IOutStockService.cs
+++ b/src/WMS.Web.Domain/IService/IOutStockService.cs
@@ -16,7 +16,7 @@ namespace WMS.Web.Domain.IService
public interface IOutStockService
{
//出库单保存
- Task Save(List dto, LoginInDto loginInfo);
+ Task Save(SaveOutStockRequest dto, LoginInDto loginInfo);
// 同步金蝶
Task Sync(OperateRequest dto);
//出库任务作废
diff --git a/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs
index 8c0948a4..50fcfac9 100644
--- a/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs
+++ b/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs
@@ -11,6 +11,10 @@ namespace WMS.Web.Domain.Infrastructure
{
// 新增
Task Add(OutStock entity, bool isTransaction = true);
+ //编辑
+ Task Edit(OutStock entity, bool isTransaction = true);
+ //根据任务单Id搜索
+ Task GetByTaskId(int taskId);
// 获取列表
Task<(List list, int total)> GetListAsync(OutStockQueryRequest dto);
/// 查询实体集合
diff --git a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs
index 2df89219..0f22ff7e 100644
--- a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs
+++ b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs
@@ -20,5 +20,7 @@ namespace WMS.Web.Domain.Infrastructure
/// 删除实体集合
Task DeleteEntityList(List ids, bool isTransaction = true);
+ //获取实体
+ Task Get(int id);
}
}
diff --git a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs
index 273a3d7b..da9a2561 100644
--- a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs
+++ b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs
@@ -12,6 +12,11 @@ namespace WMS.Web.Domain.Mappers
public OutStockMapper()
{
CreateMap();
+
+ CreateMap()
+ .ForMember(x => x.Id, ops => ops.Ignore())
+ .ForMember(x => x.Fid, ops => ops.Ignore())
+ .ForMember(x => x.Qty, ops => ops.Ignore());
}
}
}
diff --git a/src/WMS.Web.Domain/Services/OutStockService.cs b/src/WMS.Web.Domain/Services/OutStockService.cs
index d30a60bf..494b9cfc 100644
--- a/src/WMS.Web.Domain/Services/OutStockService.cs
+++ b/src/WMS.Web.Domain/Services/OutStockService.cs
@@ -44,11 +44,28 @@ namespace WMS.Web.Domain.Services
///
///
///
- public async Task Save(List dto, LoginInDto loginInfo)
+ public async Task Save(SaveOutStockRequest dto, LoginInDto loginInfo)
{
- OutStock entity = new OutStock();
- entity.Details = _mapper.Map>(dto);
- entity.Create(loginInfo.UserInfo.StaffId);
+ var outStockTask = await _outStockTaskRepositories.Get(dto.TaskId);
+ OutStock entity = await _outStockRepositories.GetByTaskId(dto.TaskId);
+
+ if (entity == null)
+ entity = new OutStock();
+ entity.Create(loginInfo.UserInfo.StaffId, outStockTask.Id, outStockTask.Type);
+ foreach (var d in dto.Details)
+ {
+ //任务单明细
+ var tDetail = outStockTask.Details.FirstOrDefault(f => f.MaterialId == d.MaterialId);
+ if (tDetail == null) continue;
+ //出库单明细
+ OutStockDetails outd = entity.Details.FirstOrDefault(f => f.MaterialId == d.MaterialId);
+ if (outd == null)
+ {
+ outd = _mapper.Map(tDetail);
+ entity.Details.Add(outd);
+ }
+ outd.Qty = outd.Qty + d.Qty;
+ }
//需要填写序列号
//需要修改库存
@@ -57,7 +74,11 @@ namespace WMS.Web.Domain.Services
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
bool isRollback = false;
bool isSuccess = true;
- entity = await _outStockRepositories.Add(entity, false);
+ if (entity.Id > 0)
+ entity = await _outStockRepositories.Edit(entity, false);
+ else
+ entity = await _outStockRepositories.Add(entity, false);
+
if (entity == null) isRollback = true;
//提交事务
diff --git a/src/WMS.Web.Repositories/OutStockRepositories.cs b/src/WMS.Web.Repositories/OutStockRepositories.cs
index fccd7462..1b9c107f 100644
--- a/src/WMS.Web.Repositories/OutStockRepositories.cs
+++ b/src/WMS.Web.Repositories/OutStockRepositories.cs
@@ -185,5 +185,53 @@ namespace WMS.Web.Repositories
return res.Clone();
}
+ ///
+ /// 编辑
+ ///
+ ///
+ ///
+ ///
+ public async Task Edit(OutStock entity, bool isTransaction = true)
+ {
+ IDbContextTransaction _transaction = null;
+ if (isTransaction)
+ _transaction = _context.Database.BeginTransaction();
+
+ try
+ {
+ var res = await _context.OutStock
+ .Include(s => s.Details)
+ .FirstOrDefaultAsync(f => f.Id == entity.Id);
+ if (res == null) return null;
+
+ _mapper.Map(entity, res);
+ _mapper.ToMapList(entity.Details, res.Details);
+ await _context.SaveChangesAsync();
+
+ if (_transaction != null)
+ _transaction.Commit();
+
+ return res;
+ }
+ catch (Exception)
+ {
+ if (_transaction != null)
+ _transaction.Rollback();
+ return null;
+ }
+ }
+ ///
+ /// 根据任务单Id获取
+ ///
+ ///
+ ///
+ public async Task GetByTaskId(int taskId)
+ {
+ var res = await _context.OutStock
+ .Include(s => s.Details)
+ .FirstOrDefaultAsync(f => taskId == f.TaskId);
+
+ return res.Clone();
+ }
}
}
diff --git a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs
index ca4d6423..b9eeba76 100644
--- a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs
+++ b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs
@@ -140,6 +140,20 @@ namespace WMS.Web.Repositories
return true;
}
+ ///
+ /// 根据Id获取实体
+ ///
+ ///
+ ///
+ public async Task Get(int id)
+ {
+ var res = await _context.OutStockTask
+ .Include(s => s.Details)
+ .FirstOrDefaultAsync(f => id == f.Id);
+
+ return res.Clone();
+ }
+
///
/// 根据单据头id获取数据
///