PosController.cs 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Linq;
  5. using System.Net.Http;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Web.Http;
  9. using Serilog;
  10. using XdCxRhDW.Dto;
  11. using XdCxRhDW.Repostory;
  12. using System.IO;
  13. using XdCxRhDW.Entity;
  14. using XdCxRhDW.Api;
  15. using XdCxRhDW.WebApi;
  16. using DPP_YH_Core.Extensions;
  17. using XdCxRhDW.App.Model;
  18. using System.Diagnostics;
  19. using System.Configuration;
  20. using System.Data.Entity.Infrastructure;
  21. using XdCxRhDW.Framework;
  22. namespace XdCxRhDW.App.Controllers
  23. {
  24. /// <summary>
  25. /// 定位功能相关接口
  26. /// </summary>
  27. public class PosController : BaseController
  28. {
  29. #region 一星一地测向定位
  30. /// <summary>
  31. /// 一星一地测向带参定位(含星历)
  32. /// </summary>
  33. /// <param name="dto">定位参数</param>
  34. /// <returns></returns>
  35. [HttpPost]
  36. public async Task<AjaxResult<PosResDto>> PosX1D1Async(X1D1PosDto dto)
  37. {
  38. TaskInfo runTask;
  39. using (RHDWContext db = new RHDWContext())
  40. {
  41. if (dto.TaskID == null)
  42. {
  43. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  44. && p.PosType == EnumPosType.X1D1CX && p.TaskState == EnumTaskState.Running);
  45. if (runTask == null)
  46. {
  47. Serilog.Log.Warning($"接收到一星一地测向带参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  48. return Error<PosResDto>($"多模式融合定位平台没有启动一星一地测向定位任务");
  49. }
  50. }
  51. else
  52. {
  53. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  54. if (runTask == null)
  55. {
  56. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  57. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  58. }
  59. }
  60. }
  61. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  62. {
  63. var StationRes = db.StationRes.Add(new StationRes()
  64. {
  65. SatTxLon = dto.SatTxLon,
  66. SatTxLat = dto.SatTxLat,
  67. CdbTxLon = dto.CdbTxLon,
  68. CdbTxLat = dto.CdbTxLat,
  69. CxLon = dto.CxLon,
  70. CxLat = dto.CxLat,
  71. RefLon = dto.RefLon,
  72. RefLat = dto.RefLat,
  73. });
  74. var ckRes = new CheckRes()
  75. {
  76. FileName = dto.CheckRes?.FileName,
  77. SmpStart = dto.CheckRes?.SmpStart,
  78. SmpCount = dto.CheckRes?.SmpCount,
  79. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  80. ModRate = dto.CheckRes?.ModRate,
  81. ModType = dto.CheckRes?.ModType,
  82. UserName = dto.CheckRes?.UserName,
  83. FfcHz = dto.CheckRes?.FfcHz,
  84. Snr = dto.CheckRes?.Snr
  85. };
  86. db.CheckRes.Add(ckRes);
  87. var cgRes = db.CgRes.Add(new CgRes()
  88. {
  89. SigTime = dto.SigTime,
  90. DtoCdb = Math.Round(dto.XdDto, 10),
  91. DfoCdb = Math.Round(dto.XdDfo, 10),
  92. SnrCdb = Math.Round(dto.XdSnr, 1),
  93. YbMainDto = Math.Round(dto.MainYbDto, 10),
  94. StationResID = StationRes.ID,
  95. MainCode = dto.MainCode,
  96. TaskID = runTask.ID,
  97. MainX = dto.MainX,
  98. MainY = dto.MainY,
  99. MainZ = dto.MainZ,
  100. TarFreqUp = dto.FreqUp,
  101. TarFreqDown = dto.FreqDown,
  102. });
  103. var cxRes = db.CxRes.Add(new CxRes()
  104. {
  105. SigTime = dto.SigTime,
  106. Fx = dto.CxRes,
  107. });
  108. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes, dto.CalcConfidence);
  109. PosRes posRes = new PosRes()
  110. {
  111. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  112. SigTime = cgRes.SigTime,
  113. TaskInfoID = runTask.ID,
  114. CxResID = cxRes.ID,
  115. CgResID = cgRes.ID,
  116. CheckResID = ckRes.ID,
  117. PosLon = res[0],
  118. PosLat = res[1],
  119. MirrLon = res[3],
  120. MirrLat = res[4],
  121. Confidence = (int)res[6],
  122. PosResType = EnumPosResType.X1D1CX,
  123. };
  124. posRes = db.PosRes.Add(posRes);
  125. await db.SaveChangesAsync();
  126. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  127. return Success(MapDto(posRes));
  128. }
  129. }
  130. /// <summary>
  131. /// 一星一地测向带参定位(无星历)
  132. /// </summary>
  133. /// <returns>返回定位结果ID</returns>
  134. [HttpPost]
  135. public async Task<AjaxResult<PosResDto>> PosX1D1NoXlAsync(X1D1NoXlPosDto dto)
  136. {
  137. TaskInfo runTask;
  138. using (RHDWContext db = new RHDWContext())
  139. {
  140. if (dto.TaskID == null)
  141. {
  142. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  143. && p.PosType == EnumPosType.X1D1CX && p.TaskState == EnumTaskState.Running);
  144. if (runTask == null)
  145. {
  146. Serilog.Log.Warning($"接收到一星一地测向带参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  147. return Error<PosResDto>($"多模式融合定位平台没有启动一星一地测向定位任务");
  148. }
  149. }
  150. else
  151. {
  152. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  153. if (runTask == null)
  154. {
  155. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  156. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  157. }
  158. }
  159. }
  160. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  161. if (xl1 == null)
  162. {
  163. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  164. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  165. }
  166. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  167. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  168. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  169. if (ephMain.code != 200)
  170. {
  171. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  172. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  173. }
  174. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  175. {
  176. var StationRes = db.StationRes.Add(new StationRes()
  177. {
  178. SatTxLon = dto.SatTxLon,
  179. SatTxLat = dto.SatTxLat,
  180. CdbTxLon = dto.CdbTxLon,
  181. CdbTxLat = dto.CdbTxLat,
  182. CxLon = dto.CxLon,
  183. CxLat = dto.CxLat,
  184. RefLon = dto.RefLon,
  185. RefLat = dto.RefLat,
  186. });
  187. var ckRes = new CheckRes()
  188. {
  189. FileName = dto.CheckRes?.FileName,
  190. SmpStart = dto.CheckRes?.SmpStart,
  191. SmpCount = dto.CheckRes?.SmpCount,
  192. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  193. ModRate = dto.CheckRes?.ModRate,
  194. ModType = dto.CheckRes?.ModType,
  195. UserName = dto.CheckRes?.UserName,
  196. FfcHz = dto.CheckRes?.FfcHz,
  197. Snr = dto.CheckRes?.Snr
  198. };
  199. db.CheckRes.Add(ckRes);
  200. var cgRes = db.CgRes.Add(new CgRes()
  201. {
  202. SigTime = dto.SigTime,
  203. DtoCdb = Math.Round(dto.XdDto, 10),
  204. DfoCdb = Math.Round(dto.XdDfo, 10),
  205. SnrCdb = Math.Round(dto.XdSnr, 1),
  206. YbMainDto = Math.Round(dto.MainYbDto, 10),
  207. StationResID = StationRes.ID,
  208. MainCode = dto.MainCode,
  209. MainXlTime = ephMain.data.TleTime,
  210. TaskID = runTask.ID,
  211. MainX = ephMain.data.X,
  212. MainY = ephMain.data.Y,
  213. MainZ = ephMain.data.Z,
  214. MainVx = ephMain.data.VX,
  215. MainVy = ephMain.data.VY,
  216. MainVz = ephMain.data.VZ,
  217. TarFreqUp = dto.FreqUp,
  218. TarFreqDown = dto.FreqDown,
  219. });
  220. var cxRes = db.CxRes.Add(new CxRes()
  221. {
  222. SigTime = dto.SigTime,
  223. Fx = dto.CxRes,
  224. });
  225. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes, dto.CalcConfidence);
  226. PosRes posRes = new PosRes()
  227. {
  228. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  229. SigTime = dto.SigTime,
  230. TaskInfoID = runTask.ID,
  231. CgResID = cgRes.ID,
  232. CxResID = cxRes.ID,
  233. CheckResID = ckRes.ID,
  234. PosLon = res[0],
  235. PosLat = res[1],
  236. MirrLon = res[3],
  237. MirrLat = res[4],
  238. Confidence = (int)res[6],
  239. PosResType = EnumPosResType.X1D1CX,
  240. };
  241. posRes = db.PosRes.Add(posRes);
  242. await db.SaveChangesAsync();
  243. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  244. return Success(MapDto(posRes));
  245. }
  246. }
  247. #endregion
  248. #region 两星一地定位
  249. /// <summary>
  250. /// 两星一地带参定位(含星历)
  251. /// </summary>
  252. /// <param name="dto">定位参数</param>
  253. /// <returns></returns>
  254. [HttpPost]
  255. public async Task<AjaxResult<PosResDto>> PosX2D1Async(X2D1PosDto dto)
  256. {
  257. try
  258. {
  259. TaskInfo runTask;
  260. using (RHDWContext db = new RHDWContext())
  261. {
  262. if (dto.TaskID == null)
  263. {
  264. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  265. && p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  266. if (runTask == null)
  267. {
  268. Serilog.Log.Warning($"接收到两星一地带参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  269. return Error<PosResDto>($"多模式融合定位平台没有启动两星一地定位任务");
  270. }
  271. }
  272. else
  273. {
  274. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  275. if (runTask == null)
  276. {
  277. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  278. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  279. }
  280. }
  281. }
  282. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  283. {
  284. var StationRes = db.StationRes.Add(new StationRes()
  285. {
  286. SatTxLon = dto.SatTxLon,
  287. SatTxLat = dto.SatTxLat,
  288. CdbTxLon = dto.CdbTxLon,
  289. CdbTxLat = dto.CdbTxLat,
  290. RefLon = dto.RefLon,
  291. RefLat = dto.RefLat,
  292. });
  293. var ckRes = new CheckRes()
  294. {
  295. FileName = dto.CheckRes?.FileName,
  296. SmpStart = dto.CheckRes?.SmpStart,
  297. SmpCount = dto.CheckRes?.SmpCount,
  298. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  299. ModRate = dto.CheckRes?.ModRate,
  300. ModType = dto.CheckRes?.ModType,
  301. UserName = dto.CheckRes?.UserName,
  302. FfcHz = dto.CheckRes?.FfcHz,
  303. Snr = dto.CheckRes?.Snr
  304. };
  305. ckRes = db.CheckRes.Add(ckRes);
  306. var cgRes = db.CgRes.Add(new CgRes()
  307. {
  308. SigTime = dto.SigTime,
  309. Dto1 = Math.Round(dto.SxDto, 10),
  310. Dfo1 = Math.Round(dto.SxDfo, 10),
  311. Snr1 = Math.Round(dto.SxSnr, 1),
  312. DtoCdb = Math.Round(dto.XdDto, 10),
  313. DfoCdb = Math.Round(dto.XdDfo, 10),
  314. SnrCdb = Math.Round(dto.XdSnr, 1),
  315. YbMainDto = Math.Round(dto.MainYbDto, 10),
  316. YbAdja1Dto = Math.Round(dto.AdjaYbDto, 10),
  317. StationResID = StationRes.ID,
  318. MainCode = dto.MainCode,
  319. Adja1Code = dto.AdjaCode,
  320. TaskID = runTask.ID,
  321. MainX = dto.MainX,
  322. MainY = dto.MainY,
  323. MainZ = dto.MainZ,
  324. Adja1X = dto.AdjaX,
  325. Adja1Y = dto.AdjaY,
  326. Adja1Z = dto.AdjaZ,
  327. MainVx = dto.MainVX,
  328. MainVy = dto.MainVY,
  329. MainVz = dto.MainVZ,
  330. Adja1Vx = dto.AdjaVX,
  331. Adja1Vy = dto.AdjaVY,
  332. Adja1Vz = dto.AdjaVZ,
  333. TarFreqUp = dto.FreqUp,
  334. TarFreqDown = dto.FreqDown,
  335. });
  336. var res = PosApi.X2D1_Pos(cgRes, StationRes, dto.CalcConfidence);
  337. PosRes posRes = new PosRes()
  338. {
  339. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  340. SigTime = cgRes.SigTime,
  341. TaskInfoID = runTask.ID,
  342. CgResID = cgRes.ID,
  343. CheckResID = ckRes.ID,
  344. PosLon = res[0],
  345. PosLat = res[1],
  346. MirrLon = res[3],
  347. MirrLat = res[4],
  348. Confidence = (int)res[6],
  349. PosResType = EnumPosResType.X2D1,
  350. };
  351. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  352. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  353. if (dto.CalcConfidence)
  354. {
  355. }
  356. posRes = db.PosRes.Add(posRes);
  357. await db.SaveChangesAsync();
  358. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  359. return Success(MapDto(posRes));
  360. }
  361. }
  362. catch (Exception)
  363. {
  364. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  365. {
  366. db.SyncDb();
  367. }
  368. throw;
  369. }
  370. }
  371. /// <summary>
  372. /// 两星一地带参定位(无星历)
  373. /// </summary>
  374. /// <returns>返回定位结果ID</returns>
  375. [HttpPost]
  376. public async Task<AjaxResult<PosResDto>> PosX2D1NoXlAsync(X2D1NoXlPosDto dto)
  377. {
  378. try
  379. {
  380. TaskInfo runTask;
  381. using (RHDWContext db = new RHDWContext())
  382. {
  383. if (dto.TaskID == null)
  384. {
  385. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  386. && p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  387. if (runTask == null)
  388. {
  389. Serilog.Log.Warning($"接收到两星一地带参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  390. return Error<PosResDto>($"多模式融合定位平台没有启动两星一地定位任务");
  391. }
  392. }
  393. else
  394. {
  395. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  396. if (runTask == null)
  397. {
  398. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  399. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  400. }
  401. }
  402. }
  403. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  404. if (xl1 == null)
  405. {
  406. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  407. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  408. }
  409. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  410. var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
  411. if (xl2 == null)
  412. {
  413. Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  414. return Error<PosResDto>($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  415. }
  416. Serilog.Log.Information($"卫星{dto.AdjaCode}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  417. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  418. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  419. if (ephMain.code != 200)
  420. {
  421. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  422. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  423. }
  424. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  425. var ephAdja = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  426. if (ephAdja.code != 200)
  427. {
  428. Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
  429. return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
  430. }
  431. //#warning 测试代码
  432. //var tarEcef = PhysicsHelper.GeoToEcef((110, 17, 0));
  433. //var ecefXl1 = (ephMain.data.X, ephMain.data.Y, ephMain.data.Z);
  434. //var ecefXl2 = (ephAdja.data.X, ephAdja.data.Y, ephAdja.data.Z);
  435. //var ecefCdb = PhysicsHelper.GeoToEcef((dto.CdbTxLon, dto.CdbTxLat, 0));
  436. //var ecefRec = PhysicsHelper.GeoToEcef((dto.SatTxLon, dto.SatTxLat, 0));
  437. //var dt1 = PhysicsHelper.Dto(tarEcef, ecefXl1, ecefRec);
  438. //var dt2 = PhysicsHelper.Dto(tarEcef, ecefXl2, ecefRec);
  439. //var dt3 = PhysicsHelper.Dto(tarEcef, ecefCdb);
  440. //var dto1 = dt1 - dt2;
  441. //var dto2 = dt1 - dt3;
  442. //dto.SxDto = Math.Round(dto1 * 1e6 + r.Next(-10, 10) + r.NextDouble(), 3);
  443. //dto.XdDto = Math.Round(dto2 * 1e6 + r.Next(-10, 10) + r.NextDouble(), 3);
  444. //var refEcef = PhysicsHelper.GeoToEcef((dto.RefLon, dto.RefLat, 0));
  445. //var refdt1 = PhysicsHelper.Dto(refEcef, ecefXl1, ecefRec);
  446. //var refdt2 = PhysicsHelper.Dto(refEcef, ecefXl2, ecefRec);
  447. //dto.MainYbDto = Math.Round(refdt1 * 1e6, 3);
  448. //dto.AdjaYbDto = Math.Round(refdt2 * 1e6, 3);
  449. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  450. {
  451. var StationRes = db.StationRes.Add(new StationRes()
  452. {
  453. SatTxLon = dto.SatTxLon,
  454. SatTxLat = dto.SatTxLat,
  455. CdbTxLon = dto.CdbTxLon,
  456. CdbTxLat = dto.CdbTxLat,
  457. RefLon = dto.RefLon,
  458. RefLat = dto.RefLat,
  459. });
  460. var ckRes = new CheckRes()
  461. {
  462. FileName = dto.CheckRes?.FileName,
  463. SmpStart = dto.CheckRes?.SmpStart,
  464. SmpCount = dto.CheckRes?.SmpCount,
  465. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  466. ModRate = dto.CheckRes?.ModRate,
  467. ModType = dto.CheckRes?.ModType,
  468. UserName = dto.CheckRes?.UserName,
  469. FfcHz = dto.CheckRes?.FfcHz,
  470. Snr = dto.CheckRes?.Snr
  471. };
  472. db.CheckRes.Add(ckRes);
  473. var cgRes = db.CgRes.Add(new CgRes()
  474. {
  475. SigTime = dto.SigTime,
  476. Dto1 = Math.Round(dto.SxDto, 10),
  477. Dfo1 = Math.Round(dto.SxDfo, 10),
  478. Snr1 = Math.Round(dto.SxSnr, 1),
  479. DtoCdb = Math.Round(dto.XdDto, 10),
  480. DfoCdb = Math.Round(dto.XdDfo, 10),
  481. SnrCdb = Math.Round(dto.XdSnr, 1),
  482. YbMainDto = Math.Round(dto.MainYbDto, 10),
  483. YbAdja1Dto = Math.Round(dto.AdjaYbDto, 10),
  484. StationResID = StationRes.ID,
  485. MainCode = dto.MainCode,
  486. MainXlTime = ephMain.data.TleTime,
  487. Adja1Code = dto.AdjaCode,
  488. Adja1XlTime = ephAdja.data.TleTime,
  489. TaskID = runTask.ID,
  490. MainX = ephMain.data.X,
  491. MainY = ephMain.data.Y,
  492. MainZ = ephMain.data.Z,
  493. MainVx = ephMain.data.VX,
  494. MainVy = ephMain.data.VY,
  495. MainVz = ephMain.data.VZ,
  496. Adja1Vx = ephAdja.data.VX,
  497. Adja1Vy = ephAdja.data.VY,
  498. Adja1Vz = ephAdja.data.VZ,
  499. Adja1X = ephAdja.data.X,
  500. Adja1Y = ephAdja.data.Y,
  501. Adja1Z = ephAdja.data.Z,
  502. TarFreqUp = dto.FreqUp,
  503. TarFreqDown = dto.FreqDown,
  504. });
  505. var res = PosApi.X2D1_Pos(cgRes, StationRes, dto.CalcConfidence);
  506. PosRes posRes = new PosRes()
  507. {
  508. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  509. SigTime = dto.SigTime,
  510. TaskInfoID = runTask.ID,
  511. CgResID = cgRes.ID,
  512. CheckResID = ckRes.ID,
  513. PosLon = res[0],
  514. PosLat = res[1],
  515. MirrLon = res[3],
  516. MirrLat = res[4],
  517. Confidence = (int)res[6],
  518. PosResType = EnumPosResType.X2D1,
  519. };
  520. if (posRes.PosLon == 999 || posRes.PosLat == 999)//有参无结果时做无参
  521. {
  522. res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  523. posRes = new PosRes()
  524. {
  525. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  526. SigTime = dto.SigTime,
  527. TaskInfoID = runTask.ID,
  528. CgResID = cgRes.ID,
  529. CheckResID = ckRes.ID,
  530. PosLon = res[0],
  531. PosLat = res[1],
  532. MirrLon = res[3],
  533. MirrLat = res[4],
  534. Confidence = (int)res[6],
  535. PosResType = EnumPosResType.X2D1NoRef,
  536. };
  537. }
  538. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  539. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  540. posRes = db.PosRes.Add(posRes);
  541. await db.SaveChangesAsync();
  542. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  543. return Success(MapDto(posRes));
  544. }
  545. }
  546. catch (Exception)
  547. {
  548. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  549. {
  550. db.SyncDb();
  551. }
  552. throw;
  553. }
  554. }
  555. /// <summary>
  556. /// 两星一地无参定位(含星历)
  557. /// </summary>
  558. /// <param name="dto">定位参数</param>
  559. /// <returns></returns>
  560. [HttpPost]
  561. public async Task<AjaxResult<PosResDto>> PosX2D1NoParAsync(X2D1NoParPosDto dto)
  562. {
  563. try
  564. {
  565. TaskInfo runTask;
  566. using (RHDWContext db = new RHDWContext())
  567. {
  568. if (dto.TaskID == null)
  569. {
  570. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  571. && p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  572. if (runTask == null)
  573. {
  574. Serilog.Log.Warning($"接收到两星一地无参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  575. return Error<PosResDto>($"多模式融合定位平台没有启动两星一地定位任务");
  576. }
  577. }
  578. else
  579. {
  580. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  581. if (runTask == null)
  582. {
  583. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  584. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  585. }
  586. }
  587. }
  588. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  589. {
  590. var StationRes = db.StationRes.Add(new StationRes()
  591. {
  592. SatTxLon = dto.SatTxLon,
  593. SatTxLat = dto.SatTxLat,
  594. CdbTxLon = dto.CdbTxLon,
  595. CdbTxLat = dto.CdbTxLat,
  596. });
  597. var ckRes = new CheckRes()
  598. {
  599. FileName = dto.CheckRes?.FileName,
  600. SmpStart = dto.CheckRes?.SmpStart,
  601. SmpCount = dto.CheckRes?.SmpCount,
  602. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  603. ModRate = dto.CheckRes?.ModRate,
  604. ModType = dto.CheckRes?.ModType,
  605. UserName = dto.CheckRes?.UserName,
  606. FfcHz = dto.CheckRes?.FfcHz,
  607. Snr = dto.CheckRes?.Snr
  608. };
  609. db.CheckRes.Add(ckRes);
  610. var cgRes = db.CgRes.Add(new CgRes()
  611. {
  612. SigTime = dto.SigTime,
  613. Dto1 = Math.Round(dto.SxDto, 10),
  614. Dfo1 = Math.Round(dto.SxDfo, 10),
  615. Snr1 = Math.Round(dto.SxSnr, 1),
  616. DtoCdb = Math.Round(dto.XdDto, 10),
  617. DfoCdb = Math.Round(dto.XdDfo, 10),
  618. SnrCdb = Math.Round(dto.XdSnr, 1),
  619. StationResID = StationRes.ID,
  620. MainCode = dto.MainCode,
  621. Adja1Code = dto.AdjaCode,
  622. TaskID = runTask.ID,
  623. MainX = dto.MainX,
  624. MainY = dto.MainY,
  625. MainZ = dto.MainZ,
  626. Adja1X = dto.AdjaX,
  627. Adja1Y = dto.AdjaY,
  628. Adja1Z = dto.AdjaZ,
  629. MainVx = dto.MainVX,
  630. MainVy = dto.MainVY,
  631. MainVz = dto.MainVZ,
  632. Adja1Vx = dto.AdjaVX,
  633. Adja1Vy = dto.AdjaVY,
  634. Adja1Vz = dto.AdjaVZ,
  635. TarFreqUp = dto.FreqUp,
  636. TarFreqDown = dto.FreqDown,
  637. });
  638. double[] res;
  639. res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  640. PosRes posRes = new PosRes()
  641. {
  642. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  643. SigTime = cgRes.SigTime,
  644. TaskInfoID = runTask.ID,
  645. CgResID = cgRes.ID,
  646. CheckResID = ckRes.ID,
  647. PosLon = res[0],
  648. PosLat = res[1],
  649. MirrLon = res[3],
  650. MirrLat = res[4],
  651. Confidence = (int)res[6],
  652. PosResType = EnumPosResType.X2D1NoRef,
  653. };
  654. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  655. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  656. posRes = db.PosRes.Add(posRes);
  657. await db.SaveChangesAsync();
  658. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  659. return Success(MapDto(posRes));
  660. }
  661. }
  662. catch (Exception)
  663. {
  664. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  665. {
  666. db.SyncDb();
  667. }
  668. throw;
  669. }
  670. }
  671. Random r = new Random();
  672. /// <summary>
  673. /// 两星一地无参定位(无星历)
  674. /// </summary>
  675. /// <returns>返回定位结果ID</returns>
  676. [HttpPost]
  677. public async Task<AjaxResult<PosResDto>> PosX2D1BeFindRefListAsync(List<X2D1NoXlNoParlPosDto> dtos)
  678. {
  679. var dto = dtos.First();
  680. try
  681. {
  682. TaskInfo runTask;
  683. using (RHDWContext db = new RHDWContext())
  684. {
  685. if (dto.TaskID == null)
  686. {
  687. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  688. && p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  689. if (runTask == null)
  690. {
  691. Serilog.Log.Warning($"接收到两星一地无参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  692. return Error<PosResDto>($"多模式融合定位平台没有启动两星一地定位任务");
  693. }
  694. }
  695. else
  696. {
  697. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  698. if (runTask == null)
  699. {
  700. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  701. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  702. }
  703. }
  704. }
  705. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  706. if (xl1 == null)
  707. {
  708. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  709. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  710. }
  711. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  712. var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
  713. if (xl2 == null)
  714. {
  715. Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  716. return Error<PosResDto>($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  717. }
  718. Serilog.Log.Information($"卫星{dto.AdjaCode}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  719. //dto.SigTime = new DateTime(2023, 12, 24, 18, 0, 0);
  720. //dto.CdbTxLon = 45;
  721. //dto.CdbTxLat = 20;
  722. //dto.SatTxLon = 45;
  723. //dto.SatTxLat = 20;
  724. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  725. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  726. if (ephMain.code != 200)
  727. {
  728. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  729. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  730. }
  731. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  732. var ephAdja = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  733. if (ephAdja.code != 200)
  734. {
  735. Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
  736. return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
  737. }
  738. X2D1PosRefService.Instance.AddPosDto(dtos);
  739. PosRes posRes = new PosRes();
  740. return Success(MapDto(posRes));
  741. }
  742. catch (Exception)
  743. {
  744. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  745. {
  746. db.SyncDb();
  747. }
  748. throw;
  749. }
  750. }
  751. /// <summary>
  752. /// 两星一地无参定位(无星历)
  753. /// </summary>
  754. /// <returns>返回定位结果ID</returns>
  755. [HttpPost]
  756. public async Task<AjaxResult<PosResDto>> PosX2D1NoXlNoParAsync(X2D1NoXlNoParlPosDto dto)
  757. {
  758. try
  759. {
  760. TaskInfo runTask;
  761. using (RHDWContext db = new RHDWContext())
  762. {
  763. if (dto.TaskID == null)
  764. {
  765. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  766. && p.PosType == EnumPosType.X2D1 && p.TaskState == EnumTaskState.Running);
  767. if (runTask == null)
  768. {
  769. Serilog.Log.Warning($"接收到两星一地无参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  770. return Error<PosResDto>($"多模式融合定位平台没有启动两星一地定位任务");
  771. }
  772. }
  773. else
  774. {
  775. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  776. if (runTask == null)
  777. {
  778. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  779. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  780. }
  781. }
  782. }
  783. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  784. if (xl1 == null)
  785. {
  786. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  787. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  788. }
  789. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  790. var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
  791. if (xl2 == null)
  792. {
  793. Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  794. return Error<PosResDto>($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  795. }
  796. Serilog.Log.Information($"卫星{dto.AdjaCode}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  797. //dto.SigTime = new DateTime(2023, 12, 24, 18, 0, 0);
  798. //dto.CdbTxLon = 45;
  799. //dto.CdbTxLat = 20;
  800. //dto.SatTxLon = 45;
  801. //dto.SatTxLat = 20;
  802. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  803. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  804. if (ephMain.code != 200)
  805. {
  806. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  807. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  808. }
  809. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  810. var ephAdja = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  811. if (ephAdja.code != 200)
  812. {
  813. Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
  814. return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
  815. }
  816. //#warning 测试代码
  817. //var tarEcef = PhysicsHelper.GeoToEcef((46, 21, 0));
  818. //var ecefXl1 = (ephMain.data.X, ephMain.data.Y, ephMain.data.Z);
  819. //var ecefXl2 = (ephAdja.data.X, ephAdja.data.Y, ephAdja.data.Z);
  820. //var ecefCdb = PhysicsHelper.GeoToEcef((dto.CdbTxLon, dto.CdbTxLat, 0));
  821. //var ecefRec = PhysicsHelper.GeoToEcef((dto.SatTxLon, dto.SatTxLat, 0));
  822. //var dt1 = PhysicsHelper.Dto(tarEcef, ecefXl1, ecefRec);
  823. //var dt2 = PhysicsHelper.Dto(tarEcef, ecefXl2, ecefRec);
  824. //var dt3 = PhysicsHelper.Dto(tarEcef, ecefCdb);
  825. //var dto1 = dt1 - dt2;
  826. //var dto2 = dt1 - dt3;
  827. //dto.SxDto = dto1 * 1e6 + r.Next(-10, 10) + Math.Round(r.NextDouble(), 3);
  828. //dto.XdDto = dto2 * 1e6 + r.Next(-10, 10) + Math.Round(r.NextDouble(), 3);
  829. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  830. {
  831. var StationRes = db.StationRes.Add(new StationRes()
  832. {
  833. SatTxLon = dto.SatTxLon,
  834. SatTxLat = dto.SatTxLat,
  835. CdbTxLon = dto.CdbTxLon,
  836. CdbTxLat = dto.CdbTxLat,
  837. });
  838. var ckRes = new CheckRes()
  839. {
  840. FileName = dto.CheckRes?.FileName,
  841. SmpStart = dto.CheckRes?.SmpStart,
  842. SmpCount = dto.CheckRes?.SmpCount,
  843. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  844. ModRate = dto.CheckRes?.ModRate,
  845. ModType = dto.CheckRes?.ModType,
  846. UserName = dto.CheckRes?.UserName,
  847. FfcHz = dto.CheckRes?.FfcHz,
  848. Snr = dto.CheckRes?.Snr
  849. };
  850. db.CheckRes.Add(ckRes);
  851. var cgRes = db.CgRes.Add(new CgRes()
  852. {
  853. SigTime = dto.SigTime,
  854. Dto1 = Math.Round(dto.SxDto, 10),
  855. Dfo1 = Math.Round(dto.SxDfo, 10),
  856. Snr1 = Math.Round(dto.SxSnr, 1),
  857. DtoCdb = Math.Round(dto.XdDto, 10),
  858. DfoCdb = Math.Round(dto.XdDfo, 10),
  859. SnrCdb = Math.Round(dto.XdSnr, 1),
  860. StationResID = StationRes.ID,
  861. FixedStationID = dto.FixedStationId,
  862. MainCode = dto.MainCode,
  863. Adja1Code = dto.AdjaCode,
  864. MainXlTime = ephMain.data.TleTime,
  865. Adja1XlTime = ephAdja.data.TleTime,
  866. TaskID = runTask.ID,
  867. MainX = ephMain.data.X,
  868. MainY = ephMain.data.Y,
  869. MainZ = ephMain.data.Z,
  870. Adja1X = ephAdja.data.X,
  871. Adja1Y = ephAdja.data.Y,
  872. Adja1Z = ephAdja.data.Z,
  873. MainVx = ephMain.data.VX,
  874. MainVy = ephMain.data.VY,
  875. MainVz = ephMain.data.VZ,
  876. Adja1Vx = ephAdja.data.VX,
  877. Adja1Vy = ephAdja.data.VY,
  878. Adja1Vz = ephAdja.data.VZ,
  879. TarFreqUp = dto.FreqUp,
  880. TarFreqDown = dto.FreqDown,
  881. });
  882. double[] res;
  883. res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  884. PosRes posRes = new PosRes()
  885. {
  886. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  887. SigTime = dto.SigTime,
  888. TaskInfoID = runTask.ID,
  889. CgResID = cgRes.ID,
  890. CheckResID = ckRes.ID,
  891. PosLon = res[0],
  892. PosLat = res[1],
  893. MirrLon = res[3],
  894. MirrLat = res[4],
  895. Confidence = (int)res[6],
  896. PosResType = EnumPosResType.X2D1NoRef,
  897. };
  898. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  899. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  900. posRes = db.PosRes.Add(posRes);
  901. await db.SaveChangesAsync();
  902. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  903. return Success(MapDto(posRes));
  904. }
  905. }
  906. catch (Exception)
  907. {
  908. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  909. {
  910. db.SyncDb();
  911. }
  912. throw;
  913. }
  914. }
  915. #endregion
  916. #region 融合定位
  917. /// <summary>
  918. /// 融合带参定位(含星历)
  919. /// </summary>
  920. /// <param name="dto">定位参数</param>
  921. /// <returns></returns>
  922. [HttpPost]
  923. public async Task<AjaxResult<PosResDto>> PosRhAsync(RHPosDto dto)
  924. {
  925. TaskInfo runTask;
  926. using (RHDWContext db = new RHDWContext())
  927. {
  928. if (dto.TaskID == null)
  929. {
  930. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  931. && p.PosType == EnumPosType.RH && p.TaskState == EnumTaskState.Running);
  932. if (runTask == null)
  933. {
  934. Serilog.Log.Warning($"接收到融合带参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  935. return Error<PosResDto>($"多模式融合定位平台没有启动融合定位任务");
  936. }
  937. }
  938. else
  939. {
  940. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  941. if (runTask == null)
  942. {
  943. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  944. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  945. }
  946. }
  947. }
  948. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  949. {
  950. var StationRes = db.StationRes.Add(new StationRes()
  951. {
  952. SatTxLon = dto.SatTxLon,
  953. SatTxLat = dto.SatTxLat,
  954. CdbTxLon = dto.CdbTxLon,
  955. CdbTxLat = dto.CdbTxLat,
  956. CxLon = dto.CxLon,
  957. CxLat = dto.CxLat,
  958. RefLon = dto.RefLon,
  959. RefLat = dto.RefLat,
  960. });
  961. var ckRes = new CheckRes()
  962. {
  963. FileName = dto.CheckRes?.FileName,
  964. SmpStart = dto.CheckRes?.SmpStart,
  965. SmpCount = dto.CheckRes?.SmpCount,
  966. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  967. ModRate = dto.CheckRes?.ModRate,
  968. ModType = dto.CheckRes?.ModType,
  969. UserName = dto.CheckRes?.UserName,
  970. FfcHz = dto.CheckRes?.FfcHz,
  971. Snr = dto.CheckRes?.Snr
  972. };
  973. db.CheckRes.Add(ckRes);
  974. var cgRes = db.CgRes.Add(new CgRes()
  975. {
  976. SigTime = dto.SigTime,
  977. Dto1 = Math.Round(dto.SxDto, 10),
  978. Dfo1 = Math.Round(dto.SxDfo, 10),
  979. Snr1 = Math.Round(dto.SxSnr, 1),
  980. DtoCdb = Math.Round(dto.XdDto, 10),
  981. DfoCdb = Math.Round(dto.XdDfo, 10),
  982. SnrCdb = Math.Round(dto.XdSnr, 1),
  983. YbMainDto = Math.Round(dto.MainYbDto, 10),
  984. YbAdja1Dto = Math.Round(dto.AdjaYbDto, 10),
  985. StationResID = StationRes.ID,
  986. MainCode = dto.MainCode,
  987. Adja1Code = dto.AdjaCode,
  988. TaskID = runTask.ID,
  989. MainX = dto.MainX,
  990. MainY = dto.MainY,
  991. MainZ = dto.MainZ,
  992. Adja1X = dto.AdjaX,
  993. Adja1Y = dto.AdjaY,
  994. Adja1Z = dto.AdjaZ,
  995. TarFreqUp = dto.FreqUp,
  996. TarFreqDown = dto.FreqDown,
  997. });
  998. var cxRes = db.CxRes.Add(new CxRes()
  999. {
  1000. SigTime = dto.SigTime,
  1001. Fx = dto.CxRes,
  1002. });
  1003. var res = PosApi.RH_Pos(cgRes, StationRes, cxRes, dto.CalcConfidence);
  1004. PosRes posRes = new PosRes()
  1005. {
  1006. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  1007. SigTime = cgRes.SigTime,
  1008. TaskInfoID = runTask.ID,
  1009. CxResID = cxRes.ID,
  1010. CgResID = cgRes.ID,
  1011. CheckResID = ckRes.ID,
  1012. PosLon = res[0],
  1013. PosLat = res[1],
  1014. MirrLon = res[3],
  1015. MirrLat = res[4],
  1016. Confidence = (int)res[6],
  1017. PosResType = EnumPosResType.RH,
  1018. };
  1019. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  1020. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  1021. posRes = db.PosRes.Add(posRes);
  1022. await db.SaveChangesAsync();
  1023. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  1024. return Success(MapDto(posRes));
  1025. }
  1026. }
  1027. /// <summary>
  1028. /// 融合带参定位(无星历)
  1029. /// </summary>
  1030. /// <returns>返回定位结果ID</returns>
  1031. [HttpPost]
  1032. public async Task<AjaxResult<PosResDto>> PosRhNoXlAsync(RHNoXlPosDto dto)
  1033. {
  1034. TaskInfo runTask;
  1035. using (RHDWContext db = new RHDWContext())
  1036. {
  1037. if (dto.TaskID == null)
  1038. {
  1039. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  1040. && p.PosType == EnumPosType.RH && p.TaskState == EnumTaskState.Running);
  1041. if (runTask == null)
  1042. {
  1043. Serilog.Log.Warning($"接收到融合带参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  1044. return Error<PosResDto>($"多模式融合定位平台没有启动融合定位任务");
  1045. }
  1046. }
  1047. else
  1048. {
  1049. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  1050. if (runTask == null)
  1051. {
  1052. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  1053. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  1054. }
  1055. }
  1056. }
  1057. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  1058. if (xl1 == null)
  1059. {
  1060. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  1061. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  1062. }
  1063. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1064. var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
  1065. if (xl2 == null)
  1066. {
  1067. Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  1068. return Error<PosResDto>($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  1069. }
  1070. Serilog.Log.Information($"卫星{dto.AdjaCode}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1071. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  1072. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  1073. if (ephMain.code != 200)
  1074. {
  1075. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  1076. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  1077. }
  1078. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  1079. var ephAdja = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  1080. if (ephAdja.code != 200)
  1081. {
  1082. Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
  1083. return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
  1084. }
  1085. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1086. {
  1087. var StationRes = db.StationRes.Add(new StationRes()
  1088. {
  1089. SatTxLon = dto.SatTxLon,
  1090. SatTxLat = dto.SatTxLat,
  1091. CdbTxLon = dto.CdbTxLon,
  1092. CdbTxLat = dto.CdbTxLat,
  1093. CxLon = dto.CxLon,
  1094. CxLat = dto.CxLat,
  1095. RefLon = dto.RefLon,
  1096. RefLat = dto.RefLat,
  1097. });
  1098. var ckRes = new CheckRes()
  1099. {
  1100. FileName = dto.CheckRes?.FileName,
  1101. SmpStart = dto.CheckRes?.SmpStart,
  1102. SmpCount = dto.CheckRes?.SmpCount,
  1103. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  1104. ModRate = dto.CheckRes?.ModRate,
  1105. ModType = dto.CheckRes?.ModType,
  1106. UserName = dto.CheckRes?.UserName,
  1107. FfcHz = dto.CheckRes?.FfcHz,
  1108. Snr = dto.CheckRes?.Snr
  1109. };
  1110. db.CheckRes.Add(ckRes);
  1111. var cgRes = db.CgRes.Add(new CgRes()
  1112. {
  1113. SigTime = dto.SigTime,
  1114. Dto1 = Math.Round(dto.SxDto, 10),
  1115. Dfo1 = Math.Round(dto.SxDfo, 10),
  1116. Snr1 = Math.Round(dto.SxSnr, 1),
  1117. DtoCdb = Math.Round(dto.XdDto, 10),
  1118. DfoCdb = Math.Round(dto.XdDfo, 10),
  1119. SnrCdb = Math.Round(dto.XdSnr, 1),
  1120. YbMainDto = Math.Round(dto.MainYbDto, 10),
  1121. YbAdja1Dto = Math.Round(dto.AdjaYbDto, 10),
  1122. StationResID = StationRes.ID,
  1123. MainCode = dto.MainCode,
  1124. Adja1Code = dto.AdjaCode,
  1125. MainXlTime = ephMain.data.TleTime,
  1126. Adja1XlTime = ephAdja.data.TleTime,
  1127. TaskID = runTask.ID,
  1128. MainX = ephMain.data.X,
  1129. MainY = ephMain.data.Y,
  1130. MainZ = ephMain.data.Z,
  1131. MainVx = ephMain.data.VX,
  1132. MainVy = ephMain.data.VY,
  1133. MainVz = ephMain.data.VZ,
  1134. Adja1X = ephAdja.data.X,
  1135. Adja1Y = ephAdja.data.Y,
  1136. Adja1Z = ephAdja.data.Z,
  1137. Adja1Vx = ephAdja.data.VX,
  1138. Adja1Vy = ephAdja.data.VY,
  1139. Adja1Vz = ephAdja.data.VZ,
  1140. TarFreqUp = dto.FreqUp,
  1141. TarFreqDown = dto.FreqDown,
  1142. });
  1143. var cxRes = db.CxRes.Add(new CxRes()
  1144. {
  1145. SigTime = dto.SigTime,
  1146. Fx = dto.CxRes,
  1147. });
  1148. var res = PosApi.RH_Pos(cgRes, StationRes, cxRes, dto.CalcConfidence);
  1149. PosRes posRes = new PosRes()
  1150. {
  1151. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  1152. SigTime = cgRes.SigTime,
  1153. TaskInfoID = runTask.ID,
  1154. CxResID = cxRes.ID,
  1155. CgResID = cgRes.ID,
  1156. CheckResID = ckRes.ID,
  1157. PosLon = res[0],
  1158. PosLat = res[1],
  1159. MirrLon = res[3],
  1160. MirrLat = res[4],
  1161. Confidence = (int)res[6],
  1162. PosResType = EnumPosResType.RH,
  1163. };
  1164. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  1165. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  1166. posRes = db.PosRes.Add(posRes);
  1167. await db.SaveChangesAsync();
  1168. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  1169. return Success(MapDto(posRes));
  1170. }
  1171. }
  1172. #endregion
  1173. #region 三星双时差定位
  1174. /// <summary>
  1175. /// 三星双时差带参定位(含星历)
  1176. /// </summary>
  1177. /// <param name="dto">定位参数</param>
  1178. /// <returns></returns>
  1179. [HttpPost]
  1180. public async Task<AjaxResult<PosResDto>> PosX3TwoDtoAsync(X3TwoDtoPosDto dto)
  1181. {
  1182. try
  1183. {
  1184. TaskInfo runTask;
  1185. using (RHDWContext db = new RHDWContext())
  1186. {
  1187. if (dto.TaskID == null)
  1188. {
  1189. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  1190. && p.PosType == EnumPosType.X3TwoDto && p.TaskState == EnumTaskState.Running);
  1191. if (runTask == null)
  1192. {
  1193. Serilog.Log.Warning($"接收到三星双时差带参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  1194. return Error<PosResDto>($"多模式融合定位平台没有启动三星双时差定位任务");
  1195. }
  1196. }
  1197. else
  1198. {
  1199. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  1200. if (runTask == null)
  1201. {
  1202. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  1203. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  1204. }
  1205. }
  1206. }
  1207. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1208. {
  1209. var StationRes = db.StationRes.Add(new StationRes()
  1210. {
  1211. SatTxLon = dto.SatTxLon,
  1212. SatTxLat = dto.SatTxLat,
  1213. RefLon = dto.RefLon,
  1214. RefLat = dto.RefLat,
  1215. });
  1216. var ckRes = new CheckRes()
  1217. {
  1218. FileName = dto.CheckRes?.FileName,
  1219. SmpStart = dto.CheckRes?.SmpStart,
  1220. SmpCount = dto.CheckRes?.SmpCount,
  1221. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  1222. ModRate = dto.CheckRes?.ModRate,
  1223. ModType = dto.CheckRes?.ModType,
  1224. UserName = dto.CheckRes?.UserName,
  1225. FfcHz = dto.CheckRes?.FfcHz,
  1226. Snr = dto.CheckRes?.Snr
  1227. };
  1228. db.CheckRes.Add(ckRes);
  1229. var cgRes = db.CgRes.Add(new CgRes()
  1230. {
  1231. SigTime = dto.SigTime,
  1232. Dto1 = Math.Round(dto.Dto1, 10),
  1233. Dfo1 = Math.Round(dto.Dfo1, 10),
  1234. Snr1 = Math.Round(dto.Snr1, 1),
  1235. Dto2 = Math.Round(dto.Dto2, 10),
  1236. Dfo2 = Math.Round(dto.Dfo2, 10),
  1237. Snr2 = Math.Round(dto.Snr2, 1),
  1238. YbMainDto = Math.Round(dto.YbMainDto, 10),
  1239. YbAdja1Dto = Math.Round(dto.YbAdja1Dto, 10),
  1240. YbAdja2Dto = Math.Round(dto.YbAdja2Dto, 10),
  1241. StationResID = StationRes.ID,
  1242. MainCode = dto.MainCode,
  1243. Adja1Code = dto.Adja1Code,
  1244. Adja2Code = dto.Adja2Code,
  1245. TaskID = runTask.ID,
  1246. MainX = dto.MainX,
  1247. MainY = dto.MainY,
  1248. MainZ = dto.MainZ,
  1249. MainVx = dto.MainVX,
  1250. MainVy = dto.MainVY,
  1251. MainVz = dto.MainVZ,
  1252. Adja1X = dto.Adja1X,
  1253. Adja1Y = dto.Adja1Y,
  1254. Adja1Z = dto.Adja1Z,
  1255. Adja1Vx = dto.Adja1VX,
  1256. Adja1Vy = dto.Adja1VY,
  1257. Adja1Vz = dto.Adja1VZ,
  1258. Adja2X = dto.Adja2X,
  1259. Adja2Y = dto.Adja2Y,
  1260. Adja2Z = dto.Adja2Z,
  1261. Adja2Vx = dto.Adja2VX,
  1262. Adja2Vy = dto.Adja2VY,
  1263. Adja2Vz = dto.Adja2VZ,
  1264. TarFreqUp = dto.FreqUp,
  1265. TarFreqDown = dto.FreqDown,
  1266. });
  1267. var res = PosApi.X3_Pos(cgRes, StationRes, dto.CalcConfidence);
  1268. PosRes posRes = new PosRes()
  1269. {
  1270. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  1271. SigTime = cgRes.SigTime,
  1272. TaskInfoID = runTask.ID,
  1273. CgResID = cgRes.ID,
  1274. CheckResID = ckRes.ID,
  1275. PosLon = res[0],
  1276. PosLat = res[1],
  1277. MirrLon = res[3],
  1278. MirrLat = res[4],
  1279. Confidence = (int)res[6],
  1280. PosResType = EnumPosResType.X3,
  1281. };
  1282. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  1283. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  1284. posRes = db.PosRes.Add(posRes);
  1285. await db.SaveChangesAsync();
  1286. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  1287. return Success(MapDto(posRes));
  1288. }
  1289. }
  1290. catch (Exception)
  1291. {
  1292. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1293. {
  1294. db.SyncDb();
  1295. }
  1296. throw;
  1297. }
  1298. }
  1299. /// <summary>
  1300. /// 三星双时差带参定位(无星历)
  1301. /// </summary>
  1302. /// <returns>返回定位结果ID</returns>
  1303. [HttpPost]
  1304. public async Task<AjaxResult<PosResDto>> PosX3TwoDtoNoXlAsync(X3TwoDtoNoXlPosDto dto)
  1305. {
  1306. try
  1307. {
  1308. TaskInfo runTask;
  1309. using (RHDWContext db = new RHDWContext())
  1310. {
  1311. if (dto.TaskID == null)
  1312. {
  1313. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  1314. && p.PosType == EnumPosType.X3TwoDto && p.TaskState == EnumTaskState.Running);
  1315. if (runTask == null)
  1316. {
  1317. Serilog.Log.Warning($"接收到三星双时差带参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  1318. return Error<PosResDto>($"多模式融合定位平台没有启动三星双时差定位任务");
  1319. }
  1320. }
  1321. else
  1322. {
  1323. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  1324. if (runTask == null)
  1325. {
  1326. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  1327. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  1328. }
  1329. }
  1330. }
  1331. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  1332. if (xl1 == null)
  1333. {
  1334. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  1335. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  1336. }
  1337. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1338. var xl2 = await XlRepository.GetLatestAsync(dto.Adja1Code, dto.SigTime);
  1339. if (xl2 == null)
  1340. {
  1341. Serilog.Log.Error($"系统缺少编号{dto.Adja1Code}卫星的星历!");
  1342. return Error<PosResDto>($"系统缺少编号{dto.Adja1Code}卫星的星历!");
  1343. }
  1344. Serilog.Log.Information($"卫星{dto.Adja1Code}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1345. var xl3 = await XlRepository.GetLatestAsync(dto.Adja2Code, dto.SigTime);
  1346. if (xl3 == null)
  1347. {
  1348. Serilog.Log.Error($"系统缺少编号{dto.Adja2Code}卫星的星历!");
  1349. return Error<PosResDto>($"系统缺少编号{dto.Adja2Code}卫星的星历!");
  1350. }
  1351. Serilog.Log.Information($"卫星{dto.Adja2Code}使用发布时刻为{xl3.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1352. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  1353. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  1354. if (ephMain.code != 200)
  1355. {
  1356. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  1357. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  1358. }
  1359. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  1360. var ephAdja1 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  1361. if (ephAdja1.code != 200)
  1362. {
  1363. Serilog.Log.Error($"推算卫星{dto.Adja1Code}的ECEF星历出错.{ephAdja1.msg}");
  1364. return Error<PosResDto>($"推算卫星{dto.Adja1Code}的ECEF星历出错");
  1365. }
  1366. var XlCalcDto3 = new XlCalcDto() { tleStr = xl3.TwoLine, SigTime = dto.SigTime };
  1367. var ephAdja2 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto3);
  1368. if (ephAdja2.code != 200)
  1369. {
  1370. Serilog.Log.Error($"推算卫星{dto.Adja2Code}的ECEF星历出错.{ephAdja2.msg}");
  1371. return Error<PosResDto>($"推算卫星{dto.Adja2Code}的ECEF星历出错");
  1372. }
  1373. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1374. {
  1375. var StationRes = db.StationRes.Add(new StationRes()
  1376. {
  1377. SatTxLon = dto.SatTxLon,
  1378. SatTxLat = dto.SatTxLat,
  1379. RefLon = dto.RefLon,
  1380. RefLat = dto.RefLat,
  1381. });
  1382. var ckRes = new CheckRes()
  1383. {
  1384. FileName = dto.CheckRes?.FileName,
  1385. SmpStart = dto.CheckRes?.SmpStart,
  1386. SmpCount = dto.CheckRes?.SmpCount,
  1387. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  1388. ModRate = dto.CheckRes?.ModRate,
  1389. ModType = dto.CheckRes?.ModType,
  1390. UserName = dto.CheckRes?.UserName,
  1391. FfcHz = dto.CheckRes?.FfcHz,
  1392. Snr = dto.CheckRes?.Snr
  1393. };
  1394. db.CheckRes.Add(ckRes);
  1395. var cgRes = db.CgRes.Add(new CgRes()
  1396. {
  1397. SigTime = dto.SigTime,
  1398. Dto1 = Math.Round(dto.Dto1, 10),
  1399. Dfo1 = Math.Round(dto.Dfo1, 10),
  1400. Snr1 = Math.Round(dto.Snr1, 1),
  1401. Dto2 = Math.Round(dto.Dto2, 10),
  1402. Dfo2 = Math.Round(dto.Dfo2, 10),
  1403. Snr2 = Math.Round(dto.Snr2, 1),
  1404. YbMainDto = Math.Round(dto.YbMainDto, 10),
  1405. YbAdja1Dto = Math.Round(dto.YbAdja1Dto, 10),
  1406. YbAdja2Dto = Math.Round(dto.YbAdja2Dto, 10),
  1407. StationResID = StationRes.ID,
  1408. MainCode = dto.MainCode,
  1409. Adja1Code = dto.Adja1Code,
  1410. Adja2Code = dto.Adja2Code,
  1411. MainXlTime = ephMain.data.TleTime,
  1412. Adja1XlTime = ephAdja1.data.TleTime,
  1413. Adja2XlTime = ephAdja2.data.TleTime,
  1414. TaskID = runTask.ID,
  1415. MainX = ephMain.data.X,
  1416. MainY = ephMain.data.Y,
  1417. MainZ = ephMain.data.Z,
  1418. MainVx = ephMain.data.VX,
  1419. MainVy = ephMain.data.VY,
  1420. MainVz = ephMain.data.VZ,
  1421. Adja1X = ephAdja1.data.X,
  1422. Adja1Y = ephAdja1.data.Y,
  1423. Adja1Z = ephAdja1.data.Z,
  1424. Adja1Vx = ephAdja1.data.VX,
  1425. Adja1Vy = ephAdja1.data.VY,
  1426. Adja1Vz = ephAdja1.data.VZ,
  1427. Adja2X = ephAdja2.data.X,
  1428. Adja2Y = ephAdja2.data.Y,
  1429. Adja2Z = ephAdja2.data.Z,
  1430. Adja2Vx = ephAdja2.data.VX,
  1431. Adja2Vy = ephAdja2.data.VY,
  1432. Adja2Vz = ephAdja2.data.VZ,
  1433. TarFreqUp = dto.FreqUp,
  1434. TarFreqDown = dto.FreqDown,
  1435. });
  1436. var res = PosApi.X3_Pos(cgRes, StationRes, dto.CalcConfidence);
  1437. PosRes posRes = new PosRes()
  1438. {
  1439. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  1440. SigTime = dto.SigTime,
  1441. TaskInfoID = runTask.ID,
  1442. CgResID = cgRes.ID,
  1443. CheckResID = ckRes.ID,
  1444. PosLon = res[0],
  1445. PosLat = res[1],
  1446. MirrLon = res[3],
  1447. MirrLat = res[4],
  1448. Confidence = (int)res[6],
  1449. PosResType = EnumPosResType.X3,
  1450. };
  1451. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  1452. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  1453. posRes = db.PosRes.Add(posRes);
  1454. await db.SaveChangesAsync();
  1455. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  1456. return Success(MapDto(posRes));
  1457. }
  1458. }
  1459. catch (Exception)
  1460. {
  1461. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1462. {
  1463. db.SyncDb();
  1464. }
  1465. throw;
  1466. }
  1467. }
  1468. /// <summary>
  1469. /// 三星双时差无参定位(含星历)
  1470. /// </summary>
  1471. /// <param name="dto">定位参数</param>
  1472. /// <returns></returns>
  1473. [HttpPost]
  1474. public async Task<AjaxResult<PosResDto>> PosX3TwoDtoNoParAsync(X3TwoDtoNoParPosDto dto)
  1475. {
  1476. try
  1477. {
  1478. TaskInfo runTask;
  1479. using (RHDWContext db = new RHDWContext())
  1480. {
  1481. if (dto.TaskID == null)
  1482. {
  1483. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  1484. && p.PosType == EnumPosType.X3TwoDto && p.TaskState == EnumTaskState.Running);
  1485. if (runTask == null)
  1486. {
  1487. Serilog.Log.Warning($"接收到三星双时差无参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  1488. return Error<PosResDto>($"多模式融合定位平台没有启动三星双时差定位任务");
  1489. }
  1490. }
  1491. else
  1492. {
  1493. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  1494. if (runTask == null)
  1495. {
  1496. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  1497. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  1498. }
  1499. }
  1500. }
  1501. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1502. {
  1503. var StationRes = db.StationRes.Add(new StationRes()
  1504. {
  1505. SatTxLon = dto.SatTxLon,
  1506. SatTxLat = dto.SatTxLat,
  1507. });
  1508. var ckRes = new CheckRes()
  1509. {
  1510. FileName = dto.CheckRes?.FileName,
  1511. SmpStart = dto.CheckRes?.SmpStart,
  1512. SmpCount = dto.CheckRes?.SmpCount,
  1513. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  1514. ModRate = dto.CheckRes?.ModRate,
  1515. ModType = dto.CheckRes?.ModType,
  1516. UserName = dto.CheckRes?.UserName,
  1517. FfcHz = dto.CheckRes?.FfcHz,
  1518. Snr = dto.CheckRes?.Snr
  1519. };
  1520. db.CheckRes.Add(ckRes);
  1521. var cgRes = db.CgRes.Add(new CgRes()
  1522. {
  1523. SigTime = dto.SigTime,
  1524. Dto1 = Math.Round(dto.Dto1, 10),
  1525. Dfo1 = Math.Round(dto.Dfo1, 10),
  1526. Snr1 = Math.Round(dto.Snr1, 1),
  1527. Dto2 = Math.Round(dto.Dto2, 10),
  1528. Dfo2 = Math.Round(dto.Dfo2, 10),
  1529. Snr2 = Math.Round(dto.Snr2, 1),
  1530. StationResID = StationRes.ID,
  1531. MainCode = dto.MainCode,
  1532. Adja1Code = dto.Adja1Code,
  1533. Adja2Code = dto.Adja2Code,
  1534. TaskID = runTask.ID,
  1535. MainX = dto.MainX,
  1536. MainY = dto.MainY,
  1537. MainZ = dto.MainZ,
  1538. MainVx = dto.MainVX,
  1539. MainVy = dto.MainVY,
  1540. MainVz = dto.MainVZ,
  1541. Adja1X = dto.Adja1X,
  1542. Adja1Y = dto.Adja1Y,
  1543. Adja1Z = dto.Adja1Z,
  1544. Adja1Vx = dto.Adja1VX,
  1545. Adja1Vy = dto.Adja1VY,
  1546. Adja1Vz = dto.Adja1VZ,
  1547. Adja2X = dto.Adja2X,
  1548. Adja2Y = dto.Adja2Y,
  1549. Adja2Z = dto.Adja2Z,
  1550. Adja2Vx = dto.Adja2VX,
  1551. Adja2Vy = dto.Adja2VY,
  1552. Adja2Vz = dto.Adja2VZ,
  1553. TarFreqUp = dto.FreqUp,
  1554. TarFreqDown = dto.FreqDown,
  1555. });
  1556. var res = PosApi.X3_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  1557. PosRes posRes = new PosRes()
  1558. {
  1559. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  1560. SigTime = cgRes.SigTime,
  1561. TaskInfoID = runTask.ID,
  1562. CgResID = cgRes.ID,
  1563. CheckResID = ckRes.ID,
  1564. PosLon = res[0],
  1565. PosLat = res[1],
  1566. MirrLon = res[3],
  1567. MirrLat = res[4],
  1568. Confidence = (int)res[6],
  1569. PosResType = EnumPosResType.X3NoRef,
  1570. };
  1571. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  1572. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  1573. posRes = db.PosRes.Add(posRes);
  1574. await db.SaveChangesAsync();
  1575. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  1576. return Success(MapDto(posRes));
  1577. }
  1578. }
  1579. catch (Exception)
  1580. {
  1581. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1582. {
  1583. db.SyncDb();
  1584. }
  1585. throw;
  1586. }
  1587. }
  1588. /// <summary>
  1589. /// 三星双时差无参定位(无星历)
  1590. /// </summary>
  1591. /// <returns>返回定位结果ID</returns>
  1592. [HttpPost]
  1593. public async Task<AjaxResult<PosResDto>> PosX3TwoDtoNoXlNoParAsync(X3TwoDtoNoXlNoParPosDto dto)
  1594. {
  1595. try
  1596. {
  1597. TaskInfo runTask;
  1598. using (RHDWContext db = new RHDWContext())
  1599. {
  1600. if (dto.TaskID == null)
  1601. {
  1602. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  1603. && p.PosType == EnumPosType.X3TwoDto && p.TaskState == EnumTaskState.Running);
  1604. if (runTask == null)
  1605. {
  1606. Serilog.Log.Warning($"接收到三星双时差无参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  1607. return Error<PosResDto>($"多模式融合定位平台没有启动三星双时差定位任务");
  1608. }
  1609. }
  1610. else
  1611. {
  1612. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  1613. if (runTask == null)
  1614. {
  1615. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  1616. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  1617. }
  1618. }
  1619. }
  1620. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  1621. if (xl1 == null)
  1622. {
  1623. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  1624. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  1625. }
  1626. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1627. var xl2 = await XlRepository.GetLatestAsync(dto.Adja1Code, dto.SigTime);
  1628. if (xl2 == null)
  1629. {
  1630. Serilog.Log.Error($"系统缺少编号{dto.Adja1Code}卫星的星历!");
  1631. return Error<PosResDto>($"系统缺少编号{dto.Adja1Code}卫星的星历!");
  1632. }
  1633. Serilog.Log.Information($"卫星{dto.Adja1Code}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1634. var xl3 = await XlRepository.GetLatestAsync(dto.Adja2Code, dto.SigTime);
  1635. if (xl3 == null)
  1636. {
  1637. Serilog.Log.Error($"系统缺少编号{dto.Adja2Code}卫星的星历!");
  1638. return Error<PosResDto>($"系统缺少编号{dto.Adja2Code}卫星的星历!");
  1639. }
  1640. Serilog.Log.Information($"卫星{dto.Adja2Code}使用发布时刻为{xl3.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1641. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  1642. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  1643. if (ephMain.code != 200)
  1644. {
  1645. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  1646. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  1647. }
  1648. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  1649. var ephAdja1 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  1650. if (ephAdja1.code != 200)
  1651. {
  1652. Serilog.Log.Error($"推算卫星{dto.Adja1Code}的ECEF星历出错.{ephAdja1.msg}");
  1653. return Error<PosResDto>($"推算卫星{dto.Adja1Code}的ECEF星历出错");
  1654. }
  1655. var XlCalcDto3 = new XlCalcDto() { tleStr = xl3.TwoLine, SigTime = dto.SigTime };
  1656. var ephAdja2 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto3);
  1657. if (ephAdja2.code != 200)
  1658. {
  1659. Serilog.Log.Error($"推算卫星{dto.Adja2Code}的ECEF星历出错.{ephAdja2.msg}");
  1660. return Error<PosResDto>($"推算卫星{dto.Adja2Code}的ECEF星历出错");
  1661. }
  1662. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1663. {
  1664. var StationRes = db.StationRes.Add(new StationRes()
  1665. {
  1666. SatTxLon = dto.SatTxLon,
  1667. SatTxLat = dto.SatTxLat,
  1668. });
  1669. var ckRes = new CheckRes()
  1670. {
  1671. FileName = dto.CheckRes?.FileName,
  1672. SmpStart = dto.CheckRes?.SmpStart,
  1673. SmpCount = dto.CheckRes?.SmpCount,
  1674. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  1675. ModRate = dto.CheckRes?.ModRate,
  1676. ModType = dto.CheckRes?.ModType,
  1677. UserName = dto.CheckRes?.UserName,
  1678. FfcHz = dto.CheckRes?.FfcHz,
  1679. Snr = dto.CheckRes?.Snr
  1680. };
  1681. db.CheckRes.Add(ckRes);
  1682. var cgRes = db.CgRes.Add(new CgRes()
  1683. {
  1684. SigTime = dto.SigTime,
  1685. Dto1 = Math.Round(dto.Dto1, 10),
  1686. Dfo1 = Math.Round(dto.Dfo1, 10),
  1687. Snr1 = Math.Round(dto.Snr1, 1),
  1688. Dto2 = Math.Round(dto.Dto2, 10),
  1689. Dfo2 = Math.Round(dto.Dfo2, 10),
  1690. Snr2 = Math.Round(dto.Snr2, 1),
  1691. StationResID = StationRes.ID,
  1692. MainCode = dto.MainCode,
  1693. Adja1Code = dto.Adja1Code,
  1694. Adja2Code = dto.Adja2Code,
  1695. MainXlTime = ephMain.data.TleTime,
  1696. Adja1XlTime = ephAdja1.data.TleTime,
  1697. Adja2XlTime = ephAdja2.data.TleTime,
  1698. TaskID = runTask.ID,
  1699. MainX = ephMain.data.X,
  1700. MainY = ephMain.data.Y,
  1701. MainZ = ephMain.data.Z,
  1702. MainVx = ephMain.data.VX,
  1703. MainVy = ephMain.data.VY,
  1704. MainVz = ephMain.data.VZ,
  1705. Adja1X = ephAdja1.data.X,
  1706. Adja1Y = ephAdja1.data.Y,
  1707. Adja1Z = ephAdja1.data.Z,
  1708. Adja1Vx = ephAdja1.data.VX,
  1709. Adja1Vy = ephAdja1.data.VY,
  1710. Adja1Vz = ephAdja1.data.VZ,
  1711. Adja2X = ephAdja2.data.X,
  1712. Adja2Y = ephAdja2.data.Y,
  1713. Adja2Z = ephAdja2.data.Z,
  1714. Adja2Vx = ephAdja2.data.VX,
  1715. Adja2Vy = ephAdja2.data.VY,
  1716. Adja2Vz = ephAdja2.data.VZ,
  1717. TarFreqUp = dto.FreqUp,
  1718. TarFreqDown = dto.FreqDown,
  1719. });
  1720. var res = PosApi.X3_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  1721. PosRes posRes = new PosRes()
  1722. {
  1723. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  1724. SigTime = dto.SigTime,
  1725. TaskInfoID = runTask.ID,
  1726. CgResID = cgRes.ID,
  1727. CheckResID = ckRes.ID,
  1728. PosLon = res[0],
  1729. PosLat = res[1],
  1730. MirrLon = res[3],
  1731. MirrLat = res[4],
  1732. Confidence = (int)res[6],
  1733. PosResType = EnumPosResType.X3NoRef,
  1734. };
  1735. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  1736. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  1737. posRes = db.PosRes.Add(posRes);
  1738. await db.SaveChangesAsync();
  1739. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  1740. return Success(MapDto(posRes));
  1741. }
  1742. }
  1743. catch (Exception)
  1744. {
  1745. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1746. {
  1747. db.SyncDb();
  1748. }
  1749. throw;
  1750. }
  1751. }
  1752. #endregion
  1753. #region 三星双频差定位
  1754. /// <summary>
  1755. /// 三星双频差带参定位(含星历)
  1756. /// </summary>
  1757. /// <param name="dto">定位参数</param>
  1758. /// <returns></returns>
  1759. [HttpPost]
  1760. public async Task<AjaxResult<PosResDto>> PosX3TwoDfoAsync(X3TwoDfoPosDto dto)
  1761. {
  1762. TaskInfo runTask;
  1763. using (RHDWContext db = new RHDWContext())
  1764. {
  1765. if (dto.TaskID == null)
  1766. {
  1767. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  1768. && p.PosType == EnumPosType.X3TwoDfo && p.TaskState == EnumTaskState.Running);
  1769. if (runTask == null)
  1770. {
  1771. Serilog.Log.Warning($"接收到三星双频差带参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  1772. return Error<PosResDto>($"多模式融合定位平台没有启动三星双频差定位任务");
  1773. }
  1774. }
  1775. else
  1776. {
  1777. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  1778. if (runTask == null)
  1779. {
  1780. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  1781. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  1782. }
  1783. }
  1784. }
  1785. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1786. {
  1787. var StationRes = db.StationRes.Add(new StationRes()
  1788. {
  1789. SatTxLon = dto.SatTxLon,
  1790. SatTxLat = dto.SatTxLat,
  1791. RefLon = dto.RefLon,
  1792. RefLat = dto.RefLat,
  1793. });
  1794. var ckRes = new CheckRes()
  1795. {
  1796. FileName = dto.CheckRes?.FileName,
  1797. SmpStart = dto.CheckRes?.SmpStart,
  1798. SmpCount = dto.CheckRes?.SmpCount,
  1799. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  1800. ModRate = dto.CheckRes?.ModRate,
  1801. ModType = dto.CheckRes?.ModType,
  1802. UserName = dto.CheckRes?.UserName,
  1803. FfcHz = dto.CheckRes?.FfcHz,
  1804. Snr = dto.CheckRes?.Snr
  1805. };
  1806. db.CheckRes.Add(ckRes);
  1807. var cgRes = db.CgRes.Add(new CgRes()
  1808. {
  1809. SigTime = dto.SigTime,
  1810. Dto1 = Math.Round(dto.Dto1, 10),
  1811. Dfo1 = Math.Round(dto.Dfo1, 10),
  1812. Snr1 = Math.Round(dto.Snr1, 1),
  1813. Dto2 = Math.Round(dto.Dto2, 10),
  1814. Dfo2 = Math.Round(dto.Dfo2, 10),
  1815. Snr2 = Math.Round(dto.Snr2, 1),
  1816. YbMainDfo = Math.Round(dto.YbMainDfo, 10),
  1817. YbAdja1Dfo = Math.Round(dto.YbAdja1Dfo, 10),
  1818. YbAdja2Dfo = Math.Round(dto.YbAdja2Dfo, 10),
  1819. TarFreqUp = dto.TarFreqUp,
  1820. TarFreqDown = dto.TarFreqDown,
  1821. RefFreqUp = dto.RefFreqUp,
  1822. RefFreqDown = dto.RefFreqDown,
  1823. StationResID = StationRes.ID,
  1824. MainCode = dto.MainCode,
  1825. Adja1Code = dto.Adja1Code,
  1826. Adja2Code = dto.Adja2Code,
  1827. TaskID = runTask.ID,
  1828. MainX = dto.MainX,
  1829. MainY = dto.MainY,
  1830. MainZ = dto.MainZ,
  1831. MainVx = dto.MainVx,
  1832. MainVy = dto.MainVy,
  1833. MainVz = dto.MainVz,
  1834. Adja1X = dto.Adja1X,
  1835. Adja1Y = dto.Adja1Y,
  1836. Adja1Z = dto.Adja1Z,
  1837. Adja1Vx = dto.Adja1Vx,
  1838. Adja1Vy = dto.Adja1Vy,
  1839. Adja1Vz = dto.Adja1Vz,
  1840. Adja2X = dto.Adja2X,
  1841. Adja2Y = dto.Adja2Y,
  1842. Adja2Z = dto.Adja2Z,
  1843. Adja2Vx = dto.Adja2Vx,
  1844. Adja2Vy = dto.Adja2Vy,
  1845. Adja2Vz = dto.Adja2Vz,
  1846. });
  1847. var res = PosApi.X3_PosTwoDfo(cgRes, StationRes, dto.CalcConfidence);
  1848. PosRes posRes = new PosRes()
  1849. {
  1850. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  1851. SigTime = cgRes.SigTime,
  1852. TaskInfoID = runTask.ID,
  1853. CgResID = cgRes.ID,
  1854. CheckResID = ckRes.ID,
  1855. PosLon = res[0],
  1856. PosLat = res[1],
  1857. MirrLon = res[3],
  1858. MirrLat = res[4],
  1859. Confidence = (int)res[6],
  1860. PosResType = EnumPosResType.X3TwoDfo,
  1861. };
  1862. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  1863. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  1864. posRes = db.PosRes.Add(posRes);
  1865. await db.SaveChangesAsync();
  1866. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  1867. return Success(MapDto(posRes));
  1868. }
  1869. }
  1870. /// <summary>
  1871. /// 三星双频差带参定位(无星历)
  1872. /// </summary>
  1873. /// <returns>返回定位结果ID</returns>
  1874. [HttpPost]
  1875. public async Task<AjaxResult<PosResDto>> PosX3TwoDfoNoXlAsync(X3TwoDfoNoXlPosDto dto)
  1876. {
  1877. TaskInfo runTask;
  1878. using (RHDWContext db = new RHDWContext())
  1879. {
  1880. if (dto.TaskID == null)
  1881. {
  1882. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  1883. && p.PosType == EnumPosType.X3TwoDfo && p.TaskState == EnumTaskState.Running);
  1884. if (runTask == null)
  1885. {
  1886. Serilog.Log.Warning($"接收到三星双频差带参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  1887. return Error<PosResDto>($"多模式融合定位平台没有启动三星双频差定位任务");
  1888. }
  1889. }
  1890. else
  1891. {
  1892. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  1893. if (runTask == null)
  1894. {
  1895. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  1896. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  1897. }
  1898. }
  1899. }
  1900. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  1901. if (xl1 == null)
  1902. {
  1903. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  1904. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  1905. }
  1906. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1907. var xl2 = await XlRepository.GetLatestAsync(dto.Adja1Code, dto.SigTime);
  1908. if (xl2 == null)
  1909. {
  1910. Serilog.Log.Error($"系统缺少编号{dto.Adja1Code}卫星的星历!");
  1911. return Error<PosResDto>($"系统缺少编号{dto.Adja1Code}卫星的星历!");
  1912. }
  1913. Serilog.Log.Information($"卫星{dto.Adja1Code}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1914. var xl3 = await XlRepository.GetLatestAsync(dto.Adja2Code, dto.SigTime);
  1915. if (xl3 == null)
  1916. {
  1917. Serilog.Log.Error($"系统缺少编号{dto.Adja2Code}卫星的星历!");
  1918. return Error<PosResDto>($"系统缺少编号{dto.Adja2Code}卫星的星历!");
  1919. }
  1920. Serilog.Log.Information($"卫星{dto.Adja2Code}使用发布时刻为{xl3.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  1921. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  1922. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  1923. if (ephMain.code != 200)
  1924. {
  1925. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  1926. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  1927. }
  1928. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  1929. var ephAdja1 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  1930. if (ephAdja1.code != 200)
  1931. {
  1932. Serilog.Log.Error($"推算卫星{dto.Adja1Code}的ECEF星历出错.{ephAdja1.msg}");
  1933. return Error<PosResDto>($"推算卫星{dto.Adja1Code}的ECEF星历出错");
  1934. }
  1935. var XlCalcDto3 = new XlCalcDto() { tleStr = xl3.TwoLine, SigTime = dto.SigTime };
  1936. var ephAdja2 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto3);
  1937. if (ephAdja2.code != 200)
  1938. {
  1939. Serilog.Log.Error($"推算卫星{dto.Adja2Code}的ECEF星历出错.{ephAdja2.msg}");
  1940. return Error<PosResDto>($"推算卫星{dto.Adja2Code}的ECEF星历出错");
  1941. }
  1942. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  1943. {
  1944. var StationRes = db.StationRes.Add(new StationRes()
  1945. {
  1946. SatTxLon = dto.SatTxLon,
  1947. SatTxLat = dto.SatTxLat,
  1948. RefLon = dto.RefLon,
  1949. RefLat = dto.RefLat,
  1950. });
  1951. var ckRes = new CheckRes()
  1952. {
  1953. FileName = dto.CheckRes?.FileName,
  1954. SmpStart = dto.CheckRes?.SmpStart,
  1955. SmpCount = dto.CheckRes?.SmpCount,
  1956. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  1957. ModRate = dto.CheckRes?.ModRate,
  1958. ModType = dto.CheckRes?.ModType,
  1959. UserName = dto.CheckRes?.UserName,
  1960. FfcHz = dto.CheckRes?.FfcHz,
  1961. Snr = dto.CheckRes?.Snr
  1962. };
  1963. db.CheckRes.Add(ckRes);
  1964. var cgRes = db.CgRes.Add(new CgRes()
  1965. {
  1966. SigTime = dto.SigTime,
  1967. Dto1 = Math.Round(dto.Dto1, 10),
  1968. Dfo1 = Math.Round(dto.Dfo1, 10),
  1969. Snr1 = Math.Round(dto.Snr1, 1),
  1970. Dto2 = Math.Round(dto.Dto2, 10),
  1971. Dfo2 = Math.Round(dto.Dfo2, 10),
  1972. Snr2 = Math.Round(dto.Snr2, 1),
  1973. YbMainDfo = Math.Round(dto.YbMainDfo, 10),
  1974. YbAdja1Dfo = Math.Round(dto.YbAdja1Dfo, 10),
  1975. YbAdja2Dfo = Math.Round(dto.YbAdja2Dfo, 10),
  1976. TarFreqUp = dto.TarFreqUp,
  1977. TarFreqDown = dto.TarFreqDown,
  1978. RefFreqUp = dto.RefFreqUp,
  1979. RefFreqDown = dto.RefFreqDown,
  1980. StationResID = StationRes.ID,
  1981. MainCode = dto.MainCode,
  1982. Adja1Code = dto.Adja1Code,
  1983. Adja2Code = dto.Adja2Code,
  1984. MainXlTime = ephMain.data.TleTime,
  1985. Adja1XlTime = ephAdja1.data.TleTime,
  1986. Adja2XlTime = ephAdja2.data.TleTime,
  1987. TaskID = runTask.ID,
  1988. MainX = ephMain.data.X,
  1989. MainY = ephMain.data.Y,
  1990. MainZ = ephMain.data.Z,
  1991. MainVx = ephMain.data.VX,
  1992. MainVy = ephMain.data.VY,
  1993. MainVz = ephMain.data.VZ,
  1994. Adja1X = ephAdja1.data.X,
  1995. Adja1Y = ephAdja1.data.Y,
  1996. Adja1Z = ephAdja1.data.Z,
  1997. Adja1Vx = ephAdja1.data.VX,
  1998. Adja1Vy = ephAdja1.data.VY,
  1999. Adja1Vz = ephAdja1.data.VZ,
  2000. Adja2X = ephAdja2.data.X,
  2001. Adja2Y = ephAdja2.data.Y,
  2002. Adja2Z = ephAdja2.data.Z,
  2003. Adja2Vx = ephAdja2.data.VX,
  2004. Adja2Vy = ephAdja2.data.VY,
  2005. Adja2Vz = ephAdja2.data.VZ,
  2006. });
  2007. var res = PosApi.X3_PosTwoDfo(cgRes, StationRes, dto.CalcConfidence);
  2008. PosRes posRes = new PosRes()
  2009. {
  2010. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  2011. SigTime = dto.SigTime,
  2012. TaskInfoID = runTask.ID,
  2013. CgResID = cgRes.ID,
  2014. CheckResID = ckRes.ID,
  2015. PosLon = res[0],
  2016. PosLat = res[1],
  2017. MirrLon = res[3],
  2018. MirrLat = res[4],
  2019. Confidence = (int)res[6],
  2020. PosResType = EnumPosResType.X3TwoDfo,
  2021. };
  2022. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  2023. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  2024. posRes = db.PosRes.Add(posRes);
  2025. await db.SaveChangesAsync();
  2026. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  2027. return Success(MapDto(posRes));
  2028. }
  2029. }
  2030. #endregion
  2031. #region 双星时频差定位
  2032. /// <summary>
  2033. /// 双星时频差带参定位(含星历)
  2034. /// </summary>
  2035. /// <param name="dto">定位参数</param>
  2036. /// <returns></returns>
  2037. [HttpPost]
  2038. public async Task<AjaxResult<PosResDto>> PosX2DtoDfoAsync(X2DtoDfoPosDto dto)
  2039. {
  2040. TaskInfo runTask;
  2041. using (RHDWContext db = new RHDWContext())
  2042. {
  2043. if (dto.TaskID == null)
  2044. {
  2045. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  2046. && p.PosType == EnumPosType.X2Dfo && p.TaskState == EnumTaskState.Running);
  2047. if (runTask == null)
  2048. {
  2049. Serilog.Log.Warning($"接收到双星时频差带参定位(含星历)参数,由于找不到执行中的任务忽略本次定位");
  2050. return Error<PosResDto>($"多模式融合定位平台没有启动双星时频差定位任务");
  2051. }
  2052. }
  2053. else
  2054. {
  2055. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  2056. if (runTask == null)
  2057. {
  2058. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  2059. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  2060. }
  2061. }
  2062. }
  2063. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  2064. {
  2065. var StationRes = db.StationRes.Add(new StationRes()
  2066. {
  2067. SatTxLon = dto.SatTxLon,
  2068. SatTxLat = dto.SatTxLat,
  2069. RefLon = dto.RefLon,
  2070. RefLat = dto.RefLat,
  2071. });
  2072. var ckRes = new CheckRes()
  2073. {
  2074. FileName = dto.CheckRes?.FileName,
  2075. SmpStart = dto.CheckRes?.SmpStart,
  2076. SmpCount = dto.CheckRes?.SmpCount,
  2077. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  2078. ModRate = dto.CheckRes?.ModRate,
  2079. ModType = dto.CheckRes?.ModType,
  2080. UserName = dto.CheckRes?.UserName,
  2081. FfcHz = dto.CheckRes?.FfcHz,
  2082. Snr = dto.CheckRes?.Snr
  2083. };
  2084. db.CheckRes.Add(ckRes);
  2085. var cgRes = db.CgRes.Add(new CgRes()
  2086. {
  2087. SigTime = dto.SigTime,
  2088. Dto1 = Math.Round(dto.Dto, 10),
  2089. Dfo1 = Math.Round(dto.Dfo, 10),
  2090. Snr1 = Math.Round(dto.Snr, 1),
  2091. YbMainDto = Math.Round(dto.YbMainDto, 10),
  2092. YbAdja1Dto = Math.Round(dto.YbAdjaDto, 10),
  2093. YbMainDfo = Math.Round(dto.YbMainDfo, 10),
  2094. YbAdja1Dfo = Math.Round(dto.YbAdjaDfo, 10),
  2095. TarFreqUp = dto.TarFreqUp,
  2096. TarFreqDown = dto.TarFreqDown,
  2097. RefFreqUp = dto.RefFreqUp,
  2098. RefFreqDown = dto.RefFreqDown,
  2099. StationResID = StationRes.ID,
  2100. MainCode = dto.MainCode,
  2101. Adja1Code = dto.AdjaCode,
  2102. TaskID = runTask.ID,
  2103. MainX = dto.MainX,
  2104. MainY = dto.MainY,
  2105. MainZ = dto.MainZ,
  2106. MainVx = dto.MainVx,
  2107. MainVy = dto.MainVy,
  2108. MainVz = dto.MainVz,
  2109. Adja1X = dto.AdjaX,
  2110. Adja1Y = dto.AdjaY,
  2111. Adja1Z = dto.AdjaZ,
  2112. Adja1Vx = dto.AdjaVx,
  2113. Adja1Vy = dto.AdjaVy,
  2114. Adja1Vz = dto.AdjaVz,
  2115. });
  2116. var res = PosApi.X2_PosDtoDfo(cgRes, StationRes, dto.CalcConfidence);
  2117. PosRes posRes = new PosRes()
  2118. {
  2119. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  2120. SigTime = cgRes.SigTime,
  2121. TaskInfoID = runTask.ID,
  2122. CgResID = cgRes.ID,
  2123. CheckResID = ckRes.ID,
  2124. PosLon = res[0],
  2125. PosLat = res[1],
  2126. MirrLon = res[3],
  2127. MirrLat = res[4],
  2128. Confidence = (int)res[6],
  2129. PosResType = EnumPosResType.X2Dfo,
  2130. };
  2131. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  2132. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  2133. posRes = db.PosRes.Add(posRes);
  2134. await db.SaveChangesAsync();
  2135. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  2136. return Success(MapDto(posRes));
  2137. }
  2138. }
  2139. /// <summary>
  2140. /// 双星时频差带参定位(无星历)
  2141. /// </summary>
  2142. /// <returns>返回定位结果ID</returns>
  2143. [HttpPost]
  2144. public async Task<AjaxResult<PosResDto>> PosX2DtoDfoNoXlAsync(X2DtoDfoNoXlPosDto dto)
  2145. {
  2146. TaskInfo runTask;
  2147. using (RHDWContext db = new RHDWContext())
  2148. {
  2149. if (dto.TaskID == null)
  2150. {
  2151. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskType == EnumTaskType.Group
  2152. && p.PosType == EnumPosType.X2Dfo && p.TaskState == EnumTaskState.Running);
  2153. if (runTask == null)
  2154. {
  2155. Serilog.Log.Warning($"接收到双星时频差带参定位(无星历)参数,由于找不到执行中的任务忽略本次定位");
  2156. return Error<PosResDto>($"多模式融合定位平台没有启动双星时频差定位任务");
  2157. }
  2158. }
  2159. else
  2160. {
  2161. runTask = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == dto.TaskID);
  2162. if (runTask == null)
  2163. {
  2164. Serilog.Log.Warning($"找不到任务,ID={dto.TaskID}");
  2165. return Error<PosResDto>($"找不到ID={dto.TaskID}的任务");
  2166. }
  2167. }
  2168. }
  2169. var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
  2170. if (xl1 == null)
  2171. {
  2172. Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
  2173. return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
  2174. }
  2175. Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  2176. var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
  2177. if (xl2 == null)
  2178. {
  2179. Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  2180. return Error<PosResDto>($"系统缺少编号{dto.AdjaCode}卫星的星历!");
  2181. }
  2182. Serilog.Log.Information($"卫星{dto.AdjaCode}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
  2183. var XlCalcDto = new XlCalcDto() { tleStr = xl1.TwoLine, SigTime = dto.SigTime };
  2184. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  2185. if (ephMain.code != 200)
  2186. {
  2187. Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
  2188. return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
  2189. }
  2190. var XlCalcDto2 = new XlCalcDto() { tleStr = xl2.TwoLine, SigTime = dto.SigTime };
  2191. var ephAdja = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto2);
  2192. if (ephAdja.code != 200)
  2193. {
  2194. Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
  2195. return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
  2196. }
  2197. using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
  2198. {
  2199. var StationRes = db.StationRes.Add(new StationRes()
  2200. {
  2201. SatTxLon = dto.SatTxLon,
  2202. SatTxLat = dto.SatTxLat,
  2203. RefLon = dto.RefLon,
  2204. RefLat = dto.RefLat,
  2205. });
  2206. var ckRes = new CheckRes()
  2207. {
  2208. FileName = dto.CheckRes?.FileName,
  2209. SmpStart = dto.CheckRes?.SmpStart,
  2210. SmpCount = dto.CheckRes?.SmpCount,
  2211. PosCheckType = (EnumPosCheckType?)dto.CheckRes?.PosCheckType,
  2212. ModRate = dto.CheckRes?.ModRate,
  2213. ModType = dto.CheckRes?.ModType,
  2214. UserName = dto.CheckRes?.UserName,
  2215. FfcHz = dto.CheckRes?.FfcHz,
  2216. Snr = dto.CheckRes?.Snr
  2217. };
  2218. db.CheckRes.Add(ckRes);
  2219. var cgRes = db.CgRes.Add(new CgRes()
  2220. {
  2221. SigTime = dto.SigTime,
  2222. Dto1 = Math.Round(dto.Dto, 10),
  2223. Dfo1 = Math.Round(dto.Dfo, 10),
  2224. Snr1 = Math.Round(dto.Snr, 1),
  2225. YbMainDto = Math.Round(dto.YbMainDto, 10),
  2226. YbAdja1Dto = Math.Round(dto.YbAdjaDto, 10),
  2227. YbMainDfo = Math.Round(dto.YbMainDfo, 10),
  2228. YbAdja1Dfo = Math.Round(dto.YbAdjaDfo, 10),
  2229. TarFreqUp = dto.TarFreqUp,
  2230. TarFreqDown = dto.TarFreqDown,
  2231. RefFreqUp = dto.RefFreqUp,
  2232. RefFreqDown = dto.RefFreqDown,
  2233. StationResID = StationRes.ID,
  2234. MainCode = dto.MainCode,
  2235. Adja1Code = dto.AdjaCode,
  2236. MainXlTime = ephMain.data.TleTime,
  2237. Adja1XlTime = ephAdja.data.TleTime,
  2238. TaskID = runTask.ID,
  2239. MainX = ephMain.data.X,
  2240. MainY = ephMain.data.Y,
  2241. MainZ = ephMain.data.Z,
  2242. MainVx = ephMain.data.VX,
  2243. MainVy = ephMain.data.VY,
  2244. MainVz = ephMain.data.VZ,
  2245. Adja1X = ephAdja.data.X,
  2246. Adja1Y = ephAdja.data.Y,
  2247. Adja1Z = ephAdja.data.Z,
  2248. Adja1Vx = ephAdja.data.VX,
  2249. Adja1Vy = ephAdja.data.VY,
  2250. Adja1Vz = ephAdja.data.VZ,
  2251. });
  2252. var res = PosApi.X2_PosDtoDfo(cgRes, StationRes, dto.CalcConfidence);
  2253. PosRes posRes = new PosRes()
  2254. {
  2255. FreqUpHz = (long)cgRes.TarFreqUp.Value,
  2256. SigTime = dto.SigTime,
  2257. TaskInfoID = runTask.ID,
  2258. CgResID = cgRes.ID,
  2259. CheckResID = ckRes.ID,
  2260. PosLon = res[0],
  2261. PosLat = res[1],
  2262. MirrLon = res[3],
  2263. MirrLat = res[4],
  2264. Confidence = (int)res[6],
  2265. PosResType = EnumPosResType.X2Dfo,
  2266. };
  2267. if (dto.TheoryDfoCalc && posRes.PosLon != 999)
  2268. posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
  2269. posRes = db.PosRes.Add(posRes);
  2270. await db.SaveChangesAsync();
  2271. Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
  2272. return Success(MapDto(posRes));
  2273. }
  2274. }
  2275. #endregion
  2276. private PosResDto MapDto(PosRes res)
  2277. {
  2278. return new PosResDto()
  2279. {
  2280. ID = res.ID,
  2281. FreqUpHz = res.FreqUpHz,
  2282. SigTime = res.SigTime,
  2283. TaskInfoID = res.TaskInfoID,
  2284. TarName = res.TargetInfo?.TargetName,
  2285. PosLon = res.PosLon,
  2286. PosLat = res.PosLat,
  2287. MirrLon = res.MirrLon,
  2288. MirrLat = res.MirrLat,
  2289. CheckType = res.CheckRes?.PosCheckType == null ? "" : res.CheckRes?.PosCheckType?.GetEnumDisplayName(),
  2290. TargetState = (EnumTargetStateDto)res.TargetState,
  2291. PosResType = (EnumPosResTypeDto)res.PosResType,
  2292. Confidence = res.Confidence,
  2293. };
  2294. }
  2295. private ModelPosRes MapModel(PosRes res)
  2296. {
  2297. return new ModelPosRes()
  2298. {
  2299. ID = res.ID,
  2300. FreqUpHz = res.FreqUpHz,
  2301. SigTime = res.SigTime,
  2302. TaskInfoID = res.TaskInfoID,
  2303. PosLon = res.PosLon,
  2304. PosLat = res.PosLat,
  2305. MirrLon = res.MirrLon,
  2306. MirrLat = res.MirrLat,
  2307. TargetState = res.TargetState,
  2308. PosResType = res.PosResType,
  2309. CgResID = res.CgResID,
  2310. CheckRes = res.CheckRes,
  2311. CheckResID = res.CheckResID,
  2312. ColorKey = res.ColorKey,
  2313. CreateTime = res.CreateTime,
  2314. CxResID = res.CxResID,
  2315. StationResID = res.StationResID,
  2316. TargetInfo = res.TargetInfo,
  2317. TargetInfoID = res.TargetInfoID,
  2318. UpdateTime = res.UpdateTime,
  2319. Confidence = res.Confidence,
  2320. };
  2321. }
  2322. }
  2323. }