using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2017/4/13 17:42:16 //Author //Description Create //---------------------------------------------------------------- using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Quote; using Muchinfo.MTPClient.Infrastructure.Cache; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.PC.Common.Helpers; namespace Muchinfo.MTPClient.Analysis.ViewModels { public class ChartViewModelBase : ViewModelBase { protected QuoteGoods _currentGoods; ////当前商品 protected IQuoteDataService _quoteDataService; public ChartViewModelBase(QuoteGoods goods) { _currentGoods = goods; _quoteDataService = SimpleIoc.Default.GetInstance(); } protected virtual void ChartInitTradePlan() { //MTP2.0-QueryQuoteTradeTime接口失效,从行情接口获取结算计划 _quoteDataService.QueryQuoteSettlementPlan((int)_currentGoods.MarketID, _currentGoods.ContainsGoodsSrc, QueryReckenSuccess, QueryReckenError); //if (UserManager.IsAccountLogin) //{ // _quoteDataService.QueryQuoteTradeTime((int)_currentGoods.MarketID, QueryTradeTimeSuccess, QueryReckenError); //} //else //{ // _quoteDataService.QueryQuoteSettlementPlan((int)_currentGoods.GoodsParameters.MarketTypeID, _currentGoods.ContainsGoodsSrc, QueryReckenSuccess, QueryReckenError); //} } /// /// /// /// protected virtual void QueryReckenSuccess(List tradeDays) { if (tradeDays != null && tradeDays.Any()) { var goodsArr = CacheManager.CacheGoodsBaseInfos.Where( (goods) => goods.GoodsParameters.MarketTypeID == _currentGoods.GoodsParameters.MarketTypeID); foreach (var quoteGoodse in goodsArr) { var goodsPlan = tradeDays.FirstOrDefault((item) => item.GoodsId == quoteGoodse.GoodsId); if (goodsPlan == null) { goodsPlan= tradeDays.FirstOrDefault((item) => item.GoodsId == 0); } if (goodsPlan != null) { CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = goodsPlan; ////设置每个商品的开休市时间 } } } } /// /// 查询结算时间失败 /// /// protected virtual void QueryReckenError(ErrorEntity errorEntity) { //todo:查询结算时间失败计算 LogHelper.WriteError(typeof(CChartViewModel), string.Format(ErrorManager.FormatErrorMsg(errorEntity))); } /// /// 查询开收市时间回应 /// /// protected virtual void QueryTradeTimeSuccess(List quoteTimes) { SetQuoteGoodsTradeTime(quoteTimes); } /// /// 设置行情交易时间 /// protected void SetQuoteGoodsTradeTime(List quoteTimes) { if (quoteTimes != null && quoteTimes.Any()) { /////设置商品组的开休市时间 var goodsArr = CacheManager.CacheGoodsBaseInfos.Where( (goods) => goods.GoodsParameters.MarketTypeID == _currentGoods.GoodsParameters.MarketTypeID); foreach (var quoteGoodse in goodsArr) { var tradeTimes = quoteTimes.Where((item) =>!string.IsNullOrWhiteSpace(item.Goodsids)&& item.Goodsids.Contains(quoteGoodse.GoodsId+string.Empty)); ////设置到商品的开收市时间 if (tradeTimes.Any()) { CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList()); continue; } tradeTimes = quoteTimes.Where((item) => quoteGoodse.GoodsParameters.SortId == item.GoodsGroupid && string.IsNullOrWhiteSpace(item.Goodsids)); ////设置到商品组的开收市时间 if (tradeTimes.Any()) { CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList()); continue; } tradeTimes = quoteTimes.Where((item) => quoteGoodse.GoodsParameters.ExchAreaID == item.ExchAreaid && item.GoodsGroupid == 0 && string.IsNullOrWhiteSpace(item.Goodsids)); ////设置到交易所的开收市时间 if (tradeTimes.Any()) { CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList()); continue; } tradeTimes = quoteTimes.Where((item) => item.ExchAreaid == 0 && item.GoodsGroupid == 0 && string.IsNullOrWhiteSpace(item.Goodsids)); ////设置到交易类型的开收市时间 if (tradeTimes.Any()) { CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList()); } } } } /// /// 转换开收市时间 /// /// protected QuoteTradePlan ConvertTradePlan(List quoteTimes) { var quoteTrade = new QuoteTradePlan() { OpenCloseDates = new List() }; if (quoteTimes != null && quoteTimes.Any()) { foreach (var quoteTradeTime in quoteTimes) { var openClose = new OpenCloseDate(); openClose.CloseDate = quoteTradeTime.EndTime; openClose.OpenDate = quoteTradeTime.BeginTime; openClose.RunStep = quoteTradeTime.RunStep; openClose.TradeDay = quoteTradeTime.TradeDate; quoteTrade.OpenCloseDates.Add(openClose); quoteTrade.TradeDay = quoteTradeTime.TradeDate; } } return quoteTrade; } } }