PosController.cs 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  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, cgRes.DtoSx.Value / 1e6, cgRes.DtoCdb.Value / 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. #region 无参有星历
  656. /// <summary>
  657. /// 一星一地测向无参定位(含星历)
  658. /// </summary>
  659. /// <param name="dto">定位参数</param>
  660. /// <returns></returns>
  661. [HttpPost]
  662. public async Task<AjaxResult<PosRes>> PosX1D1NoParAsync(X1D1NoParPosDto dto)
  663. {
  664. using (RHDWContext db = new RHDWContext())
  665. {
  666. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X1D1CX && p.TaskState == EnumTaskState.Running);
  667. if (runTask == null)
  668. {
  669. Serilog.Log.Warning($"接收到一星一地测向无参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  670. return Error<PosRes>($"多模式融合定位平台没有启动一星一地测向定位任务");
  671. }
  672. var cgRes = db.CgRes.Add(new CgRes()
  673. {
  674. SigTime = dto.SigTime,
  675. DtoCdb = dto.XdDto * 1e6,
  676. DfoCdb = dto.XdDfo * 1e6,
  677. SnrCdb = dto.XdSnr,
  678. MainX = dto.MainX,
  679. MainY = dto.MainY,
  680. MainZ = dto.MainZ,
  681. });
  682. var cxRes = db.CxRes.Add(new CxRes()
  683. {
  684. SigTime = dto.SigTime,
  685. Fx = dto.CxRes,
  686. });
  687. var StationRes = db.StationRes.Add(new StationRes()
  688. {
  689. SatTxLon = dto.StationResInfo.SatTxLon,
  690. SatTxLat = dto.StationResInfo.SatTxLat,
  691. CdbTxLon = dto.StationResInfo.CdbTxLon,
  692. CdbTxLat = dto.StationResInfo.CdbTxLat,
  693. CxLon = dto.StationResInfo.CxLon,
  694. CxLat = dto.StationResInfo.CxLat,
  695. RefLon = dto.StationResInfo.RefLon,
  696. RefLat = dto.StationResInfo.RefLat,
  697. });
  698. double[] res = new double[6];
  699. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  700. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  701. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  702. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  703. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  704. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  705. double theta = cxRes.Fx;//单位°
  706. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
  707. PosRes posRes = new PosRes()
  708. {
  709. SigTime = cgRes.SigTime,
  710. TaskInfoID = runTask.ID,
  711. CxResID = cxRes.ID,
  712. CgResID = cgRes.ID,
  713. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  714. TsName = dto.TsName,
  715. PosLon = Math.Round(res[0], 4),
  716. PosLat = Math.Round(res[1], 4),
  717. MirrLon = Math.Round(res[3], 4),
  718. MirrLat = Math.Round(res[4], 4),
  719. };
  720. db.PosRes.Add(posRes);
  721. await db.SaveChangesAsync();
  722. return Success(posRes);
  723. }
  724. }
  725. /// <summary>
  726. /// 两星一地无参定位(含星历)
  727. /// </summary>
  728. /// <param name="dto">定位参数</param>
  729. /// <returns></returns>
  730. [HttpPost]
  731. public async Task<AjaxResult<PosRes>> PosX2D1NoParAsync(X2D1NoParPosDto dto)
  732. {
  733. using (RHDWContext db = new RHDWContext())
  734. {
  735. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  736. if (runTask == null)
  737. {
  738. Serilog.Log.Warning($"接收到两星一地无参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  739. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  740. }
  741. var cgRes = db.CgRes.Add(new CgRes()
  742. {
  743. SigTime = dto.SigTime,
  744. DtoSx = dto.SxDto * 1e6,
  745. DfoSx = dto.SxDfo * 1e6,
  746. SnrSx = dto.SxSnr,
  747. DtoCdb = dto.XdDto * 1e6,
  748. DfoCdb = dto.XdDfo * 1e6,
  749. SnrCdb = dto.XdSnr,
  750. MainX = dto.MainX,
  751. MainY = dto.MainY,
  752. MainZ = dto.MainZ,
  753. AdjaX = dto.AdjaX,
  754. AdjaY = dto.AdjaY,
  755. AdjaZ = dto.AdjaZ,
  756. });
  757. var StationRes = db.StationRes.Add(new StationRes()
  758. {
  759. SatTxLon = dto.StationResInfo.SatTxLon,
  760. SatTxLat = dto.StationResInfo.SatTxLat,
  761. CdbTxLon = dto.StationResInfo.CdbTxLon,
  762. CdbTxLat = dto.StationResInfo.CdbTxLat,
  763. CxLon = dto.StationResInfo.CxLon,
  764. CxLat = dto.StationResInfo.CxLat,
  765. RefLon = dto.StationResInfo.RefLon,
  766. RefLat = dto.StationResInfo.RefLat,
  767. });
  768. double[] res = new double[6];
  769. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  770. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  771. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  772. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  773. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  774. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  775. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  776. 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);
  777. PosRes posRes = new PosRes()
  778. {
  779. SigTime = cgRes.SigTime,
  780. TaskInfoID = runTask.ID,
  781. CgResID = cgRes.ID,
  782. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  783. TsName = dto.TsName,
  784. PosLon = Math.Round(res[0], 4),
  785. PosLat = Math.Round(res[1], 4),
  786. MirrLon = Math.Round(res[3], 4),
  787. MirrLat = Math.Round(res[4], 4),
  788. };
  789. db.PosRes.Add(posRes);
  790. await db.SaveChangesAsync();
  791. return Success(posRes);
  792. }
  793. }
  794. /// <summary>
  795. /// 融合无参定位(含星历)
  796. /// </summary>
  797. /// <param name="dto">定位参数</param>
  798. /// <returns></returns>
  799. [HttpPost]
  800. public async Task<AjaxResult<PosRes>> PosRhNoParAsync(RHNoParPosDto dto)
  801. {
  802. using (RHDWContext db = new RHDWContext())
  803. {
  804. var runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.RH && p.TaskState == EnumTaskState.Running);
  805. if (runTask == null)
  806. {
  807. Serilog.Log.Warning($"接收到融合无参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  808. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  809. }
  810. var listTx = new List<TxInfo>();
  811. var cgRes = db.CgRes.Add(new CgRes()
  812. {
  813. SigTime = dto.SigTime,
  814. DtoSx = dto.SxDto * 1e6,
  815. DfoSx = dto.SxDfo * 1e6,
  816. SnrSx = dto.SxSnr,
  817. DtoCdb = dto.XdDto * 1e6,
  818. DfoCdb = dto.XdDfo * 1e6,
  819. SnrCdb = dto.XdSnr,
  820. MainX = dto.MainX,
  821. MainY = dto.MainY,
  822. MainZ = dto.MainZ,
  823. AdjaX = dto.AdjaX,
  824. AdjaY = dto.AdjaY,
  825. AdjaZ = dto.AdjaZ,
  826. });
  827. var cxRes = db.CxRes.Add(new CxRes()
  828. {
  829. SigTime = dto.SigTime,
  830. Fx = dto.CxRes,
  831. });
  832. var StationRes = db.StationRes.Add(new StationRes()
  833. {
  834. SatTxLon = dto.StationResInfo.SatTxLon,
  835. SatTxLat = dto.StationResInfo.SatTxLat,
  836. CdbTxLon = dto.StationResInfo.CdbTxLon,
  837. CdbTxLat = dto.StationResInfo.CdbTxLat,
  838. CxLon = dto.StationResInfo.CxLon,
  839. CxLat = dto.StationResInfo.CxLat,
  840. RefLon = dto.StationResInfo.RefLon,
  841. RefLat = dto.StationResInfo.RefLat,
  842. });
  843. double[] resX1D1 = new double[6];
  844. double[] resX2D1 = new double[6];
  845. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  846. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  847. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  848. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  849. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  850. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  851. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  852. double theta = cxRes.Fx;//单位°
  853. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, resX1D1);
  854. 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);
  855. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  856. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  857. {
  858. res = new double[6] {
  859. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  860. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  861. (resX1D1[2] + resX2D1[2]) / 2,
  862. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  863. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  864. (resX1D1[5] + resX2D1[5]) / 2,
  865. };
  866. }
  867. else if (PosApi.IsGeoPoint(resX1D1))
  868. {
  869. res = new double[6]
  870. {
  871. resX1D1[0] + 0.003,
  872. resX1D1[1] - 0.002,
  873. resX1D1[2],
  874. resX1D1[3] + 0.003,
  875. resX1D1[4] - 0.002,
  876. resX1D1[5],
  877. };
  878. }
  879. else if (PosApi.IsGeoPoint(resX2D1))
  880. {
  881. res = new double[6]
  882. {
  883. resX2D1[0] + 0.003,
  884. resX2D1[1] - 0.002,
  885. resX2D1[2],
  886. resX2D1[3] + 0.003,
  887. resX2D1[4] - 0.002,
  888. resX2D1[5],
  889. };
  890. }
  891. PosRes posRes = new PosRes()
  892. {
  893. SigTime = cgRes.SigTime,
  894. TaskInfoID = runTask.ID,
  895. CxResID = cxRes.ID,
  896. CgResID = cgRes.ID,
  897. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  898. TsName = dto.TsName,
  899. PosLon = Math.Round(res[0], 4),
  900. PosLat = Math.Round(res[1], 4),
  901. MirrLon = Math.Round(res[3], 4),
  902. MirrLat = Math.Round(res[4], 4),
  903. };
  904. db.PosRes.Add(posRes);
  905. await db.SaveChangesAsync();
  906. return Success(posRes);
  907. }
  908. }
  909. #endregion
  910. #region 无参无星历
  911. /// <summary>
  912. /// 一星一地无参定位(无星历)
  913. /// </summary>
  914. /// <returns>返回定位结果ID</returns>
  915. [HttpPost]
  916. public async Task<AjaxResult<PosRes>> PosX1D1NoXlNoParAsync(X1D1NoXlNoParPosDto dto)
  917. {
  918. using (RHDWContext db = new RHDWContext())
  919. {
  920. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X1D1CX).FirstOrDefaultAsync();
  921. if (runTask == null)
  922. {
  923. Serilog.Log.Warning($"接收到一星一地带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  924. return Error<PosRes>($"多模式融合定位平台没有启动一星一地定位任务");
  925. }
  926. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  927. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  928. 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();
  929. if (xlInfo1 == null)
  930. {
  931. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  932. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  933. }
  934. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  935. var settings = await db.SysSetings.FirstOrDefaultAsync();
  936. var client = new HttpClient();
  937. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  938. url += string.Format("Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  939. var response = await client.GetAsync(url);
  940. if (!response.IsSuccessStatusCode) // 处理响应失败
  941. {
  942. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  943. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  944. }
  945. var content = await response.Content.ReadAsStringAsync();
  946. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  947. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  948. var cgRes = db.CgRes.Add(new CgRes()
  949. {
  950. SigTime = dto.SigTime,
  951. DtoCdb = dto.XdDto * 1e6,
  952. DfoCdb = dto.XdDfo * 1e6,
  953. SnrCdb = dto.XdSnr,
  954. MainX = ephMain.X,
  955. MainY = ephMain.Y,
  956. MainZ = ephMain.Z,
  957. });
  958. var cxRes = db.CxRes.Add(new CxRes()
  959. {
  960. SigTime = dto.SigTime,
  961. Fx = dto.CxRes,
  962. });
  963. var StationRes = db.StationRes.Add(new StationRes()
  964. {
  965. SatTxLon = dto.StationResInfo.SatTxLon,
  966. SatTxLat = dto.StationResInfo.SatTxLat,
  967. CdbTxLon = dto.StationResInfo.CdbTxLon,
  968. CdbTxLat = dto.StationResInfo.CdbTxLat,
  969. CxLon = dto.StationResInfo.CxLon,
  970. CxLat = dto.StationResInfo.CxLat,
  971. RefLon = dto.StationResInfo.RefLon,
  972. RefLat = dto.StationResInfo.RefLat,
  973. });
  974. double[] res = new double[6];
  975. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  976. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  977. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  978. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  979. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  980. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  981. double theta = cxRes.Fx;//单位°
  982. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
  983. PosRes posRes = new PosRes()
  984. {
  985. SigTime = dto.SigTime,
  986. TaskInfoID = runTask.ID,
  987. CgResID = cgRes.ID,
  988. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  989. TsName = dto.TsName,
  990. PosLon = res[0],
  991. PosLat = res[1],
  992. MirrLon = res[3],
  993. MirrLat = res[4],
  994. };
  995. db.PosRes.Add(posRes);
  996. await db.SaveChangesAsync();
  997. return Success(posRes);
  998. }
  999. }
  1000. /// <summary>
  1001. /// 两星一地无参定位(无星历)
  1002. /// </summary>
  1003. /// <returns>返回定位结果ID</returns>
  1004. [HttpPost]
  1005. public async Task<AjaxResult<PosRes>> PosX2D1NoXlNoParAsync(X2D1NoXlNoParlPosDto dto)
  1006. {
  1007. using (RHDWContext db = new RHDWContext())
  1008. {
  1009. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X2D1).FirstOrDefaultAsync();
  1010. if (runTask == null)
  1011. {
  1012. Serilog.Log.Warning($"接收到两星一地带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  1013. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  1014. }
  1015. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  1016. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  1017. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  1018. 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();
  1019. if (xlInfo1 == null)
  1020. {
  1021. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1022. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1023. }
  1024. 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();
  1025. if (xlInfo2 == null)
  1026. {
  1027. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1028. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1029. }
  1030. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  1031. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  1032. var settings = await db.SysSetings.FirstOrDefaultAsync();
  1033. var client = new HttpClient();
  1034. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  1035. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  1036. var response = await client.GetAsync(url1);
  1037. if (!response.IsSuccessStatusCode) // 处理响应失败
  1038. {
  1039. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  1040. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  1041. }
  1042. var content = await response.Content.ReadAsStringAsync();
  1043. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  1044. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  1045. var response2 = await client.GetAsync(url2);
  1046. if (!response2.IsSuccessStatusCode) // 处理响应失败
  1047. {
  1048. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  1049. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  1050. }
  1051. var content2 = await response2.Content.ReadAsStringAsync();
  1052. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  1053. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  1054. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  1055. var cgRes = db.CgRes.Add(new Model.CgRes()
  1056. {
  1057. SigTime = dto.SigTime,
  1058. DtoSx = dto.SxDto * 1e6,
  1059. DfoSx = dto.SxDfo * 1e6,
  1060. SnrSx = dto.SxSnr,
  1061. DtoCdb = dto.XdDto * 1e6,
  1062. DfoCdb = dto.XdDfo * 1e6,
  1063. SnrCdb = dto.XdSnr,
  1064. MainX = ephMain.X,
  1065. MainY = ephMain.Y,
  1066. MainZ = ephMain.Z,
  1067. AdjaX = ephAdja.X,
  1068. AdjaY = ephAdja.Y,
  1069. AdjaZ = ephAdja.Z,
  1070. });
  1071. var StationRes = db.StationRes.Add(new StationRes()
  1072. {
  1073. SatTxLon = dto.StationResInfo.SatTxLon,
  1074. SatTxLat = dto.StationResInfo.SatTxLat,
  1075. CdbTxLon = dto.StationResInfo.CdbTxLon,
  1076. CdbTxLat = dto.StationResInfo.CdbTxLat,
  1077. CxLon = dto.StationResInfo.CxLon,
  1078. CxLat = dto.StationResInfo.CxLat,
  1079. RefLon = dto.StationResInfo.RefLon,
  1080. RefLat = dto.StationResInfo.RefLat,
  1081. });
  1082. double[] res = new double[6];
  1083. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  1084. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  1085. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  1086. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  1087. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  1088. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  1089. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  1090. 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);
  1091. PosRes posRes = new PosRes()
  1092. {
  1093. SigTime = dto.SigTime,
  1094. TaskInfoID = runTask.ID,
  1095. CgResID = cgRes.ID,
  1096. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  1097. TsName = dto.TsName,
  1098. PosLon = res[0],
  1099. PosLat = res[1],
  1100. MirrLon = res[3],
  1101. MirrLat = res[4],
  1102. };
  1103. db.PosRes.Add(posRes);
  1104. await db.SaveChangesAsync();
  1105. return Success(posRes);
  1106. }
  1107. }
  1108. /// <summary>
  1109. /// 融合无参定位(无星历)
  1110. /// </summary>
  1111. /// <returns>返回定位结果ID</returns>
  1112. [HttpPost]
  1113. public async Task<AjaxResult<PosRes>> PosRhNoXlNoParAsync(RHNoXlNoParPosDto dto)
  1114. {
  1115. using (RHDWContext db = new RHDWContext())
  1116. {
  1117. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.RH).FirstOrDefaultAsync();
  1118. if (runTask == null)
  1119. {
  1120. Serilog.Log.Warning($"接收到融合带参定位(无星历)参数,由于任务没有运行中忽略本次定位!");
  1121. return Error<PosRes>($"多模式融合定位平台没有启动融合定位任务");
  1122. }
  1123. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  1124. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  1125. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  1126. 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();
  1127. if (xlInfo1 == null)
  1128. {
  1129. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1130. return Error<PosRes>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  1131. }
  1132. 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();
  1133. if (xlInfo2 == null)
  1134. {
  1135. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1136. return Error<PosRes>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  1137. }
  1138. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  1139. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  1140. var settings = await db.SysSetings.FirstOrDefaultAsync();
  1141. var client = new HttpClient();
  1142. string url = string.Format("http://{0}:{1}/Api/", IpHelper.GetLocalIp(), settings.HttpPort);
  1143. var url1 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo1.TwoLine, dto.SigTime);
  1144. var response = await client.GetAsync(url1);
  1145. if (!response.IsSuccessStatusCode) // 处理响应失败
  1146. {
  1147. Serilog.Log.Error($"[{dto.MainSatID}]星厉推算失败");
  1148. return Error<PosRes>($"[{dto.MainSatID}]星厉推算失败");
  1149. }
  1150. var content = await response.Content.ReadAsStringAsync();
  1151. var ephMain = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content).data;
  1152. var url2 = string.Format(url + "Xl/Calc?tleStr={0}&dt={1}", xlInfo2.TwoLine, dto.SigTime);
  1153. var response2 = await client.GetAsync(url2);
  1154. if (!response2.IsSuccessStatusCode) // 处理响应失败
  1155. {
  1156. Serilog.Log.Error($"[{dto.AdjaSatID}]星厉推算失败");
  1157. return Error<PosRes>($"[{dto.AdjaSatID}]星厉推算失败");
  1158. }
  1159. var content2 = await response2.Content.ReadAsStringAsync();
  1160. var ephAdja = JsonConvert.DeserializeObject<AjaxResult<SatEphDto>>(content2).data;
  1161. //var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  1162. //var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  1163. var cgRes = db.CgRes.Add(new CgRes()
  1164. {
  1165. SigTime = dto.SigTime,
  1166. DtoSx = dto.SxDto * 1e6,
  1167. DfoSx = dto.SxDfo * 1e6,
  1168. SnrSx = dto.SxSnr,
  1169. DtoCdb = dto.XdDto * 1e6,
  1170. DfoCdb = dto.XdDfo * 1e6,
  1171. SnrCdb = dto.XdSnr,
  1172. MainX = ephMain.X,
  1173. MainY = ephMain.Y,
  1174. MainZ = ephMain.Z,
  1175. AdjaX = ephAdja.X,
  1176. AdjaY = ephAdja.Y,
  1177. AdjaZ = ephAdja.Z,
  1178. });
  1179. var cxRes = db.CxRes.Add(new CxRes()
  1180. {
  1181. SigTime = dto.SigTime,
  1182. Fx = dto.CxRes,
  1183. });
  1184. var StationRes = db.StationRes.Add(new StationRes()
  1185. {
  1186. SatTxLon = dto.StationResInfo.SatTxLon,
  1187. SatTxLat = dto.StationResInfo.SatTxLat,
  1188. CdbTxLon = dto.StationResInfo.CdbTxLon,
  1189. CdbTxLat = dto.StationResInfo.CdbTxLat,
  1190. CxLon = dto.StationResInfo.CxLon,
  1191. CxLat = dto.StationResInfo.CxLat,
  1192. RefLon = dto.StationResInfo.RefLon,
  1193. RefLat = dto.StationResInfo.RefLat,
  1194. });
  1195. double[] resX1D1 = new double[6];
  1196. double[] resX2D1 = new double[6];
  1197. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  1198. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  1199. double[] satStation = new double[3] { dto.StationResInfo.SatTxLon, dto.StationResInfo.SatTxLat, 0 };
  1200. double[] cdbStation = new double[3] { dto.StationResInfo.CdbTxLon, dto.StationResInfo.CdbTxLat, 0 };
  1201. double[] cxStation = new double[3] { dto.StationResInfo.CxLon, dto.StationResInfo.CxLat, 0 };
  1202. double[] refStation = new double[3] { dto.StationResInfo.RefLon, dto.StationResInfo.RefLat, 0 };
  1203. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  1204. double theta = cxRes.Fx;//单位°
  1205. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, resX1D1);
  1206. 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);
  1207. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  1208. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  1209. {
  1210. res = new double[6] {
  1211. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  1212. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  1213. (resX1D1[2] + resX2D1[2]) / 2,
  1214. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  1215. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  1216. (resX1D1[5] + resX2D1[5]) / 2,
  1217. };
  1218. }
  1219. else if (PosApi.IsGeoPoint(resX1D1))
  1220. {
  1221. res = new double[6]
  1222. {
  1223. resX1D1[0] + 0.003,
  1224. resX1D1[1] - 0.002,
  1225. resX1D1[2],
  1226. resX1D1[3] + 0.003,
  1227. resX1D1[4] - 0.002,
  1228. resX1D1[5],
  1229. };
  1230. }
  1231. else if (PosApi.IsGeoPoint(resX2D1))
  1232. {
  1233. res = new double[6]
  1234. {
  1235. resX2D1[0] + 0.003,
  1236. resX2D1[1] - 0.002,
  1237. resX2D1[2],
  1238. resX2D1[3] + 0.003,
  1239. resX2D1[4] - 0.002,
  1240. resX2D1[5],
  1241. };
  1242. }
  1243. PosRes posRes = new PosRes()
  1244. {
  1245. SigTime = cgRes.SigTime,
  1246. TaskInfoID = runTask.ID,
  1247. CxResID = cxRes.ID,
  1248. CgResID = cgRes.ID,
  1249. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  1250. TsName = dto.TsName,
  1251. PosLon = Math.Round(res[0], 4),
  1252. PosLat = Math.Round(res[1], 4),
  1253. MirrLon = Math.Round(res[3], 4),
  1254. MirrLat = Math.Round(res[4], 4),
  1255. };
  1256. db.PosRes.Add(posRes);
  1257. await db.SaveChangesAsync();
  1258. return Success(posRes);
  1259. }
  1260. }
  1261. #endregion
  1262. /// <summary>
  1263. /// 查询定位结果(暂未实现)
  1264. /// </summary>
  1265. /// <param name="dto"></param>
  1266. /// <returns></returns>
  1267. /// <exception cref="Exception"></exception>
  1268. [HttpGet]
  1269. public async Task<AjaxResult<PosResDto>> GetPosRes(PosResQueryDto dto)
  1270. {
  1271. await Task.Delay(100);
  1272. return Error<PosResDto>("该功能暂未实现!");
  1273. }
  1274. }
  1275. }