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.

225 lines
8.6 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
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
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 Dapper;
  2. using Npgsql;
  3. using Shentun.Peis.Enums;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.Common;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace Shentun.Peis.PlugIns
  11. {
  12. public class ChargeRequestPlugInsBase : ThirdPlugInsBase
  13. {
  14. public ChargeRequestPlugInsBase(string parmValue) : base(parmValue)
  15. {
  16. }
  17. public virtual async Task<ChargeRequestPlugInsOut> SendChargeRequestAsync(ChargeRequestPlugInsInput input)
  18. {
  19. var result = new ChargeRequestPlugInsOut();
  20. return result;
  21. }
  22. public virtual async Task<ChargeRequestPlugInsOut> CancelChargeRequestAsync(ChargeRequestPlugInsInput input)
  23. {
  24. var result = new ChargeRequestPlugInsOut();
  25. return result;
  26. }
  27. public virtual async Task<ChargeRequestPlugInsOut> RefundRequestAsync(ChargeRequestPlugInsInput input)
  28. {
  29. var result = new ChargeRequestPlugInsOut();
  30. return result;
  31. }
  32. public async Task<PatientRegisterForPlugIns> GetPatientRegisterAsync(Guid chargeRequestId)
  33. {
  34. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  35. {
  36. string sql;
  37. sql = @"SELECT DISTINCT patient.id as patient_id,
  38. patient_register.id as patient_register_id,
  39. patient_register.patient_register_no,
  40. patient.patient_no ,
  41. patient_register.his_patient_id,
  42. patient_register.medical_center_id,
  43. patient_register.patient_name,
  44. patient_register.sex_id,
  45. patient_register.marital_status_id,
  46. patient_register.birth_date,
  47. patient_register.age,
  48. patient.nation_id,
  49. patient.id_no,
  50. patient.email,
  51. patient.telephone,
  52. patient.mobile_telephone,
  53. patient.address
  54. from patient,patient_register,charge_request
  55. where patient.id = patient_register.patient_id and
  56. patient_register.id = charge_request.patient_register_id and
  57. charge_request.id =@ChargeRequestId
  58. ";
  59. var patientRegisterForPlugIns = (await conn.QueryAsync<PatientRegisterForPlugIns>(sql,
  60. new { ChargeRequestId = chargeRequestId })).SingleOrDefault();
  61. return patientRegisterForPlugIns;
  62. }
  63. }
  64. public async Task<ChargeRequestForPlugIns> GetChargeRequestAsync(Guid chargeRequestId)
  65. {
  66. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  67. {
  68. string sql;
  69. sql = @"SELECT id as charge_request_id,
  70. charge_request_no,
  71. his_charge_no,
  72. charge_request_flag,
  73. concurrency_stamp
  74. FROM charge_request
  75. WHERE id =@ChargeRequestId
  76. ";
  77. var chargeRequestForPlugIns = (await conn.QueryAsync<ChargeRequestForPlugIns>(sql,
  78. new { ChargeRequestId = chargeRequestId })).SingleOrDefault();
  79. if (chargeRequestForPlugIns == null)
  80. {
  81. return null;
  82. }
  83. sql = @"
  84. SELECT register_check_asbitem.asbitem_id,
  85. asbitem.display_name as asbitem_name,
  86. register_check_asbitem.amount * register_check_asbitem.charge_price as charges,
  87. register_check_asbitem.concurrency_stamp
  88. from register_check
  89. JOIN register_check_asbitem on register_check.id = register_check_asbitem.register_check_id
  90. JOIN charge_request on register_check_asbitem.charge_request_id = charge_request.id
  91. JOIN asbitem on register_check_asbitem.asbitem_id = asbitem.id
  92. where
  93. charge_request.id=@ChargeRequestId
  94. ";
  95. chargeRequestForPlugIns.Asbitems = (await conn.QueryAsync<ChargeRequestAsbitemForPlugIns>(sql,
  96. new { ChargeRequestId = chargeRequestId })).ToList();
  97. return chargeRequestForPlugIns;
  98. }
  99. }
  100. public async Task<List<ChargeRequestForPlugIns>> GetRequests(int days)
  101. {
  102. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  103. {
  104. string sql;
  105. var startDate = DateTime.Now.Date.AddDays(-days);
  106. sql = @"SELECT id as charge_request_id,
  107. charge_request_no,
  108. his_charge_no,
  109. charge_request_flag,
  110. concurrency_stamp
  111. FROM charge_request
  112. WHERE (charge_request_flag = '0' or
  113. charge_request_flag = '2' or
  114. charge_request_flag = '4')and
  115. creation_time >@StartDate
  116. ";
  117. var chargeRequestForPlugInss = (await conn.QueryAsync<ChargeRequestForPlugIns>(sql,
  118. new { StartDate = startDate })).ToList();
  119. return chargeRequestForPlugInss;
  120. }
  121. }
  122. //public async Task CancelAppChargeRequestAsync(Guid chargeRequestId)
  123. //{
  124. // using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  125. // {
  126. // string sql;
  127. // sql = @" update charge_request set charge_request_flag = '2' where id = @ChargeRequestId
  128. // ";
  129. // conn.Execute(sql,
  130. // new { ChargeRequestId = chargeRequestId });
  131. // }
  132. //}
  133. //public async Task RefundAppChargeRequestAsync(Guid chargeRequestId)
  134. //{
  135. // using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  136. // {
  137. // string sql;
  138. // sql = @" update charge_request set charge_request_flag = '3' where id = @ChargeRequestId
  139. // ";
  140. // conn.Execute(sql,
  141. // new { ChargeRequestId = chargeRequestId });
  142. // }
  143. //}
  144. public async Task SetAppChargeRequestFlagAsync(ChargeRequestForPlugIns chargeRequestForPlugIns,
  145. char chargeRequestFlag)
  146. {
  147. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  148. {
  149. //加ConcurrencyStamp,以防止并发
  150. string sql;
  151. sql = @" update charge_request set charge_request_flag =" + chargeRequestFlag +
  152. @" where id = @ChargeRequestId and concurrency_stamp = @ConcurrencyStamp
  153. ";
  154. conn.Execute(sql,
  155. new { ChargeRequestId = chargeRequestForPlugIns.ChargeRequestId,
  156. ConcurrencyStamp = chargeRequestForPlugIns.ConcurrencyStamp
  157. });
  158. foreach(var chargeRequestAsbitem in chargeRequestForPlugIns.Asbitems)
  159. {
  160. if (chargeRequestFlag == ChargeRequestFlag.AlreadyCharge)
  161. {
  162. sql = @" update register_check_asbitem set is_charge = 'Y'
  163. where charge_request_id = @ChargeRequestId and concurrency_stamp = @ConcurrencyStamp
  164. ";
  165. conn.Execute(sql,
  166. new { ChargeRequestId = chargeRequestForPlugIns.ChargeRequestId,
  167. ConcurrencyStamp = chargeRequestAsbitem.ConcurrencyStamp
  168. });
  169. }
  170. else if (chargeRequestFlag == ChargeRequestFlag.AlreadyRefund)
  171. {
  172. sql = @" update register_check_asbitem set is_charge = 'N'
  173. where charge_request_id = @ChargeRequestId and concurrency_stamp = @ConcurrencyStamp
  174. ";
  175. conn.Execute(sql,
  176. new
  177. {
  178. ChargeRequestId = chargeRequestForPlugIns.ChargeRequestId,
  179. ConcurrencyStamp = chargeRequestAsbitem.ConcurrencyStamp
  180. });
  181. }
  182. }
  183. }
  184. }
  185. public virtual async Task SyncChargeRequestFlagFromInterfaceAsync(Guid chargeRequestId)
  186. {
  187. }
  188. }
  189. public class ChargeRequestPlugInsInput
  190. {
  191. public Guid ChargeRequestId { get; set; }
  192. }
  193. //public class ChargeRequestAsbitemPlugInsInput
  194. //{
  195. //}
  196. public class ChargeRequestPlugInsOut
  197. {
  198. public string? ThirdChargeRequestId { get; set; }
  199. }
  200. }