12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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.TimeUTC).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="sigTime">时刻</param>
- /// <returns></returns>
- public static async Task<XlInfo> GetLatestAsync(int satCode, DateTime sigTime)
- {
- var sql = $"SELECT min(abs(JULIANDAY(TimeUTC)-JULIANDAY('{sigTime:yyyy-MM-dd HH:mm:ss}')))" +
- $" as NearDaySpan,* FROM XlInfo where satcode={satCode}";
- try
- {
- using (RHDWContext db = new RHDWContext())
- {
- var res= await db.XlInfos.SqlQuery(sql).FirstOrDefaultAsync();
- return res;
- }
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"获取卫星[{satCode}]--{sigTime:yyyyMMddHHmmss}时刻附近的双行根数出错!Sql={sql}");
- return null;
- }
- }
- }
- }
|