PosController.cs 35 KB

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