X2D1PosHandle.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using DevExpress.Utils.About;
  2. using System;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Data.Entity;
  6. using System.Linq;
  7. using System.Security.Policy;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Documents;
  11. using XdCxRhDW.Dto;
  12. using XdCxRhDW.Entity;
  13. using XdCxRhDW.Repostory;
  14. namespace XdCxRhDW.App
  15. {
  16. /// <summary>
  17. /// 两星一地定位取参考
  18. /// </summary>
  19. public class X2D1PosHandle
  20. {
  21. public int TaskId;
  22. //十分钟时间内的数据
  23. private int TimeSeconds = 30 * 60;//十分钟
  24. private bool isRuning = true;
  25. BlockingCollection<X2D1NoXlNoParlPosDto> posItems = new BlockingCollection<X2D1NoXlNoParlPosDto>();
  26. public X2D1PosHandle(int taskId)
  27. {
  28. TaskId = taskId;
  29. StartMonitor();
  30. }
  31. public void StartMonitor()
  32. {
  33. Task.Run(async () =>
  34. {
  35. while (isRuning)
  36. {
  37. try
  38. {
  39. var dto = posItems.Take();
  40. FixedStation fixedStation;
  41. int fixedStationId = dto.FixedStationId.HasValue ? dto.FixedStationId.Value : 0;
  42. using (RHDWContext db = new RHDWContext())
  43. {
  44. fixedStation = await db.FixedStation.FirstOrDefaultAsync(f => f.ID == dto.FixedStationId.Value);
  45. }
  46. if (fixedStation == null)//没有固定站
  47. {
  48. SendX2D1NoXlNoParAsync(dto);
  49. continue;
  50. }
  51. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  52. {
  53. DateTime min = dto.SigTime.AddSeconds(-TimeSeconds);
  54. DateTime max = dto.SigTime.AddSeconds(TimeSeconds);
  55. //获取设定分钟之内的固定站数据
  56. var cgResRefs = await db.CgRes.Where(m => m.TaskID == dto.TaskID && m.FixedStationID == dto.FixedStationId && m.SigTime >= min && m.SigTime <= max).OrderBy(d => d.SigTime).ToListAsync();
  57. List<CgRes> matchCgList = new List<CgRes>();
  58. cgResRefs.ForEach(c =>
  59. {
  60. if ((dto.SigTime - c.SigTime).TotalSeconds <= TimeSeconds)
  61. {
  62. matchCgList.Add(c);
  63. }
  64. });
  65. var cgOrderList = matchCgList.OrderBy(d => d.SigTime).ToList();
  66. var point1 = cgOrderList.Where(c => c.SigTime <= dto.SigTime).FirstOrDefault();
  67. var point2 = cgOrderList.Where(c => c.SigTime >= dto.SigTime).FirstOrDefault();
  68. if (point1 == null || point2 == null)//若参考频点未出结果,查找目标信号出
  69. {
  70. bool isTarAny = await db.CgRes.AnyAsync(m => m.TaskID == dto.TaskID && m.TarFreqUp.HasValue&&m.TarFreqUp.Value== fixedStation.FreqUpHz && m.SigTime >= dto.SigTime);
  71. if (!isTarAny)//目标未出结果
  72. {
  73. Append(dto);
  74. continue;
  75. }
  76. }
  77. bool isSucces = false;
  78. if (point1 != null && point2 != null)
  79. {
  80. //通过双星时差及超短波时差怎么计算参考信息的时差
  81. double refDto = LinearInterpolation.CalSigTimeDto(dto.SigTime, point1.SigTime, point2.SigTime, point1.Dto1.Value, point2.Dto1.Value);
  82. double refDtoCdb = LinearInterpolation.CalSigTimeDto(dto.SigTime, point1.SigTime, point2.SigTime, point1.DtoCdb.Value, point2.DtoCdb.Value);
  83. //执行两星一地有参定位
  84. X2D1NoXlPosDto X2D1NoXlPosDto = new X2D1NoXlPosDto()
  85. {
  86. SigTime = dto.SigTime,
  87. MainCode = dto.MainCode,
  88. AdjaCode = dto.AdjaCode,
  89. SxDto = dto.SxDto,
  90. XdDto = dto.XdDto,
  91. MainYbDto = refDto,
  92. AdjaYbDto = refDtoCdb,
  93. SatTxLon = dto.SatTxLon,
  94. SatTxLat = dto.SatTxLat,
  95. CdbTxLon = dto.CdbTxLon,
  96. CdbTxLat = dto.CdbTxLat,
  97. RefLon = fixedStation.Lon,
  98. RefLat = fixedStation.Lat,
  99. FreqDown = dto.FreqDown,
  100. FreqUp = dto.FreqUp,
  101. XdDfo = dto.XdDfo,
  102. XdSnr = dto.XdSnr,
  103. SxDfo = dto.SxDfo,
  104. SxSnr = dto.SxSnr,
  105. CalcConfidence = true,
  106. TheoryDfoCalc = true,
  107. };
  108. var result = await HttpHelper.PostRequestAsync<PosResDto>(SysConfig.GetUrl("Pos/PosX2D1NoXlAsync"), X2D1NoXlPosDto);
  109. if (result.code != 200)
  110. {
  111. isSucces = false;
  112. Serilog.Log.Error($"{dto.SigTime:yyyy-MM-dd HH:mm:ss}两星一地有参定位失败{result.msg}");
  113. }
  114. else
  115. {
  116. isSucces = true;
  117. Serilog.Log.Error($"{dto.SigTime:yyyy-MM-dd HH:mm:ss}两星一地有参定位完成{result.msg}");
  118. }
  119. if (isSucces && result.data.PosLon == 999)
  120. {
  121. isSucces = false;
  122. }
  123. }
  124. if (!isSucces)
  125. {
  126. SendX2D1NoXlNoParAsync(dto);
  127. }
  128. }
  129. }
  130. catch (Exception ex)
  131. {
  132. Serilog.Log.Error(ex, $"【取参考信号流程异常{ex.Message}");
  133. }
  134. }
  135. });
  136. }
  137. /// <summary>
  138. /// 发送两星一地无参定位
  139. /// </summary>
  140. /// <param name="dto"></param>
  141. private async void SendX2D1NoXlNoParAsync(X2D1NoXlNoParlPosDto dto)
  142. {
  143. dto.BeFindRef = false;
  144. dto.FixedStationId = null;
  145. var result = await HttpHelper.PostRequestAsync<PosResDto>(SysConfig.GetUrl("Pos/PosX2D1NoXlNoParAsync"), dto);
  146. if (result.code != 200)
  147. {
  148. Serilog.Log.Error($"{dto.SigTime:yyyy-MM-dd HH:mm:ss}两星一地无参定位失败{result.msg}");
  149. }
  150. else
  151. {
  152. Serilog.Log.Error($"{dto.SigTime:yyyy-MM-dd HH:mm:ss}两星一地无参定位完成{result.msg}");
  153. }
  154. }
  155. public void Append(X2D1NoXlNoParlPosDto dto)
  156. {
  157. bool ret = posItems.TryAdd(dto);
  158. if (!ret)
  159. {
  160. Serilog.Log.Error($"【任务{dto.TaskID}】添加取参考Dto");
  161. }
  162. }
  163. public void Stop()
  164. {
  165. //当前任务停止处理
  166. isRuning = false;
  167. }
  168. }
  169. }