出库任务合并和作废

This commit is contained in:
18942506660
2023-10-28 14:53:00 +08:00
parent 914654f749
commit 8abdbd9746
11 changed files with 312 additions and 5 deletions

View File

@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using WMS.Web.Core;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.Values;
namespace WMS.Web.Domain.Entitys
@@ -12,7 +14,7 @@ namespace WMS.Web.Domain.Entitys
/// </summary>
[Serializable]
[Table("t_erp_outstock_task")]
public class OutStockTask: EntityBase
public class OutStockTask : EntityBase
{
public OutStockTask() { }
/// <summary>
@@ -49,5 +51,46 @@ namespace WMS.Web.Domain.Entitys
/// 明细
/// </summary>
public List<OutStockTaskDetails> Details = new List<OutStockTaskDetails>();
/// <summary>
/// 作废
/// </summary>
public void Repeal(int creatorId)
{
this.OperatorId = creatorId;
this.OperateTime = DateTime.Now;
this.Status = OutStockStatus.Repeal;
}
/// <summary>
/// 合并
/// </summary>
/// <param name="list"></param>
/// <param name="creatorId"></param>
/// <returns></returns>
public Result Merge(List<OutStockTask> list, int creatorId)
{
// 符合合并数据逻辑:出库状态为”待拣货”+出库类型为:销售出库+发货组织一致+收货客户一致+发货仓库一致
if (list.Where(w => w.Status != OutStockStatus.Wait).Any()) return Result.ReFailure(ResultCodes.MergeStatusError);
if (list.Where(w => w.Type != OrderType.Sal_Out).Any()) return Result.ReFailure(ResultCodes.MergeStatusError);
var details = list.SelectMany(s => s.Details).ToList();
if (details.GroupBy(g => g.DeliveryOrgId).Count() > 1) return Result.ReFailure(ResultCodes.MergeStatusError);
if (details.GroupBy(g => g.ReceiptCustomerId).Count() > 1) return Result.ReFailure(ResultCodes.MergeStatusError);
if (details.GroupBy(g => g.StockId).Count() > 1) return Result.ReFailure(ResultCodes.MergeStatusError);
//清空数据绑定
foreach (var d in details)
{
d.Id = 0;
d.Fid = 0;
}
this.OperatorId = creatorId;
this.OperateTime = DateTime.Now;
this.Status = OutStockStatus.Wait;
this.Type = OrderType.Sal_Out;
this.Details = details;
return Result.ReSuccess();
}
}
}

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto;
using WMS.Web.Core.Dto.Login;
using WMS.Web.Core.Dto.OutStock;
using WMS.Web.Core.Internal.Results;
@@ -18,7 +19,9 @@ namespace WMS.Web.Domain.IService
Task<Result> Save(List<SaveOutStockRequest> dto, LoginInDto loginInfo);
// 同步金蝶
Task<Result> Sync(int id);
//出库任务作废
Task<Result> Repeal(OperateRequest dto, LoginInDto loginInfo);
//出库任务作废
Task<Result> merge(OperateRequest dto, LoginInDto loginInfo);
}
}

View File

@@ -13,5 +13,9 @@ namespace WMS.Web.Domain.Infrastructure
Task<OutStock> Add(OutStock entity, bool isTransaction = true);
// 获取列表
Task<(List<OutStockQueryInfoResponse> list, int total)> GetListAsync(OutStockQueryRequest dto);
/// 查询实体集合
Task<List<OutStock>> GetEntityList(List<int> ids);
/// 修改实体集合
Task<bool> EditEntityList(List<OutStock> entitys, bool isTransaction = true);
}
}

View File

@@ -13,5 +13,12 @@ namespace WMS.Web.Domain.Infrastructure
Task<OutStockTask> Add(OutStockTask entity, bool isTransaction = true);
// 获取列表
Task<(List<OutStockTaskQueryInfoResponse> list, int total)> GetListAsync(OutStockTaskQueryRequest dto);
/// 查询实体集合
Task<List<OutStockTask>> GetEntityList(List<int> ids);
/// 修改实体集合
Task<bool> EditEntityList(List<OutStockTask> entitys, bool isTransaction = true);
/// 删除实体集合
Task<bool> DeleteEntityList(List<int> ids, bool isTransaction = true);
}
}

View File

@@ -2,8 +2,10 @@
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto;
using WMS.Web.Core.Dto.Login;
using WMS.Web.Core.Dto.OutStock;
using WMS.Web.Core.Dto.TakeStock;
@@ -25,15 +27,23 @@ namespace WMS.Web.Domain.Services
private readonly ILoginService _loginService;
public readonly ITransactionRepositories _transactionRepositories;
private readonly IOutStockRepositories _outStockRepositories;
private readonly IOutStockTaskRepositories _outStockTaskRepositories;
public OutStockService(IMapper mapper, ILoginService loginService,
ITransactionRepositories transactionRepositories,
IOutStockRepositories outStockRepositories)
IOutStockRepositories outStockRepositories, IOutStockTaskRepositories outStockTaskRepositories)
{
_mapper = mapper;
_loginService = loginService;
_transactionRepositories = transactionRepositories;
_outStockRepositories = outStockRepositories;
_outStockTaskRepositories = outStockTaskRepositories;
}
/// <summary>
/// 出库单
/// </summary>
/// <param name="dto"></param>
/// <param name="loginInfo"></param>
/// <returns></returns>
public async Task<Result> Save(List<SaveOutStockRequest> dto, LoginInDto loginInfo)
{
OutStock entity = new OutStock();
@@ -66,5 +76,50 @@ namespace WMS.Web.Domain.Services
{
return Task.FromResult(Result.ReSuccess());
}
/// <summary>
/// 出库任务作废
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public async Task<Result> Repeal(OperateRequest dto, LoginInDto loginInfo)
{
var list = await _outStockTaskRepositories.GetEntityList(dto.Ids);
foreach (var entity in list)
{
//作废
entity.Repeal(loginInfo.UserInfo.StaffId);
}
var isSuccess = await _outStockTaskRepositories.EditEntityList(list, true);
if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
return Result.ReSuccess();
}
/// <summary>
/// 出库任务合并
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public async Task<Result> merge(OperateRequest dto, LoginInDto loginInfo)
{
var list = await _outStockTaskRepositories.GetEntityList(dto.Ids);
// 2:符合合并数据逻辑:出库状态为”待拣货”+出库类型为:销售出库+发货组织一致+收货客户一致+发货仓库一致
OutStockTask entity = new OutStockTask();
var res = entity.Merge(list, loginInfo.UserInfo.StaffId);
if (!res.IsSuccess) return res;
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
bool isRollback = false;
bool isSuccess = true;
entity = await _outStockTaskRepositories.Add(entity, false);
if (entity == null) isRollback = true;
isSuccess = await _outStockTaskRepositories.DeleteEntityList(list.Select(s => s.Id).ToList(), false);
if (isSuccess == false) isRollback = true;
//提交事务
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError);
return Result.ReSuccess();
}
}
}

View File

@@ -20,5 +20,9 @@ namespace WMS.Web.Domain.Values
/// 数据操作失败
/// </summary>
public static ValueTuple<int, string> DateWriteError = (40004, "数据操作失败");
//出库任务单
public static ValueTuple<int, string> MergeStatusError = (70000, "所选单据数据不一致,不能合并");
}
}