PosController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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.Net.Http;
  8. using System.Security.Cryptography.Xml;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Web.Http;
  12. using System.Windows.Documents;
  13. using DevExpress.Mvvm.Native;
  14. using DevExpress.XtraCharts;
  15. using DevExpress.XtraPrinting;
  16. using Newtonsoft.Json;
  17. using PosResAnalysis;
  18. using Serilog;
  19. using Swashbuckle.Swagger;
  20. using XdCxRhDw.Dto;
  21. using XdCxRhDW.App.Api;
  22. using XdCxRhDW.App.App.Properties;
  23. using XdCxRhDW.App.EFContext;
  24. using XdCxRhDW.App.Model;
  25. using XdCxRhDW.App.WebAPI.DTO;
  26. using XdCxRhDW.Dto;
  27. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  28. using static XdCxRhDw.CpuCgTools.FormCpuCg;
  29. using CgRes = XdCxRhDW.App.Model.CgRes;
  30. namespace XdCxRhDW.App.WebAPI
  31. {
  32. /// <summary>
  33. /// 定位功能相关接口
  34. /// </summary>
  35. public class PosController : BaseController
  36. {
  37. /// <summary>
  38. /// 一星一地带参定位(无星历)
  39. /// </summary>
  40. /// <returns>返回定位结果ID</returns>
  41. [HttpPost]
  42. public async Task<AjaxResult<PosRes>> PosX1D1NoXlAsync(X1D1NoXlPosDto dto)
  43. {
  44. using (RHDWContext db = new RHDWContext())
  45. {
  46. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X1D1CX).FirstOrDefaultAsync();
  47. if (runTask == null)
  48. {
  49. Serilog.Log.Warning($"接收到一星一地定位参数,由于任务没有运行中忽略本次定位!");
  50. return Error<PosRes>($"多模式融合定位平台没有启动一星一地定位任务");
  51. }
  52. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  53. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  54. 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();
  55. if (xlInfo1 == null)
  56. {
  57. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  58. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  59. }
  60. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  61. var settings = await db.SysSetings.FirstOrDefaultAsync();
  62. var client = new HttpClient();
  63. string url = string.Format("http://{0}:{1}/Api/", settings.ServerIp, settings.HttpPort);
  64. url += string.Format("Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  65. var response = await client.GetAsync(url);
  66. if (!response.IsSuccessStatusCode) // 处理响应失败
  67. {
  68. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  69. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  70. }
  71. var content = await response.Content.ReadAsStringAsync();
  72. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  73. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  74. var listTx = new List<TxInfo>();
  75. var cgRes = new CgRes();
  76. var cxRes = new CxRes();
  77. cgRes = db.CgRes.Add(new CgRes()
  78. {
  79. SigTime = dto.SigTime,
  80. DtoCdb = dto.XdDto * 1e6,
  81. DfoCdb = dto.XdDfo * 1e6,
  82. SnrCdb = dto.XdSnr,
  83. YbMain = dto.MainYbDto * 1e6,
  84. MainX = ephMain.X,
  85. MainY = ephMain.Y,
  86. MainZ = ephMain.Z,
  87. });
  88. listTx = await db.TxInfos.ToListAsync();
  89. cxRes = db.CxRes.Add(new CxRes()
  90. {
  91. SigTime = dto.SigTime,
  92. Fx = dto.CxRes,
  93. });
  94. double[] res = new double[6];
  95. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  96. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  97. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  98. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  99. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  100. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  101. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  102. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  103. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  104. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  105. double theta = cxRes.Fx;//单位°
  106. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, res);
  107. PosRes posRes = new PosRes()
  108. {
  109. SigTime = dto.SigTime,
  110. TaskID = runTask.ID,
  111. CgResID = cgRes.ID,
  112. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  113. TsName = dto.TsName,
  114. PosLon = res[0],
  115. PosLat = res[1],
  116. MirrLon = res[3],
  117. MirrLat = res[4],
  118. };
  119. db.PosRes.Add(posRes);
  120. await db.SaveChangesAsync();
  121. return Success(posRes);
  122. }
  123. }
  124. /// <summary>
  125. /// 两星一地带参定位(无星历)
  126. /// </summary>
  127. /// <returns>返回定位结果ID</returns>
  128. [HttpPost]
  129. public async Task<AjaxResult<PosRes>> PosX2D1NoXlAsync(X2D1NoXlPosDto dto)
  130. {
  131. using (RHDWContext db = new RHDWContext())
  132. {
  133. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X2D1).FirstOrDefaultAsync();
  134. if (runTask == null)
  135. {
  136. Serilog.Log.Warning($"接收到两星一地定位参数,由于任务没有运行中忽略本次定位!");
  137. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  138. }
  139. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  140. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  141. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  142. 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();
  143. if (xlInfo1 == null)
  144. {
  145. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  146. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  147. }
  148. 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();
  149. if (xlInfo2 == null)
  150. {
  151. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  152. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  153. }
  154. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  155. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  156. var settings = await db.SysSetings.FirstOrDefaultAsync();
  157. var client = new HttpClient();
  158. string url = string.Format("http://{0}:{1}/Api/", settings.ServerIp, settings.HttpPort);
  159. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  160. var response = await client.GetAsync(url1);
  161. if (!response.IsSuccessStatusCode) // 处理响应失败
  162. {
  163. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  164. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  165. }
  166. var content = await response.Content.ReadAsStringAsync();
  167. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  168. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  169. var response2 = await client.GetAsync(url2);
  170. if (!response2.IsSuccessStatusCode) // 处理响应失败
  171. {
  172. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  173. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  174. }
  175. var content2 = await response2.Content.ReadAsStringAsync();
  176. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  177. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  178. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  179. var cgRes = db.CgRes.Add(new Model.CgRes()
  180. {
  181. SigTime = dto.SigTime,
  182. DtoSx = dto.SxDto * 1e6,
  183. DfoSx = dto.SxDfo * 1e6,
  184. SnrSx = dto.SxSnr,
  185. DtoCdb = dto.XdDto * 1e6,
  186. DfoCdb = dto.XdDfo * 1e6,
  187. SnrCdb = dto.XdSnr,
  188. YbMain = dto.MainYbDto * 1e6,
  189. YbAdja = dto.AdjaYbDto * 1e6,
  190. MainX = ephMain.X,
  191. MainY = ephMain.Y,
  192. MainZ = ephMain.Z,
  193. AdjaX = ephAdja.X,
  194. AdjaY = ephAdja.Y,
  195. AdjaZ = ephAdja.Z,
  196. });
  197. var listTx = await db.TxInfos.ToListAsync();
  198. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  199. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  200. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  201. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  202. double[] mainSat = new double[3] { ephMain.X, ephMain.Y, ephMain.Z };
  203. double[] adjaSat = new double[3] { ephAdja.X, ephAdja.Y, ephAdja.Z };
  204. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  205. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  206. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  207. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  208. double[] res = new double[6];
  209. 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);
  210. PosRes posRes = new PosRes()
  211. {
  212. SigTime = dto.SigTime,
  213. TaskID = runTask.ID,
  214. CgResID = cgRes.ID,
  215. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  216. TsName = dto.TsName,
  217. PosLon = res[0],
  218. PosLat = res[1],
  219. MirrLon = res[3],
  220. MirrLat = res[4],
  221. };
  222. db.PosRes.Add(posRes);
  223. await db.SaveChangesAsync();
  224. return Success(posRes);
  225. }
  226. }
  227. /// <summary>
  228. /// 融合带参定位(无星历)
  229. /// </summary>
  230. /// <returns>返回定位结果ID</returns>
  231. [HttpPost]
  232. public async Task<AjaxResult<PosRes>> PosRhNoXlAsync(RHNoXlPosDto dto)
  233. {
  234. using (RHDWContext db = new RHDWContext())
  235. {
  236. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.RH).FirstOrDefaultAsync();
  237. if (runTask == null)
  238. {
  239. Serilog.Log.Warning($"接收到融合定位参数,由于任务没有运行中忽略本次定位!");
  240. return Error<PosRes>($"多模式融合定位平台没有启动融合定位任务");
  241. }
  242. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  243. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  244. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  245. 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();
  246. if (xlInfo1 == null)
  247. {
  248. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  249. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  250. }
  251. 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();
  252. if (xlInfo2 == null)
  253. {
  254. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  255. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  256. }
  257. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  258. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  259. var settings = await db.SysSetings.FirstOrDefaultAsync();
  260. var client = new HttpClient();
  261. string url = string.Format("http://{0}:{1}/Api/", settings.ServerIp, settings.HttpPort);
  262. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  263. var response = await client.GetAsync(url1);
  264. if (!response.IsSuccessStatusCode) // 处理响应失败
  265. {
  266. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  267. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  268. }
  269. var content = await response.Content.ReadAsStringAsync();
  270. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  271. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  272. var response2 = await client.GetAsync(url2);
  273. if (!response2.IsSuccessStatusCode) // 处理响应失败
  274. {
  275. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  276. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  277. }
  278. var content2 = await response2.Content.ReadAsStringAsync();
  279. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  280. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  281. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  282. var listTx = new List<TxInfo>();
  283. var cgRes = new CgRes();
  284. var cxRes = new CxRes();
  285. cgRes = db.CgRes.Add(new CgRes()
  286. {
  287. SigTime = dto.SigTime,
  288. DtoSx = dto.SxDto * 1e6,
  289. DfoSx = dto.SxDfo * 1e6,
  290. SnrSx = dto.SxSnr,
  291. DtoCdb = dto.XdDto * 1e6,
  292. DfoCdb = dto.XdDfo * 1e6,
  293. SnrCdb = dto.XdSnr,
  294. YbMain = dto.MainYbDto * 1e6,
  295. YbAdja = dto.AdjaYbDto * 1e6,
  296. MainX = ephMain.X,
  297. MainY = ephMain.Y,
  298. MainZ = ephMain.Z,
  299. AdjaX = ephAdja.X,
  300. AdjaY = ephAdja.Y,
  301. AdjaZ = ephAdja.Z,
  302. });
  303. listTx = await db.TxInfos.ToListAsync();
  304. cxRes = db.CxRes.Add(new CxRes()
  305. {
  306. SigTime = dto.SigTime,
  307. Fx = dto.CxRes,
  308. });
  309. double[] resX1D1 = new double[6];
  310. double[] resX2D1 = new double[6];
  311. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  312. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  313. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  314. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  315. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  316. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  317. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  318. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  319. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  320. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  321. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  322. double theta = cxRes.Fx;//单位°
  323. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, resX1D1);
  324. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx / 1e6, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, cgRes.YbAdja / 1e6, resX2D1);
  325. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  326. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  327. {
  328. res = new double[6] {
  329. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  330. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  331. (resX1D1[2] + resX2D1[2]) / 2,
  332. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  333. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  334. (resX1D1[5] + resX2D1[5]) / 2,
  335. };
  336. }
  337. else if (PosApi.IsGeoPoint(resX1D1))
  338. {
  339. res = new double[6]
  340. {
  341. resX1D1[0] + 0.003,
  342. resX1D1[1] - 0.002,
  343. resX1D1[2],
  344. resX1D1[3] + 0.003,
  345. resX1D1[4] - 0.002,
  346. resX1D1[5],
  347. };
  348. }
  349. else if (PosApi.IsGeoPoint(resX2D1))
  350. {
  351. res = new double[6]
  352. {
  353. resX2D1[0] + 0.003,
  354. resX2D1[1] - 0.002,
  355. resX2D1[2],
  356. resX2D1[3] + 0.003,
  357. resX2D1[4] - 0.002,
  358. resX2D1[5],
  359. };
  360. }
  361. PosRes posRes = new PosRes()
  362. {
  363. SigTime = cgRes.SigTime,
  364. TaskID = runTask.ID,
  365. CxResID = cxRes.ID,
  366. CgResID = cgRes.ID,
  367. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  368. TsName = dto.TsName,
  369. PosLon = Math.Round(res[0], 4),
  370. PosLat = Math.Round(res[1], 4),
  371. MirrLon = Math.Round(res[3], 4),
  372. MirrLat = Math.Round(res[4], 4),
  373. };
  374. db.PosRes.Add(posRes);
  375. await db.SaveChangesAsync();
  376. return Success(posRes);
  377. }
  378. }
  379. /// <summary>
  380. /// 一星一地测向带参定位(含星历)
  381. /// </summary>
  382. /// <param name="dto">定位参数</param>
  383. /// <returns></returns>
  384. [HttpPost]
  385. public async Task<AjaxResult<PosRes>> PosX1D1Async(X1D1PosDto dto)
  386. {
  387. using (RHDWContext db = new RHDWContext())
  388. {
  389. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X1D1CX && p.TaskState == EnumTaskState.Running);
  390. if (runTask == null)
  391. {
  392. Serilog.Log.Warning($"接收到一星一地测向带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  393. return Error<PosRes>($"多模式融合定位平台没有启动一星一地测向定位任务");
  394. }
  395. var listTx = new List<TxInfo>();
  396. var cgRes = new CgRes();
  397. var cxRes = new CxRes();
  398. cgRes = db.CgRes.Add(new CgRes()
  399. {
  400. SigTime = dto.SigTime,
  401. DtoCdb = dto.XdDto * 1e6,
  402. DfoCdb = dto.XdDfo * 1e6,
  403. SnrCdb = dto.XdSnr,
  404. YbMain = dto.MainYbDto * 1e6,
  405. MainX = dto.MainX,
  406. MainY = dto.MainY,
  407. MainZ = dto.MainZ,
  408. });
  409. listTx = await db.TxInfos.ToListAsync();
  410. cxRes = db.CxRes.Add(new CxRes()
  411. {
  412. SigTime = dto.SigTime,
  413. Fx = dto.CxRes,
  414. });
  415. double[] res = new double[6];
  416. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  417. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  418. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  419. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  420. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  421. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  422. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  423. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  424. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  425. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  426. double theta = cxRes.Fx;//单位°
  427. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, res);
  428. PosRes posRes = new PosRes()
  429. {
  430. SigTime = cgRes.SigTime,
  431. TaskID = runTask.ID,
  432. CxResID = cxRes.ID,
  433. CgResID = cgRes.ID,
  434. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  435. TsName = dto.TsName,
  436. PosLon = Math.Round(res[0], 4),
  437. PosLat = Math.Round(res[1], 4),
  438. MirrLon = Math.Round(res[3], 4),
  439. MirrLat = Math.Round(res[4], 4),
  440. };
  441. db.PosRes.Add(posRes);
  442. await db.SaveChangesAsync();
  443. return Success(posRes);
  444. }
  445. }
  446. /// <summary>
  447. /// 两星一地定位(含星历)
  448. /// </summary>
  449. /// <param name="dto">定位参数</param>
  450. /// <returns></returns>
  451. [HttpPost]
  452. public async Task<AjaxResult<PosRes>> PosX2D1Async(X2D1PosDto dto)
  453. {
  454. using (RHDWContext db = new RHDWContext())
  455. {
  456. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  457. if (runTask == null)
  458. {
  459. Serilog.Log.Warning($"接收到两星一地带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  460. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  461. }
  462. var listTx = new List<TxInfo>();
  463. var cgRes = new CgRes();
  464. cgRes = db.CgRes.Add(new CgRes()
  465. {
  466. SigTime = dto.SigTime,
  467. DtoSx = dto.SxDto * 1e6,
  468. DfoSx = dto.SxDfo * 1e6,
  469. SnrSx = dto.SxSnr,
  470. DtoCdb = dto.XdDto * 1e6,
  471. DfoCdb = dto.XdDfo * 1e6,
  472. SnrCdb = dto.XdSnr,
  473. YbMain = dto.MainYbDto * 1e6,
  474. YbAdja = dto.AdjaYbDto * 1e6,
  475. MainX = dto.MainX,
  476. MainY = dto.MainY,
  477. MainZ = dto.MainZ,
  478. AdjaX = dto.AdjaX,
  479. AdjaY = dto.AdjaY,
  480. AdjaZ = dto.AdjaZ,
  481. });
  482. listTx = await db.TxInfos.ToListAsync();
  483. double[] res = new double[6];
  484. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  485. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  486. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  487. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  488. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  489. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  490. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  491. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  492. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  493. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  494. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  495. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx / 1e6, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, cgRes.YbAdja / 1e6, res);
  496. PosRes posRes = new PosRes()
  497. {
  498. SigTime = cgRes.SigTime,
  499. TaskID = runTask.ID,
  500. CgResID = cgRes.ID,
  501. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  502. TsName = dto.TsName,
  503. PosLon = Math.Round(res[0], 4),
  504. PosLat = Math.Round(res[1], 4),
  505. MirrLon = Math.Round(res[3], 4),
  506. MirrLat = Math.Round(res[4], 4),
  507. };
  508. db.PosRes.Add(posRes);
  509. await db.SaveChangesAsync();
  510. return Success(posRes);
  511. }
  512. }
  513. /// <summary>
  514. /// 融合定位(含星历)
  515. /// </summary>
  516. /// <param name="dto">定位参数</param>
  517. /// <returns></returns>
  518. [HttpPost]
  519. public async Task<AjaxResult<PosRes>> PosRhAsync(RHPosDto dto)
  520. {
  521. using (RHDWContext db = new RHDWContext())
  522. {
  523. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.RH && p.TaskState == EnumTaskState.Running);
  524. if (runTask == null)
  525. {
  526. Serilog.Log.Warning($"接收到融合带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  527. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  528. }
  529. var listTx = new List<TxInfo>();
  530. var cgRes = new CgRes();
  531. var cxRes = new CxRes();
  532. cgRes = db.CgRes.Add(new CgRes()
  533. {
  534. SigTime = dto.SigTime,
  535. DtoSx = dto.SxDto * 1e6,
  536. DfoSx = dto.SxDfo * 1e6,
  537. SnrSx = dto.SxSnr,
  538. DtoCdb = dto.XdDto * 1e6,
  539. DfoCdb = dto.XdDfo * 1e6,
  540. SnrCdb = dto.XdSnr,
  541. YbMain = dto.MainYbDto * 1e6,
  542. YbAdja = dto.AdjaYbDto * 1e6,
  543. MainX = dto.MainX,
  544. MainY = dto.MainY,
  545. MainZ = dto.MainZ,
  546. AdjaX = dto.AdjaX,
  547. AdjaY = dto.AdjaY,
  548. AdjaZ = dto.AdjaZ,
  549. });
  550. listTx = await db.TxInfos.ToListAsync();
  551. cxRes = db.CxRes.Add(new CxRes()
  552. {
  553. SigTime = dto.SigTime,
  554. Fx = dto.CxRes,
  555. });
  556. double[] resX1D1 = new double[6];
  557. double[] resX2D1 = new double[6];
  558. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  559. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  560. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  561. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  562. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  563. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  564. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  565. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  566. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  567. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  568. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  569. double theta = cxRes.Fx;//单位°
  570. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, resX1D1);
  571. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx / 1e6, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, cgRes.YbAdja / 1e6, resX2D1);
  572. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  573. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  574. {
  575. res = new double[6] {
  576. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  577. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  578. (resX1D1[2] + resX2D1[2]) / 2,
  579. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  580. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  581. (resX1D1[5] + resX2D1[5]) / 2,
  582. };
  583. }
  584. else if (PosApi.IsGeoPoint(resX1D1))
  585. {
  586. res = new double[6]
  587. {
  588. resX1D1[0] + 0.003,
  589. resX1D1[1] - 0.002,
  590. resX1D1[2],
  591. resX1D1[3] + 0.003,
  592. resX1D1[4] - 0.002,
  593. resX1D1[5],
  594. };
  595. }
  596. else if (PosApi.IsGeoPoint(resX2D1))
  597. {
  598. res = new double[6]
  599. {
  600. resX2D1[0] + 0.003,
  601. resX2D1[1] - 0.002,
  602. resX2D1[2],
  603. resX2D1[3] + 0.003,
  604. resX2D1[4] - 0.002,
  605. resX2D1[5],
  606. };
  607. }
  608. PosRes posRes = new PosRes()
  609. {
  610. SigTime = cgRes.SigTime,
  611. TaskID = runTask.ID,
  612. CxResID = cxRes.ID,
  613. CgResID = cgRes.ID,
  614. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  615. TsName = dto.TsName,
  616. PosLon = Math.Round(res[0], 4),
  617. PosLat = Math.Round(res[1], 4),
  618. MirrLon = Math.Round(res[3], 4),
  619. MirrLat = Math.Round(res[4], 4),
  620. };
  621. db.PosRes.Add(posRes);
  622. await db.SaveChangesAsync();
  623. return Success(posRes);
  624. }
  625. }
  626. /// <summary>
  627. /// 查询定位结果(暂未实现)
  628. /// </summary>
  629. /// <param name="dto"></param>
  630. /// <returns></returns>
  631. /// <exception cref="Exception"></exception>
  632. [HttpGet]
  633. public async Task<AjaxResult<PosResDto>> GetPosRes(PosResQueryDto dto)
  634. {
  635. await Task.Delay(100);
  636. return Error<PosResDto>("该功能暂未实现!");
  637. }
  638. }
  639. }