PosController.cs 33 KB

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