PosController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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.Security.Cryptography.Xml;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Web.Http;
  11. using System.Windows.Documents;
  12. using DevExpress.Mvvm.Native;
  13. using DevExpress.XtraPrinting;
  14. using Newtonsoft.Json;
  15. using PosResAnalysis;
  16. using Serilog;
  17. using Swashbuckle.Swagger;
  18. using XdCxRhDw.Dto;
  19. using XdCxRhDW.App.Api;
  20. using XdCxRhDW.App.EFContext;
  21. using XdCxRhDW.App.Model;
  22. using XdCxRhDW.App.WebAPI.DTO;
  23. using XdCxRhDW.Dto;
  24. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  25. using static XdCxRhDw.CpuCgTools.FormCpuCg;
  26. using CgRes = XdCxRhDW.App.Model.CgRes;
  27. namespace XdCxRhDW.App.WebAPI
  28. {
  29. /// <summary>
  30. /// 定位功能相关接口
  31. /// </summary>
  32. public class PosController : BaseController
  33. {
  34. /// <summary>
  35. /// 两星一地带参定位(无星历)
  36. /// </summary>
  37. /// <returns>返回定位结果ID</returns>
  38. [HttpPost]
  39. public async Task<AjaxResult<long>> PosX2D1Async(X2D1NoXlPosDto dto)
  40. {
  41. using (RHDWContext db = new RHDWContext())
  42. {
  43. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X2D1).FirstOrDefaultAsync();
  44. if (runTask == null)
  45. {
  46. Serilog.Log.Warning($"接收到两星一地定位参数,由于任务没有运行中忽略本次定位!");
  47. return Error<long>($"多模式融合定位平台没有启动两星一地定位任务");
  48. }
  49. var listTx = await db.TxInfos.ToListAsync();
  50. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  51. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  52. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  53. 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();
  54. if (xlInfo1 == null)
  55. {
  56. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  57. return Error<long>($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  58. }
  59. 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();
  60. if (xlInfo2 == null)
  61. {
  62. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  63. return Error<long>($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  64. }
  65. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  66. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  67. var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  68. var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  69. var cgRes = db.CgRes.Add(new Model.CgRes()
  70. {
  71. SigTime = dto.SigTime,
  72. DtoSx = dto.SxDto,
  73. DfoSx = dto.SxDfo,
  74. SnrSx = dto.SxSnr,
  75. DtoCdb = dto.XdDto,
  76. DfoCdb = dto.XdDfo,
  77. SnrCdb = dto.XdSnr,
  78. YbMain = dto.MainYbDto,
  79. YbAdja = dto.AdjaYbDto,
  80. MainX = ephMain.X,
  81. MainY = ephMain.Y,
  82. MainZ = ephMain.Z,
  83. AdjaX = ephAdja.X,
  84. AdjaY = ephAdja.Y,
  85. AdjaZ = ephAdja.Z,
  86. });
  87. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  88. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  89. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  90. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  91. double[] mainSat = new double[3] { ephMain.X, ephMain.Y, ephMain.Z };
  92. double[] adjaSat = new double[3] { ephAdja.X, ephAdja.Y, ephAdja.Z };
  93. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  94. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  95. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  96. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  97. double[] res = new double[6];
  98. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, dto.SxDto / 1e6, dto.XdDto / 1e6, dto.MainYbDto / 1e6, dto.AdjaYbDto / 1e6, res);
  99. PosRes posRes = new PosRes()
  100. {
  101. SigTime = dto.SigTime,
  102. TaskID = runTask.ID,
  103. CgResID = cgRes.ID,
  104. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  105. TsName = dto.TsName,
  106. PosLon = res[0],
  107. PosLat = res[1],
  108. MirrLon = res[3],
  109. MirrLat = res[4],
  110. };
  111. var tmp = db.PosRes.Add(posRes);
  112. await db.SaveChangesAsync();
  113. return Success(posRes.ID);
  114. }
  115. }
  116. /// <summary>
  117. /// 一星一地测向带参定位(含星历)
  118. /// </summary>
  119. /// <param name="dto">定位参数</param>
  120. /// <returns></returns>
  121. [HttpPost]
  122. public async Task<AjaxResult<PosRes>> PosX1D1Async(X1D1PosDto dto)
  123. {
  124. PosRes posRes = new PosRes();
  125. using (RHDWContext db = new RHDWContext())
  126. {
  127. var tsk1X1D = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X1D1CX && p.TaskState == EnumTaskState.Running);
  128. if (tsk1X1D == null)
  129. {
  130. Serilog.Log.Warning($"接收到一星一地测向带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  131. return Error<PosRes>($"多模式融合定位平台没有启动一星一地测向定位任务");
  132. }
  133. var sigTime = DateTime.Now;
  134. var listTx = new List<TxInfo>();
  135. var cgRes = new CgRes();
  136. var cxRes = new CxRes();
  137. cgRes = db.CgRes.Add(new CgRes()
  138. {
  139. SigTime = sigTime,
  140. DtoSx = dto.SxDto * 1e6,
  141. DtoCdb = dto.XdDto * 1e6,
  142. YbMain = dto.MainYbDto * 1e6,
  143. YbAdja = dto.AdjaYbDto * 1e6,
  144. MainX = dto.MainX,
  145. MainY = dto.MainY,
  146. MainZ = dto.MainZ,
  147. });
  148. listTx = await db.TxInfos.ToListAsync();
  149. cxRes = db.CxRes.Add(new CxRes()
  150. {
  151. SigTime = sigTime,
  152. Fx = dto.CxRes,
  153. });
  154. double[] res = new double[6];
  155. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  156. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  157. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  158. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  159. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  160. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  161. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  162. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  163. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  164. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  165. double theta = cxRes.Fx;//单位°
  166. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, res);
  167. posRes = new PosRes()
  168. {
  169. SigTime = cgRes.SigTime,
  170. TaskID = tsk1X1D.ID,
  171. CxResID = cxRes.ID,
  172. CgResID = cgRes.ID,
  173. TarName = "未知目标",
  174. TsName = "DAMA--56-115ms",
  175. PosLon = Math.Round(res[0], 4),
  176. PosLat = Math.Round(res[1], 4),
  177. MirrLon = Math.Round(res[3], 4),
  178. MirrLat = Math.Round(res[4], 4),
  179. };
  180. db.PosRes.Add(posRes);
  181. }
  182. return Success(posRes);
  183. }
  184. /// <summary>
  185. /// 两星一地定位(含星历)
  186. /// </summary>
  187. /// <param name="dto">定位参数</param>
  188. /// <returns></returns>
  189. [HttpPost]
  190. public async Task<AjaxResult<PosRes>> PosX2D1Async(X2D1PosDto dto)
  191. {
  192. PosRes posRes = new PosRes();
  193. using (RHDWContext db = new RHDWContext())
  194. {
  195. var tsk2X1D = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  196. if (tsk2X1D == null)
  197. {
  198. Serilog.Log.Warning($"接收到两星一地带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  199. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  200. }
  201. var sigTime = DateTime.Now;
  202. var listTx = new List<TxInfo>();
  203. var cgRes = new CgRes();
  204. cgRes = db.CgRes.Add(new CgRes()
  205. {
  206. SigTime = sigTime,
  207. DtoSx = dto.SxDto * 1e6,
  208. DtoCdb = dto.XdDto * 1e6,
  209. YbMain = dto.MainYbDto * 1e6,
  210. YbAdja = dto.AdjaYbDto * 1e6,
  211. MainX = dto.MainX,
  212. MainY = dto.MainY,
  213. MainZ = dto.MainZ,
  214. AdjaX = dto.AdjaX,
  215. AdjaY = dto.AdjaY,
  216. AdjaZ = dto.AdjaZ,
  217. });
  218. listTx = await db.TxInfos.ToListAsync();
  219. double[] res = new double[6];
  220. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  221. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  222. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  223. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  224. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  225. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  226. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  227. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  228. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  229. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  230. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  231. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx / 1e6, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, cgRes.YbAdja / 1e6, res);
  232. posRes = new PosRes()
  233. {
  234. SigTime = cgRes.SigTime,
  235. TaskID = tsk2X1D.ID,
  236. CgResID = cgRes.ID,
  237. TarName = "未知目标",
  238. TsName = "DAMA-225-173ms",
  239. PosLon = Math.Round(res[0], 4),
  240. PosLat = Math.Round(res[1], 4),
  241. MirrLon = Math.Round(res[3], 4),
  242. MirrLat = Math.Round(res[4], 4),
  243. };
  244. db.PosRes.Add(posRes);
  245. }
  246. return Success(posRes);
  247. }
  248. /// <summary>
  249. /// 融合定位(含星历)
  250. /// </summary>
  251. /// <param name="dto">定位参数</param>
  252. /// <returns></returns>
  253. [HttpPost]
  254. public async Task<AjaxResult<PosRes>> PosRhAsync(RHPosDto dto)
  255. {
  256. PosRes posRes = new PosRes();
  257. using (RHDWContext db = new RHDWContext())
  258. {
  259. var tskRh = await db.TaskInfos.FirstOrDefaultAsync(p => p.PosType == EnumPosType.RH && p.TaskState == EnumTaskState.Running);
  260. if (tskRh == null)
  261. {
  262. Serilog.Log.Warning($"接收到融合带参定位(含星历)参数,由于任务没有运行中忽略本次定位!");
  263. return Error<PosRes>($"多模式融合定位平台没有启动两星一地定位任务");
  264. }
  265. var sigTime = DateTime.Now;
  266. var listTx = new List<TxInfo>();
  267. var cgRes = new CgRes();
  268. var cxRes = new CxRes();
  269. cgRes = db.CgRes.Add(new CgRes()
  270. {
  271. SigTime = sigTime,
  272. DtoSx = dto.SxDto * 1e6,
  273. DtoCdb = dto.XdDto * 1e6,
  274. YbMain = dto.MainYbDto * 1e6,
  275. YbAdja = dto.AdjaYbDto * 1e6,
  276. MainX = dto.MainX,
  277. MainY = dto.MainY,
  278. MainZ = dto.MainZ,
  279. AdjaX = dto.AdjaX,
  280. AdjaY = dto.AdjaY,
  281. AdjaZ = dto.AdjaZ,
  282. });
  283. listTx = await db.TxInfos.ToListAsync();
  284. cxRes = db.CxRes.Add(new CxRes()
  285. {
  286. SigTime = sigTime,
  287. Fx = dto.CxRes,
  288. });
  289. double[] resX1D1 = new double[6];
  290. double[] resX2D1 = new double[6];
  291. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  292. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  293. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  294. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  295. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  296. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  297. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  298. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  299. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  300. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  301. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  302. double theta = cxRes.Fx;//单位°
  303. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, resX1D1);
  304. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx / 1e6, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, cgRes.YbAdja / 1e6, resX2D1);
  305. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  306. if (PosApi.IsGeoPoint(resX1D1) && PosApi.IsGeoPoint(resX2D1))
  307. {
  308. res = new double[6] {
  309. (resX1D1[0] + resX2D1[0]) / 2 + 0.003,
  310. (resX1D1[1] + resX2D1[1]) / 2 - 0.002,
  311. (resX1D1[2] + resX2D1[2]) / 2,
  312. (resX1D1[3] + resX2D1[3]) / 2 + 0.003,
  313. (resX1D1[4] + resX2D1[4]) / 2 - 0.002,
  314. (resX1D1[5] + resX2D1[5]) / 2,
  315. };
  316. }
  317. else if (PosApi.IsGeoPoint(resX1D1))
  318. {
  319. res = new double[6]
  320. {
  321. resX1D1[0] + 0.003,
  322. resX1D1[1] - 0.002,
  323. resX1D1[2],
  324. resX1D1[3] + 0.003,
  325. resX1D1[4] - 0.002,
  326. resX1D1[5],
  327. };
  328. }
  329. else if (PosApi.IsGeoPoint(resX2D1))
  330. {
  331. res = new double[6]
  332. {
  333. resX2D1[0] + 0.003,
  334. resX2D1[1] - 0.002,
  335. resX2D1[2],
  336. resX2D1[3] + 0.003,
  337. resX2D1[4] - 0.002,
  338. resX2D1[5],
  339. };
  340. }
  341. posRes = new PosRes()
  342. {
  343. SigTime = cgRes.SigTime,
  344. TaskID = tskRh.ID,
  345. CxResID = cxRes.ID,
  346. CgResID = cgRes.ID,
  347. TarName = "未知目标",
  348. TsName = "DAMA-225-173ms",
  349. PosLon = Math.Round(res[0], 4),
  350. PosLat = Math.Round(res[1], 4),
  351. MirrLon = Math.Round(res[3], 4),
  352. MirrLat = Math.Round(res[4], 4),
  353. };
  354. db.PosRes.Add(posRes);
  355. }
  356. return Success(posRes);
  357. }
  358. /// <summary>
  359. /// 查询定位结果(暂未实现)
  360. /// </summary>
  361. /// <param name="dto"></param>
  362. /// <returns></returns>
  363. /// <exception cref="Exception"></exception>
  364. [HttpGet]
  365. public async Task<AjaxResult<PosResDto>> GetPosRes(PosResQueryDto dto)
  366. {
  367. await Task.Delay(100);
  368. return Error<PosResDto>("该功能暂未实现!");
  369. }
  370. }
  371. }