HL7_Lock_Scanner.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using MediII.Adapter.ReceiveToScanModel;
  2. using MediII.Adapter.Scanner;
  3. using System;
  4. using System.Configuration;
  5. using Microsoft.Practices.EnterpriseLibrary.Data;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Data;
  10. using IL.Common;
  11. namespace MediII.Adapter.BizComponent.UE
  12. {
  13. public class HL7_Lock_Scanner : DBScaner
  14. {
  15. private int TaskRunTime = 5;
  16. public HL7_Lock_Scanner()
  17. {
  18. var tm = ConfigurationManager.AppSettings["TaskRunTime"];
  19. if (!int.TryParse(tm, out TaskRunTime))
  20. {
  21. TaskRunTime = 5;
  22. }
  23. }
  24. protected override long OnDo(DateTime dtEventTime, Action<LogModel> setLog)
  25. {
  26. if (setLog != null)
  27. setLog(new LogModel { Message = "开始一次解锁消息处理扫描 " });
  28. var sql = string.Format(" SELECT * FROM dbo.HL7_Receive WHERE TaskStatus=2 AND StartTime<DATEADD(mi,-{0},getdate()) ", TaskRunTime);//操作中数据
  29. try
  30. {
  31. var listRow = SqlDataAccess.ExecuteSqlStringAccessor<HL7_ReceiveEntity>(ctx, sql).Take(100).ToList();
  32. if (listRow.Count() > 0)
  33. {
  34. process(listRow, setLog);
  35. }
  36. }
  37. catch (Exception ex)
  38. {
  39. if (setLog != null)
  40. setLog(new LogModel { Message = "解锁消息发生错误", ErrorMsg = ex.Message + "\r\n" + ex.StackTrace });
  41. }
  42. return 1;
  43. }
  44. private void process(IEnumerable<HL7_ReceiveEntity> listRow, Action<LogModel> setLog)
  45. {
  46. listRow.ToList().ForEach(o =>
  47. {
  48. try
  49. {
  50. if (setLog != null)
  51. setLog(new LogModel { Message = "解锁消息:"+o.MsgContent, MessageID = o.MessageID });
  52. var sql = "UPDATE dbo.HL7_Receive SET TaskStatus=1,StartTime=NULL,TaskIP=NULL,TaskMsg = null, TaskMac=NULL WHERE ID=@ID";
  53. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, sql);
  54. SqlDataAccess.AddInParameter(ctx, cmd, "ID", DbType.String, o.ID);
  55. SqlDataAccess.ExecuteNonQuery(ctx, cmd);
  56. }
  57. catch (Exception ex)
  58. {
  59. if (setLog != null)
  60. setLog(new LogModel
  61. {
  62. Message = string.Format("解锁消息发生错误:HL7ReceiveID:{0}", o.ID),
  63. ErrorMsg = ex.Message + "\r\n" + ex.StackTrace
  64. });
  65. }
  66. });
  67. }
  68. }
  69. }