| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 | using DevExpress.Xpo;using Ips.Eph.ResolveUtil;using Ips.EphAlgorithm;using Ips.Library.Entity;using Ips.Sps.Sats;using System;using System.Collections.Concurrent;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Ips.Sps.Ephs{    public sealed class EphManager    {        public static readonly EphManager Default = new EphManager();        private EphManager() { }        Session session = new Session();        ConcurrentDictionary<string, EphResult> _ephCache = new ConcurrentDictionary<string, EphResult>();        public EphResult GetEph(int satNum, DateTime time, CancellationToken token = default)        {            string key = $"{satNum}_{time:yyyyMMddHHmmss}";            EphResult result;            if (_ephCache.ContainsKey(key))            {                result = _ephCache[key];            }            else            {                result = GetEphHigh(satNum, time, token);                if (result == null)                {                    result = GetEphTle(satNum, time, token);                }                if (result != null)                    _ephCache.TryAdd(key, result);            }            while (_ephCache.Count > 2000)            {                _ephCache.TryRemove(_ephCache.First());            }            return result;        }        public EphResult GetEphHigh(int satNum, DateTime time, CancellationToken token = default)        {            EphResult result = null;            var eph = session.Query<Eph>()                .Where(m => m.SatNum == satNum && m.EphType == EphType.High && m.StartTime <= time && m.EndTime >= time)                .OrderByDescending(m => m.Id)                .FirstOrDefault();            if (eph != null)            {                var ephHigh = session.Query<EphHigh>()                     .Where(m => m.EphId == eph.Id && m.EphTime == time)                     .FirstOrDefault();                if (ephHigh != null)                {                    result = new EphResult(satNum, EphType.High, time, ephHigh.X, ephHigh.Y, ephHigh.Z);                }            }            return result;        }        public EphResult GetEphTle(int satNum, DateTime time, CancellationToken token = default)        {            var ephModel = session.Query<Eph>()                .Where(m => m.SatNum == satNum && m.EphType == EphType.Tle && m.StartTime <= time)                .OrderByDescending(m => m.StartTime)                .FirstOrDefault();            if (ephModel == null)            {                ephModel = session.Query<Eph>()                .Where(m => m.SatNum == satNum && m.StartTime > time)                .OrderBy(m => m.StartTime)                .FirstOrDefault();            }            if (ephModel == null) return null;            var lineArr = ephModel.Content.Split(';');            if (lineArr.Length != 2) return null;            ExeResult<EphResult> ephResult;            if (SpsConst.EnablEphTle)            {                ephResult = Task.Run(() => EphTleUtil2.Get(lineArr[0], lineArr[1], time, token)).Result;            }            else            {                ephResult = Task.Run(() => EphTleUtil.Get(lineArr[0], lineArr[1], time, token)).Result;            }            if (ephResult != null && ephResult.Result != null && ephResult.Result.SatNum == 0)            {                ephResult.Result.SatNum = satNum;                ephResult.Result.EphType = EphType.Tle;            }            return ephResult.Result;        }        public void ClearCache()        {            _ephCache.Clear();        }        public void DeleteEph(int[] ephIds)        {            using var uow = new UnitOfWork();            var ephList = uow.Query<Eph>().Where(m => ephIds.Contains(m.Id)).ToList();            foreach (var ephItem in ephList)            {                if (ephItem.EphType == EphType.High)                {                    uow.ExecuteNonQuery($"delete from ephhigh where ephid={ephItem.Id}");                }                ephItem.Delete();            }            uow.CommitChanges();        }    }}
 |