出库任务合并和作废
This commit is contained in:
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto;
|
||||
using WMS.Web.Core.Dto.OutStockTask;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
@@ -50,5 +51,38 @@ namespace WMS.Web.Api.Controllers
|
||||
var result = ResultPagedList<OutStockTaskQueryInfoResponse>.ReSuccess(list, count);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 作废
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("Repeal")]
|
||||
public async Task<Result> Repeal(OperateRequest dto)
|
||||
{
|
||||
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
||||
if (loginInfo == null || loginInfo.UserInfo == null)
|
||||
return Result.ReFailure(ResultCodes.Token_Invalid_Error);
|
||||
|
||||
return await _outStockService.Repeal(dto,loginInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("merge")]
|
||||
public async Task<Result> merge(OperateRequest dto)
|
||||
{
|
||||
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
||||
if (loginInfo == null || loginInfo.UserInfo == null)
|
||||
return Result.ReFailure(ResultCodes.Token_Invalid_Error);
|
||||
|
||||
return await _outStockService.merge(dto, loginInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
22
src/WMS.Web.Core/Dto/OperateRequest.cs
Normal file
22
src/WMS.Web.Core/Dto/OperateRequest.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作 Id集合
|
||||
/// </summary>
|
||||
public class OperateRequest
|
||||
{
|
||||
public List<int> Ids { get; set; } = new List<int>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 操作 Id集合
|
||||
/// </summary>
|
||||
public class OperatePagedRequest : PaginationBaseRequestDto
|
||||
{
|
||||
public List<int> Ids { get; set; } = new List<int>();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,5 +20,9 @@ namespace WMS.Web.Domain.Values
|
||||
/// 数据操作失败
|
||||
/// </summary>
|
||||
public static ValueTuple<int, string> DateWriteError = (40004, "数据操作失败");
|
||||
|
||||
|
||||
//出库任务单
|
||||
public static ValueTuple<int, string> MergeStatusError = (70000, "所选单据数据不一致,不能合并");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using WMS.Web.Core.Dto.OutStock;
|
||||
using WMS.Web.Core.Help;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.Mappers;
|
||||
using WMS.Web.Repositories.Configuration;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
@@ -101,5 +102,54 @@ namespace WMS.Web.Repositories
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EditEntityList(List<OutStock> 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.OutStock
|
||||
.Include(s => s.Details)
|
||||
.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());
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据单据头id获取数据
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<OutStock>> GetEntityList(List<int> ids)
|
||||
{
|
||||
var res = await _context.OutStock
|
||||
.Include(s => s.Details)
|
||||
.Where(f => ids.Contains(f.Id))
|
||||
.ToListAsync();
|
||||
|
||||
return res.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@ using WMS.Web.Core.Dto.OutStockTask;
|
||||
using WMS.Web.Core.Help;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.Mappers;
|
||||
using WMS.Web.Repositories.Configuration;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
{
|
||||
public class OutStockTaskRepositories: IOutStockTaskRepositories
|
||||
public class OutStockTaskRepositories : IOutStockTaskRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
@@ -61,6 +62,90 @@ namespace WMS.Web.Repositories
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量删除(合并后删除原数据)
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeleteEntityList(List<int> ids, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var res_list = await _context.OutStockTask
|
||||
.Include(s => s.Details)
|
||||
.Where(f => ids.Contains(f.Id))
|
||||
.ToListAsync();
|
||||
|
||||
_context.OutStockTask.RemoveRange(res_list);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EditEntityList(List<OutStockTask> 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.OutStockTask
|
||||
.Include(s => s.Details)
|
||||
.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());
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据单据头id获取数据
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<OutStockTask>> GetEntityList(List<int> ids)
|
||||
{
|
||||
var res = await _context.OutStockTask
|
||||
.Include(s => s.Details)
|
||||
.Where(f => ids.Contains(f.Id))
|
||||
.ToListAsync();
|
||||
|
||||
return res.Clone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user