AdminTestFunctionExcutor.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Threading.Tasks;
  11. using DirectService.Tools;
  12. using JLHHJSvr.BLL;
  13. using JLHHJSvr.Com;
  14. using JLHHJSvr.Com.Model;
  15. using JLHHJSvr.DBA.DBModle;
  16. using JLHHJSvr.Helper;
  17. using JLHHJSvr.LJException;
  18. using LJLib.DAL.SQL;
  19. using LJLib.Net.SPI.Server;
  20. using LJLib.SQLEX;
  21. using LJLib.TextLog;
  22. using LJLib.Tools.Encry;
  23. using Newtonsoft.Json.Linq;
  24. namespace JLHHJSvr.Excutor
  25. {
  26. internal sealed class AdminTestFunctionExcutor : ExcutorBase<AdminTestFunctionRequest, AdminTestFunctionResponse>
  27. {
  28. string path = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"), "filterlog.log");
  29. string path2 = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"), "filterlog_result2.log");
  30. protected override void ExcuteInternal(AdminTestFunctionRequest request, object state2, AdminTestFunctionResponse rslt)
  31. {
  32. //FilterLogs("8:00", "16:00");
  33. psw_bczh3 pswhelper = new psw_bczh3();
  34. var psw = pswhelper.GetEntrypt(request.requestStr, 1, "123457851239866");
  35. rslt.resultStr = psw;
  36. //new RequestLogger();
  37. //string path = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"), "filterlog.log");
  38. //string path2 = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"), "filterlog_result.log");
  39. //#region
  40. //try
  41. //{
  42. // var filteredLogs = new List<string>();
  43. // int matchCount = 0;
  44. // var currentBlock = new StringBuilder(1024);
  45. // bool isTargetRequest = false;
  46. // bool hasTargetMattressId = false;
  47. // foreach (string line in File.ReadLines(path))
  48. // {
  49. // if (line.StartsWith("===================================================================="))
  50. // {
  51. // // 检查当前块是否匹配
  52. // if (isTargetRequest && hasTargetMattressId)
  53. // {
  54. // filteredLogs.Add(currentBlock.ToString());
  55. // matchCount++;
  56. // }
  57. // // 重置状态,开始新块
  58. // currentBlock.Clear();
  59. // isTargetRequest = false;
  60. // hasTargetMattressId = false;
  61. // }
  62. // currentBlock.AppendLine(line);
  63. // // 快速检测关键信息
  64. // if (line.Contains("SaveMattressInterfaceRequest请求报文:"))
  65. // {
  66. // isTargetRequest = true;
  67. // }
  68. // if (isTargetRequest && line.Contains("\"mattressid\":21665686"))
  69. // {
  70. // hasTargetMattressId = true;
  71. // }
  72. // }
  73. // // 检查最后一个块
  74. // if (isTargetRequest && hasTargetMattressId)
  75. // {
  76. // filteredLogs.Add(currentBlock.ToString());
  77. // matchCount++;
  78. // }
  79. // File.WriteAllText(path2, string.Join("\n\n", filteredLogs));
  80. // Console.WriteLine($"筛选完成!共找到 {matchCount} 条符合条件的日志");
  81. //}
  82. //catch (Exception ex)
  83. //{
  84. // Console.WriteLine($"错误: {ex.Message}");
  85. //}
  86. //#endregion
  87. }
  88. private void FilterLogs(string startTimeInput, string endTimeInput)
  89. {
  90. try
  91. {
  92. TimeSpan startTime = TimeSpan.Parse(startTimeInput);
  93. TimeSpan endTime = TimeSpan.Parse(endTimeInput);
  94. var filteredLogs = new List<string>();
  95. int matchCount = 0;
  96. var currentBlock = new StringBuilder(1024);
  97. bool isTargetRequest = false;
  98. bool hasTargetMattressId = false;
  99. DateTime? currentTime = null;
  100. foreach (string line in File.ReadLines(path))
  101. {
  102. if (line.StartsWith("===================================================================="))
  103. {
  104. // 检查当前块是否在指定时间范围内且包含目标mattressid
  105. if (currentTime.HasValue && IsInTimeRange(currentTime.Value, startTime, endTime) &&
  106. isTargetRequest && hasTargetMattressId)
  107. {
  108. filteredLogs.Add(currentBlock.ToString());
  109. matchCount++;
  110. }
  111. // 重置状态
  112. currentBlock.Clear();
  113. isTargetRequest = false;
  114. hasTargetMattressId = false;
  115. currentTime = null;
  116. }
  117. currentBlock.AppendLine(line);
  118. // 解析时间
  119. if (line.StartsWith("时间:") && currentTime == null)
  120. {
  121. string timeStr = line.Substring(3).Trim();
  122. if (DateTime.TryParse(timeStr, out DateTime parsedTime))
  123. {
  124. currentTime = parsedTime;
  125. }
  126. }
  127. // 检测关键信息
  128. if (line.Contains("RefreshMattressInterfaceQdRequest请求报文:") || line.Contains("SaveMattressInterfaceRequest请求报文:"))
  129. {
  130. isTargetRequest = true;
  131. }
  132. if (line.Contains("\"mattressid\":21669844"))
  133. {
  134. hasTargetMattressId = true;
  135. }
  136. }
  137. // 处理最后一个块
  138. if (currentTime.HasValue && IsInTimeRange(currentTime.Value, startTime, endTime) &&
  139. isTargetRequest && hasTargetMattressId)
  140. {
  141. filteredLogs.Add(currentBlock.ToString());
  142. matchCount++;
  143. }
  144. File.WriteAllText(path2, string.Join("\n\n", filteredLogs));
  145. Console.WriteLine($"筛选完成!共找到 {matchCount} 条 {startTime}-{endTime} 时间段的日志");
  146. }
  147. catch (Exception ex)
  148. {
  149. Console.WriteLine($"错误: {ex.Message}");
  150. }
  151. }
  152. private static bool IsInTimeRange(DateTime time, TimeSpan start, TimeSpan end)
  153. {
  154. TimeSpan currentTime = time.TimeOfDay;
  155. return currentTime >= start && currentTime <= end;
  156. }
  157. }
  158. }