diff --git a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 index 12ed97eb..20883aa2 100644 Binary files a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 and b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 differ diff --git a/src/WMS.Web.Api/Controllers/OutStockTaskController.cs b/src/WMS.Web.Api/Controllers/OutStockTaskController.cs index 2a97a0b2..07d6b5b6 100644 --- a/src/WMS.Web.Api/Controllers/OutStockTaskController.cs +++ b/src/WMS.Web.Api/Controllers/OutStockTaskController.cs @@ -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.ReSuccess(list, count); return result; } + + /// + /// 作废 + /// + /// + /// + [HttpPost] + [Route("Repeal")] + public async Task 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); + } + + /// + /// 合并 + /// + /// + /// + [HttpPost] + [Route("merge")] + public async Task 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); + } + } } diff --git a/src/WMS.Web.Core/Dto/OperateRequest.cs b/src/WMS.Web.Core/Dto/OperateRequest.cs new file mode 100644 index 00000000..1d8ba550 --- /dev/null +++ b/src/WMS.Web.Core/Dto/OperateRequest.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto +{ + /// + /// 操作 Id集合 + /// + public class OperateRequest + { + public List Ids { get; set; } = new List(); + } + + /// + /// 操作 Id集合 + /// + public class OperatePagedRequest : PaginationBaseRequestDto + { + public List Ids { get; set; } = new List(); + } +} diff --git a/src/WMS.Web.Domain/Entitys/OutStockTask.cs b/src/WMS.Web.Domain/Entitys/OutStockTask.cs index 00a82828..9a5a4cca 100644 --- a/src/WMS.Web.Domain/Entitys/OutStockTask.cs +++ b/src/WMS.Web.Domain/Entitys/OutStockTask.cs @@ -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 /// [Serializable] [Table("t_erp_outstock_task")] - public class OutStockTask: EntityBase + public class OutStockTask : EntityBase { public OutStockTask() { } /// @@ -49,5 +51,46 @@ namespace WMS.Web.Domain.Entitys /// 明细 /// public List Details = new List(); + + /// + /// 作废 + /// + public void Repeal(int creatorId) + { + this.OperatorId = creatorId; + this.OperateTime = DateTime.Now; + this.Status = OutStockStatus.Repeal; + } + /// + /// 合并 + /// + /// + /// + /// + public Result Merge(List 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(); + } } } diff --git a/src/WMS.Web.Domain/IService/IOutStockService.cs b/src/WMS.Web.Domain/IService/IOutStockService.cs index ea8873b0..a2915edc 100644 --- a/src/WMS.Web.Domain/IService/IOutStockService.cs +++ b/src/WMS.Web.Domain/IService/IOutStockService.cs @@ -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 Save(List dto, LoginInDto loginInfo); // 同步金蝶 Task Sync(int id); - - + //出库任务作废 + Task Repeal(OperateRequest dto, LoginInDto loginInfo); + //出库任务作废 + Task merge(OperateRequest dto, LoginInDto loginInfo); } } diff --git a/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs index f6ec7a34..8c0948a4 100644 --- a/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IOutStockRepositories.cs @@ -13,5 +13,9 @@ namespace WMS.Web.Domain.Infrastructure Task Add(OutStock entity, bool isTransaction = true); // 获取列表 Task<(List list, int total)> GetListAsync(OutStockQueryRequest dto); + /// 查询实体集合 + Task> GetEntityList(List ids); + /// 修改实体集合 + Task EditEntityList(List entitys, bool isTransaction = true); } } diff --git a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs index e041570a..2df89219 100644 --- a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs @@ -13,5 +13,12 @@ namespace WMS.Web.Domain.Infrastructure Task Add(OutStockTask entity, bool isTransaction = true); // 获取列表 Task<(List list, int total)> GetListAsync(OutStockTaskQueryRequest dto); + /// 查询实体集合 + Task> GetEntityList(List ids); + /// 修改实体集合 + Task EditEntityList(List entitys, bool isTransaction = true); + + /// 删除实体集合 + Task DeleteEntityList(List ids, bool isTransaction = true); } } diff --git a/src/WMS.Web.Domain/Services/OutStockService.cs b/src/WMS.Web.Domain/Services/OutStockService.cs index 18a4683f..d2846b24 100644 --- a/src/WMS.Web.Domain/Services/OutStockService.cs +++ b/src/WMS.Web.Domain/Services/OutStockService.cs @@ -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; } + /// + /// 出库单 + /// + /// + /// + /// public async Task Save(List dto, LoginInDto loginInfo) { OutStock entity = new OutStock(); @@ -66,5 +76,50 @@ namespace WMS.Web.Domain.Services { return Task.FromResult(Result.ReSuccess()); } + /// + /// 出库任务作废 + /// + /// + /// + public async Task 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(); + } + /// + /// 出库任务合并 + /// + /// + /// + public async Task 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(); + } } } diff --git a/src/WMS.Web.Domain/Values/ResultCodes.cs b/src/WMS.Web.Domain/Values/ResultCodes.cs index 50def08b..cddf6d70 100644 --- a/src/WMS.Web.Domain/Values/ResultCodes.cs +++ b/src/WMS.Web.Domain/Values/ResultCodes.cs @@ -20,5 +20,9 @@ namespace WMS.Web.Domain.Values /// 数据操作失败 /// public static ValueTuple DateWriteError = (40004, "数据操作失败"); + + + //出库任务单 + public static ValueTuple MergeStatusError = (70000, "所选单据数据不一致,不能合并"); } } diff --git a/src/WMS.Web.Repositories/OutStockRepositories.cs b/src/WMS.Web.Repositories/OutStockRepositories.cs index 90cfa57a..b0a095fd 100644 --- a/src/WMS.Web.Repositories/OutStockRepositories.cs +++ b/src/WMS.Web.Repositories/OutStockRepositories.cs @@ -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); } + /// + /// 批量修改 + /// + /// + /// + /// + public async Task EditEntityList(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + List 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; + + } + /// + /// 根据单据头id获取数据 + /// + /// + /// + public async Task> GetEntityList(List ids) + { + var res = await _context.OutStock + .Include(s => s.Details) + .Where(f => ids.Contains(f.Id)) + .ToListAsync(); + + return res.Clone(); + } } } diff --git a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs index ee9ee67d..ee70a539 100644 --- a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs +++ b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs @@ -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 } } + /// + /// 批量删除(合并后删除原数据) + /// + /// + /// + /// + public async Task DeleteEntityList(List 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; + } + } + + /// + /// 批量修改 + /// + /// + /// + /// + public async Task EditEntityList(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + List 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; + + } + /// + /// 根据单据头id获取数据 + /// + /// + /// + public async Task> GetEntityList(List ids) + { + var res = await _context.OutStockTask + .Include(s => s.Details) + .Where(f => ids.Contains(f.Id)) + .ToListAsync(); + + return res.Clone(); + } + /// /// 列表 ///