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.

259 lines
12 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 weeks 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Microsoft.EntityFrameworkCore;
  2. using Microsoft.Extensions.Configuration;
  3. using Shentun.Peis.Enums;
  4. using Shentun.Peis.Models;
  5. using Shentun.Peis.PlugIns.ChargeRequests;
  6. using Shentun.Peis.SysParmValues;
  7. using Shentun.Utilities;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using Volo.Abp;
  16. using Volo.Abp.Domain.Repositories;
  17. using Volo.Abp.Domain.Services;
  18. namespace Shentun.Peis.ChargeRequests
  19. {
  20. public class ChargeRequestManager : DomainService
  21. {
  22. private readonly IRepository<ChargeRequest, Guid> _repository;
  23. private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
  24. private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository;
  25. private readonly IRepository<RegisterCheckAsbitem, Guid> _registerCheckAsbitemRepository;
  26. private readonly IRepository<PrimarykeyBuilder> _primarykeyBuilderRepository;
  27. private readonly SysParmValueManager _sysParmValueManager;
  28. private readonly IRepository<ThirdInterface, Guid> _thirdInterfaceRepository;
  29. public ChargeRequestManager(IRepository<ChargeRequest, Guid> repository,
  30. IRepository<PrimarykeyBuilder> primarykeyBuilderRepository,
  31. SysParmValueManager sysParmValueManager,
  32. IRepository<PatientRegister, Guid> patientRegisterRepository,
  33. IRepository<ThirdInterface, Guid> thirdInterfaceRepository,
  34. IRepository<RegisterCheck, Guid> registerCheckRepository,
  35. IRepository<RegisterCheckAsbitem, Guid> registerCheckAsbitemRepository)
  36. {
  37. _repository = repository;
  38. _primarykeyBuilderRepository = primarykeyBuilderRepository;
  39. _sysParmValueManager = sysParmValueManager;
  40. _patientRegisterRepository = patientRegisterRepository;
  41. _thirdInterfaceRepository = thirdInterfaceRepository;
  42. _registerCheckRepository = registerCheckRepository;
  43. _registerCheckAsbitemRepository = registerCheckAsbitemRepository;
  44. }
  45. /// <summary>
  46. /// 创建
  47. /// </summary>
  48. /// <param name="entity"></param>
  49. /// <returns></returns>
  50. public async Task<ChargeRequest> CreateAsync(
  51. ChargeRequest entity
  52. )
  53. {
  54. var patientRegister = await _patientRegisterRepository.GetAsync( entity.PatientRegisterId );
  55. return new ChargeRequest(
  56. GuidGenerator.Create()
  57. )
  58. {
  59. PatientRegisterId = entity.PatientRegisterId,
  60. HisChargeNo = entity.HisChargeNo,
  61. ChargeRequestNo = await CreateChargeRequestNo(patientRegister.MedicalCenterId),
  62. ChargeRequestFlag = ChargeRequestFlag.ChargeRequest,
  63. };
  64. }
  65. /// <summary>
  66. /// 发送申请单
  67. /// </summary>
  68. /// <param name="id"></param>
  69. /// <param name="funName"></param>
  70. /// <returns></returns>
  71. public async Task SendThirChargeRequestAsync(Guid id,string funName)
  72. {
  73. var patientRegisterEntity = (from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  74. join registerCheck in await _registerCheckRepository.GetQueryableAsync()
  75. on patientRegister.Id equals registerCheck.PatientRegisterId
  76. join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync()
  77. on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
  78. join chargeRequest in await _repository.GetQueryableAsync()
  79. on registerCheckAsbitem.ChargeRequestId equals chargeRequest.Id
  80. where chargeRequest.Id == id
  81. select new
  82. {
  83. patientRegister
  84. }).ToList().FirstOrDefault();
  85. if (patientRegisterEntity == null)
  86. {
  87. return;
  88. }
  89. var thirdInterfaces = (await _thirdInterfaceRepository.GetListAsync(o => o.ThirdInterfaceType == ThirdInterfaceTypeFlag.ChargeRequest
  90. && o.MedicalCenterId == patientRegisterEntity.patientRegister.MedicalCenterId))
  91. .OrderBy(o => o.DisplayOrder).ToList();
  92. foreach (var thirdInterface in thirdInterfaces)
  93. {
  94. var chargeRequestPlugInsInput = new ChargeRequestPlugInsInput()
  95. {
  96. ChargeRequestId = id
  97. };
  98. var parmValue = thirdInterface.ParmValue;
  99. var configurationBuilder = new ConfigurationBuilder()
  100. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  101. var config = configurationBuilder.Build();
  102. var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value;
  103. var className = config.GetSection("Interface").GetSection("ClassName").Value;
  104. object[] objects = new object[] { chargeRequestPlugInsInput };
  105. var chargeRequestPluginsOut = await ReflectionHelper.InvokeAsync<ChargeRequestPlugInsOut>(assemblyName,
  106. className, [thirdInterface.Id], funName, objects);
  107. }
  108. }
  109. //private async Task<ChargeRequestPlugInsOut> InvokeAsync(string assemblyName, string className, string classConstructorArg, string methodName, object[] args = null)
  110. //{
  111. // Assembly assembly = Assembly.Load(assemblyName);
  112. // Type type = assembly.GetType(className);
  113. // // 创建类的实例
  114. // object instance = Activator.CreateInstance(type, classConstructorArg);
  115. // // 获取方法信息
  116. // MethodInfo method = type.GetMethod(methodName);
  117. // // 调用方法,如果方法需要参数,可以传入对应的参数数组,例如: new object[] { arg1, arg2 }
  118. // ChargeRequestPlugInsOut returnValue;
  119. // var isAsync = (method.ReturnType == typeof(Task) ||
  120. // (method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)));
  121. // if (isAsync)
  122. // {
  123. // // 使用反射调用方法
  124. // //object returnValue = method.Invoke(instance, args);
  125. // returnValue = await (Task<ChargeRequestPlugInsOut>)method.Invoke(instance, args);
  126. // }
  127. // else
  128. // {
  129. // returnValue = (ChargeRequestPlugInsOut)method.Invoke(instance, args);
  130. // }
  131. // return returnValue;
  132. //}
  133. private async Task<string> CreateChargeRequestNo(Guid medicalCenterId)
  134. {
  135. string LisRequestNo = ""; //条码号
  136. string request_no_rule_coding = "0"; // 模式(0 日期+尾号 1.顺序递增)
  137. string request_no_rule_tail_len = "4"; //尾号长度
  138. string request_no_rule_prefix = "T"; //前缀
  139. request_no_rule_coding = await _sysParmValueManager.GetSysParmValueAsync(medicalCenterId, "charge_request_no_rule_coding");
  140. request_no_rule_tail_len = await _sysParmValueManager.GetSysParmValueAsync(medicalCenterId, "charge_request_no_rule_tail_len");
  141. request_no_rule_prefix = await _sysParmValueManager.GetSysParmValueAsync(medicalCenterId, "charge_request_no_rule_prefix");
  142. if (string.IsNullOrWhiteSpace(request_no_rule_coding))
  143. {
  144. throw new UserFriendlyException("收费申请单号编码方式不能为空");
  145. }
  146. if (string.IsNullOrWhiteSpace(request_no_rule_tail_len))
  147. {
  148. throw new UserFriendlyException("收费申请单号编码尾号长度不能为空");
  149. }
  150. int tailLen = 0;
  151. if (!int.TryParse(request_no_rule_tail_len, out tailLen))
  152. {
  153. throw new UserFriendlyException("收费申请单号编码尾号长度不能为空");
  154. }
  155. if (tailLen < 3)
  156. {
  157. throw new UserFriendlyException("收费申请单号编码尾号长度至少为3位");
  158. }
  159. if (string.IsNullOrWhiteSpace(request_no_rule_prefix))
  160. {
  161. request_no_rule_prefix = "";
  162. }
  163. var primarykeyBuilderEnt = await _primarykeyBuilderRepository.FirstOrDefaultAsync(f => f.PrimarykeyBuilderId == "charge_request_no");
  164. string maxnum = "1";
  165. string date = DateTime.Now.ToString("yyMMdd");// 当天
  166. if (request_no_rule_coding == "0")
  167. {
  168. //日期+尾号
  169. #region 模式0 日期+尾号
  170. if (primarykeyBuilderEnt != null)
  171. {
  172. if (primarykeyBuilderEnt.DateString != date)
  173. {
  174. //新的日期 为1 maxnum
  175. primarykeyBuilderEnt.DateString = date;
  176. maxnum = "1";
  177. }
  178. else
  179. {
  180. maxnum = (Convert.ToInt32(primarykeyBuilderEnt.SerialNo) + 1).ToString();
  181. }
  182. primarykeyBuilderEnt.SerialNo = maxnum; //更新新的序列号
  183. LisRequestNo = request_no_rule_prefix + date + maxnum.PadLeft(Convert.ToInt32(request_no_rule_tail_len), '0');
  184. await _primarykeyBuilderRepository.UpdateAsync(primarykeyBuilderEnt);
  185. }
  186. else
  187. {
  188. //初始写入
  189. LisRequestNo = request_no_rule_prefix + date + maxnum.PadLeft(Convert.ToInt32(request_no_rule_tail_len), '0');
  190. primarykeyBuilderEnt = new PrimarykeyBuilder
  191. {
  192. PrimarykeyBuilderId = "charge_request_no",
  193. DateString = date,
  194. SerialNo = maxnum
  195. };
  196. await _primarykeyBuilderRepository.InsertAsync(primarykeyBuilderEnt,true);
  197. }
  198. #endregion
  199. }
  200. else
  201. {
  202. //模式1 顺序递增
  203. #region 模式1 顺序递增
  204. if (primarykeyBuilderEnt != null)
  205. {
  206. maxnum = (Convert.ToInt32(primarykeyBuilderEnt.SerialNo) + 1).ToString();
  207. primarykeyBuilderEnt.SerialNo = maxnum; //更新num
  208. await _primarykeyBuilderRepository.UpdateAsync(primarykeyBuilderEnt);
  209. }
  210. else
  211. {
  212. //初始写入
  213. primarykeyBuilderEnt = new PrimarykeyBuilder
  214. {
  215. PrimarykeyBuilderId = "charge_request_no",
  216. DateString = "",
  217. SerialNo = maxnum
  218. };
  219. await _primarykeyBuilderRepository.InsertAsync(primarykeyBuilderEnt,true);
  220. }
  221. LisRequestNo = request_no_rule_prefix + maxnum.PadLeft(Convert.ToInt32(request_no_rule_tail_len), '0');
  222. #endregion
  223. }
  224. return LisRequestNo;
  225. }
  226. }
  227. }