入库单创建人条件查询优化

This commit is contained in:
tongfei
2024-01-27 09:12:26 +08:00
parent e5c725ae20
commit 99d7364b13

View File

@@ -36,6 +36,7 @@ namespace WMS.Web.Repositories
private readonly ISingleDataService _singleDataService; private readonly ISingleDataService _singleDataService;
private readonly IErpService _erpService; private readonly IErpService _erpService;
private readonly IErpBasicDataExtendService _erpBasicDataExtendService; private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
private readonly IBasicsRepositories _basicsRepositories;
public InStockRepositories(RepositoryDbContext context, public InStockRepositories(RepositoryDbContext context,
@@ -44,11 +45,13 @@ namespace WMS.Web.Repositories
ILoginRepositories loginRepositories, ILoginRepositories loginRepositories,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
ISingleDataService singleDataService, ISingleDataService singleDataService,
IBasicsRepositories basicsRepositories,
IErpBasicDataExtendService erpBasicDataExtendService) IErpBasicDataExtendService erpBasicDataExtendService)
{ {
_context = context; _context = context;
_mapper = mapper; _mapper = mapper;
_erpService = erpService; _erpService = erpService;
_basicsRepositories = basicsRepositories;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_loginRepositories = loginRepositories; _loginRepositories = loginRepositories;
_singleDataService = singleDataService; _singleDataService = singleDataService;
@@ -282,6 +285,16 @@ namespace WMS.Web.Repositories
if (!string.IsNullOrEmpty(dto.MaterialNumber)) if (!string.IsNullOrEmpty(dto.MaterialNumber))
materials = materials.Where(w => w.MaterialNumber.Contains(dto.MaterialNumber)).ToList(); materials = materials.Where(w => w.MaterialNumber.Contains(dto.MaterialNumber)).ToList();
if (companyId == 0)
companyId = _loginRepositories.CompanyId;
List<int> cr_ids = new List<int>();
if (!string.IsNullOrEmpty(dto.Creator))
{
var staffList = await _basicsRepositories.GetStaffListAsync(companyId);
if (staffList != null)
cr_ids = staffList.Where(w => w.Name.Contains(dto.Creator)).Select(s => s.Id).ToList();
}
var query = _context.InStockTotalDetails var query = _context.InStockTotalDetails
.GroupJoin(_context.Instock, detail => detail.InStockId, order => order.Id, (detail, orders) => new { detail, orders }) .GroupJoin(_context.Instock, detail => detail.InStockId, order => order.Id, (detail, orders) => new { detail, orders })
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order }) .SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
@@ -302,6 +315,9 @@ namespace WMS.Web.Repositories
query = query.Where(w => w.detail.MaterialId == 0); query = query.Where(w => w.detail.MaterialId == 0);
} }
if (cr_ids.Count!=0)
query = query.Where(w => cr_ids.Contains(w.order.CreatorId));
if (dto.SupplierId.HasValue) if (dto.SupplierId.HasValue)
query = query.Where(w => w.detail.SupplierId == dto.SupplierId.Value); query = query.Where(w => w.detail.SupplierId == dto.SupplierId.Value);