PosController.cs 102 KB

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