PosController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Data.SqlClient;
  5. using System.Data.SQLite;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Web.Http;
  10. using PosResAnalysis;
  11. using Serilog;
  12. using XdCxRhDw.Dto;
  13. using XdCxRhDW.App.Api;
  14. using XdCxRhDW.App.EFContext;
  15. using XdCxRhDW.App.Model;
  16. using XdCxRhDW.App.WebAPI.DTO;
  17. using XdCxRhDW.Dto;
  18. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  19. using static XdCxRhDw.CpuCgTools.FormCpuCg;
  20. namespace XdCxRhDW.App.WebAPI
  21. {
  22. /// <summary>
  23. /// 定位功能相关接口
  24. /// </summary>
  25. public class PosController : BaseController
  26. {
  27. /// <summary>
  28. /// 执行两星一地定位
  29. /// </summary>
  30. /// <returns></returns>
  31. [HttpPost]
  32. public async Task<AjaxResult> PosX2D1Async(X2D1PosDto dto)
  33. {
  34. using (RHDWContext db = new RHDWContext())
  35. {
  36. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X2D1).FirstOrDefaultAsync();
  37. if (runTask == null)
  38. {
  39. Serilog.Log.Warning($"接收到两星一地定位参数,由于任务没有运行中忽略本次定位!");
  40. return Error($"多模式融合定位平台没有启动两星一地定位任务");
  41. }
  42. var listTx = await db.TxInfos.ToListAsync();
  43. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  44. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  45. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  46. var xlInfo1 = await db.XlInfos.SqlQuery("select * from XlInfo where ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))=(select min(ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))) from XlInfo where satcode=@satcode)", parameter1, parameter2).FirstOrDefaultAsync();
  47. if (xlInfo1 == null)
  48. {
  49. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  50. return Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  51. }
  52. var xlInfo2 = await db.XlInfos.SqlQuery("select * from XlInfo where ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))=(select min(ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))) from XlInfo where satcode=@satcode)", parameter1, parameter3).FirstOrDefaultAsync();
  53. if (xlInfo2 == null)
  54. {
  55. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  56. return Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  57. }
  58. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  59. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  60. var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  61. var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  62. var cgRes = db.CgRes.Add(new Model.CgRes()
  63. {
  64. SigTime = dto.SigTime,
  65. DtoSx = dto.SxDto,
  66. DfoSx = dto.SxDfo,
  67. SnrSx = dto.SxSnr,
  68. DtoCdb = dto.XdDto,
  69. DfoCdb = dto.XdDfo,
  70. SnrCdb = dto.XdSnr,
  71. YbMain = dto.MainYbDto,
  72. YbAdja = dto.AdjaYbDto,
  73. MainX = ephMain.X,
  74. MainY = ephMain.Y,
  75. MainZ = ephMain.Z,
  76. AdjaX = ephAdja.X,
  77. AdjaY = ephAdja.Y,
  78. AdjaZ = ephAdja.Z,
  79. });
  80. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  81. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  82. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  83. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  84. double[] mainSat = new double[3] { ephMain.X, ephMain.Y, ephMain.Z };
  85. double[] adjaSat = new double[3] { ephAdja.X, ephAdja.Y, ephAdja.Z };
  86. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  87. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  88. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  89. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  90. double[] res = new double[6];
  91. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, dto.SxDto / 1e6, dto.XdDto / 1e6, dto.MainYbDto / 1e6, dto.AdjaYbDto / 1e6, res);
  92. PosRes posRes = new PosRes()
  93. {
  94. SigTime = dto.SigTime,
  95. TaskID = runTask.ID,
  96. CgResID = cgRes.ID,
  97. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  98. TsName = dto.TsName,
  99. PosLon = res[0],
  100. PosLat = res[1],
  101. MirrLon = res[3],
  102. MirrLat = res[4],
  103. };
  104. db.PosRes.Add(posRes);
  105. await db.SaveChangesAsync();
  106. }
  107. return Success();
  108. }
  109. /// <summary>
  110. /// 查询定位结果(暂未实现)
  111. /// </summary>
  112. /// <param name="dto"></param>
  113. /// <returns></returns>
  114. /// <exception cref="Exception"></exception>
  115. [HttpGet]
  116. public async Task<AjaxResult<PosResDto>> GetPosRes(PosResQueryDto dto)
  117. {
  118. await Task.Delay(100);
  119. return Error<PosResDto>("该功能暂未实现!");
  120. }
  121. }
  122. }