ChartViewModelBase.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //----------------------------------------------------------------
  6. //Module Name: $safeprojectname$
  7. //Purpose:
  8. //CopyRight: Muchinfo
  9. //History:
  10. //----------------------------------------------------------------
  11. //DateTime 2017/4/13 17:42:16
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using GalaSoft.MvvmLight;
  16. using GalaSoft.MvvmLight.Ioc;
  17. using Muchinfo.MTPClient.Data;
  18. using Muchinfo.MTPClient.Data.Model;
  19. using Muchinfo.MTPClient.Data.Quote;
  20. using Muchinfo.MTPClient.Infrastructure.Cache;
  21. using Muchinfo.MTPClient.Infrastructure.Utilities;
  22. using Muchinfo.MTPClient.IService;
  23. using Muchinfo.PC.Common.Helpers;
  24. namespace Muchinfo.MTPClient.Analysis.ViewModels
  25. {
  26. public class ChartViewModelBase : ViewModelBase
  27. {
  28. protected QuoteGoods _currentGoods; ////当前商品
  29. protected IQuoteDataService _quoteDataService;
  30. public ChartViewModelBase(QuoteGoods goods)
  31. {
  32. _currentGoods = goods;
  33. _quoteDataService = SimpleIoc.Default.GetInstance<IQuoteDataService>();
  34. }
  35. protected virtual void ChartInitTradePlan()
  36. {
  37. //MTP2.0-QueryQuoteTradeTime接口失效,从行情接口获取结算计划
  38. _quoteDataService.QueryQuoteSettlementPlan((int)_currentGoods.MarketID, _currentGoods.ContainsGoodsSrc, QueryReckenSuccess, QueryReckenError);
  39. //if (UserManager.IsAccountLogin)
  40. //{
  41. // _quoteDataService.QueryQuoteTradeTime((int)_currentGoods.MarketID, QueryTradeTimeSuccess, QueryReckenError);
  42. //}
  43. //else
  44. //{
  45. // _quoteDataService.QueryQuoteSettlementPlan((int)_currentGoods.GoodsParameters.MarketTypeID, _currentGoods.ContainsGoodsSrc, QueryReckenSuccess, QueryReckenError);
  46. //}
  47. }
  48. /// <summary>
  49. ///
  50. /// </summary>
  51. /// <param name="tradeDays"></param>
  52. protected virtual void QueryReckenSuccess(List<QuoteTradePlan> tradeDays)
  53. {
  54. if (tradeDays != null && tradeDays.Any())
  55. {
  56. var goodsArr = CacheManager.CacheGoodsBaseInfos.Where(
  57. (goods) => goods.GoodsParameters.MarketTypeID == _currentGoods.GoodsParameters.MarketTypeID);
  58. foreach (var quoteGoodse in goodsArr)
  59. {
  60. var goodsPlan = tradeDays.FirstOrDefault((item) => item.GoodsId == quoteGoodse.GoodsId);
  61. if (goodsPlan == null)
  62. {
  63. goodsPlan= tradeDays.FirstOrDefault((item) => item.GoodsId == 0);
  64. }
  65. if (goodsPlan != null)
  66. {
  67. CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = goodsPlan; ////设置每个商品的开休市时间
  68. }
  69. }
  70. }
  71. }
  72. /// <summary>
  73. /// 查询结算时间失败
  74. /// </summary>
  75. /// <param name="errorEntity"></param>
  76. protected virtual void QueryReckenError(ErrorEntity errorEntity)
  77. {
  78. //todo:查询结算时间失败计算
  79. LogHelper.WriteError(typeof(CChartViewModel), string.Format(ErrorManager.FormatErrorMsg(errorEntity)));
  80. }
  81. /// <summary>
  82. /// 查询开收市时间回应
  83. /// </summary>
  84. /// <param name="quoteTimes"></param>
  85. protected virtual void QueryTradeTimeSuccess(List<QuoteTradeTime> quoteTimes)
  86. {
  87. SetQuoteGoodsTradeTime(quoteTimes);
  88. }
  89. /// <summary>
  90. /// 设置行情交易时间
  91. /// </summary>
  92. protected void SetQuoteGoodsTradeTime(List<QuoteTradeTime> quoteTimes)
  93. {
  94. if (quoteTimes != null && quoteTimes.Any())
  95. {
  96. /////设置商品组的开休市时间
  97. var goodsArr = CacheManager.CacheGoodsBaseInfos.Where(
  98. (goods) => goods.GoodsParameters.MarketTypeID == _currentGoods.GoodsParameters.MarketTypeID);
  99. foreach (var quoteGoodse in goodsArr)
  100. {
  101. var tradeTimes = quoteTimes.Where((item) =>!string.IsNullOrWhiteSpace(item.Goodsids)&& item.Goodsids.Contains(quoteGoodse.GoodsId+string.Empty)); ////设置到商品的开收市时间
  102. if (tradeTimes.Any())
  103. {
  104. CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList());
  105. continue;
  106. }
  107. tradeTimes = quoteTimes.Where((item) => quoteGoodse.GoodsParameters.SortId == item.GoodsGroupid && string.IsNullOrWhiteSpace(item.Goodsids)); ////设置到商品组的开收市时间
  108. if (tradeTimes.Any())
  109. {
  110. CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList());
  111. continue;
  112. }
  113. tradeTimes = quoteTimes.Where((item) => quoteGoodse.GoodsParameters.ExchAreaID == item.ExchAreaid && item.GoodsGroupid == 0 && string.IsNullOrWhiteSpace(item.Goodsids)); ////设置到交易所的开收市时间
  114. if (tradeTimes.Any())
  115. {
  116. CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList());
  117. continue;
  118. }
  119. tradeTimes = quoteTimes.Where((item) => item.ExchAreaid == 0 && item.GoodsGroupid == 0 && string.IsNullOrWhiteSpace(item.Goodsids)); ////设置到交易类型的开收市时间
  120. if (tradeTimes.Any())
  121. {
  122. CacheManager.TradeDayPlan[quoteGoodse.GoodsId] = ConvertTradePlan(tradeTimes.ToList());
  123. }
  124. }
  125. }
  126. }
  127. /// <summary>
  128. /// 转换开收市时间
  129. /// </summary>
  130. /// <param name="quoteTimes"></param>
  131. protected QuoteTradePlan ConvertTradePlan(List<QuoteTradeTime> quoteTimes)
  132. {
  133. var quoteTrade = new QuoteTradePlan() { OpenCloseDates = new List<OpenCloseDate>() };
  134. if (quoteTimes != null && quoteTimes.Any())
  135. {
  136. foreach (var quoteTradeTime in quoteTimes)
  137. {
  138. var openClose = new OpenCloseDate();
  139. openClose.CloseDate = quoteTradeTime.EndTime;
  140. openClose.OpenDate = quoteTradeTime.BeginTime;
  141. openClose.RunStep = quoteTradeTime.RunStep;
  142. openClose.TradeDay = quoteTradeTime.TradeDate;
  143. quoteTrade.OpenCloseDates.Add(openClose);
  144. quoteTrade.TradeDay = quoteTradeTime.TradeDate;
  145. }
  146. }
  147. return quoteTrade;
  148. }
  149. }
  150. }