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.

252 lines
10 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
10 months ago
5 months ago
3 weeks ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years 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. BranchCompany = s.BranchCompany
  111. }).ToList();
  112. foreach (var item in entListDto)
  113. {
  114. Guid customerOrgGroupId;
  115. if (!Guid.TryParse(item.CustomerOrgGroupId, out customerOrgGroupId))
  116. {
  117. customerOrgGroupId = Guid.Empty;
  118. }
  119. if (customerOrgGroupId != Guid.Empty)
  120. {
  121. item.CustomerOrgGroupName = _cacheService.GetCustomerOrgGroupAsync(customerOrgGroupId).GetAwaiter().GetResult().DisplayName;
  122. }
  123. if (item.CustomerOrgId != null && item.CustomerOrgId != Guid.Empty)
  124. {
  125. item.CustomerOrgName = _cacheService.GetCustomerOrgAsync(item.CustomerOrgId.Value).GetAwaiter().GetResult().DisplayName;
  126. }
  127. }
  128. return entListDto;
  129. }
  130. /// <summary>
  131. /// 导入体检预约
  132. /// </summary>
  133. /// <param name="input"></param>
  134. /// <returns></returns>
  135. [HttpPost("api/app/ThirdBooking/CreateBookingMedicalByExcel")]
  136. public async Task CreateBookingMedicalByExcelAsync(CreateBookingMedicalByExcelInputDto input)
  137. {
  138. if (string.IsNullOrWhiteSpace(input.PatientName))
  139. throw new UserFriendlyException("名字不能为空");
  140. if (string.IsNullOrWhiteSpace(input.BookingDate))
  141. throw new UserFriendlyException("日期不能为空");
  142. if (!string.IsNullOrWhiteSpace(input.MaritalStatus)
  143. && input.MaritalStatus != "0"
  144. && input.MaritalStatus != "1")
  145. {
  146. throw new UserFriendlyException("婚姻状况格式不正确");
  147. }
  148. if (!string.IsNullOrWhiteSpace(input.EmpStatus)
  149. && input.EmpStatus != "0"
  150. && input.EmpStatus != "1")
  151. {
  152. throw new UserFriendlyException("是否在职格式不正确");
  153. }
  154. var thirdBookingEnt = new ThirdBooking(GuidGenerator.Create())
  155. {
  156. Age = input.Age,
  157. BookingDate = Convert.ToDateTime(input.BookingDate),
  158. ChildCompanyName = input.ChildCompanyName,
  159. CustomerOrgGroupId = input.CustomerOrgGroupId,
  160. DepartmentName = input.DepartmentName,
  161. EmpStatus = input.EmpStatus,
  162. ICode = "",
  163. IdNo = input.IdNo,
  164. IdType = "0",
  165. MaritalStatus = input.MaritalStatus,
  166. MedicalStatus = '0',
  167. PatientName = input.PatientName,
  168. Phone = input.Phone,
  169. PositionName = input.PositionName,
  170. SexName = input.SexName,
  171. SourceChannel = "1",
  172. BookingType = "4",
  173. ConfirmType = "2",
  174. ThirdMedicalCenterId = input.ThirdMedicalCenterId
  175. };
  176. await _thirdBookingRepository.InsertAsync(thirdBookingEnt);
  177. }
  178. /// <summary>
  179. /// 转换性别
  180. /// </summary>
  181. /// <returns></returns>
  182. private static char GetSexId(string SexName)
  183. {
  184. char SexId = 'U';
  185. if (SexName == "0" || SexName == "男")
  186. {
  187. SexId = 'M';
  188. }
  189. if (SexName == "1" || SexName == "女")
  190. {
  191. SexId = 'F';
  192. }
  193. return SexId;
  194. }
  195. /// <summary>
  196. /// 获取部门ID
  197. /// </summary>
  198. /// <param name="customerOrgList"></param>
  199. /// <param name="topCustomerOrgId">一级单位ID 集团ID</param>
  200. /// <param name="childCompanyName">子公司名称 预约填的</param>
  201. /// <param name="departmentName">部门名称 部门</param>
  202. /// <returns></returns>
  203. private static Guid? GetCustomerOrgId(List<CustomerOrg> customerOrgList, Guid? topCustomerOrgId, string childCompanyName, string departmentName)
  204. {
  205. if (topCustomerOrgId != null)
  206. {
  207. if (!string.IsNullOrWhiteSpace(childCompanyName))
  208. {
  209. var childCompanyEnt = customerOrgList.FirstOrDefault(f => f.ParentId == topCustomerOrgId && f.DisplayName == childCompanyName);
  210. if (childCompanyEnt != null)
  211. {
  212. topCustomerOrgId = childCompanyEnt.Id;
  213. if (!string.IsNullOrWhiteSpace(departmentName))
  214. {
  215. var departmentNameEnt = customerOrgList.FirstOrDefault(f => f.ParentId == topCustomerOrgId && f.DisplayName == departmentName);
  216. if (departmentNameEnt != null)
  217. {
  218. topCustomerOrgId = departmentNameEnt.Id;
  219. }
  220. }
  221. }
  222. }
  223. }
  224. return topCustomerOrgId;
  225. }
  226. }
  227. }