XlCache.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using XdCxRhDW.Repostory.EFContext;
  9. using XdCxRhDW.Repostory.Model;
  10. namespace XdCxRhDW.Repostory
  11. {
  12. public static class XlCache
  13. {
  14. /// <summary>
  15. /// 获取数据库所有双行根数
  16. /// </summary>
  17. /// <param name="maxCount">最大条数.超过此条数时不再继续查询,为0则不限制条数</param>
  18. /// <returns></returns>
  19. public static async Task<List<XlInfo>> GetAllAsync()
  20. {
  21. try
  22. {
  23. using (RHDWContext db = new RHDWContext())
  24. {
  25. var res = await db.XlInfos.OrderByDescending(p => p.TimeBJ).OrderByDescending(p => p.Lon).ToListAsync();
  26. return res;
  27. }
  28. }
  29. catch (Exception ex)
  30. {
  31. Serilog.Log.Error(ex, "加载星历信息异常");
  32. return null;
  33. }
  34. }
  35. /// <summary>
  36. /// 获取某个星某个时刻最近的双行根(可能返回null)
  37. /// </summary>
  38. /// <param name="satCode">卫星编号</param>
  39. /// <param name="timeBj">时刻</param>
  40. /// <returns></returns>
  41. public static async Task<XlInfo> GetLatestAsync(int satCode, DateTime timeBj)
  42. {
  43. try
  44. {
  45. using (RHDWContext db = new RHDWContext())
  46. {
  47. var res= await db.XlInfos.Where(p => p.SatCode == satCode).OrderBy(p => (p.TimeBJ - timeBj).Duration()).FirstOrDefaultAsync();
  48. return res;
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. Serilog.Log.Error(ex, $"获取卫星[{satCode}]--{timeBj:yyyyMMddHHmmss}时刻附近的双行根数出错!");
  54. return null;
  55. }
  56. }
  57. }
  58. }