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.

352 lines
16 KiB

5 months ago
5 months ago
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Configuration.UserSecrets;
  4. using Newtonsoft.Json;
  5. using Shentun.PeisReport.Api.Dto;
  6. using SqlSugar;
  7. using System.Data;
  8. using static Dm.net.buffer.ByteArrayBuffer;
  9. namespace Shentun.PeisReport.Api.Controllers
  10. {
  11. /// <summary>
  12. /// 青海五院数据上传接口
  13. /// </summary>
  14. [Route("api/[controller]/[action]")]
  15. [ApiController]
  16. [ApiExplorerSettings(GroupName = "QingHaiWuYuanApi")]
  17. public class ReportController : ControllerBase
  18. {
  19. private readonly SqlSugarClient _peisDb;
  20. private readonly SqlSugarClient _reportDb;
  21. private readonly IConfiguration _configuration;
  22. private readonly ILogger<ReportController> _logger;
  23. public ReportController(
  24. IConfiguration configuration,
  25. ILogger<ReportController> logger)
  26. {
  27. _configuration = configuration;
  28. _logger = logger;
  29. _reportDb = new SqlSugarClient(new ConnectionConfig()
  30. {
  31. ConnectionString = _configuration.GetSection("ConnectionStrings:Report").Value,
  32. DbType = SqlSugar.DbType.Oracle,
  33. IsAutoCloseConnection = true
  34. });
  35. //_reportDb.Aop.OnLogExecuting = (sql, pars) =>
  36. //{
  37. // _logger.LogError(sql);
  38. // _logger.LogError("参数:" + string.Join(",", pars.Select(p => $"{p.ParameterName}={p.Value}")));
  39. //};
  40. _peisDb = new SqlSugarClient(new ConnectionConfig()
  41. {
  42. ConnectionString = _configuration.GetSection("ConnectionStrings:Default").Value,
  43. DbType = SqlSugar.DbType.SqlServer,
  44. IsAutoCloseConnection = true
  45. });
  46. }
  47. /// <summary>
  48. /// 上传体检数据
  49. /// </summary>
  50. /// <param name="input"></param>
  51. /// <returns></returns>
  52. [HttpPost]
  53. public async Task<UploadReportDto> UploadReportAsync(UploadReportInputDto input)
  54. {
  55. var result = new UploadReportDto
  56. {
  57. Code = 100,
  58. Message = "请求失败"
  59. };
  60. try
  61. {
  62. var peisQuery = await _peisDb.Ado.GetDataTableAsync($"select name as patient_name from patient_register where patient_register_id='{input.PatientRegisterId}' and create_pdf_flag='1'");
  63. if (peisQuery.Rows.Count > 0)
  64. {
  65. string patientName = peisQuery.Rows[0]["patient_name"].ToString();
  66. string directoryDate = input.PatientRegisterId.Substring(0, 6);
  67. string zWHostAddress = _configuration.GetSection("ZWHostAddress").Value;
  68. string reportVirtual = _configuration.GetSection("ReportVirtualPath:RequestPath").Value;
  69. string reportUrl = $"{zWHostAddress + reportVirtual}/{directoryDate}/{input.PatientRegisterId}({patientName}).pdf";
  70. input.bgdz = reportUrl;
  71. }
  72. var query = await _reportDb.Ado.GetDataTableAsync($"select * from TJDJ_00.tj_jbxxb where examRequestCode='{input.examRequestCode}' " +
  73. $" and yljgdm='{input.yljgdm}' and yljgmc='{input.yljgmc}' ");
  74. if (query.Rows.Count > 0)
  75. {
  76. ////修改
  77. //var exeCount = await _reportDb.Ado.ExecuteCommandAsync("update TJDJ_00.tj_jbxxb set name=@name,iDCard=@iDCard,identityType=@identityType,birthDate=@birthDate,xb=@xb,age=@age," +
  78. // "telephone=@telephone,mz=@mz,kh=@kh,klx=@klx,gzdw=@gzdw,xjzdz=@xjzdz,regCode=@regCode,scheduleDate=@scheduleDate,iTypeName=@iTypeName," +
  79. // "groupName=@groupName,tjzje=@tjzje,bgdz=@bgdz,scheduleStatus=@scheduleStatus,xgbz=@xgbz,scsj=@scsj,yljgdm=@yljgdm,yljgmc=@yljgmc where examRequestCode=@examRequestCode",
  80. // new List<SugarParameter>() {
  81. // new SugarParameter("name",input.name),
  82. // new SugarParameter("iDCard",input.iDCard),
  83. // new SugarParameter("identityType",input.identityType),
  84. // new SugarParameter("birthDate",input.birthDate),
  85. // new SugarParameter("xb",input.xb),
  86. // new SugarParameter("age",input.age),
  87. // new SugarParameter("telephone",input.telephone),
  88. // new SugarParameter("mz",input.mz),
  89. // new SugarParameter("kh",input.kh),
  90. // new SugarParameter("klx",input.klx),
  91. // new SugarParameter("gzdw",input.gzdw),
  92. // new SugarParameter("xjzdz",input.xjzdz),
  93. // new SugarParameter("examRequestCode",input.examRequestCode),
  94. // new SugarParameter("scheduleDate",input.scheduleDate),
  95. // new SugarParameter("iTypeName",input.iTypeName),
  96. // new SugarParameter("groupName",input.groupName),
  97. // new SugarParameter("regCode",input.regCode),
  98. // new SugarParameter("tjzje",input.tjzje),
  99. // new SugarParameter("bgdz",input.bgdz),
  100. // new SugarParameter("scheduleStatus",input.scheduleStatus),
  101. // new SugarParameter("xgbz","2"),
  102. // new SugarParameter("scsj",input.scsj),
  103. // new SugarParameter("yljgdm",input.yljgdm),
  104. // new SugarParameter("yljgmc",input.yljgmc)
  105. // });
  106. //修改
  107. var exeCount = await _reportDb.Ado.ExecuteCommandAsync($"update TJDJ_00.tj_jbxxb set name='{input.name}',iDCard='{input.iDCard}',identityType='{input.identityType}'," +
  108. $"birthDate='{input.birthDate}',xb='{input.xb}',age='{input.age}',telephone='{input.telephone}',mz='{input.mz}',kh='{input.kh}',klx='{input.klx}',gzdw='{input.gzdw}'," +
  109. $"xjzdz='{input.xjzdz}',regCode='{input.regCode}',scheduleDate='{input.scheduleDate}',iTypeName='{input.iTypeName}',groupName='{input.groupName}',tjzje='{input.tjzje}'," +
  110. $"bgdz='{input.bgdz}',scheduleStatus='{input.scheduleStatus}',xgbz='{input.xgbz}',scsj='{input.scsj}' " +
  111. $" where examRequestCode='{input.examRequestCode}' and yljgdm='{input.yljgdm}' and yljgmc='{input.yljgmc}' ");
  112. if (exeCount == 0)
  113. {
  114. _logger.LogError($"接口UploadReportAsync异常,更新失败:{JsonConvert.SerializeObject(input)}");
  115. result = new UploadReportDto
  116. {
  117. Code = 100,
  118. Message = "更新失败"
  119. };
  120. }
  121. else
  122. {
  123. result = new UploadReportDto
  124. {
  125. Code = 200,
  126. Message = "更新成功"
  127. };
  128. }
  129. }
  130. else
  131. {
  132. ////新增
  133. //var exeCount = await _reportDb.Ado.ExecuteCommandAsync("INSERT INTO TJDJ_00.tj_jbxxb(name,iDCard,identityType,birthDate,xb,age,telephone,mz,kh,klx,gzdw,xjzdz,examRequestCode,scheduleDate,iTypeName," +
  134. // "groupName,regCode,tjzje,bgdz,scheduleStatus,xgbz,scsj,yljgdm,yljgmc) VALUES (@name,@iDCard,@identityType,@birthDate,@xb,@age,@telephone,@mz,@kh,@klx,@gzdw,@xjzdz,@examRequestCode," +
  135. // "@scheduleDate,@iTypeName,@groupName,@regCode,@tjzje,@bgdz,@scheduleStatus,@xgbz,@scsj,@yljgdm,@yljgmc);",
  136. // new List<SugarParameter>() {
  137. // new SugarParameter("name",input.name),
  138. // new SugarParameter("iDCard",input.iDCard),
  139. // new SugarParameter("identityType",input.identityType),
  140. // new SugarParameter("birthDate",input.birthDate),
  141. // new SugarParameter("xb",input.xb),
  142. // new SugarParameter("age",input.age),
  143. // new SugarParameter("telephone",input.telephone),
  144. // new SugarParameter("mz",input.mz),
  145. // new SugarParameter("kh",input.kh),
  146. // new SugarParameter("klx",input.klx),
  147. // new SugarParameter("gzdw",input.gzdw),
  148. // new SugarParameter("xjzdz",input.xjzdz),
  149. // new SugarParameter("examRequestCode",input.examRequestCode),
  150. // new SugarParameter("scheduleDate",input.scheduleDate),
  151. // new SugarParameter("iTypeName",input.iTypeName),
  152. // new SugarParameter("groupName",input.groupName),
  153. // new SugarParameter("regCode",input.regCode),
  154. // new SugarParameter("tjzje",input.tjzje),
  155. // new SugarParameter("bgdz",input.bgdz),
  156. // new SugarParameter("scheduleStatus",input.scheduleStatus),
  157. // new SugarParameter("xgbz","1"),
  158. // new SugarParameter("scsj",input.scsj),
  159. // new SugarParameter("yljgdm",input.yljgdm),
  160. // new SugarParameter("yljgmc",input.yljgmc)
  161. // });
  162. //新增
  163. var exeCount = await _reportDb.Ado.ExecuteCommandAsync($"INSERT INTO TJDJ_00.tj_jbxxb(name,iDCard,identityType,birthDate,xb,age,telephone,mz,kh,klx,gzdw,xjzdz,examRequestCode,scheduleDate,iTypeName," +
  164. $"groupName,regCode,tjzje,bgdz,scheduleStatus,xgbz,scsj,yljgdm,yljgmc) VALUES ('{input.name}','{input.iDCard}','{input.identityType}','{input.birthDate}','{input.xb}','{input.age}'," +
  165. $"'{input.telephone}','{input.mz}','{input.kh}','{input.klx}','{input.gzdw}','{input.xjzdz}','{input.examRequestCode}'," +
  166. $"'{input.scheduleDate}','{input.iTypeName}','{input.groupName}','{input.regCode}','{input.tjzje}','{input.bgdz}','{input.scheduleStatus}','1','{input.scsj}','{input.yljgdm}','{input.yljgmc}');");
  167. if (exeCount == 0)
  168. {
  169. _logger.LogError($"接口UploadReportAsync异常,上传失败:{JsonConvert.SerializeObject(input)}");
  170. result = new UploadReportDto
  171. {
  172. Code = 100,
  173. Message = "上传失败"
  174. };
  175. }
  176. else
  177. {
  178. result = new UploadReportDto
  179. {
  180. Code = 200,
  181. Message = "上传成功"
  182. };
  183. }
  184. }
  185. }
  186. catch (Exception ex)
  187. {
  188. result.Message = ex.Message;
  189. _logger.LogError($"接口UploadReportAsync异常,上传失败:{JsonConvert.SerializeObject(input)},异常信息:{ex.ToString()}");
  190. }
  191. return result;
  192. }
  193. /// <summary>
  194. /// 撤销上传的数据
  195. /// </summary>
  196. /// <param name="input"></param>
  197. /// <returns></returns>
  198. [HttpPost]
  199. public async Task<UploadReportDto> DeleteReportAsync(DeleteReportInputDto input)
  200. {
  201. var result = new UploadReportDto
  202. {
  203. Code = 100,
  204. Message = "请求失败"
  205. };
  206. try
  207. {
  208. var query = await _reportDb.Ado.GetDataTableAsync($"select * from TJDJ_00.tj_jbxxb where examRequestCode='{input.examRequestCode}' and yljgdm='{input.yljgdm}' and yljgmc='{input.yljgmc}' ");
  209. if (query.Rows.Count > 0)
  210. {
  211. //修改
  212. var exeCount = await _reportDb.Ado.ExecuteCommandAsync($"update TJDJ_00.tj_jbxxb set xgbz='3' where examRequestCode='{input.examRequestCode}' " +
  213. " and yljgdm='{input.yljgdm}' and yljgmc='{input.yljgmc}' ");
  214. if (exeCount == 0)
  215. {
  216. _logger.LogError($"接口DeleteReportAsync异常,更新失败:{JsonConvert.SerializeObject(input)}");
  217. result = new UploadReportDto
  218. {
  219. Code = 100,
  220. Message = "更新失败"
  221. };
  222. }
  223. else
  224. {
  225. result = new UploadReportDto
  226. {
  227. Code = 200,
  228. Message = "更新成功"
  229. };
  230. }
  231. }
  232. else
  233. {
  234. result = new UploadReportDto
  235. {
  236. Code = 100,
  237. Message = "数据不存在"
  238. };
  239. }
  240. }
  241. catch (Exception ex)
  242. {
  243. result.Message = ex.Message;
  244. _logger.LogError($"接口DeleteReportAsync异常,上传失败:{JsonConvert.SerializeObject(input)},异常信息:{ex.ToString()}");
  245. }
  246. return result;
  247. }
  248. /// <summary>
  249. /// 查询测试
  250. /// </summary>
  251. /// <returns></returns>
  252. [HttpPost]
  253. public async Task<PublicResultDto> TestSqlAsync()
  254. {
  255. var result = new PublicResultDto
  256. {
  257. Code = 100,
  258. Message = "请求失败"
  259. };
  260. try
  261. {
  262. var query = _reportDb.Ado.GetScalar("select count(*) from TJDJ_00.tj_jbxxb");
  263. result = new PublicResultDto
  264. {
  265. Code = 200,
  266. Message = query.ToString()
  267. };
  268. }
  269. catch (Exception ex)
  270. {
  271. result.Message = ex.Message;
  272. _logger.LogError($"接口TestSqlAsync异常,上传失败:{ex.Message}");
  273. }
  274. return result;
  275. }
  276. ///// <summary>
  277. ///// 删除测试
  278. ///// </summary>
  279. ///// <returns></returns>
  280. //[HttpPost]
  281. //public async Task<PublicResultDto> TestDeleteSqlAsync(string examRequestCode)
  282. //{
  283. // var result = new PublicResultDto
  284. // {
  285. // Code = 100,
  286. // Message = "请求失败"
  287. // };
  288. // try
  289. // {
  290. // var query = _reportDb.Ado.ExecuteCommand("delete from TJDJ_00.tj_jbxxb where examRequestCode='{examRequestCode}' ");
  291. // result = new PublicResultDto
  292. // {
  293. // Code = 200,
  294. // Message = query.ToString()
  295. // };
  296. // }
  297. // catch (Exception ex)
  298. // {
  299. // result.Message = ex.Message;
  300. // _logger.LogError($"接口TestDeleteSqlAsync异常,失败:{ex.Message}");
  301. // }
  302. // return result;
  303. //}
  304. }
  305. }