From 319c5a8c778feebcae0b7f357a0c52474b277104 Mon Sep 17 00:00:00 2001 From: tongfei <244188119@qq.com> Date: Mon, 22 Apr 2024 09:37:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml | 20 +- src/WMS.Web.Domain/Entitys/InStockTaskBox.cs | 5 + .../IInStockTaskBoxRepositories.cs | 14 +- .../Services/InStockTaskBoxService.cs | 13 +- .../InStockTaskBoxRepositories.cs | 51 ++-- .../InStockTaskRepositories.cs | 228 ++++-------------- 6 files changed, 112 insertions(+), 219 deletions(-) diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 46013013..511d4777 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -1100,6 +1100,11 @@ 收货人 + + + 是否解绑 + + 明细 @@ -2874,13 +2879,6 @@ 箱与任务单绑定(收货)关系表-仓储接口 - - - 集合:任务单ID - - - - 集合:根据boxIDS @@ -2926,6 +2924,14 @@ + + + 修改 + + + + + 入库任务-仓储接口 diff --git a/src/WMS.Web.Domain/Entitys/InStockTaskBox.cs b/src/WMS.Web.Domain/Entitys/InStockTaskBox.cs index cb2f4ba2..2fa38600 100644 --- a/src/WMS.Web.Domain/Entitys/InStockTaskBox.cs +++ b/src/WMS.Web.Domain/Entitys/InStockTaskBox.cs @@ -49,6 +49,11 @@ namespace WMS.Web.Domain.Entitys /// public int? ReceiverId { get; set; } + /// + /// 是否解绑 + /// + public bool? UnBind { get; set; } = false; + /// /// 明细 /// diff --git a/src/WMS.Web.Domain/Infrastructure/IInStockTaskBoxRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IInStockTaskBoxRepositories.cs index 5c162c05..79ff2f25 100644 --- a/src/WMS.Web.Domain/Infrastructure/IInStockTaskBoxRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IInStockTaskBoxRepositories.cs @@ -11,12 +11,6 @@ namespace WMS.Web.Domain.Infrastructure /// public interface IInStockTaskBoxRepositories { - /// - /// 集合:任务单ID - /// - /// - /// - Task> GetListBy(int taskId); /// /// 集合:根据boxIDS @@ -62,5 +56,13 @@ namespace WMS.Web.Domain.Infrastructure /// /// Task DeleteRange(List ids, bool isTransaction = true); + + /// + /// 修改 + /// + /// + /// + /// + Task UpdateRange(List entitys, bool isTransaction = true); } } diff --git a/src/WMS.Web.Domain/Services/InStockTaskBoxService.cs b/src/WMS.Web.Domain/Services/InStockTaskBoxService.cs index b5971b43..d31b96ff 100644 --- a/src/WMS.Web.Domain/Services/InStockTaskBoxService.cs +++ b/src/WMS.Web.Domain/Services/InStockTaskBoxService.cs @@ -38,7 +38,7 @@ namespace WMS.Web.Domain.Services var t_boxIds = boxIds.Distinct().ToList(); var list= await _inStockTaskBoxRepositories.GetListBy(t_boxIds); - delete_ids= list.Select(x => x.Id).ToList(); + //delete_ids= list.Select(x => x.Id).ToList(); //var boxInvetList = await _boxInventoryRepositories.GetList(t_boxIds); //foreach (var item in list) //{ @@ -47,9 +47,16 @@ namespace WMS.Web.Domain.Services // delete_ids.Add(item.Id); //} - if (delete_ids.Count != 0) + //if (delete_ids.Count != 0) + //{ + // var isSuccess= await _inStockTaskBoxRepositories.DeleteRange(delete_ids, isTransaction); + // if (!isSuccess) + // return Result.ReFailure(ResultCodes.DateWriteError); + //} + + if (list.Count != 0) { - var isSuccess= await _inStockTaskBoxRepositories.DeleteRange(delete_ids, isTransaction); + var isSuccess = await _inStockTaskBoxRepositories.UpdateRange(list, isTransaction); if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError); } diff --git a/src/WMS.Web.Repositories/InStockTaskBoxRepositories.cs b/src/WMS.Web.Repositories/InStockTaskBoxRepositories.cs index 485e6473..df6cc9e1 100644 --- a/src/WMS.Web.Repositories/InStockTaskBoxRepositories.cs +++ b/src/WMS.Web.Repositories/InStockTaskBoxRepositories.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using WMS.Web.Domain.Entitys; using WMS.Web.Domain.Infrastructure; using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Mappers; using WMS.Web.Repositories.Configuration; namespace WMS.Web.Repositories @@ -47,18 +48,6 @@ namespace WMS.Web.Repositories _erpBasicDataExtendService = erpBasicDataExtendService; } - /// - /// 集合:根据任务ID - /// - /// - /// - public async Task> GetListBy(int taskId) - { - var entitys = await _context.InstockTaskBox - .Include(s => s.Details).Where(x => x.TaskId == taskId).ToListAsync(); - return entitys; - } - /// /// 集合:根据boxIDS /// @@ -67,7 +56,7 @@ namespace WMS.Web.Repositories public async Task> GetListBy(List boxIds) { var entitys = await _context.InstockTaskBox - .Include(s => s.Details).Where(x => boxIds.Contains(x.BoxId)).ToListAsync(); + .Include(s => s.Details).Where(x => boxIds.Contains(x.BoxId) && (x.UnBind==null || x.UnBind==false)).ToListAsync(); return entitys; } @@ -79,7 +68,7 @@ namespace WMS.Web.Repositories public async Task> GetListBy(List boxBillNos) { var entitys = await _context.InstockTaskBox - .Include(s => s.Details).Where(x => boxBillNos.Contains(x.BoxBillNo)).ToListAsync(); + .Include(s => s.Details).Where(x => boxBillNos.Contains(x.BoxBillNo) && (x.UnBind == null || x.UnBind == false)).ToListAsync(); return entitys; } @@ -91,7 +80,7 @@ namespace WMS.Web.Repositories public async Task GetBy(string boxBillNo) { var entity = await _context.InstockTaskBox - .Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo).FirstOrDefaultAsync(); + .Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo && (x.UnBind == null || x.UnBind == false)).FirstOrDefaultAsync(); return entity; } @@ -103,7 +92,7 @@ namespace WMS.Web.Repositories public async Task GetBy(string boxBillNo, int? taskId) { var query = _context.InstockTaskBox - .Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo); + .Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo && (x.UnBind == null || x.UnBind == false)); if (taskId.HasValue) query = query.Where(x => x.TaskId == taskId.Value); @@ -169,5 +158,35 @@ namespace WMS.Web.Repositories } return true; } + + /// + /// 批量修改 + /// + /// + /// + public async Task UpdateRange(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.InstockTaskBox.Include(x => x.Details).Where(f => list.Contains(f.Id)).ToListAsync(); + _mapper.Map(entitys, res); + var tt = await _context.SaveChangesAsync(); + if (_transaction != null) + _transaction.Commit(); + } + catch (Exception ex) + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + return true; + } + } } } diff --git a/src/WMS.Web.Repositories/InStockTaskRepositories.cs b/src/WMS.Web.Repositories/InStockTaskRepositories.cs index f301831d..d58fdb98 100644 --- a/src/WMS.Web.Repositories/InStockTaskRepositories.cs +++ b/src/WMS.Web.Repositories/InStockTaskRepositories.cs @@ -157,195 +157,49 @@ namespace WMS.Web.Repositories var entity = await _context.InStockTask.Include(x => x.Details).Where(x => x.Id == id).FirstOrDefaultAsync(); - if (entity != null) + if (entity == null) + return null; + + var response = new InStockTaskInfoDto() { - var response = new InStockTaskInfoDto() - { - Id = entity.Id, - BillNo = entity.BillNo, - SaleBillNo = (string.Join(",", entity.Details.Select(x => x.SaleBillNo).ToList()).TrimEnd(',')), - SourceBillNo = entity.SourceBillNo, - Status = entity.Status.GetRemark(), - Type = entity.Type.GetRemark(), - Supplier = _erpBasicDataExtendService.GetSupplierName(suppliers, entity.SupplierId ?? 0), - Org = _erpBasicDataExtendService.GetOrgName(orgs, entity.OrgCode), - CreateTime = entity.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") - }; - if (entity.Type == InstockType.Purchase) - { - //采购任务的箱明细 - var boxList = await _context.InStockTaskBoxDetails - .GroupJoin(_context.InstockTaskBox, boxde => boxde.Fid, ts => ts.Id, (detail, ts) => new { detail, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, box }) - .GroupJoin(_context.InStockTaskDetails, p => p.box.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.box, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.box, taskDet }) - .Where(x => x.box.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto() - { - BoxId = x.box.BoxId, - BoxBillNo = x.box.BoxBillNo, - SaleBillNo = x.taskDet.SaleBillNo, - Method = InventoryInOutMethod.Box.GetRemark(), - MaterialNumber = x.detail.MaterialNumber, - Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber), - ReceiveTime = x.box.CreateTime.HasValue ? x.box.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", - Receiver = x.box.ReceiverId.HasValue ? _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.box.ReceiverId.Value) : "", - Qty = x.detail.ReceiveQty, - ReceiveQty = x.detail.ReceiveQty, - SerialNumbers = x.detail.SerialNumbers != null && x.detail.SerialNumbers.Count() > 0 ? (string.Join(",", x.detail.SerialNumbers).TrimEnd(',')) : "", - }).ToListAsync(); + Id = entity.Id, + BillNo = entity.BillNo, + SaleBillNo = (string.Join(",", entity.Details.Select(x => x.SaleBillNo).ToList()).TrimEnd(',')), + SourceBillNo = entity.SourceBillNo, + Status = entity.Status.GetRemark(), + Type = entity.Type.GetRemark(), + Supplier = _erpBasicDataExtendService.GetSupplierName(suppliers, entity.SupplierId ?? 0), + Org = _erpBasicDataExtendService.GetOrgName(orgs, entity.OrgCode), + CreateTime = entity.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") + }; + var boxList = await _context.InStockDetails + .GroupJoin(_context.Instock, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts }) + .SelectMany(x => x.ts.DefaultIfEmpty(), (p, order) => new { p.detail, order }) + .GroupJoin(_context.Box, p => p.detail.BoxId, ts => ts.Id, (p, ts) => new { p.detail, p.order, ts }) + .SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box }) + .GroupJoin(_context.InStockTaskDetails, p => p.detail.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.order, p.box, ts }) + .SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.order, p.box, taskDet }) + .Where(x => x.detail.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto() + { + BoxId = x.box.Id, + BoxBillNo = x.box.BoxBillNo, + Method = x.order.Method.GetRemark(), + MethodForInt = (int)x.order.Method, + MaterialNumber = x.detail.MaterialNumber, + Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber), + SaleBillNo = x.taskDet.SaleBillNo, + Qty = x.detail.Qty, + RealityQty = x.detail.Qty, + ReceiveQty = x.detail.Qty, + ShelfTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), + Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId), + Receiver = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId), + ReceiveTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), + SerialNumbers = (string.Join(",", x.detail.SerialNumbers).TrimEnd(',')) - if (boxList != null && boxList.Count != 0) - { - //采购入库明细 - var boxInstockList_details = await _context.InStockDetails.Where(x => x.TaskId == entity.Id).ToListAsync(); - - if (boxInstockList_details != null && boxInstockList_details.Count != 0) - { - var instockOrder_ids = boxInstockList_details.GroupBy(x => x.Fid).Select(x => x.Key).ToList(); - var instockOrder = await _context.Instock.Where(x => instockOrder_ids.Contains(x.Id)).ToListAsync(); - boxList.ForEach(x => - { - var currentInstock = boxInstockList_details.Where(t => t.BoxId == x.BoxId && t.MaterialNumber == x.MaterialNumber).FirstOrDefault(); - if (currentInstock != null) - { - var order = instockOrder.Where(o => o.Id == currentInstock.Fid).FirstOrDefault(); - x.RealityQty = currentInstock.Qty; - x.Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, (order == null ? 0 : order.CreatorId)); - x.ShelfTime = order == null ? "" : order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"); - } - }); - } - } - else - { - boxList = await _context.InStockDetails - .GroupJoin(_context.Instock, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, order) => new { p.detail, order }) - .GroupJoin(_context.Box, p => p.detail.BoxId, ts => ts.Id, (p, ts) => new { p.detail, p.order, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box }) - .GroupJoin(_context.InStockTaskDetails, p => p.detail.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.order, p.box, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.order, p.box, taskDet }) - .Where(x => x.detail.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto() - { - BoxId = x.box.Id, - BoxBillNo = x.box.BoxBillNo, - Method = x.order.Method.GetRemark(), - MethodForInt = (int)x.order.Method, - MaterialNumber = x.detail.MaterialNumber, - Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber), - SaleBillNo = x.taskDet.SaleBillNo, - Qty = 0, - RealityQty = x.detail.Qty, - ShelfTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), - Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId), - ReceiveQty = x.detail.Qty, - Receiver = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId), - ReceiveTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), - SerialNumbers = (string.Join(",", x.detail.SerialNumbers).TrimEnd(',')) - - }).ToListAsync(); - if (boxList != null && boxList.Count != 0) - { - var boxIds = boxList.GroupBy(x => x.BoxId).Select(x => x.Key).ToList(); - - var boxdetails = await _context.BoxDetails - .GroupJoin(_context.Box, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, box }) - .Where(x => boxIds.Contains(x.box.Id)).Select(x => new - { - BoxId = x.box.Id, - MaterialNumber = x.detail.MaterialNumber, - Qty = x.detail.Qty - }).ToListAsync(); - - if (boxdetails != null && boxdetails.Count != 0) - { - boxList.ForEach(x => - { - var method = (InventoryInOutMethod)x.MethodForInt; - if (method == InventoryInOutMethod.Box) - { - var currentBoxDet = boxdetails.Where(t => t.BoxId == x.BoxId && t.MaterialNumber == x.MaterialNumber).FirstOrDefault(); - if (currentBoxDet != null) - { - x.Qty = currentBoxDet.Qty; - } - } - }); - } - } - } - - response.Boxs = boxList; - } - else - { - var boxList = await _context.InStockDetails - .GroupJoin(_context.Instock, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, order) => new { p.detail, order }) - .GroupJoin(_context.Box, p => p.detail.BoxId, ts => ts.Id, (p, ts) => new { p.detail, p.order, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box }) - .GroupJoin(_context.InStockTaskDetails, p => p.detail.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.order, p.box, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.order, p.box, taskDet }) - .Where(x => x.detail.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto() - { - BoxId = x.box.Id, - BoxBillNo = x.box.BoxBillNo, - Method = x.order.Method.GetRemark(), - MethodForInt = (int)x.order.Method, - MaterialNumber = x.detail.MaterialNumber, - Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber), - SaleBillNo = x.taskDet.SaleBillNo, - Qty = 0, - RealityQty = x.detail.Qty, - ShelfTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), - Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId), - - ReceiveQty = x.detail.Qty, - Receiver = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId), - ReceiveTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), - - SerialNumbers = (string.Join(",", x.detail.SerialNumbers).TrimEnd(',')) - - }).ToListAsync(); - - if (boxList != null && boxList.Count != 0) - { - var boxIds = boxList.GroupBy(x => x.BoxId).Select(x => x.Key).ToList(); - - var boxdetails = await _context.BoxDetails - .GroupJoin(_context.Box, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts }) - .SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, box }) - .Where(x => boxIds.Contains(x.box.Id)).Select(x => new - { - BoxId = x.box.Id, - MaterialNumber = x.detail.MaterialNumber, - Qty = x.detail.Qty - }).ToListAsync(); - - if (boxdetails != null && boxdetails.Count != 0) - { - boxList.ForEach(x => - { - var method = (InventoryInOutMethod)x.MethodForInt; - if (method == InventoryInOutMethod.Box) - { - var currentBoxDet = boxdetails.Where(t => t.BoxId == x.BoxId && t.MaterialNumber == x.MaterialNumber).FirstOrDefault(); - if (currentBoxDet != null) - { - x.Qty = currentBoxDet.Qty; - } - } - }); - } - } - - response.Boxs = boxList; - } - - return response; - } - return null; + }).ToListAsync(); + response.Boxs = boxList; + return response; } ///