1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDW.Entity;
- namespace XdCxRhDW.Repostory
- {
- public static class XlRepository
- {
- /// <summary>
- /// 获取数据库所有双行根数
- /// </summary>
- /// <returns></returns>
- public static async Task<List<XlInfo>> GetAllAsync()
- {
- try
- {
- using (RHDWContext db = new RHDWContext())
- {
- var res = await db.XlInfos.OrderByDescending(p => p.TimeBJ).OrderByDescending(p => p.Lon).ToListAsync();
- return res;
- }
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, "加载星历信息异常");
- return null;
- }
- }
- /// <summary>
- /// 获取某个星某个时刻最近的双行根(可能返回null)
- /// </summary>
- /// <param name="satCode">卫星编号</param>
- /// <param name="timeBj">时刻</param>
- /// <returns></returns>
- public static async Task<XlInfo> GetLatestAsync(int satCode, DateTime timeBj)
- {
- try
- {
- using (RHDWContext db = new RHDWContext())
- {
- var res= await db.XlInfos.Where(p => p.SatCode == satCode).OrderBy(p => (p.TimeBJ - timeBj).Duration()).FirstOrDefaultAsync();
- return res;
- }
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"获取卫星[{satCode}]--{timeBj:yyyyMMddHHmmss}时刻附近的双行根数出错!");
- return null;
- }
- }
- }
- }
|