You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
8.2 KiB

6 months ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  4. using NPOI.POIFS.Storage;
  5. using Shentun.Peis.DirectorManagement;
  6. using Shentun.Peis.Enums;
  7. using Shentun.Peis.Models;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Net.Http.Headers;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using Volo.Abp;
  15. using Volo.Abp.Application.Services;
  16. using Volo.Abp.Domain.Repositories;
  17. namespace Shentun.Peis.DirectorManagements
  18. {
  19. /// <summary>
  20. /// 主任管理报表数据
  21. /// </summary>
  22. [ApiExplorerSettings(GroupName = "Work")]
  23. [Authorize]
  24. public class DirectorManagementAppService : ApplicationService
  25. {
  26. private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
  27. private readonly IRepository<Patient, Guid> _patientRepository;
  28. private readonly CacheService _cacheService;
  29. private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository;
  30. private readonly IRepository<RegisterCheckAsbitem, Guid> _registerCheckAsbitemRepository;
  31. public DirectorManagementAppService(
  32. IRepository<PatientRegister, Guid> patientRegisterRepository,
  33. IRepository<Patient, Guid> patientRepository,
  34. CacheService cacheService,
  35. IRepository<RegisterCheck, Guid> registerCheckRepository,
  36. IRepository<RegisterCheckAsbitem, Guid> registerCheckAsbitemRepository)
  37. {
  38. _patientRegisterRepository = patientRegisterRepository;
  39. _patientRepository = patientRepository;
  40. _cacheService = cacheService;
  41. _registerCheckRepository = registerCheckRepository;
  42. _registerCheckAsbitemRepository = registerCheckAsbitemRepository;
  43. }
  44. /// <summary>
  45. /// 查询客户信息
  46. /// </summary>
  47. /// <returns></returns>
  48. [HttpPost("api/app/DirectorManagement/GetPatientList")]
  49. public async Task<List<GetPatientListDto>> GetPatientListAsync(GetPatientListInputDto input)
  50. {
  51. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  52. join patient in await _patientRepository.GetQueryableAsync() on patientRegister.PatientId equals patient.Id
  53. select new
  54. {
  55. idNo = patient.IdNo,
  56. mobileTelephone = patient.MobileTelephone,
  57. nationId = patient.NationId,
  58. patientRegister
  59. };
  60. if (!string.IsNullOrWhiteSpace(input.IdNo))
  61. {
  62. query = query.Where(m => m.idNo == input.IdNo);
  63. }
  64. if (!string.IsNullOrWhiteSpace(input.PatientName))
  65. {
  66. query = query.Where(m => m.patientRegister.PatientName == input.PatientName);
  67. }
  68. if (input.DateType != null
  69. && !string.IsNullOrWhiteSpace(input.StartDate)
  70. && !string.IsNullOrWhiteSpace(input.EndDate))
  71. {
  72. if (input.DateType == '1')
  73. {
  74. query = query.Where(m => m.patientRegister.CreationTime >= Convert.ToDateTime(input.StartDate)
  75. && m.patientRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
  76. }
  77. else if (input.DateType == '2')
  78. {
  79. query = query.Where(m => m.patientRegister.MedicalStartDate != null
  80. && m.patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate)
  81. && m.patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1));
  82. }
  83. else if (input.DateType == '3')
  84. {
  85. query = query.Where(m => m.patientRegister.SummaryDate != null
  86. && m.patientRegister.SummaryDate.Value >= Convert.ToDateTime(input.StartDate)
  87. && m.patientRegister.SummaryDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1));
  88. }
  89. }
  90. var entListDto = query.ToList().Select(s => new GetPatientListDto
  91. {
  92. Age = s.patientRegister.Age == null ? "" : s.patientRegister.Age.Value.ToString(),
  93. CompleteFlag = s.patientRegister.CompleteFlag.ToString(),
  94. IdNo = s.idNo,
  95. MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(s.patientRegister.MaritalStatusId).GetAwaiter().GetResult(),
  96. MedicalStartDate = DataHelper.ConversionDateToString(s.patientRegister.MedicalStartDate),
  97. MedicalTimes = s.patientRegister.MedicalTimes,
  98. MobileTelephone = s.mobileTelephone,
  99. NationName = _cacheService.GetNationNameAsync(s.nationId).GetAwaiter().GetResult(),
  100. PatientName = s.patientRegister.PatientName,
  101. SexName = _cacheService.GetSexNameAsync(s.patientRegister.SexId).GetAwaiter().GetResult()
  102. }).ToList();
  103. return entListDto;
  104. }
  105. /// <summary>
  106. /// 收入统计 查询某个时间断
  107. /// </summary>
  108. /// <param name="input"></param>
  109. /// <returns></returns>
  110. [HttpPost("api/app/DirectorManagement/GetRevenueReport")]
  111. public async Task<GetRevenueReportDto> GetRevenueReportAsync(GetRevenueReportInputDto input)
  112. {
  113. if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate))
  114. {
  115. throw new UserFriendlyException("请选择查询时间段");
  116. }
  117. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  118. join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId
  119. join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
  120. where patientRegister.MedicalStartDate != null
  121. && patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate)
  122. && patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)
  123. select new
  124. {
  125. patientRegisterId = patientRegister.Id,
  126. customerOrgId = patientRegister.CustomerOrgId,
  127. ischarge = registerCheckAsbitem.IsCharge,
  128. standardPrice = registerCheckAsbitem.StandardPrice,
  129. chargePrice = registerCheckAsbitem.ChargePrice,
  130. amount = registerCheckAsbitem.Amount
  131. };
  132. if (input.IsCharge != null)
  133. {
  134. query = query.Where(m => m.ischarge == input.IsCharge);
  135. }
  136. var queryList = query.ToList();
  137. if (queryList.Count == 0)
  138. {
  139. return new GetRevenueReportDto
  140. {
  141. ChargeMoney = 0,
  142. CustomerOrgCount = 0,
  143. PersonCount = 0,
  144. StandardMoney = 0,
  145. SumCount = 0
  146. };
  147. }
  148. var chargeMoney = queryList.Sum(s => s.chargePrice * s.amount);
  149. var standardMoney = queryList.Sum(s => s.standardPrice * s.amount);
  150. var sumCount = queryList.GroupBy(g => g.patientRegisterId).Count();
  151. var customerOrgCount = queryList.Where(m => m.customerOrgId != GuidFlag.PersonCustomerOrgId).GroupBy(g => g.patientRegisterId).Count();
  152. var personCount = queryList.Where(m => m.customerOrgId == GuidFlag.PersonCustomerOrgId).GroupBy(g => g.patientRegisterId).Count();
  153. var entDto = new GetRevenueReportDto
  154. {
  155. ChargeMoney = chargeMoney,
  156. StandardMoney = standardMoney,
  157. SumCount = sumCount,
  158. CustomerOrgCount = customerOrgCount,
  159. PersonCount = personCount
  160. };
  161. return entDto;
  162. }
  163. }
  164. }