diff --git a/src/WMS.Web.Api/Controllers/InventoryController.cs b/src/WMS.Web.Api/Controllers/InventoryController.cs index 938ac8f0..ce64bda5 100644 --- a/src/WMS.Web.Api/Controllers/InventoryController.cs +++ b/src/WMS.Web.Api/Controllers/InventoryController.cs @@ -22,14 +22,17 @@ namespace WMS.Web.Api.Controllers private readonly ILoginService _loginService; private readonly IInventoryDetailsRepositories _inventoryDetailsRepositories; private readonly IInventoryInOutDetailsRepositories _inventoryInOutDetailsRepositories; - + private readonly IBoxInventoryRepositories _boxInventoryRepositories; + public InventoryController(ILoginService loginService, IInventoryDetailsRepositories inventoryDetailsRepositories, - IInventoryInOutDetailsRepositories inventoryInOutDetailsRepositories) + IInventoryInOutDetailsRepositories inventoryInOutDetailsRepositories, + IBoxInventoryRepositories boxInventoryRepositories) { this._loginService = loginService; this._inventoryDetailsRepositories = inventoryDetailsRepositories; this._inventoryInOutDetailsRepositories = inventoryInOutDetailsRepositories; + this._boxInventoryRepositories = boxInventoryRepositories; } /// @@ -63,5 +66,21 @@ namespace WMS.Web.Api.Controllers var result = await _inventoryInOutDetailsRepositories.GetPagedList(dto); return result; } + + /// + /// 列表-箱库存明细 + /// + /// + /// + [HttpPost] + [Route("GetListBox")] + public async Task> GetPagedListBox([FromBody] BoxInventoryQueryRequest dto) + { + var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); + if (loginInfo == null || loginInfo.UserInfo == null) + return ResultPagedList.ReFailure(ResultCodes.Token_Invalid_Error); + var result = await _boxInventoryRepositories.GetPagedList(dto); + return result; + } } } diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml index d324c964..f52f3a5d 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml @@ -113,6 +113,13 @@ + + + 列表-箱库存明细 + + + + 登录接口 diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml index eb3f89aa..6ad4f45b 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml @@ -840,6 +840,86 @@ 明细 + + + 箱库存-查询请求对象 + + + + + 仓库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 01775fe3..2452347b 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -1036,6 +1036,34 @@ + + + 箱库存-仓储接口 + + + + + 列表-查询 + + + + + + + 批量添加 + + + + + + + + 批量修改 + + + + + 老ops箱信息 diff --git a/src/WMS.Web.Core/Dto/Inventory/BoxInventoryQueryRequest.cs b/src/WMS.Web.Core/Dto/Inventory/BoxInventoryQueryRequest.cs new file mode 100644 index 00000000..340b5446 --- /dev/null +++ b/src/WMS.Web.Core/Dto/Inventory/BoxInventoryQueryRequest.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto.Inventory +{ + /// + /// 箱库存-查询请求对象 + /// + public class BoxInventoryQueryRequest : PaginationBaseRequestDto + { + /// + /// 仓库ID + /// + public int? StockId { get; set; } + + /// + /// 仓位 + /// + public int? SubStockId { get; set; } + + /// + /// 箱号 + /// + public string BoxBillNo { get; set; } + + /// + /// 物料编码 + /// + public string MaterialNumber { get; set; } + } +} diff --git a/src/WMS.Web.Core/Dto/Inventory/BoxInventoryQueryResponse.cs b/src/WMS.Web.Core/Dto/Inventory/BoxInventoryQueryResponse.cs new file mode 100644 index 00000000..37a1f227 --- /dev/null +++ b/src/WMS.Web.Core/Dto/Inventory/BoxInventoryQueryResponse.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto.Inventory +{ + /// + /// 箱库存-查询响应对象 + /// + public class BoxInventoryQueryResponse + { + /// + /// ID + /// + public int Id { get; set; } + + /// + /// 明细ID + /// + public int DetailsId { get; set; } + + /// + /// 箱号 + /// + public string BoxBillNo { get; set; } + /// + /// 仓库 + /// + public string Stock { get; set; } + /// + /// 仓位 + /// + public string SubStock { get; set; } + /// + /// 物料名称 + /// + public string MaterialName { get; set; } + /// + /// 物料编码 + /// + public string MaterialNumber { get; set; } + /// + /// 物料规格型号 + /// + public string Specifications { get; set; } + /// + /// 序列号集 + /// + public string SerialNumbers { get; set; } + /// + /// 物料库存数量 + /// + public decimal Qty { get; set; } + } +} diff --git a/src/WMS.Web.Domain/Infrastructure/IBoxInventoryRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IBoxInventoryRepositories.cs new file mode 100644 index 00000000..5d9cf45f --- /dev/null +++ b/src/WMS.Web.Domain/Infrastructure/IBoxInventoryRepositories.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Dto.Inventory; +using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.Entitys; + +namespace WMS.Web.Domain.Infrastructure +{ + /// + /// 箱库存-仓储接口 + /// + public interface IBoxInventoryRepositories + { + /// + /// 列表-查询 + /// + /// + /// + Task> GetPagedList(BoxInventoryQueryRequest dto); + /// + /// 批量添加 + /// + /// + /// + /// + Task AddRange(List entitys, bool isTransaction = true); + + /// + /// 批量修改 + /// + /// + /// + /// + Task UpdateRange(List entitys, bool isTransaction = true); + } +} diff --git a/src/WMS.Web.Repositories/BoxInventoryRepositories.cs b/src/WMS.Web.Repositories/BoxInventoryRepositories.cs new file mode 100644 index 00000000..c9f751a1 --- /dev/null +++ b/src/WMS.Web.Repositories/BoxInventoryRepositories.cs @@ -0,0 +1,151 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +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.Inventory; +using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.Entitys; +using WMS.Web.Domain.Infrastructure; +using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Values.Single; +using WMS.Web.Repositories.Configuration; + +namespace WMS.Web.Repositories +{ + /// + /// 箱库存-仓储 + /// + public class BoxInventoryRepositories: IBoxInventoryRepositories + { + private readonly IMapper _mapper; + private readonly IServiceProvider _serviceProvider; + private readonly ILoginRepositories _loginRepositories; + private readonly RepositoryDbContext _context; + private readonly ISingleDataService _singleDataService; + + + public BoxInventoryRepositories(RepositoryDbContext context, + IMapper mapper, + ILoginRepositories loginRepositories, + IServiceProvider serviceProvider, + ISingleDataService singleDataService) + { + _context = context; + _mapper = mapper; + _serviceProvider = serviceProvider; + _loginRepositories = loginRepositories; + _singleDataService = singleDataService; + } + + /// + /// 列表-分页 + /// + /// + /// + public async Task> GetPagedList(BoxInventoryQueryRequest dto) + { + var query = _context.BoxInventoryDetails + .GroupJoin(_context.BoxInventory, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders }) + .SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order }) + .GroupJoin(_context.Box, p => p.order.BoxId, t => t.Id, (p, ts) => new { p.detail,p.order, ts }) + .SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box }) + .Where(adv => 1 == 1); + + if (!string.IsNullOrEmpty(dto.BoxBillNo)) + query = query.Where(w => EF.Functions.Like(w.box.BoxBillNo, "%" + dto.BoxBillNo + "%")); + + //if (!string.IsNullOrEmpty(dto.MaterialNumber)) + // query = query.Where(w => EF.Functions.Like(w.detail.BillNo, "%" + dto.BillNo + "%")); + + if (dto.StockId.HasValue) + query = query.Where(w => w.order.StockId == dto.StockId.Value); + + if (dto.SubStockId.HasValue) + query = query.Where(w => w.order.SubStockId == dto.SubStockId.Value); + + var response = new ResultPagedList(); + int total = await query.CountAsync(); + response.TotalCount = total; + + var list = await query.Select(s => new BoxInventoryQueryResponse() + { + Id = s.order.Id, + DetailsId = s.detail.Id, + BoxBillNo = s.box.BoxBillNo, + MaterialName = "", + MaterialNumber = "", + Specifications = "", + Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.order.StockId), + SubStock="", + Qty = s.detail.Qty, + }).OrderByDescending(x => x.Id).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync(); + + response.Data = list; + return response; + } + + /// + /// 批量添加 + /// + /// + /// + /// + public async Task AddRange(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + if (entitys != null && entitys.Count != 0) + { + await _context.BoxInventory.AddRangeAsync(entitys); + await _context.SaveChangesAsync(); + } + if (_transaction != null) + _transaction.Commit(); + return true; + } + catch + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + } + + /// + /// 批量修改 + /// + /// + /// + 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.BoxInventory.Include(x => x.Details).Where(f => list.Contains(f.Id)).ToListAsync(); + _mapper.Map(entitys, res); + 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/DependencyInjection/AppBuilderExtensions.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs index 4fb86fe4..3c56a965 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs @@ -42,6 +42,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient();