| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- 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<IQuoteDataService>();
- }
- 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);
- //}
-
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="tradeDays"></param>
- protected virtual void QueryReckenSuccess(List<QuoteTradePlan> 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; ////设置每个商品的开休市时间
- }
- }
- }
- }
-
- /// <summary>
- /// 查询结算时间失败
- /// </summary>
- /// <param name="errorEntity"></param>
- protected virtual void QueryReckenError(ErrorEntity errorEntity)
- {
- //todo:查询结算时间失败计算
-
- LogHelper.WriteError(typeof(CChartViewModel), string.Format(ErrorManager.FormatErrorMsg(errorEntity)));
- }
- /// <summary>
- /// 查询开收市时间回应
- /// </summary>
- /// <param name="quoteTimes"></param>
- protected virtual void QueryTradeTimeSuccess(List<QuoteTradeTime> quoteTimes)
- {
- SetQuoteGoodsTradeTime(quoteTimes);
- }
- /// <summary>
- /// 设置行情交易时间
- /// </summary>
- protected void SetQuoteGoodsTradeTime(List<QuoteTradeTime> 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());
- }
- }
- }
- }
- /// <summary>
- /// 转换开收市时间
- /// </summary>
- /// <param name="quoteTimes"></param>
- protected QuoteTradePlan ConvertTradePlan(List<QuoteTradeTime> quoteTimes)
- {
- var quoteTrade = new QuoteTradePlan() { OpenCloseDates = new List<OpenCloseDate>() };
- 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;
- }
- }
- }
|