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.

351 lines
16 KiB

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