PosController.cs 33 KB

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