X2D1PosHandle.cs 8.1 KB

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