public async Task <PagerResult <PurchaseGoodsBillnoListApiModel> > GetPagerListByHospitalAsync(PagerQuery <PurchaseGoodsBillnoListQueryModel> query, int hospitalId) { var sql = from r in _context.PurchaseGoodsBillno join p in _context.PurchaseGoods on r.PurchaseGoodsId equals p.Id join x in _context.Purchase on p.PurchaseId equals x.Id join d in _context.HospitalDepartment on x.HospitalDepartmentId equals d.Id join u in _context.User on r.CreateUserId equals u.Id where d.HospitalId == hospitalId orderby r.Id descending select new PurchaseGoodsBillnoListApiModel { CreateTime = r.CreateTime, Id = r.Id, Qty = r.Qty, HospitalGoods = new GetHospitalGoodsResponse { Id = p.HospitalGoodsId, }, Billno = r.Billno, Enddate = r.Enddate, CreateUserName = u.Username, Price = r.Price, HospitalClient = new GetHospitalClientResponse { Id = p.HospitalClientId }, Status = r.Status, Purchase = new PurchaseValueModel { Id = p.PurchaseId, HospitalDepartment = new GetHospitalDepartmentResponse { Hospital = new GetHospitalResponse { Id = d.HospitalId }, Id = d.Id } }, }; sql = GetQueryableForList(sql, query.Query); var data = new PagerResult <PurchaseGoodsBillnoListApiModel>(query.Index, query.Size, sql); if (data.Total > 0) { var purachses = await _purchaseRespository.GetValueAsync(data.Result.Select(x => x.Purchase.Id).ToArray()); var clients = await _mediator.ListByIdsAsync <GetHospitalClientRequest, GetHospitalClientResponse>(data.Select(x => x.HospitalClient.Id)); var goods = await _mediator.ListByIdsAsync <GetHospitalGoodsRequest, GetHospitalGoodsResponse>(data.Select(x => x.HospitalGoods.Id).ToList()); foreach (var m in data.Result) { m.HospitalGoods = goods.FirstOrDefault(x => x.Id == m.HospitalGoods.Id); m.Purchase = purachses.FirstOrDefault(x => x.Id == m.Purchase.Id); m.HospitalClient = clients.FirstOrDefault(x => x.Id == m.HospitalClient.Id); } } return(data); }
public async Task <PagerResult <PurchaseGoodsListApiModel> > GetPagerListAsync(PagerQuery <PurchaseGoodsListQueryModel> query) { var sql = from r in _context.PurchaseGoods orderby r.Id descending select new PurchaseGoodsListApiModel { CreateTime = r.CreateTime, Id = r.Id, Qty = r.Qty, Purchase = new PurchaseValueModel { Id = r.PurchaseId, }, Status = r.Status, HospitalGoods = new GetHospitalGoodsResponse { Id = r.HospitalGoodsId, }, HospitalClient = new GetHospitalClientResponse { Id = r.HospitalClientId }, }; if (query.Query?.HospitalGoodsId != null) { sql = sql.Where(x => query.Query.HospitalGoodsId.Value == x.HospitalGoods.Id); } if (query.Query?.Status != null) { sql = sql.Where(x => query.Query.Status.Value == x.Status); } if (query.Query?.HospitalClientId != null) { sql = sql.Where(x => query.Query.HospitalClientId.Value == x.HospitalClient.Id); } if (query.Query?.HospitalGoodsId != null) { sql = sql.Where(x => query.Query.HospitalGoodsId.Value == x.HospitalGoods.Id); } if (query.Query?.PurchaseId != null) { sql = sql.Where(x => x.Purchase.Id == query.Query.PurchaseId.Value); } var data = new PagerResult <PurchaseGoodsListApiModel>(query.Index, query.Size, sql); if (data.Total > 0) { var clients = await _mediator.ListByIdsAsync <GetHospitalClientRequest, GetHospitalClientResponse>(data.Select(x => x.HospitalClient.Id)); var goods = await _mediator.ListByIdsAsync <GetHospitalGoodsRequest, GetHospitalGoodsResponse>(data.Select(x => x.HospitalGoods.Id).ToList()); var purachses = await _purchaseRespository.GetValueAsync(data.Result.Select(x => x.Purchase.Id).ToArray()); foreach (var m in data.Result) { m.HospitalClient = clients.FirstOrDefault(x => x.Id == m.HospitalClient.Id); m.HospitalGoods = goods.FirstOrDefault(x => x.Id == m.HospitalGoods.Id); m.Purchase = purachses.FirstOrDefault(x => x.Id == m.Purchase.Id); } } return(data); }