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.

125 lines
4.6 KiB

1 year ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Configuration;
  4. using Shentun.Peis.Enums;
  5. using Shentun.Peis.Models;
  6. using Shentun.Peis.PlugIns.Sms;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Volo.Abp.Application.Services;
  14. using Volo.Abp.Domain.Repositories;
  15. namespace Shentun.Peis.ThirdBookings
  16. {
  17. /// <summary>
  18. /// 第三方预约记录
  19. /// </summary>
  20. [Authorize]
  21. [ApiExplorerSettings(GroupName = "Work")]
  22. public class ThirdBookingAppService : ApplicationService
  23. {
  24. private readonly IRepository<ThirdBooking, Guid> _thirdBookingRepository;
  25. private readonly IRepository<ThirdInterface, Guid> _thirdInterfaceRepository;
  26. public ThirdBookingAppService(
  27. IRepository<ThirdBooking, Guid> thirdBookingRepository,
  28. IRepository<ThirdInterface, Guid> thirdInterfaceRepository)
  29. {
  30. _thirdBookingRepository = thirdBookingRepository;
  31. _thirdInterfaceRepository = thirdInterfaceRepository;
  32. }
  33. /// <summary>
  34. /// 获取人寿预约记录
  35. /// </summary>
  36. /// <param name="input"></param>
  37. /// <returns></returns>
  38. [HttpPost("api/app/ThirdBooking/GetThirdBookingList")]
  39. public async Task<List<GetThirdBookingListDto>> GetThirdBookingListAsync(GetThirdBookingListInputDto input)
  40. {
  41. Guid? customerOrgRegisterId = null;
  42. Guid? customerOrgId = null;
  43. var thirdBookingInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(o => o.ThirdInterfaceType ==
  44. ThirdInterfaceTypeFlag.ThirdBooking);
  45. if (thirdBookingInterface != null && thirdBookingInterface.IsActive == 'Y')
  46. {
  47. var parmValue = thirdBookingInterface.ParmValue;
  48. var configurationBuilder = new ConfigurationBuilder()
  49. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  50. var interfaceConfig = configurationBuilder.Build();
  51. var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
  52. var customerOrgRegisterIdPara = interfaceConfig.GetSection("Interface").GetSection("CustomerOrgRegisterId").Value;
  53. var customerOrgIdPara = interfaceConfig.GetSection("Interface").GetSection("CustomerOrgId").Value;
  54. if (!string.IsNullOrWhiteSpace(isActive)
  55. && isActive == "Y")
  56. {
  57. customerOrgRegisterId = Guid.Parse(customerOrgRegisterIdPara);
  58. customerOrgId = Guid.Parse(customerOrgIdPara);
  59. }
  60. }
  61. var query = await _thirdBookingRepository.GetQueryableAsync();
  62. if (!string.IsNullOrWhiteSpace(input.StartDate) && !string.IsNullOrWhiteSpace(input.StartDate))
  63. {
  64. query = query.Where(m => m.BookingDate >= Convert.ToDateTime(input.StartDate) &&
  65. m.BookingDate < Convert.ToDateTime(input.EndDate).AddDays(1));
  66. }
  67. if (!string.IsNullOrWhiteSpace(input.KeyWord))
  68. {
  69. query = query.Where(m => m.PatientName == input.KeyWord
  70. || m.IdNo == input.KeyWord || m.Phone == input.KeyWord);
  71. }
  72. if (input.MedicalStatus != null)
  73. {
  74. query = query.Where(m => m.MedicalStatus == input.MedicalStatus);
  75. }
  76. var entListDto = query.Select(s => new GetThirdBookingListDto
  77. {
  78. ThirdBookingId = s.Id,
  79. Age = s.Age,
  80. BookingDate = s.BookingDate,
  81. CustomerOrgGroupId = s.CustomerOrgGroupId,
  82. IdNo = s.IdNo,
  83. MedicalStatus = s.MedicalStatus,
  84. PatientName = s.PatientName,
  85. Phone = s.Phone,
  86. SexId = GetSexId(s.SexName),
  87. CustomerOrgId = customerOrgId,
  88. CustomerOrgRegisterId = customerOrgRegisterId,
  89. }).ToList();
  90. return entListDto;
  91. }
  92. /// <summary>
  93. /// 转换性别
  94. /// </summary>
  95. /// <returns></returns>
  96. private static char GetSexId(string SexName)
  97. {
  98. char SexId = 'U';
  99. if (SexName == "0" || SexName == "男")
  100. {
  101. SexId = 'M';
  102. }
  103. if (SexName == "1" || SexName == "女")
  104. {
  105. SexId = 'F';
  106. }
  107. return SexId;
  108. }
  109. }
  110. }