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.

251 lines
9.9 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
6 months ago
1 month ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Configuration;
  4. using Newtonsoft.Json;
  5. using Shentun.Peis.Enums;
  6. using Shentun.Peis.Models;
  7. using Shentun.Peis.PlugIns.Sms;
  8. using SqlSugar;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using Volo.Abp;
  16. using Volo.Abp.Application.Services;
  17. using Volo.Abp.Domain.Repositories;
  18. namespace Shentun.Peis.ThirdBookings
  19. {
  20. /// <summary>
  21. /// 第三方预约记录
  22. /// </summary>
  23. [Authorize]
  24. [ApiExplorerSettings(GroupName = "Work")]
  25. public class ThirdBookingAppService : ApplicationService
  26. {
  27. private readonly IRepository<ThirdBooking, Guid> _thirdBookingRepository;
  28. private readonly IRepository<ThirdInterface, Guid> _thirdInterfaceRepository;
  29. private readonly IRepository<CustomerOrg, Guid> _customerOrgRepository;
  30. private readonly CacheService _cacheService;
  31. public ThirdBookingAppService(
  32. IRepository<ThirdBooking, Guid> thirdBookingRepository,
  33. IRepository<ThirdInterface, Guid> thirdInterfaceRepository,
  34. IRepository<CustomerOrg, Guid> customerOrgRepository,
  35. CacheService cacheService)
  36. {
  37. _thirdBookingRepository = thirdBookingRepository;
  38. _thirdInterfaceRepository = thirdInterfaceRepository;
  39. _customerOrgRepository = customerOrgRepository;
  40. _cacheService = cacheService;
  41. }
  42. /// <summary>
  43. /// 获取人寿预约记录
  44. /// </summary>
  45. /// <param name="input"></param>
  46. /// <returns></returns>
  47. [HttpPost("api/app/ThirdBooking/GetThirdBookingList")]
  48. public async Task<List<GetThirdBookingListDto>> GetThirdBookingListAsync(GetThirdBookingListInputDto input)
  49. {
  50. Guid? customerOrgRegisterId = null;
  51. Guid? customerOrgId = null;
  52. var thirdBookingInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(o => o.ThirdInterfaceType ==
  53. ThirdInterfaceTypeFlag.ThirdBooking);
  54. if (thirdBookingInterface != null && thirdBookingInterface.IsActive == 'Y')
  55. {
  56. var parmValue = thirdBookingInterface.ParmValue;
  57. var configurationBuilder = new ConfigurationBuilder()
  58. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  59. var interfaceConfig = configurationBuilder.Build();
  60. var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
  61. var customerOrgRegisterIdPara = interfaceConfig.GetSection("Interface").GetSection("CustomerOrgRegisterId").Value;
  62. var customerOrgIdPara = interfaceConfig.GetSection("Interface").GetSection("CustomerOrgId").Value;
  63. if (!string.IsNullOrWhiteSpace(isActive)
  64. && isActive == "Y")
  65. {
  66. customerOrgRegisterId = Guid.Parse(customerOrgRegisterIdPara);
  67. customerOrgId = Guid.Parse(customerOrgIdPara);
  68. }
  69. }
  70. else
  71. {
  72. throw new UserFriendlyException("请开启第三方预约");
  73. }
  74. var query = await _thirdBookingRepository.GetQueryableAsync();
  75. if (!string.IsNullOrWhiteSpace(input.StartDate) && !string.IsNullOrWhiteSpace(input.StartDate))
  76. {
  77. query = query.Where(m => m.BookingDate >= Convert.ToDateTime(input.StartDate) &&
  78. m.BookingDate < Convert.ToDateTime(input.EndDate).AddDays(1));
  79. }
  80. if (!string.IsNullOrWhiteSpace(input.KeyWord))
  81. {
  82. query = query.Where(m => m.PatientName == input.KeyWord
  83. || m.IdNo == input.KeyWord
  84. || m.Phone == input.KeyWord
  85. || m.ChildCompanyName == input.KeyWord
  86. || m.DepartmentName == input.KeyWord);
  87. }
  88. if (input.MedicalStatus != null)
  89. {
  90. query = query.Where(m => m.MedicalStatus == input.MedicalStatus);
  91. }
  92. var customerOrgList = await _customerOrgRepository.GetListAsync();
  93. var entListDto = query.ToList().Select(s => new GetThirdBookingListDto
  94. {
  95. ThirdBookingId = s.Id,
  96. Age = s.Age,
  97. BookingDate = s.BookingDate,
  98. CustomerOrgGroupId = s.CustomerOrgGroupId,
  99. IdNo = s.IdNo,
  100. MedicalStatus = s.MedicalStatus,
  101. PatientName = s.PatientName,
  102. Phone = s.Phone,
  103. SexId = GetSexId(s.SexName),
  104. ChildCompanyName = s.ChildCompanyName,
  105. DepartmentName = s.DepartmentName,
  106. CustomerOrgId = GetCustomerOrgId(customerOrgList, customerOrgId, s.ChildCompanyName, s.DepartmentName),
  107. CustomerOrgRegisterId = customerOrgRegisterId,
  108. PositionName = s.PositionName,
  109. Position2 = s.Position2
  110. }).ToList();
  111. foreach (var item in entListDto)
  112. {
  113. Guid customerOrgGroupId;
  114. if (!Guid.TryParse(item.CustomerOrgGroupId, out customerOrgGroupId))
  115. {
  116. customerOrgGroupId = Guid.Empty;
  117. }
  118. if (customerOrgGroupId != Guid.Empty)
  119. {
  120. item.CustomerOrgGroupName = _cacheService.GetCustomerOrgGroupAsync(customerOrgGroupId).GetAwaiter().GetResult().DisplayName;
  121. }
  122. if (item.CustomerOrgId != null && item.CustomerOrgId != Guid.Empty)
  123. {
  124. item.CustomerOrgName = _cacheService.GetCustomerOrgAsync(item.CustomerOrgId.Value).GetAwaiter().GetResult().DisplayName;
  125. }
  126. }
  127. return entListDto;
  128. }
  129. /// <summary>
  130. /// 导入体检预约
  131. /// </summary>
  132. /// <param name="input"></param>
  133. /// <returns></returns>
  134. [HttpPost("api/app/ThirdBooking/CreateBookingMedicalByExcel")]
  135. public async Task CreateBookingMedicalByExcelAsync(CreateBookingMedicalByExcelInputDto input)
  136. {
  137. if (string.IsNullOrWhiteSpace(input.PatientName))
  138. throw new UserFriendlyException("名字不能为空");
  139. if (string.IsNullOrWhiteSpace(input.BookingDate))
  140. throw new UserFriendlyException("日期不能为空");
  141. if (!string.IsNullOrWhiteSpace(input.MaritalStatus)
  142. && input.MaritalStatus != "0"
  143. && input.MaritalStatus != "1")
  144. {
  145. throw new UserFriendlyException("婚姻状况格式不正确");
  146. }
  147. if (!string.IsNullOrWhiteSpace(input.EmpStatus)
  148. && input.EmpStatus != "0"
  149. && input.EmpStatus != "1")
  150. {
  151. throw new UserFriendlyException("是否在职格式不正确");
  152. }
  153. var thirdBookingEnt = new ThirdBooking(GuidGenerator.Create())
  154. {
  155. Age = input.Age,
  156. BookingDate = Convert.ToDateTime(input.BookingDate),
  157. ChildCompanyName = input.ChildCompanyName,
  158. CustomerOrgGroupId = input.CustomerOrgGroupId,
  159. DepartmentName = input.DepartmentName,
  160. EmpStatus = input.EmpStatus,
  161. ICode = "",
  162. IdNo = input.IdNo,
  163. IdType = "0",
  164. MaritalStatus = input.MaritalStatus,
  165. MedicalStatus = '0',
  166. PatientName = input.PatientName,
  167. Phone = input.Phone,
  168. PositionName = input.PositionName,
  169. SexName = input.SexName,
  170. SourceChannel = "1",
  171. BookingType = "4",
  172. ConfirmType = "2",
  173. ThirdMedicalCenterId = input.ThirdMedicalCenterId
  174. };
  175. await _thirdBookingRepository.InsertAsync(thirdBookingEnt);
  176. }
  177. /// <summary>
  178. /// 转换性别
  179. /// </summary>
  180. /// <returns></returns>
  181. private static char GetSexId(string SexName)
  182. {
  183. char SexId = 'U';
  184. if (SexName == "0" || SexName == "男")
  185. {
  186. SexId = 'M';
  187. }
  188. if (SexName == "1" || SexName == "女")
  189. {
  190. SexId = 'F';
  191. }
  192. return SexId;
  193. }
  194. /// <summary>
  195. /// 获取部门ID
  196. /// </summary>
  197. /// <param name="customerOrgList"></param>
  198. /// <param name="topCustomerOrgId">一级单位ID 集团ID</param>
  199. /// <param name="childCompanyName">子公司名称 预约填的</param>
  200. /// <param name="departmentName">部门名称 部门</param>
  201. /// <returns></returns>
  202. private static Guid? GetCustomerOrgId(List<CustomerOrg> customerOrgList, Guid? topCustomerOrgId, string childCompanyName, string departmentName)
  203. {
  204. if (topCustomerOrgId != null)
  205. {
  206. if (!string.IsNullOrWhiteSpace(childCompanyName))
  207. {
  208. var childCompanyEnt = customerOrgList.FirstOrDefault(f => f.ParentId == topCustomerOrgId && f.DisplayName == childCompanyName);
  209. if (childCompanyEnt != null)
  210. {
  211. topCustomerOrgId = childCompanyEnt.Id;
  212. if (!string.IsNullOrWhiteSpace(departmentName))
  213. {
  214. var departmentNameEnt = customerOrgList.FirstOrDefault(f => f.ParentId == topCustomerOrgId && f.DisplayName == departmentName);
  215. if (departmentNameEnt != null)
  216. {
  217. topCustomerOrgId = departmentNameEnt.Id;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. return topCustomerOrgId;
  224. }
  225. }
  226. }