diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointReports/CustomerOrgInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointReports/CustomerOrgInputDto.cs new file mode 100644 index 0000000..f9761c4 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/AppointReports/CustomerOrgInputDto.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace Shentun.WebPeis.AppointReports +{ + public class CustomerOrgInputDto + { + /// + /// 单位ID 需要包含查出子级ID + /// + public Guid CustomerOrgId { get; set; } + + /// + /// 单位体检次数ID + /// + public Guid CustomerOrgRegisterId { get; set; } + + /// + /// + /// + public List CustomerOrgGroupId { get; set; } = new List(); + + /// + /// 日期类型(1、登记日期 2、体检日期 3、总检日期) + /// + public char DateType { get; set; } + + /// + /// 开始日期 + /// + public string StartDate { get; set; } + + + /// + /// 结束日期 + /// + public string EndDate { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointReports/GetAppointStatisticsReportDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointReports/GetAppointStatisticsReportDto.cs new file mode 100644 index 0000000..a8d659a --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/AppointReports/GetAppointStatisticsReportDto.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.AppointReports +{ + public class GetAppointStatisticsReportDto + { + /// + /// 单位名称 + /// + public string CustomerOrgName { get; set; } + + /// + /// 登记人数 备单人数 + /// + public int RegisterCount { get; set; } + + /// + /// 预约人数 + /// + public int AppointCount { get; set;} + + /// + /// 未预约人数 + /// + public int UnAppointCount { get; set; } + + /// + /// 已开始检查人数 + /// + public int CheckCount { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application/AppointReports/AppointReportAppService.cs b/src/Shentun.WebPeis.Application/AppointReports/AppointReportAppService.cs new file mode 100644 index 0000000..6bfb7dd --- /dev/null +++ b/src/Shentun.WebPeis.Application/AppointReports/AppointReportAppService.cs @@ -0,0 +1,120 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Shentun.WebPeis.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace Shentun.WebPeis.AppointReports +{ + /// + /// 统计 + /// + [ApiExplorerSettings(GroupName = "Work")] + //[Authorize] + public class AppointReportAppService : ApplicationService + { + private readonly IRepository _appointPatientRegisterRepository; + private readonly IRepository _patientRegisterRepository; + private readonly IRepository _customerOrgRepository; + private readonly IRepository _customerOrgRegisterRepository; + + public AppointReportAppService( + IRepository appointPatientRegisterRepository, + IRepository patientRegisterRepository, + IRepository customerOrgRepository, + IRepository customerOrgRegisterRepository) + { + _appointPatientRegisterRepository = appointPatientRegisterRepository; + _patientRegisterRepository = patientRegisterRepository; + _customerOrgRepository = customerOrgRepository; + _customerOrgRegisterRepository = customerOrgRegisterRepository; + } + + + /// + /// 获取预约统计报表 + /// + /// + [HttpPost("api/app/AppointReport/GetAppointStatisticsReport")] + public async Task> GetAppointStatisticsReportAsync(List input) + { + List result = new List(); + + if (!input.Any()) + throw new UserFriendlyException("请选择单位"); + + foreach (var item in input) + { + var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync() + join appointPatientRegister in await _appointPatientRegisterRepository.GetQueryableAsync() + on patientRegister.PatientRegisterId equals appointPatientRegister.PatientRegisterId into appointPatientRegisterTemp + from appointPatientRegisterEmpty in appointPatientRegisterTemp.DefaultIfEmpty() + join customerOrgRegister in await _customerOrgRegisterRepository.GetQueryableAsync() + on patientRegister.CustomerOrgRegisterId equals customerOrgRegister.CustomerOrgRegisterId + join customerOrg in await _customerOrgRepository.GetQueryableAsync() + on customerOrgRegister.CustomerOrgId equals customerOrg.CustomerOrgId + select new + { + patientRegister, + appointPatientRegisterEmpty, + customerOrg + }; + + if (item.CustomerOrgId == Guid.Empty) + throw new UserFriendlyException("单位不能为空"); + + if (item.CustomerOrgRegisterId == Guid.Empty) + throw new UserFriendlyException("单位体检次数不能为空"); + + + query = query.Where(m => m.patientRegister.CustomerOrgRegisterId == item.CustomerOrgRegisterId); + + if (item.CustomerOrgGroupId.Any()) + query = query.Where(m => m.patientRegister.CustomerOrgGroupId != null + && item.CustomerOrgGroupId.Contains(m.patientRegister.CustomerOrgGroupId.Value)); + + + if (!string.IsNullOrEmpty(item.StartDate) && !string.IsNullOrEmpty(item.EndDate)) + { + if (item.DateType == '1') + { + query = query.Where(m => m.patientRegister.CreationTime >= Convert.ToDateTime(item.StartDate) && + m.patientRegister.CreationTime < Convert.ToDateTime(item.EndDate).AddDays(1)); + } + else if (item.DateType == '2') + { + query = query.Where(m => m.patientRegister.MedicalStartDate >= Convert.ToDateTime(item.StartDate) && + m.patientRegister.MedicalStartDate < Convert.ToDateTime(item.EndDate).AddDays(1)); + } + else if (item.DateType == '3') + { + query = query.Where(m => m.patientRegister.SummaryDate != null && m.patientRegister.SummaryDate >= Convert.ToDateTime(item.StartDate) && + m.patientRegister.SummaryDate < Convert.ToDateTime(item.EndDate).AddDays(1)); + } + } + + var customerOrgGroup = query.ToList().GroupBy(g => g.customerOrg); + + var appointStatisticsReports = customerOrgGroup.Select(s => new GetAppointStatisticsReportDto + { + CustomerOrgName = s.Key.CustomerOrgName, + AppointCount = s.Where(m => m.appointPatientRegisterEmpty != null).Count(), + CheckCount = s.Where(m => m.patientRegister.IsMedicalStart == 'Y').Count(), + RegisterCount = s.Count(), + UnAppointCount = s.Count() - s.Where(m => m.appointPatientRegisterEmpty != null).Count() + }).ToList(); + + result.AddRange(appointStatisticsReports); + + } + + return result; + } + } +}