PosController.cs 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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.ObServer;
  27. using XdCxRhDW.App.WebAPI.DTO;
  28. using XdCxRhDW.Dto;
  29. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  30. using static XdCxRhDw.CpuCgTools.FormCpuCg;
  31. using CgRes = XdCxRhDW.App.Model.CgRes;
  32. namespace XdCxRhDW.App.WebAPI
  33. {
  34. /// <summary>
  35. /// 定位功能相关接口
  36. /// </summary>
  37. public class PosController : BaseController
  38. {
  39. #region 带参有星历
  40. /// <summary>
  41. /// 一星一地测向带参定位(含星历)
  42. /// </summary>
  43. /// <param name="dto">定位参数</param>
  44. /// <returns></returns>
  45. [HttpPost]
  46. public async Task<AjaxResult<PosRes>> PosX1D1Async(X1D1PosDto dto)
  47. {
  48. using (RHDWContext db = new RHDWContext())
  49. {
  50. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X1D1CX && p.TaskState == EnumTaskState.Running);
  51. if (runTask == null)
  52. {
  53. Serilog.Log.Warning($"接收到一星一地测向带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  54. return Error<PosRes>($"多模式融合定位平台没有启动一星一地测向定位任务");
  55. }
  56. var cgRes = db.CgRes.Add(new CgRes()
  57. {
  58. SigTime = dto.SigTime,
  59. DtoCdb = dto.XdDto * 1e6,
  60. DfoCdb = dto.XdDfo * 1e6,
  61. SnrCdb = dto.XdSnr,
  62. YbMain = dto.MainYbDto * 1e6,
  63. MainX = dto.MainX,
  64. MainY = dto.MainY,
  65. MainZ = dto.MainZ,
  66. });
  67. var cxRes = db.CxRes.Add(new CxRes()
  68. {
  69. SigTime = dto.SigTime,
  70. Fx = dto.CxRes,
  71. });
  72. var StationRes = db.StationRes.Add(new StationRes()
  73. {
  74. SatTxLon = dto.StationResInfo.SatTxLon,
  75. SatTxLat = dto.StationResInfo.SatTxLat,
  76. CdbTxLon = dto.StationResInfo.CdbTxLon,
  77. CdbTxLat = dto.StationResInfo.CdbTxLat,
  78. CxLon = dto.StationResInfo.CxLon,
  79. CxLat = dto.StationResInfo.CxLat,
  80. RefLon = dto.StationResInfo.RefLon,
  81. RefLat = dto.StationResInfo.RefLat,
  82. });
  83. double[] res = new double[6];
  84. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  85. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  86. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  87. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  88. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  89. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  90. double theta = cxRes.Fx;//单位°
  91. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
  92. PosRes posRes = new PosRes()
  93. {
  94. SigTime = cgRes.SigTime,
  95. TaskInfoID = runTask.ID,
  96. CxResID = cxRes.ID,
  97. CgResID = cgRes.ID,
  98. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  99. TsName = dto.TsName,
  100. PosLon = Math.Round(res[0], 4),
  101. PosLat = Math.Round(res[1], 4),
  102. MirrLon = Math.Round(res[3], 4),
  103. MirrLat = Math.Round(res[4], 4),
  104. };
  105. db.PosRes.Add(posRes);
  106. await db.SaveChangesAsync();
  107. return Success(posRes);
  108. }
  109. }
  110. /// <summary>
  111. /// 两星一地带参定位(含星历)
  112. /// </summary>
  113. /// <param name="dto">定位参数</param>
  114. /// <returns></returns>
  115. [HttpPost]
  116. public async Task<AjaxResult<PosRes>> PosX2D1Async(X2D1PosDto dto)
  117. {
  118. using (RHDWContext db = new RHDWContext())
  119. {
  120. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  121. if (runTask == null)
  122. {
  123. Serilog.Log.Warning($"接收到两星一地带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  124. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  125. }
  126. var cgRes = db.CgRes.Add(new CgRes()
  127. {
  128. SigTime = dto.SigTime,
  129. DtoSx = dto.SxDto * 1e6,
  130. DfoSx = dto.SxDfo * 1e6,
  131. SnrSx = dto.SxSnr,
  132. DtoCdb = dto.XdDto * 1e6,
  133. DfoCdb = dto.XdDfo * 1e6,
  134. SnrCdb = dto.XdSnr,
  135. YbMain = dto.MainYbDto * 1e6,
  136. YbAdja = dto.AdjaYbDto * 1e6,
  137. MainX = dto.MainX,
  138. MainY = dto.MainY,
  139. MainZ = dto.MainZ,
  140. AdjaX = dto.AdjaX,
  141. AdjaY = dto.AdjaY,
  142. AdjaZ = dto.AdjaZ,
  143. });
  144. var StationRes = db.StationRes.Add(new StationRes()
  145. {
  146. SatTxLon = dto.StationResInfo.SatTxLon,
  147. SatTxLat = dto.StationResInfo.SatTxLat,
  148. CdbTxLon = dto.StationResInfo.CdbTxLon,
  149. CdbTxLat = dto.StationResInfo.CdbTxLat,
  150. CxLon = dto.StationResInfo.CxLon,
  151. CxLat = dto.StationResInfo.CxLat,
  152. RefLon = dto.StationResInfo.RefLon,
  153. RefLat = dto.StationResInfo.RefLat,
  154. });
  155. double[] res = new double[6];
  156. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  157. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  158. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  159. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  160. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  161. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  162. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  163. 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);
  164. PosRes posRes = new PosRes()
  165. {
  166. SigTime = cgRes.SigTime,
  167. TaskInfoID = runTask.ID,
  168. CgResID = cgRes.ID,
  169. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  170. TsName = dto.TsName,
  171. PosLon = Math.Round(res[0], 4),
  172. PosLat = Math.Round(res[1], 4),
  173. MirrLon = Math.Round(res[3], 4),
  174. MirrLat = Math.Round(res[4], 4),
  175. };
  176. posRes=db.PosRes.Add(posRes);
  177. await db.SaveChangesAsync();
  178. PosObServer.Instance.Pub(posRes);
  179. return Success(posRes);
  180. }
  181. }
  182. /// <summary>
  183. /// 融合带参定位(含星历)
  184. /// </summary>
  185. /// <param name="dto">定位参数</param>
  186. /// <returns></returns>
  187. [HttpPost]
  188. public async Task<AjaxResult<PosRes>> PosRhAsync(RHPosDto dto)
  189. {
  190. using (RHDWContext db = new RHDWContext())
  191. {
  192. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.RH && p.TaskState == EnumTaskState.Running);
  193. if (runTask == null)
  194. {
  195. Serilog.Log.Warning($"接收到融合带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  196. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  197. }
  198. var listTx = new List<TxInfo>();
  199. var cgRes = db.CgRes.Add(new CgRes()
  200. {
  201. SigTime = dto.SigTime,
  202. DtoSx = dto.SxDto * 1e6,
  203. DfoSx = dto.SxDfo * 1e6,
  204. SnrSx = dto.SxSnr,
  205. DtoCdb = dto.XdDto * 1e6,
  206. DfoCdb = dto.XdDfo * 1e6,
  207. SnrCdb = dto.XdSnr,
  208. YbMain = dto.MainYbDto * 1e6,
  209. YbAdja = dto.AdjaYbDto * 1e6,
  210. MainX = dto.MainX,
  211. MainY = dto.MainY,
  212. MainZ = dto.MainZ,
  213. AdjaX = dto.AdjaX,
  214. AdjaY = dto.AdjaY,
  215. AdjaZ = dto.AdjaZ,
  216. });
  217. var cxRes = db.CxRes.Add(new CxRes()
  218. {
  219. SigTime = dto.SigTime,
  220. Fx = dto.CxRes,
  221. });
  222. var StationRes = db.StationRes.Add(new StationRes()
  223. {
  224. SatTxLon = dto.StationResInfo.SatTxLon,
  225. SatTxLat = dto.StationResInfo.SatTxLat,
  226. CdbTxLon = dto.StationResInfo.CdbTxLon,
  227. CdbTxLat = dto.StationResInfo.CdbTxLat,
  228. CxLon = dto.StationResInfo.CxLon,
  229. CxLat = dto.StationResInfo.CxLat,
  230. RefLon = dto.StationResInfo.RefLon,
  231. RefLat = dto.StationResInfo.RefLat,
  232. });
  233. double[] resX1D1 = new double[6];
  234. double[] resX2D1 = new double[6];
  235. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  236. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  237. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  238. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  239. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  240. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  241. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  242. double theta = cxRes.Fx;//单位°
  243. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, resX1D1);
  244. 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);
  245. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  246. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  247. {
  248. res = new double[6] {
  249. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  250. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  251. (resX1D1[2] + resX2D1[2]) / 2,
  252. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  253. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  254. (resX1D1[5] + resX2D1[5]) / 2,
  255. };
  256. }
  257. else if (PosApi.IsGeoPoint(resX1D1))
  258. {
  259. res = new double[6]
  260. {
  261. resX1D1[0] + 0.003,
  262. resX1D1[1] - 0.002,
  263. resX1D1[2],
  264. resX1D1[3] + 0.003,
  265. resX1D1[4] - 0.002,
  266. resX1D1[5],
  267. };
  268. }
  269. else if (PosApi.IsGeoPoint(resX2D1))
  270. {
  271. res = new double[6]
  272. {
  273. resX2D1[0] + 0.003,
  274. resX2D1[1] - 0.002,
  275. resX2D1[2],
  276. resX2D1[3] + 0.003,
  277. resX2D1[4] - 0.002,
  278. resX2D1[5],
  279. };
  280. }
  281. PosRes posRes = new PosRes()
  282. {
  283. SigTime = cgRes.SigTime,
  284. TaskInfoID = runTask.ID,
  285. CxResID = cxRes.ID,
  286. CgResID = cgRes.ID,
  287. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  288. TsName = dto.TsName,
  289. PosLon = Math.Round(res[0], 4),
  290. PosLat = Math.Round(res[1], 4),
  291. MirrLon = Math.Round(res[3], 4),
  292. MirrLat = Math.Round(res[4], 4),
  293. };
  294. db.PosRes.Add(posRes);
  295. await db.SaveChangesAsync();
  296. return Success(posRes);
  297. }
  298. }
  299. #endregion
  300. #region 带参无星历
  301. /// <summary>
  302. /// 一星一地带参定位(无星历)
  303. /// </summary>
  304. /// <returns>返回定位结果ID</returns>
  305. [HttpPost]
  306. public async Task<AjaxResult<PosRes>> PosX1D1NoXlAsync(X1D1NoXlPosDto dto)
  307. {
  308. using (RHDWContext db = new RHDWContext())
  309. {
  310. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X1D1CX).FirstOrDefaultAsync();
  311. if (runTask == null)
  312. {
  313. Serilog.Log.Warning($"接收到一星一地带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  314. return Error<PosRes>($"多模式融合定位平台没有启动一星一地定位任务");
  315. }
  316. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  317. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  318. 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();
  319. if (xlInfo1 == null)
  320. {
  321. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  322. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  323. }
  324. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  325. var settings = await db.SysSetings.FirstOrDefaultAsync();
  326. var client = new HttpClient();
  327. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  328. url += string.Format("Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  329. var response = await client.GetAsync(url);
  330. if (!response.IsSuccessStatusCode) // 处理响应失败
  331. {
  332. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  333. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  334. }
  335. var content = await response.Content.ReadAsStringAsync();
  336. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  337. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  338. var cgRes = db.CgRes.Add(new CgRes()
  339. {
  340. SigTime = dto.SigTime,
  341. DtoCdb = dto.XdDto * 1e6,
  342. DfoCdb = dto.XdDfo * 1e6,
  343. SnrCdb = dto.XdSnr,
  344. YbMain = dto.MainYbDto * 1e6,
  345. MainX = ephMain.X,
  346. MainY = ephMain.Y,
  347. MainZ = ephMain.Z,
  348. });
  349. var cxRes = db.CxRes.Add(new CxRes()
  350. {
  351. SigTime = dto.SigTime,
  352. Fx = dto.CxRes,
  353. });
  354. var StationRes = db.StationRes.Add(new StationRes()
  355. {
  356. SatTxLon = dto.StationResInfo.SatTxLon,
  357. SatTxLat = dto.StationResInfo.SatTxLat,
  358. CdbTxLon = dto.StationResInfo.CdbTxLon,
  359. CdbTxLat = dto.StationResInfo.CdbTxLat,
  360. CxLon = dto.StationResInfo.CxLon,
  361. CxLat = dto.StationResInfo.CxLat,
  362. RefLon = dto.StationResInfo.RefLon,
  363. RefLat = dto.StationResInfo.RefLat,
  364. });
  365. double[] res = new double[6];
  366. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  367. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  368. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  369. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  370. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  371. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  372. double theta = cxRes.Fx;//单位°
  373. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
  374. PosRes posRes = new PosRes()
  375. {
  376. SigTime = dto.SigTime,
  377. TaskInfoID = runTask.ID,
  378. CgResID = cgRes.ID,
  379. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  380. TsName = dto.TsName,
  381. PosLon = res[0],
  382. PosLat = res[1],
  383. MirrLon = res[3],
  384. MirrLat = res[4],
  385. };
  386. db.PosRes.Add(posRes);
  387. await db.SaveChangesAsync();
  388. return Success(posRes);
  389. }
  390. }
  391. /// <summary>
  392. /// 两星一地带参定位(无星历)
  393. /// </summary>
  394. /// <returns>返回定位结果ID</returns>
  395. [HttpPost]
  396. public async Task<AjaxResult<PosRes>> PosX2D1NoXlAsync(X2D1NoXlPosDto dto)
  397. {
  398. using (RHDWContext db = new RHDWContext())
  399. {
  400. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X2D1).FirstOrDefaultAsync();
  401. if (runTask == null)
  402. {
  403. Serilog.Log.Warning($"接收到两星一地带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  404. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  405. }
  406. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  407. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  408. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  409. 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();
  410. if (xlInfo1 == null)
  411. {
  412. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  413. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  414. }
  415. 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();
  416. if (xlInfo2 == null)
  417. {
  418. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  419. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  420. }
  421. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  422. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  423. var settings = await db.SysSetings.FirstOrDefaultAsync();
  424. var client = new HttpClient();
  425. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  426. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  427. var response = await client.GetAsync(url1);
  428. if (!response.IsSuccessStatusCode) // 处理响应失败
  429. {
  430. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  431. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  432. }
  433. var content = await response.Content.ReadAsStringAsync();
  434. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  435. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  436. var response2 = await client.GetAsync(url2);
  437. if (!response2.IsSuccessStatusCode) // 处理响应失败
  438. {
  439. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  440. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  441. }
  442. var content2 = await response2.Content.ReadAsStringAsync();
  443. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  444. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  445. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  446. var cgRes = db.CgRes.Add(new Model.CgRes()
  447. {
  448. SigTime = dto.SigTime,
  449. DtoSx = dto.SxDto * 1e6,
  450. DfoSx = dto.SxDfo * 1e6,
  451. SnrSx = dto.SxSnr,
  452. DtoCdb = dto.XdDto * 1e6,
  453. DfoCdb = dto.XdDfo * 1e6,
  454. SnrCdb = dto.XdSnr,
  455. YbMain = dto.MainYbDto * 1e6,
  456. YbAdja = dto.AdjaYbDto * 1e6,
  457. MainX = ephMain.X,
  458. MainY = ephMain.Y,
  459. MainZ = ephMain.Z,
  460. AdjaX = ephAdja.X,
  461. AdjaY = ephAdja.Y,
  462. AdjaZ = ephAdja.Z,
  463. });
  464. var StationRes = db.StationRes.Add(new StationRes()
  465. {
  466. SatTxLon = dto.StationResInfo.SatTxLon,
  467. SatTxLat = dto.StationResInfo.SatTxLat,
  468. CdbTxLon = dto.StationResInfo.CdbTxLon,
  469. CdbTxLat = dto.StationResInfo.CdbTxLat,
  470. CxLon = dto.StationResInfo.CxLon,
  471. CxLat = dto.StationResInfo.CxLat,
  472. RefLon = dto.StationResInfo.RefLon,
  473. RefLat = dto.StationResInfo.RefLat,
  474. });
  475. double[] res = new double[6];
  476. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  477. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  478. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  479. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  480. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  481. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  482. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  483. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx.Value / 1e6, cgRes.DtoCdb.Value / 1e6, dto.MainYbDto / 1e6, dto.AdjaYbDto / 1e6, res);
  484. PosRes posRes = new PosRes()
  485. {
  486. SigTime = dto.SigTime,
  487. TaskInfoID = runTask.ID,
  488. CgResID = cgRes.ID,
  489. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  490. TsName = dto.TsName,
  491. PosLon = res[0],
  492. PosLat = res[1],
  493. MirrLon = res[3],
  494. MirrLat = res[4],
  495. };
  496. db.PosRes.Add(posRes);
  497. await db.SaveChangesAsync();
  498. return Success(posRes);
  499. }
  500. }
  501. /// <summary>
  502. /// 融合带参定位(无星历)
  503. /// </summary>
  504. /// <returns>返回定位结果ID</returns>
  505. [HttpPost]
  506. public async Task<AjaxResult<PosRes>> PosRhNoXlAsync(RHNoXlPosDto dto)
  507. {
  508. using (RHDWContext db = new RHDWContext())
  509. {
  510. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.RH).FirstOrDefaultAsync();
  511. if (runTask == null)
  512. {
  513. Serilog.Log.Warning($"接收到融合带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  514. return Error<PosRes>($"多模式融合定位平台没有启动融合定位任务");
  515. }
  516. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  517. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  518. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  519. 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();
  520. if (xlInfo1 == null)
  521. {
  522. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  523. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  524. }
  525. 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();
  526. if (xlInfo2 == null)
  527. {
  528. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  529. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  530. }
  531. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  532. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  533. var settings = await db.SysSetings.FirstOrDefaultAsync();
  534. var client = new HttpClient();
  535. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  536. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  537. var response = await client.GetAsync(url1);
  538. if (!response.IsSuccessStatusCode) // 处理响应失败
  539. {
  540. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  541. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  542. }
  543. var content = await response.Content.ReadAsStringAsync();
  544. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  545. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  546. var response2 = await client.GetAsync(url2);
  547. if (!response2.IsSuccessStatusCode) // 处理响应失败
  548. {
  549. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  550. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  551. }
  552. var content2 = await response2.Content.ReadAsStringAsync();
  553. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  554. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  555. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  556. var cgRes = db.CgRes.Add(new CgRes()
  557. {
  558. SigTime = dto.SigTime,
  559. DtoSx = dto.SxDto * 1e6,
  560. DfoSx = dto.SxDfo * 1e6,
  561. SnrSx = dto.SxSnr,
  562. DtoCdb = dto.XdDto * 1e6,
  563. DfoCdb = dto.XdDfo * 1e6,
  564. SnrCdb = dto.XdSnr,
  565. YbMain = dto.MainYbDto * 1e6,
  566. YbAdja = dto.AdjaYbDto * 1e6,
  567. MainX = ephMain.X,
  568. MainY = ephMain.Y,
  569. MainZ = ephMain.Z,
  570. AdjaX = ephAdja.X,
  571. AdjaY = ephAdja.Y,
  572. AdjaZ = ephAdja.Z,
  573. });
  574. var cxRes = db.CxRes.Add(new CxRes()
  575. {
  576. SigTime = dto.SigTime,
  577. Fx = dto.CxRes,
  578. });
  579. var StationRes = db.StationRes.Add(new StationRes()
  580. {
  581. SatTxLon = dto.StationResInfo.SatTxLon,
  582. SatTxLat = dto.StationResInfo.SatTxLat,
  583. CdbTxLon = dto.StationResInfo.CdbTxLon,
  584. CdbTxLat = dto.StationResInfo.CdbTxLat,
  585. CxLon = dto.StationResInfo.CxLon,
  586. CxLat = dto.StationResInfo.CxLat,
  587. RefLon = dto.StationResInfo.RefLon,
  588. RefLat = dto.StationResInfo.RefLat,
  589. });
  590. double[] resX1D1 = new double[6];
  591. double[] resX2D1 = new double[6];
  592. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  593. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  594. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  595. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  596. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  597. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  598. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  599. double theta = cxRes.Fx;//单位°
  600. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, resX1D1);
  601. 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);
  602. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  603. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  604. {
  605. res = new double[6] {
  606. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  607. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  608. (resX1D1[2] + resX2D1[2]) / 2,
  609. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  610. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  611. (resX1D1[5] + resX2D1[5]) / 2,
  612. };
  613. }
  614. else if (PosApi.IsGeoPoint(resX1D1))
  615. {
  616. res = new double[6]
  617. {
  618. resX1D1[0] + 0.003,
  619. resX1D1[1] - 0.002,
  620. resX1D1[2],
  621. resX1D1[3] + 0.003,
  622. resX1D1[4] - 0.002,
  623. resX1D1[5],
  624. };
  625. }
  626. else if (PosApi.IsGeoPoint(resX2D1))
  627. {
  628. res = new double[6]
  629. {
  630. resX2D1[0] + 0.003,
  631. resX2D1[1] - 0.002,
  632. resX2D1[2],
  633. resX2D1[3] + 0.003,
  634. resX2D1[4] - 0.002,
  635. resX2D1[5],
  636. };
  637. }
  638. PosRes posRes = new PosRes()
  639. {
  640. SigTime = cgRes.SigTime,
  641. TaskInfoID = runTask.ID,
  642. CxResID = cxRes.ID,
  643. CgResID = cgRes.ID,
  644. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  645. TsName = dto.TsName,
  646. PosLon = Math.Round(res[0], 4),
  647. PosLat = Math.Round(res[1], 4),
  648. MirrLon = Math.Round(res[3], 4),
  649. MirrLat = Math.Round(res[4], 4),
  650. };
  651. db.PosRes.Add(posRes);
  652. await db.SaveChangesAsync();
  653. return Success(posRes);
  654. }
  655. }
  656. #endregion
  657. #region 无参有星历
  658. /// <summary>
  659. /// 一星一地测向无参定位(含星历)
  660. /// </summary>
  661. /// <param name="dto">定位参数</param>
  662. /// <returns></returns>
  663. [HttpPost]
  664. public async Task<AjaxResult<PosRes>> PosX1D1NoParAsync(X1D1NoParPosDto dto)
  665. {
  666. using (RHDWContext db = new RHDWContext())
  667. {
  668. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X1D1CX && p.TaskState == EnumTaskState.Running);
  669. if (runTask == null)
  670. {
  671. Serilog.Log.Warning($"接收到一星一地测向无参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  672. return Error<PosRes>($"多模式融合定位平台没有启动一星一地测向定位任务");
  673. }
  674. var cgRes = db.CgRes.Add(new CgRes()
  675. {
  676. SigTime = dto.SigTime,
  677. DtoCdb = dto.XdDto * 1e6,
  678. DfoCdb = dto.XdDfo * 1e6,
  679. SnrCdb = dto.XdSnr,
  680. MainX = dto.MainX,
  681. MainY = dto.MainY,
  682. MainZ = dto.MainZ,
  683. });
  684. var cxRes = db.CxRes.Add(new CxRes()
  685. {
  686. SigTime = dto.SigTime,
  687. Fx = dto.CxRes,
  688. });
  689. var StationRes = db.StationRes.Add(new StationRes()
  690. {
  691. SatTxLon = dto.StationResInfo.SatTxLon,
  692. SatTxLat = dto.StationResInfo.SatTxLat,
  693. CdbTxLon = dto.StationResInfo.CdbTxLon,
  694. CdbTxLat = dto.StationResInfo.CdbTxLat,
  695. CxLon = dto.StationResInfo.CxLon,
  696. CxLat = dto.StationResInfo.CxLat,
  697. RefLon = dto.StationResInfo.RefLon,
  698. RefLat = dto.StationResInfo.RefLat,
  699. });
  700. double[] res = new double[6];
  701. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  702. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  703. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  704. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  705. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  706. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  707. double theta = cxRes.Fx;//单位°
  708. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
  709. PosRes posRes = new PosRes()
  710. {
  711. SigTime = cgRes.SigTime,
  712. TaskInfoID = runTask.ID,
  713. CxResID = cxRes.ID,
  714. CgResID = cgRes.ID,
  715. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  716. TsName = dto.TsName,
  717. PosLon = Math.Round(res[0], 4),
  718. PosLat = Math.Round(res[1], 4),
  719. MirrLon = Math.Round(res[3], 4),
  720. MirrLat = Math.Round(res[4], 4),
  721. };
  722. db.PosRes.Add(posRes);
  723. await db.SaveChangesAsync();
  724. return Success(posRes);
  725. }
  726. }
  727. /// <summary>
  728. /// 两星一地无参定位(含星历)
  729. /// </summary>
  730. /// <param name="dto">定位参数</param>
  731. /// <returns></returns>
  732. [HttpPost]
  733. public async Task<AjaxResult<PosRes>> PosX2D1NoParAsync(X2D1NoParPosDto dto)
  734. {
  735. using (RHDWContext db = new RHDWContext())
  736. {
  737. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  738. if (runTask == null)
  739. {
  740. Serilog.Log.Warning($"接收到两星一地无参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  741. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  742. }
  743. var cgRes = db.CgRes.Add(new CgRes()
  744. {
  745. SigTime = dto.SigTime,
  746. DtoSx = dto.SxDto * 1e6,
  747. DfoSx = dto.SxDfo * 1e6,
  748. SnrSx = dto.SxSnr,
  749. DtoCdb = dto.XdDto * 1e6,
  750. DfoCdb = dto.XdDfo * 1e6,
  751. SnrCdb = dto.XdSnr,
  752. MainX = dto.MainX,
  753. MainY = dto.MainY,
  754. MainZ = dto.MainZ,
  755. AdjaX = dto.AdjaX,
  756. AdjaY = dto.AdjaY,
  757. AdjaZ = dto.AdjaZ,
  758. });
  759. var StationRes = db.StationRes.Add(new StationRes()
  760. {
  761. SatTxLon = dto.StationResInfo.SatTxLon,
  762. SatTxLat = dto.StationResInfo.SatTxLat,
  763. CdbTxLon = dto.StationResInfo.CdbTxLon,
  764. CdbTxLat = dto.StationResInfo.CdbTxLat,
  765. CxLon = dto.StationResInfo.CxLon,
  766. CxLat = dto.StationResInfo.CxLat,
  767. RefLon = dto.StationResInfo.RefLon,
  768. RefLat = dto.StationResInfo.RefLat,
  769. });
  770. double[] res = new double[6];
  771. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  772. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  773. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  774. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  775. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  776. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  777. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  778. 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);
  779. PosRes posRes = new PosRes()
  780. {
  781. SigTime = cgRes.SigTime,
  782. TaskInfoID = runTask.ID,
  783. CgResID = cgRes.ID,
  784. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  785. TsName = dto.TsName,
  786. PosLon = Math.Round(res[0], 4),
  787. PosLat = Math.Round(res[1], 4),
  788. MirrLon = Math.Round(res[3], 4),
  789. MirrLat = Math.Round(res[4], 4),
  790. };
  791. db.PosRes.Add(posRes);
  792. await db.SaveChangesAsync();
  793. return Success(posRes);
  794. }
  795. }
  796. /// <summary>
  797. /// 融合无参定位(含星历)
  798. /// </summary>
  799. /// <param name="dto">定位参数</param>
  800. /// <returns></returns>
  801. [HttpPost]
  802. public async Task<AjaxResult<PosRes>> PosRhNoParAsync(RHNoParPosDto dto)
  803. {
  804. using (RHDWContext db = new RHDWContext())
  805. {
  806. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.RH && p.TaskState == EnumTaskState.Running);
  807. if (runTask == null)
  808. {
  809. Serilog.Log.Warning($"接收到融合无参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  810. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  811. }
  812. var listTx = new List<TxInfo>();
  813. var cgRes = db.CgRes.Add(new CgRes()
  814. {
  815. SigTime = dto.SigTime,
  816. DtoSx = dto.SxDto * 1e6,
  817. DfoSx = dto.SxDfo * 1e6,
  818. SnrSx = dto.SxSnr,
  819. DtoCdb = dto.XdDto * 1e6,
  820. DfoCdb = dto.XdDfo * 1e6,
  821. SnrCdb = dto.XdSnr,
  822. MainX = dto.MainX,
  823. MainY = dto.MainY,
  824. MainZ = dto.MainZ,
  825. AdjaX = dto.AdjaX,
  826. AdjaY = dto.AdjaY,
  827. AdjaZ = dto.AdjaZ,
  828. });
  829. var cxRes = db.CxRes.Add(new CxRes()
  830. {
  831. SigTime = dto.SigTime,
  832. Fx = dto.CxRes,
  833. });
  834. var StationRes = db.StationRes.Add(new StationRes()
  835. {
  836. SatTxLon = dto.StationResInfo.SatTxLon,
  837. SatTxLat = dto.StationResInfo.SatTxLat,
  838. CdbTxLon = dto.StationResInfo.CdbTxLon,
  839. CdbTxLat = dto.StationResInfo.CdbTxLat,
  840. CxLon = dto.StationResInfo.CxLon,
  841. CxLat = dto.StationResInfo.CxLat,
  842. RefLon = dto.StationResInfo.RefLon,
  843. RefLat = dto.StationResInfo.RefLat,
  844. });
  845. double[] resX1D1 = new double[6];
  846. double[] resX2D1 = new double[6];
  847. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  848. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  849. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  850. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  851. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  852. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  853. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  854. double theta = cxRes.Fx;//单位°
  855. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, resX1D1);
  856. 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);
  857. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  858. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  859. {
  860. res = new double[6] {
  861. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  862. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  863. (resX1D1[2] + resX2D1[2]) / 2,
  864. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  865. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  866. (resX1D1[5] + resX2D1[5]) / 2,
  867. };
  868. }
  869. else if (PosApi.IsGeoPoint(resX1D1))
  870. {
  871. res = new double[6]
  872. {
  873. resX1D1[0] + 0.003,
  874. resX1D1[1] - 0.002,
  875. resX1D1[2],
  876. resX1D1[3] + 0.003,
  877. resX1D1[4] - 0.002,
  878. resX1D1[5],
  879. };
  880. }
  881. else if (PosApi.IsGeoPoint(resX2D1))
  882. {
  883. res = new double[6]
  884. {
  885. resX2D1[0] + 0.003,
  886. resX2D1[1] - 0.002,
  887. resX2D1[2],
  888. resX2D1[3] + 0.003,
  889. resX2D1[4] - 0.002,
  890. resX2D1[5],
  891. };
  892. }
  893. PosRes posRes = new PosRes()
  894. {
  895. SigTime = cgRes.SigTime,
  896. TaskInfoID = runTask.ID,
  897. CxResID = cxRes.ID,
  898. CgResID = cgRes.ID,
  899. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  900. TsName = dto.TsName,
  901. PosLon = Math.Round(res[0], 4),
  902. PosLat = Math.Round(res[1], 4),
  903. MirrLon = Math.Round(res[3], 4),
  904. MirrLat = Math.Round(res[4], 4),
  905. };
  906. db.PosRes.Add(posRes);
  907. await db.SaveChangesAsync();
  908. return Success(posRes);
  909. }
  910. }
  911. #endregion
  912. #region 无参无星历
  913. /// <summary>
  914. /// 一星一地无参定位(无星历)
  915. /// </summary>
  916. /// <returns>返回定位结果ID</returns>
  917. [HttpPost]
  918. public async Task<AjaxResult<PosRes>> PosX1D1NoXlNoParAsync(X1D1NoXlNoParPosDto dto)
  919. {
  920. using (RHDWContext db = new RHDWContext())
  921. {
  922. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X1D1CX).FirstOrDefaultAsync();
  923. if (runTask == null)
  924. {
  925. Serilog.Log.Warning($"接收到一星一地带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  926. return Error<PosRes>($"多模式融合定位平台没有启动一星一地定位任务");
  927. }
  928. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  929. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  930. 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();
  931. if (xlInfo1 == null)
  932. {
  933. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  934. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  935. }
  936. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  937. var settings = await db.SysSetings.FirstOrDefaultAsync();
  938. var client = new HttpClient();
  939. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  940. url += string.Format("Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  941. var response = await client.GetAsync(url);
  942. if (!response.IsSuccessStatusCode) // 处理响应失败
  943. {
  944. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  945. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  946. }
  947. var content = await response.Content.ReadAsStringAsync();
  948. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  949. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  950. var cgRes = db.CgRes.Add(new CgRes()
  951. {
  952. SigTime = dto.SigTime,
  953. DtoCdb = dto.XdDto * 1e6,
  954. DfoCdb = dto.XdDfo * 1e6,
  955. SnrCdb = dto.XdSnr,
  956. MainX = ephMain.X,
  957. MainY = ephMain.Y,
  958. MainZ = ephMain.Z,
  959. });
  960. var cxRes = db.CxRes.Add(new CxRes()
  961. {
  962. SigTime = dto.SigTime,
  963. Fx = dto.CxRes,
  964. });
  965. var StationRes = db.StationRes.Add(new StationRes()
  966. {
  967. SatTxLon = dto.StationResInfo.SatTxLon,
  968. SatTxLat = dto.StationResInfo.SatTxLat,
  969. CdbTxLon = dto.StationResInfo.CdbTxLon,
  970. CdbTxLat = dto.StationResInfo.CdbTxLat,
  971. CxLon = dto.StationResInfo.CxLon,
  972. CxLat = dto.StationResInfo.CxLat,
  973. RefLon = dto.StationResInfo.RefLon,
  974. RefLat = dto.StationResInfo.RefLat,
  975. });
  976. double[] res = new double[6];
  977. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  978. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  979. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  980. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  981. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  982. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  983. double theta = cxRes.Fx;//单位°
  984. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
  985. PosRes posRes = new PosRes()
  986. {
  987. SigTime = dto.SigTime,
  988. TaskInfoID = runTask.ID,
  989. CgResID = cgRes.ID,
  990. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  991. TsName = dto.TsName,
  992. PosLon = res[0],
  993. PosLat = res[1],
  994. MirrLon = res[3],
  995. MirrLat = res[4],
  996. };
  997. db.PosRes.Add(posRes);
  998. await db.SaveChangesAsync();
  999. return Success(posRes);
  1000. }
  1001. }
  1002. /// <summary>
  1003. /// 两星一地无参定位(无星历)
  1004. /// </summary>
  1005. /// <returns>返回定位结果ID</returns>
  1006. [HttpPost]
  1007. public async Task<AjaxResult<PosRes>> PosX2D1NoXlNoParAsync(X2D1NoXlNoParlPosDto dto)
  1008. {
  1009. using (RHDWContext db = new RHDWContext())
  1010. {
  1011. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X2D1).FirstOrDefaultAsync();
  1012. if (runTask == null)
  1013. {
  1014. Serilog.Log.Warning($"接收到两星一地带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  1015. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  1016. }
  1017. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  1018. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  1019. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  1020. 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();
  1021. if (xlInfo1 == null)
  1022. {
  1023. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1024. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1025. }
  1026. 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();
  1027. if (xlInfo2 == null)
  1028. {
  1029. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1030. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1031. }
  1032. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  1033. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  1034. var settings = await db.SysSetings.FirstOrDefaultAsync();
  1035. var client = new HttpClient();
  1036. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  1037. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  1038. var response = await client.GetAsync(url1);
  1039. if (!response.IsSuccessStatusCode) // 处理响应失败
  1040. {
  1041. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  1042. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  1043. }
  1044. var content = await response.Content.ReadAsStringAsync();
  1045. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  1046. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  1047. var response2 = await client.GetAsync(url2);
  1048. if (!response2.IsSuccessStatusCode) // 处理响应失败
  1049. {
  1050. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  1051. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  1052. }
  1053. var content2 = await response2.Content.ReadAsStringAsync();
  1054. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  1055. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  1056. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  1057. var cgRes = db.CgRes.Add(new Model.CgRes()
  1058. {
  1059. SigTime = dto.SigTime,
  1060. DtoSx = dto.SxDto * 1e6,
  1061. DfoSx = dto.SxDfo * 1e6,
  1062. SnrSx = dto.SxSnr,
  1063. DtoCdb = dto.XdDto * 1e6,
  1064. DfoCdb = dto.XdDfo * 1e6,
  1065. SnrCdb = dto.XdSnr,
  1066. MainX = ephMain.X,
  1067. MainY = ephMain.Y,
  1068. MainZ = ephMain.Z,
  1069. AdjaX = ephAdja.X,
  1070. AdjaY = ephAdja.Y,
  1071. AdjaZ = ephAdja.Z,
  1072. });
  1073. var StationRes = db.StationRes.Add(new StationRes()
  1074. {
  1075. SatTxLon = dto.StationResInfo.SatTxLon,
  1076. SatTxLat = dto.StationResInfo.SatTxLat,
  1077. CdbTxLon = dto.StationResInfo.CdbTxLon,
  1078. CdbTxLat = dto.StationResInfo.CdbTxLat,
  1079. CxLon = dto.StationResInfo.CxLon,
  1080. CxLat = dto.StationResInfo.CxLat,
  1081. RefLon = dto.StationResInfo.RefLon,
  1082. RefLat = dto.StationResInfo.RefLat,
  1083. });
  1084. double[] res = new double[6];
  1085. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  1086. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  1087. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  1088. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  1089. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  1090. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  1091. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  1092. 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);
  1093. PosRes posRes = new PosRes()
  1094. {
  1095. SigTime = dto.SigTime,
  1096. TaskInfoID = runTask.ID,
  1097. CgResID = cgRes.ID,
  1098. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  1099. TsName = dto.TsName,
  1100. PosLon = res[0],
  1101. PosLat = res[1],
  1102. MirrLon = res[3],
  1103. MirrLat = res[4],
  1104. };
  1105. db.PosRes.Add(posRes);
  1106. await db.SaveChangesAsync();
  1107. return Success(posRes);
  1108. }
  1109. }
  1110. /// <summary>
  1111. /// 融合无参定位(无星历)
  1112. /// </summary>
  1113. /// <returns>返回定位结果ID</returns>
  1114. [HttpPost]
  1115. public async Task<AjaxResult<PosRes>> PosRhNoXlNoParAsync(RHNoXlNoParPosDto dto)
  1116. {
  1117. using (RHDWContext db = new RHDWContext())
  1118. {
  1119. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.RH).FirstOrDefaultAsync();
  1120. if (runTask == null)
  1121. {
  1122. Serilog.Log.Warning($"接收到融合带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  1123. return Error<PosRes>($"多模式融合定位平台没有启动融合定位任务");
  1124. }
  1125. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  1126. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  1127. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  1128. 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();
  1129. if (xlInfo1 == null)
  1130. {
  1131. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1132. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1133. }
  1134. 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();
  1135. if (xlInfo2 == null)
  1136. {
  1137. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1138. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1139. }
  1140. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  1141. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  1142. var settings = await db.SysSetings.FirstOrDefaultAsync();
  1143. var client = new HttpClient();
  1144. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  1145. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  1146. var response = await client.GetAsync(url1);
  1147. if (!response.IsSuccessStatusCode) // 处理响应失败
  1148. {
  1149. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  1150. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  1151. }
  1152. var content = await response.Content.ReadAsStringAsync();
  1153. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  1154. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  1155. var response2 = await client.GetAsync(url2);
  1156. if (!response2.IsSuccessStatusCode) // 处理响应失败
  1157. {
  1158. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  1159. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  1160. }
  1161. var content2 = await response2.Content.ReadAsStringAsync();
  1162. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  1163. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  1164. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  1165. var cgRes = db.CgRes.Add(new CgRes()
  1166. {
  1167. SigTime = dto.SigTime,
  1168. DtoSx = dto.SxDto * 1e6,
  1169. DfoSx = dto.SxDfo * 1e6,
  1170. SnrSx = dto.SxSnr,
  1171. DtoCdb = dto.XdDto * 1e6,
  1172. DfoCdb = dto.XdDfo * 1e6,
  1173. SnrCdb = dto.XdSnr,
  1174. MainX = ephMain.X,
  1175. MainY = ephMain.Y,
  1176. MainZ = ephMain.Z,
  1177. AdjaX = ephAdja.X,
  1178. AdjaY = ephAdja.Y,
  1179. AdjaZ = ephAdja.Z,
  1180. });
  1181. var cxRes = db.CxRes.Add(new CxRes()
  1182. {
  1183. SigTime = dto.SigTime,
  1184. Fx = dto.CxRes,
  1185. });
  1186. var StationRes = db.StationRes.Add(new StationRes()
  1187. {
  1188. SatTxLon = dto.StationResInfo.SatTxLon,
  1189. SatTxLat = dto.StationResInfo.SatTxLat,
  1190. CdbTxLon = dto.StationResInfo.CdbTxLon,
  1191. CdbTxLat = dto.StationResInfo.CdbTxLat,
  1192. CxLon = dto.StationResInfo.CxLon,
  1193. CxLat = dto.StationResInfo.CxLat,
  1194. RefLon = dto.StationResInfo.RefLon,
  1195. RefLat = dto.StationResInfo.RefLat,
  1196. });
  1197. double[] resX1D1 = new double[6];
  1198. double[] resX2D1 = new double[6];
  1199. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  1200. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  1201. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  1202. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  1203. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  1204. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  1205. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  1206. double theta = cxRes.Fx;//单位°
  1207. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, resX1D1);
  1208. 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);
  1209. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  1210. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  1211. {
  1212. res = new double[6] {
  1213. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  1214. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  1215. (resX1D1[2] + resX2D1[2]) / 2,
  1216. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  1217. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  1218. (resX1D1[5] + resX2D1[5]) / 2,
  1219. };
  1220. }
  1221. else if (PosApi.IsGeoPoint(resX1D1))
  1222. {
  1223. res = new double[6]
  1224. {
  1225. resX1D1[0] + 0.003,
  1226. resX1D1[1] - 0.002,
  1227. resX1D1[2],
  1228. resX1D1[3] + 0.003,
  1229. resX1D1[4] - 0.002,
  1230. resX1D1[5],
  1231. };
  1232. }
  1233. else if (PosApi.IsGeoPoint(resX2D1))
  1234. {
  1235. res = new double[6]
  1236. {
  1237. resX2D1[0] + 0.003,
  1238. resX2D1[1] - 0.002,
  1239. resX2D1[2],
  1240. resX2D1[3] + 0.003,
  1241. resX2D1[4] - 0.002,
  1242. resX2D1[5],
  1243. };
  1244. }
  1245. PosRes posRes = new PosRes()
  1246. {
  1247. SigTime = cgRes.SigTime,
  1248. TaskInfoID = runTask.ID,
  1249. CxResID = cxRes.ID,
  1250. CgResID = cgRes.ID,
  1251. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  1252. TsName = dto.TsName,
  1253. PosLon = Math.Round(res[0], 4),
  1254. PosLat = Math.Round(res[1], 4),
  1255. MirrLon = Math.Round(res[3], 4),
  1256. MirrLat = Math.Round(res[4], 4),
  1257. };
  1258. db.PosRes.Add(posRes);
  1259. await db.SaveChangesAsync();
  1260. return Success(posRes);
  1261. }
  1262. }
  1263. #endregion
  1264. /// <summary>
  1265. /// 查询定位结果(暂未实现)
  1266. /// </summary>
  1267. /// <param name="dto"></param>
  1268. /// <returns></returns>
  1269. /// <exception cref="Exception"></exception>
  1270. [HttpGet]
  1271. public async Task<AjaxResult<PosResDto>> GetPosRes(PosResQueryDto dto)
  1272. {
  1273. await Task.Delay(100);
  1274. return Error<PosResDto>("该功能暂未实现!");
  1275. }
  1276. }
  1277. }