123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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.SqlQuery($"SELECT min(abs(JULIANDAY(timebj)-JULIANDAY('{timeBj:yyyy-MM-dd HH:mm:ss}')))" +
- " as NearDaySpan,* FROM XlInfo where satcode=23467").FirstOrDefaultAsync();
- return res;
- }
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"获取卫星[{satCode}]--{timeBj:yyyyMMddHHmmss}时刻附近的双行根数出错!");
- return null;
- }
- }
- }
- }
|