Exemple #1
0
        public async Task <PagerResult <InvoiceListApiModel> > GetPagerListAsync(PagerQuery <InvoiceListQueryModel> query, int hospitalId)
        {
            var sql = from r in _context.Invoice
                      join u in _context.User on r.CreateUserId equals u.Id
                      join t in _context.DataInvoiceType on r.InvoiceTypeId equals t.Id
                      join p in _context.HospitalDepartment on r.HospitalDepartmentId equals p.Id
                      orderby r.Id descending
                      where p.HospitalId == hospitalId
                      select new InvoiceListApiModel
            {
                CreateTime         = r.CreateTime,
                Id                 = r.Id,
                CreateUserName     = u.Username,
                Name               = r.Name,
                Remark             = r.Remark,
                EndDate            = r.EndDate,
                StartDate          = r.StartDate,
                InvoiceType        = t,
                Status             = r.Status,
                HospitalDepartment = new GetHospitalDepartmentResponse {
                    Id = r.HospitalDepartmentId,
                }
            };

            if (query.Query?.HospitalDepartmentId != null)
            {
                sql = sql.Where(x => x.HospitalDepartment.Id == query.Query.HospitalDepartmentId.Value);
            }
            if (query.Query?.Status != null)
            {
                sql = sql.Where(x => x.Status == query.Query.Status.Value);
            }
            if (query.Query?.Type != null)
            {
                sql = sql.Where(x => x.InvoiceType.Id == (int)query.Query.Type.Value);
            }
            var data = new PagerResult <InvoiceListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var departments = await _mediator.ListByIdsAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(data.Select(x => x.HospitalDepartment.Id));

                foreach (var m in data.Result)
                {
                    m.HospitalDepartment = departments.FirstOrDefault(x => x.Id == m.HospitalDepartment.Id);
                }
            }
            return(data);
        }
        public async Task <PagerResult <PurchaseSettingThresholdListApiModel> > GetPagerListAsync(PagerQuery <PurchaseSettingThresholdListQueryModel> query)
        {
            var sql = from r in _context.PurchaseSettingThreshold
                      join p in _context.PurchaseSetting on r.PurchaseSettingId equals p.Id
                      join u in _context.User on r.CreateUserId equals u.Id
                      join t in _context.DataPurchaseThresholdType on r.ThresholdTypeId equals t.Id
                      orderby r.Id descending
                      select new PurchaseSettingThresholdListApiModel
            {
                CreateTime     = r.CreateTime,
                Id             = r.Id,
                CreateUserName = u.Username,
                DownQty        = r.DownQty,
                UpQty          = r.UpQty,
                HospitalGoods  = new GetHospitalGoodsResponse
                {
                    Id = r.HospitalGoodsId,
                },
                ThresholdType = t,
            };
            var data = new PagerResult <PurchaseSettingThresholdListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                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);
                }
            }
            return(data);
        }
Exemple #3
0
        public async Task <PagerResult <UserClientListApiModel> > GetPagerListAsync(PagerQuery <UserClientListQueryModel> query)
        {
            var sql = from r in _context.UserClient
                      join u in _context.User on r.CreateUserId equals u.Id
                      join s in _context.User on r.UserId equals s.Id
                      orderby r.Id descending
                      select new UserClientListApiModel
            {
                CreateTime     = r.CreateTime,
                Id             = r.Id,
                Name           = r.Name,
                CreateUserName = u.Username,
                User           = new UserValueModel
                {
                    Id       = s.Id,
                    Phone    = s.Phone,
                    Username = s.Username,
                },
                Client = new GetClientResponse
                {
                    Id = r.ClientId,
                }
            };

            if (query.Query != null && query.Query.ClientId != null)
            {
                sql = sql.Where(x => x.Client.Id == query.Query.ClientId.Value);
            }
            if (!string.IsNullOrEmpty(query.Query?.Phone))
            {
                sql = sql.Where(x => x.User.Phone.Contains(query.Query.Phone));
            }
            if (!string.IsNullOrEmpty(query.Query?.Name))
            {
                sql = sql.Where(x => x.Name.Contains(query.Query.Name));
            }
            var data = new PagerResult <UserClientListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var clients = await _mediator.ListByIdsAsync <GetClientRequest, GetClientResponse>(data.Select(x => x.Client.Id));

                foreach (var m in data.Result)
                {
                    m.Client = clients.FirstOrDefault(x => x.Id == m.Client.Id);
                }
            }
            return(data);
        }
Exemple #4
0
        public async Task <PagerResult <PurchaseGoodsListApiModel> > GetPagerListByClientAsync(PagerQuery <PurchaseGoodsListQueryModel> query, int clientId)
        {
            var sql = from r in _context.PurchaseGoods
                      join x in _context.Purchase on r.PurchaseId equals x.Id
                      join d in _context.HospitalDepartment on x.HospitalDepartmentId equals d.Id
                      join g in _context.Client2HospitalClient on r.HospitalClientId equals g.HospitalClientId
                      where g.ClientId == clientId
                      select new PurchaseGoodsListApiModel
            {
                CreateTime = r.CreateTime,
                Id         = r.Id,
                Qty        = r.Qty,
                Purchase   = new PurchaseValueModel
                {
                    Id = r.PurchaseId,
                    HospitalDepartment = new GetHospitalDepartmentResponse
                    {
                        Hospital = new GetHospitalResponse {
                            Id = d.HospitalId
                        },
                        Id = d.Id
                    }
                },
                Status        = r.Status,
                HospitalGoods = new GetHospitalGoodsResponse {
                    Id = r.HospitalGoodsId,
                },
                HospitalClient = new GetHospitalClientResponse {
                    Id = r.HospitalClientId
                },
            };

            if (query.Query?.Status != null)
            {
                sql = sql.Where(x => query.Query.Status.Value == x.Status);
            }
            if (query.Query?.PurchaseId != null)
            {
                sql = sql.Where(x => x.Purchase.Id == query.Query.PurchaseId.Value);
            }
            if (query.Query?.HospitalId != null)
            {
                sql = sql.Where(x => x.Purchase.HospitalDepartment.Hospital.Id == query.Query.HospitalId.Value);
            }
            if (query.Query?.HospitalGoodsId != null)
            {
                sql = sql.Where(x => x.HospitalGoods.Id == query.Query.HospitalGoodsId.Value);
            }
            if (query.Query?.HospitalClientId != null)
            {
                sql = sql.Where(x => query.Query.HospitalClientId.Value == x.HospitalClient.Id);
            }

            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);
        }
Exemple #5
0
        public async Task <PagerResult <StoreInoutListApiModel> > GetPagerListAsync(PagerQuery <StoreInoutListQueryModel> query)
        {
            var sql = from r in _context.StoreInout
                      join u in _context.User on r.CreateUserId equals u.Id
                      join d in _context.DataStoreChangeType on r.ChangeTypeId equals d.Id
                      orderby r.Id descending
                      select new StoreInoutListApiModel
            {
                CreateTime         = r.CreateTime,
                Id                 = r.Id,
                CreateUserName     = u.Username,
                Name               = r.Name,
                Remark             = r.Remark,
                ChangeType         = d,
                Status             = r.Status,
                HospitalDepartment = new GetHospitalDepartmentResponse {
                    Id = r.HospitalDepartmentId,
                }
            };

            if (query.Query?.HospitalDepartmentId != null)
            {
                sql = sql.Where(x => x.HospitalDepartment.Id == query.Query.HospitalDepartmentId.Value);
            }
            if (query.Query?.ChangeTypeId != null)
            {
                sql = sql.Where(x => x.ChangeType.Id == query.Query.ChangeTypeId.Value);
            }
            if (query.Query?.Status != null)
            {
                sql = sql.Where(x => x.Status == query.Query.Status.Value);
            }
            if (!string.IsNullOrEmpty(query.Query?.Name))
            {
                sql = sql.Where(x => x.Name.Contains(query.Query.Name));
            }
            var data = new PagerResult <StoreInoutListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var departments = await _mediator.ListByIdsAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(data.Select(x => x.HospitalDepartment.Id));

                foreach (var m in data.Result)
                {
                    m.HospitalDepartment = departments.FirstOrDefault(x => x.Id == m.HospitalDepartment.Id);
                }
            }
            return(data);
        }
Exemple #6
0
        public async Task <PagerResult <CheckListGoodsPreviewListApiModel> > GetPagerPreviewListAsync(int checkListId, PagerQuery <CheckListGoodsPreviewQueryModel> query)
        {
            var sql = from r in _context.CheckListGoods
                      join u in _context.User on r.CreateUserId equals u.Id
                      where r.CheckListId == checkListId
                      select new CheckListGoodsPreviewListApiModel
            {
                CreateTime    = r.CreateTime,
                Id            = r.Id,
                CheckQty      = r.CheckQty,
                HospitalGoods = new GetHospitalGoodsResponse
                {
                    Id = r.HospitalGoodsId,
                },
                CreateUsername = u.Username,
                StoreQty       = r.StoreQty,
            };
            var data = new PagerResult <CheckListGoodsPreviewListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                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);
                }
            }
            return(data);
        }
        public async Task <PagerResult <ListHospitalClientResponse> > Handle(IReceiveContext <PagerQuery <ListHospitalClientRequest> > context, CancellationToken cancellationToken)
        {
            var query = context.Message;
            var sql   = from r in _context.HospitalClient
                        join u in _context.User on r.CreateUserId equals u.Id
                        orderby r.Id descending
                        select new ListHospitalClientResponse
            {
                CreateTime = r.CreateTime,
                Id         = r.Id,
                Name       = r.Name,
                Hospital   = new GetHospitalResponse
                {
                    Id = r.HospitalId,
                },
                CreateUserName = u.Username,
            };

            if (query.Query?.HospitalId != null)
            {
                sql = sql.Where(x => x.Hospital.Id == query.Query.HospitalId.Value);
            }
            if (!string.IsNullOrEmpty(query.Query?.Name))
            {
                sql = sql.Where(x => x.Name.Contains(query.Query.Name));
            }
            var data = new PagerResult <ListHospitalClientResponse>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var hospitals = await _mediator.ListByIdsAsync <GetHospitalRequest, GetHospitalResponse>(data.Select(x => x.Hospital.Id));

                foreach (var m in data.Result)
                {
                    m.Hospital = hospitals.FirstOrDefault(x => x.Id == m.Hospital.Id);
                }
            }
            return(data);
        }
Exemple #8
0
        public async Task <PagerResult <StoreRecordListApiModel> > GetPagerRecordListByReportIdAsync(PagerQuery <int> query)
        {
            var sql = from r in _context.StoreRecord
                      join uc in _context.User on r.CreateUserId equals uc.Id
                      join ct in _context.DataStoreChangeType on r.ChangeTypeId equals ct.Id
                      join rts in _context.InvoiceReportRecord on r.Id equals rts.StoreRecordId
                      where rts.InvoiceReportId == query.Query
                      select new StoreRecordListApiModel
            {
                Id                 = r.Id,
                CreateTime         = r.CreateTime,
                CreateUserName     = uc.Username,
                ChangeQty          = r.ChangeQty,
                BeforeQty          = r.BeforeQty,
                Price              = r.Price,
                ChangeType         = ct,
                HospitalDepartment = new GetHospitalDepartmentResponse
                {
                    Id = r.HospitalDepartmentId,
                },
                HospitalGoods = new GetHospitalGoodsResponse
                {
                    Id = r.HospitalGoodsId,
                },
            };
            var data = new PagerResult <StoreRecordListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var departments = await _mediator.ListByIdsAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(data.Select(x => x.HospitalDepartment.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.HospitalDepartment = departments.FirstOrDefault(x => x.Id == m.HospitalDepartment.Id);
                }
            }
            return(data);
        }
Exemple #9
0
        public async Task <PagerResult <StoreRecordListApiModel> > GetPagerRecordListByInvoiceIdAsync(PagerQuery <int> query)
        {
            var invoice = _context.Invoice.First(x => x.Id == query.Query);
            IQueryable <StoreRecordListApiModel> sql;

            if (invoice.InvoiceTypeId == (int)InvoiceType.Client)
            {
                sql = GetPagerRecordListForClientByInvoiceId(invoice);
            }
            else
            {
                sql = GetPagerRecordListForChangeTypeByInvoiceId(invoice);
            }
            var data = new PagerResult <StoreRecordListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var departments = await _mediator.ListByIdsAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(data.Select(x => x.HospitalDepartment.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.HospitalDepartment = departments.FirstOrDefault(x => x.Id == m.HospitalDepartment.Id);
                }
            }
            return(data);
        }
Exemple #10
0
        public async Task <PagerResult <StoreRecordListApiModel> > GetPagerListAsync(PagerQuery <StoreRecordListQueryModel> query)
        {
            var sql = from r in _context.StoreRecord
                      join uc in _context.User on r.CreateUserId equals uc.Id
                      join ct in _context.DataStoreChangeType on r.ChangeTypeId equals ct.Id
                      orderby r.Id descending
                      select new StoreRecordListApiModel
            {
                Id                 = r.Id,
                CreateTime         = r.CreateTime,
                CreateUserName     = uc.Username,
                ChangeQty          = r.ChangeQty,
                BeforeQty          = r.BeforeQty,
                Price              = r.Price,
                ChangeType         = ct,
                HospitalDepartment = new GetHospitalDepartmentResponse
                {
                    Id = r.HospitalDepartmentId,
                },
                HospitalGoods = new GetHospitalGoodsResponse
                {
                    Id = r.HospitalGoodsId,
                },
            };

            if (query.Query?.HospitalDepartmentId != null)
            {
                sql = sql.Where(x => x.HospitalDepartment.Id == query.Query.HospitalDepartmentId.Value);
            }
            if (query.Query?.HospitalGoodsId != null)
            {
                sql = sql.Where(x => x.HospitalGoods.Id == query.Query.HospitalGoodsId.Value);
            }
            if (query.Query?.BeginDate != null)
            {
                sql = sql.Where(x => x.CreateTime >= query.Query.BeginDate.Value);
            }
            if (query.Query?.EndDate != null)
            {
                sql = sql.Where(x => x.CreateTime < query.Query.EndDate.Value.AddDays(1));
            }
            var data = new PagerResult <StoreRecordListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var departments = await _mediator.ListByIdsAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(data.Select(x => x.HospitalDepartment.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.HospitalDepartment = departments.FirstOrDefault(x => x.Id == m.HospitalDepartment.Id);
                }
            }
            return(data);
        }
        public async Task <PagerResult <ListHospitalGoodsStoreResponse> > Handle(IReceiveContext <PagerQuery <ListHospitalGoodsStoreRequest> > context, CancellationToken cancellationToken)
        {
            var query = context.Message;
            var sql   = from r in _context.HospitalGoods
                        join u in _context.User on r.CreateUserId equals u.Id
                        join s in _context.Store on new { HospitalGoodsId = r.Id, HospitalDepartmentId = query.Query.HospitalDepartmentId } equals new { s.HospitalGoodsId, s.HospitalDepartmentId } into ss
            from ssx in ss.DefaultIfEmpty()
            select new ListHospitalGoodsStoreResponse
            {
                CreateTime = r.CreateTime,
                Id         = r.Id,
                Name       = r.Name,
                Code       = r.Code,
                Hospital   = new GetHospitalResponse
                {
                    Id = r.HospitalId,
                },
                Producer       = r.Producer,
                Spec           = r.Spec,
                Unit           = r.Unit,
                CreateUserName = u.Username,
                IsActive       = r.IsActive,
                PinShou        = r.PinShou,
                Price          = r.Price,
                Barcode        = r.Barcode,
                Qty            = ssx != null ? ssx.Qty : 0,
            };

            if (!string.IsNullOrEmpty(query.Query?.PinShou))
            {
                sql = sql.Where(x => x.PinShou.Contains(query.Query.PinShou));
            }
            if (!string.IsNullOrEmpty(query.Query?.Barcode))
            {
                sql = sql.Where(x => x.Barcode.Contains(query.Query.Barcode));
            }
            if (!string.IsNullOrEmpty(query.Query?.Name))
            {
                sql = sql.Where(x => x.Name.Contains(query.Query.Name));
            }
            if (!string.IsNullOrEmpty(query.Query?.Code))
            {
                sql = sql.Where(x => x.Code.Contains(query.Query.Code));
            }
            if (query.Query?.IsActive != null)
            {
                sql = sql.Where(x => x.IsActive == query.Query.IsActive);
            }
            var data = new PagerResult <ListHospitalGoodsStoreResponse>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var hospitals = await _mediator.ListByIdsAsync <GetHospitalRequest, GetHospitalResponse>(data.Select(x => x.Hospital.Id));

                foreach (var m in data.Result)
                {
                    m.Hospital = hospitals.FirstOrDefault(x => x.Id == m.Hospital.Id);
                }
            }
            return(data);
        }
        public async Task <PagerResult <PurchaseGoodsBillnoListApiModel> > GetPagerListByClientAsync(PagerQuery <PurchaseGoodsBillnoListQueryModel> query, int clientId)
        {
            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 m in _context.Client2HospitalClient on p.HospitalClientId equals m.HospitalClientId
                      join u in _context.User on r.CreateUserId equals u.Id
                      where m.ClientId == clientId
                      orderby r.Id descending
                      select new PurchaseGoodsBillnoListApiModel
            {
                CreateTime      = r.CreateTime,
                Id              = r.Id,
                Qty             = r.Qty,
                PurchaseGoodsId = r.PurchaseGoodsId,
                Status          = r.Status,
                HospitalGoods   = new GetHospitalGoodsResponse {
                    Id = p.HospitalGoodsId,
                },
                HospitalClient = new GetHospitalClientResponse {
                    Id = p.HospitalClientId
                },
                Billno         = r.Billno,
                Enddate        = r.Enddate,
                CreateUserName = u.Username,
                Price          = r.Price,
                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);
        }
Exemple #13
0
        public async Task <PagerResult <StoreInoutGoodsListApiModel> > GetPagerListAsync(PagerQuery <StoreInoutGoodsListQueryModel> query)
        {
            var sql = from r in _context.StoreInoutGoods
                      orderby r.Id descending
                      select new StoreInoutGoodsListApiModel
            {
                CreateTime    = r.CreateTime,
                Id            = r.Id,
                Qty           = r.Qty,
                StoreInoutId  = r.StoreInoutId,
                HospitalGoods = new GetHospitalGoodsResponse
                {
                    Id = r.HospitalGoodsId,
                },
            };

            if (query.Query?.StoreInoutId != null)
            {
                sql = sql.Where(x => x.StoreInoutId == query.Query.StoreInoutId.Value);
            }
            var data = new PagerResult <StoreInoutGoodsListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                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);
                }
            }
            return(data);
        }
Exemple #14
0
        public async Task <PagerResult <StoreListApiModel> > GetPagerListAsync(PagerQuery <StoreListQueryModel> query)
        {
            var sql = from r in _context.Store
                      join uc in _context.User on r.CreateUserId equals uc.Id
                      join uu in _context.User on r.UpdateUserId equals uu.Id
                      select new StoreListApiModel
            {
                Id                 = r.Id,
                CreateTime         = r.CreateTime,
                CreateUserName     = uc.Username,
                UpdateTime         = r.UpdateTime,
                UpdateUserName     = uu.Username,
                Qty                = r.Qty,
                HospitalDepartment = new GetHospitalDepartmentResponse
                {
                    Id = r.HospitalDepartmentId,
                },
                HospitalGoods = new GetHospitalGoodsResponse
                {
                    Id = r.HospitalGoodsId,
                },
            };

            if (query.Query?.HospitalDepartmentId != null)
            {
                sql = sql.Where(x => x.HospitalDepartment.Id == query.Query.HospitalDepartmentId.Value);
            }
            if (query.Query?.HospitalGoodsId != null)
            {
                sql = sql.Where(x => x.HospitalGoods.Id == query.Query.HospitalGoodsId.Value);
            }
            var data = new PagerResult <StoreListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var departments = await _mediator.ListByIdsAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(data.Select(x => x.HospitalDepartment.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.HospitalDepartment = departments.FirstOrDefault(x => x.Id == m.HospitalDepartment.Id);
                }
            }
            return(data);
        }
        public async Task <PagerResult <ListHospitalDepartmentResponse> > Handle(IReceiveContext <PagerQuery <ListHospitalDepartmentRequest> > context, CancellationToken cancellationToken)
        {
            var query = context.Message;
            var sql   = from r in _context.HospitalDepartment
                        join u in _context.User on r.CreateUserId equals u.Id
                        join d in _context.DataDepartmentType on r.DepartmentTypeId equals d.Id
                        join rp in _context.HospitalDepartment on r.ParentId equals rp.Id into rp_def
                        from rp_def_t in rp_def.DefaultIfEmpty()
                        orderby r.Id descending
                        select new ListHospitalDepartmentResponse
            {
                CreateTime = r.CreateTime,
                Id         = r.Id,
                Name       = r.Name,
                Hospital   = new GetHospitalResponse
                {
                    Id = r.HospitalId
                },
                CreateUserName  = u.Username,
                DepartmentType  = d,
                IsPurchaseCheck = r.IsPurchaseCheck,
                Parent          = rp_def_t != null ? new IdNameValueModel {
                    Id = rp_def_t.Id, Name = rp_def_t.Name
                } : null,
            };

            if (query.Query?.HospitalId != null)
            {
                sql = sql.Where(x => x.Hospital.Id == query.Query.HospitalId.Value);
            }
            if (query.Query?.DepartmentTypeId != null)
            {
                sql = sql.Where(x => x.DepartmentType.Id == query.Query.DepartmentTypeId.Value);
            }
            if (!string.IsNullOrEmpty(query.Query?.Name))
            {
                sql = sql.Where(x => x.Name.Contains(query.Query.Name));
            }
            var data = new PagerResult <ListHospitalDepartmentResponse>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var hospitals = await _mediator.ListByIdsAsync <GetHospitalRequest, GetHospitalResponse>(data.Select(x => x.Hospital.Id).ToList());

                foreach (var m in data.Result)
                {
                    m.Hospital = hospitals.FirstOrDefault(x => x.Id == m.Hospital.Id);
                }
            }
            return(data);
        }
Exemple #16
0
        public async Task <PagerResult <PrescriptionListApiModel> > GetPagerListAsync(PagerQuery <PrescriptionListQueryModel> query, int hospitalId)
        {
            var sql = from p in _context.Prescription
                      join u in _context.User on p.CreateUserId equals u.Id
                      join d in _context.HospitalDepartment on p.HospitalDepartmentId equals d.Id
                      where d.HospitalId == hospitalId
                      orderby p.Id descending
                      select new PrescriptionListApiModel
            {
                Cardno             = p.Cardno,
                CreateTime         = p.CreateTime,
                CreateUserName     = u.Username,
                Id                 = p.Id,
                Status             = p.Status,
                HospitalDepartment = new GetHospitalDepartmentResponse {
                    Id = p.HospitalDepartmentId
                },
            };

            if (query.Query?.HospitalDepartmentId != null)
            {
                sql = sql.Where(x => x.HospitalDepartment.Id == query.Query.HospitalDepartmentId.Value);
            }
            if (!string.IsNullOrEmpty(query.Query?.Cardno))
            {
                sql = sql.Where(x => x.Cardno.Contains(query.Query.Cardno));
            }
            if (query.Query?.Status != null)
            {
                sql = sql.Where(x => x.Status == query.Query.Status.Value);
            }
            if (query.Query?.BeginDate != null)
            {
                sql = sql.Where(x => x.CreateTime >= query.Query.BeginDate.Value);
            }
            if (query.Query?.EndDate != null)
            {
                sql = sql.Where(x => x.CreateTime < query.Query.EndDate.Value.AddDays(1));
            }
            var data = new PagerResult <PrescriptionListApiModel>(query.Index, query.Size, sql);

            if (data.Total > 0)
            {
                var departments = await _mediator.ListByIdsAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(data.Select(x => x.HospitalDepartment.Id));

                foreach (var m in data.Result)
                {
                    m.HospitalDepartment = departments.FirstOrDefault(x => x.Id == m.HospitalDepartment.Id);
                }
            }
            return(data);
        }