public void CheckTrackSum(uint trackId) { StockSum sum = StockSumList.Find(c => c.track_id == trackId); uint goodsid = StockList.Find(c => c.track_id == trackId && c.goods_id != 0)?.goods_id ?? 0; if (sum == null) { Track track = PubMaster.Track.GetTrack(trackId); sum = new StockSum() { track_id = trackId, goods_id = goodsid, produce_time = StockList.Find(c => trackId == c.track_id).produce_time, area = track.area, track_type = track.type }; StockSumList.Add(sum); SortSumList(); } if (goodsid > 0) { Goods goods = GoodsList.Find(c => c.id == goodsid); if (goods != null) { sum.count = (uint)StockList.Count(c => c.track_id == trackId); sum.stack = sum.count * goods.stack; sum.pieces = sum.stack * goods.pieces; SendSumMsg(sum, ActionTypeE.Update); } } }
private DateTime?GetEarliestTime(uint trackid) { Stock stock = StockList.Find(c => c.track_id == trackid && c.PosType == StockPosE.顶部); if (stock != null) { return(stock.produce_time); } DateTime? earytime = null; List <Stock> list = StockList.FindAll(c => c.track_id == trackid); foreach (Stock item in list) { if (earytime == null) { earytime = item.produce_time; } if (earytime is DateTime areat && item.produce_time is DateTime stime) { if (stime.CompareTo(areat) < 0) { earytime = stime; } } } return(earytime); }
public void SetActiveStock(string symbol) { ActiveStock = StockList.Find(stock => stock.Symbol == symbol); if (ActiveStock != null) { OnActiveStockProcessed(ActiveStock); } }
/// <summary> /// 添加下砖记录 /// </summary> /// <param name="stockid"></param> public void AddStockInLog(uint stockid) { Stock stock = StockList.Find(c => c.id == stockid); if (stock != null) { PubMaster.Mod.GoodSql.AddStockInLog(stock); } }
/// <summary> /// 生成上砖记录 /// </summary> /// <param name="stockid"></param> /// <param name="iD"></param> /// <param name="leftTrackId"></param> public void AddStockOutLog(uint stockid, uint trackid, uint tileid) { Stock stock = StockList.Find(c => c.id == stockid); if (stock != null) { PubMaster.Mod.GoodSql.AddStockOutLog(stock, trackid, tileid); } }
public Stock GetTrackTopStock(uint trackid) { Stock stock = StockList.Find(c => c.track_id == trackid && c.PosType == StockPosE.顶部); if (stock == null) { stock = CheckGetStockTop(trackid); } return(stock); }
public uint GetTrackTopStockId(uint trackid) { uint stockid = StockList.Find(c => c.track_id == trackid && c.PosType == StockPosE.顶部)?.id ?? 0; if (stockid == 0) { stockid = CheckStockTop(trackid); } return(stockid); }
public Stock CheckGetStockTop(uint trackid) { if (!StockList.Exists(c => c.track_id == trackid && c.PosType == StockPosE.顶部)) { List <Stock> stocks = StockList.FindAll(c => c.track_id == trackid); if (stocks.Count > 0) { stocks.Sort((x, y) => x.pos.CompareTo(y.pos)); SetStockTop(stocks[0]); return(stocks[0]); } } return(StockList.Find(c => c.track_id == trackid && c.PosType == StockPosE.顶部)); }
/// <summary> /// 转移库存 /// </summary> /// <param name="stock_id"></param> /// <param name="to_track_id"></param> public void MoveStock(uint stock_id, uint to_track_id) { Stock stock = StockList.Find(c => c.id == stock_id); if (stock != null && stock.track_id != to_track_id) { uint from_track_id = stock.track_id; bool istostore = PubMaster.Track.IsStoreTrack(to_track_id); bool isfromstore = PubMaster.Track.IsStoreTrack(from_track_id); StockSumChange(stock, to_track_id); Track totrack = PubMaster.Track.GetTrack(to_track_id); stock.track_id = to_track_id; stock.area = totrack.area; stock.track_type = totrack.type; #region [更新储砖轨道] if (istostore) { UpdateTrackPos(stock); PubMaster.Mod.GoodSql.EditStock(stock, StockUpE.Pos); } if (isfromstore) { CheckStockTop(from_track_id); if (PubMaster.Track.IsTrackFull(from_track_id)) { PubMaster.Track.UpdateStockStatus(from_track_id, TrackStockStatusE.砖, ""); } } #endregion PubMaster.Mod.GoodSql.EditStock(stock, StockUpE.Track); PubMaster.Track.UpdateStockStatus(to_track_id, TrackStockStatusE.砖, ""); //由设备检查轨道没砖后才制空轨道 //if(!ExistStockInTrack(from_track_id) // && !PubMaster.Track.IsStoreTrack(from_track_id)) //{ // PubMaster.Track.UpdateStockStatus(from_track_id, TrackStockStatusE.空砖); //} } }
public void UpdateStockProTime(uint id, DateTime?produceTime) { if (!Monitor.TryEnter(_so, TimeSpan.FromSeconds(2))) { try { Stock stock = StockList.Find(c => c.id == id); if (stock != null) { stock.produce_time = produceTime; PubMaster.Mod.GoodSql.EditStock(stock, StockUpE.ProduceTime); } } finally { Monitor.Exit(_so); } } }
public bool DeleteStock(uint stockid, out string rs) { Stock stock = StockList.Find(c => c.id == stockid); if (stock == null) { rs = "找不到库存记录"; return(false); } StockList.Remove(stock); PubMaster.Mod.GoodSql.DeleteStock(stock); StockSumChange(stock, 0); if (stock.PosType == StockPosE.顶部) { CheckStockTop(stock.track_id); } rs = ""; return(true); }
public async Task Start() { var list = new List <string>() { "AMD", "TSLA" }; //var alpacaPriceMonitor = new AlpacaPriceMonitor(list, 5); //var monitoring = alpacaPriceMonitor.KickStartMonitoring(); StockList = await BR.FindProcessedStocks(); ActiveList = await BR.GetTradeNotifications(); foreach (var active in ActiveList) { var symbol = StockList.Find(e => e.Id == active.SymbolId); list.Add(symbol.Symbol); // avoid repeat symbols } list = list.Distinct().ToList(); StringList = list; var alpacaPriceMonitor = new AlpacaPriceMonitor(StringList, RefreshFrequency); var monitoring = alpacaPriceMonitor.KickStartMonitoring(); do { Thread.Sleep(20000); } while (alpacaPriceMonitor.CycleCount == 0); while (true) { var start = DateTime.Now; var results = alpacaPriceMonitor.RefreshResult; CheckRefreshResults(results); var timespan = new TimeSpan(DateTime.Now.Ticks - start.Ticks); Thread.Sleep((60000 * RefreshFrequency) - (int)timespan.TotalMilliseconds); } }
/// <summary> /// 获取轨道库存最大规格 /// </summary> /// <param name="trackid"></param> /// <returns></returns> private Goods GetTrackGoods(uint trackid) { uint goodsid = StockList.Find(c => c.track_id == trackid)?.goods_id ?? 0; if (goodsid != 0) { //是否存在不同规格的库存在同一个轨道 if (StockList.Exists(c => c.track_id == trackid && c.goods_id != goodsid)) { var goodsids = StockList.FindAll(c => c.track_id == trackid) .GroupBy(x => new { x.goods_id }) .Select(t => t.Key.goods_id); foreach (var goodid in goodsids) { if (CampareGoodWidth(goodsid, goodid)) { goodsid = goodid; } } } return(GoodsList.Find(c => c.id == goodsid)); } return(null); }
public Stock GetStock(string symbol) { return(StockList.Find(stock => stock.Symbol == symbol)); }
public uint GetStockTileId(uint stock_id) { return(StockList.Find(c => c.id == stock_id && c.tilelifter_id != 0)?.tilelifter_id ?? 0); }
public Stock GetStock(int id) { return(StockList.Find(c => c.id == id)); }
public uint GetTrackStockId(uint trackid) { return(StockList.Find(c => c.track_id == trackid)?.id ?? 0); }
public uint GetGoodsId(uint id) { return(StockList.Find(c => c.track_id == id)?.goods_id ?? 0); }
public bool HaveStockInTrack(uint trackid, uint goodsid, out uint stockid) { stockid = StockList.Find(c => c.track_id == trackid && c.goods_id == goodsid)?.id ?? 0; return(stockid != 0); }