using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Metadata.Internal; using NPOI.POIFS.Storage; using Shentun.Peis.DirectorManagement; using Shentun.Peis.Enums; using Shentun.Peis.Models; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; namespace Shentun.Peis.DirectorManagements { /// /// 主任管理报表数据 /// [ApiExplorerSettings(GroupName = "Work")] [Authorize] public class DirectorManagementAppService : ApplicationService { private readonly IRepository _patientRegisterRepository; private readonly IRepository _patientRepository; private readonly CacheService _cacheService; private readonly IRepository _registerCheckRepository; private readonly IRepository _registerCheckAsbitemRepository; public DirectorManagementAppService( IRepository patientRegisterRepository, IRepository patientRepository, CacheService cacheService, IRepository registerCheckRepository, IRepository registerCheckAsbitemRepository) { _patientRegisterRepository = patientRegisterRepository; _patientRepository = patientRepository; _cacheService = cacheService; _registerCheckRepository = registerCheckRepository; _registerCheckAsbitemRepository = registerCheckAsbitemRepository; } /// /// 查询客户信息 /// /// [HttpPost("api/app/DirectorManagement/GetPatientList")] public async Task> GetPatientListAsync(GetPatientListInputDto input) { var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync() join patient in await _patientRepository.GetQueryableAsync() on patientRegister.PatientId equals patient.Id select new { idNo = patient.IdNo, mobileTelephone = patient.MobileTelephone, nationId = patient.NationId, patientRegister }; if (!string.IsNullOrWhiteSpace(input.IdNo)) { query = query.Where(m => m.idNo == input.IdNo); } if (!string.IsNullOrWhiteSpace(input.PatientName)) { query = query.Where(m => m.patientRegister.PatientName == input.PatientName); } if (input.DateType != null && !string.IsNullOrWhiteSpace(input.StartDate) && !string.IsNullOrWhiteSpace(input.EndDate)) { if (input.DateType == '1') { query = query.Where(m => m.patientRegister.CreationTime >= Convert.ToDateTime(input.StartDate) && m.patientRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1)); } else if (input.DateType == '2') { query = query.Where(m => m.patientRegister.MedicalStartDate != null && m.patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate) && m.patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)); } else if (input.DateType == '3') { query = query.Where(m => m.patientRegister.SummaryDate != null && m.patientRegister.SummaryDate.Value >= Convert.ToDateTime(input.StartDate) && m.patientRegister.SummaryDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)); } } var entListDto = query.ToList().Select(s => new GetPatientListDto { Age = s.patientRegister.Age == null ? "" : s.patientRegister.Age.Value.ToString(), CompleteFlag = s.patientRegister.CompleteFlag.ToString(), IdNo = s.idNo, MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(s.patientRegister.MaritalStatusId).GetAwaiter().GetResult(), MedicalStartDate = DataHelper.ConversionDateToString(s.patientRegister.MedicalStartDate), MedicalTimes = s.patientRegister.MedicalTimes, MobileTelephone = s.mobileTelephone, NationName = _cacheService.GetNationNameAsync(s.nationId).GetAwaiter().GetResult(), PatientName = s.patientRegister.PatientName, SexName = _cacheService.GetSexNameAsync(s.patientRegister.SexId).GetAwaiter().GetResult() }).ToList(); return entListDto; } /// /// 收入统计 查询某个时间断 /// /// /// [HttpPost("api/app/DirectorManagement/GetRevenueReport")] public async Task GetRevenueReportAsync(GetRevenueReportInputDto input) { if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate)) { throw new UserFriendlyException("请选择查询时间段"); } var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync() join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId where patientRegister.MedicalStartDate != null && patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate) && patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1) select new { patientRegisterId = patientRegister.Id, customerOrgId = patientRegister.CustomerOrgId, ischarge = registerCheckAsbitem.IsCharge, standardPrice = registerCheckAsbitem.StandardPrice, chargePrice = registerCheckAsbitem.ChargePrice, amount = registerCheckAsbitem.Amount }; if (input.IsCharge != null) { query = query.Where(m => m.ischarge == input.IsCharge); } var queryList = query.ToList(); if (queryList.Count == 0) { return new GetRevenueReportDto { ChargeMoney = 0, CustomerOrgCount = 0, PersonCount = 0, StandardMoney = 0, SumCount = 0 }; } var chargeMoney = queryList.Sum(s => s.chargePrice * s.amount); var standardMoney = queryList.Sum(s => s.standardPrice * s.amount); var sumCount = queryList.GroupBy(g => g.patientRegisterId).Count(); var customerOrgCount = queryList.Where(m => m.customerOrgId != GuidFlag.PersonCustomerOrgId).GroupBy(g => g.patientRegisterId).Count(); var personCount = queryList.Where(m => m.customerOrgId == GuidFlag.PersonCustomerOrgId).GroupBy(g => g.patientRegisterId).Count(); var entDto = new GetRevenueReportDto { ChargeMoney = chargeMoney, StandardMoney = standardMoney, SumCount = sumCount, CustomerOrgCount = customerOrgCount, PersonCount = personCount }; return entDto; } } }