HC1Trend.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CB.Data;
  6. using CB.Entity;
  7. using CB.Interface;
  8. using CB.Interface.Infrastructure;
  9. namespace CB.TrendChart.LotteryTrendChart
  10. {
  11. public class HC1Trend
  12. {
  13. public static int Cid = 28;//Cid用于设置样式值
  14. /// <summary>
  15. /// 生成走势图,生成当前term数据及以后数据
  16. /// </summary>
  17. /// <param name="chartId">走势图ID</param>
  18. /// <param name="chartType">走势图类型</param>
  19. /// <param name="term">需要生成走势图期数</param>
  20. /// <param name="LotterySearchField">彩种开奖数据额外查询条件</param>
  21. /// <returns></returns>
  22. public static Tuple<bool, string> CreateTrendChart(int chartId, TrendChartType chartType, long term, LotterySearchField fields = null)
  23. {
  24. //获取走势图项及配置数据
  25. var trendChartItem = TrendChartItemService.ToListByChartId(chartId, chartType);
  26. if (null == trendChartItem || 0 >= trendChartItem.Count)
  27. return new Tuple<bool, string>(false, string.Format("未找到【ChartId={0}】走势图的项配置数据", chartId));
  28. int count = trendChartItem.Count;
  29. IList<IChartItem<HC1Info>> chartItem = new List<IChartItem<HC1Info>>(count);
  30. IList<ChartCssConfigInfo> cssConfig = new List<ChartCssConfigInfo>(count);
  31. foreach (var item in trendChartItem)
  32. {
  33. //实例化项类型
  34. chartItem.Add(TrendChartUtils.GetTrendChartInterface<HC1Info>(item.ClassName));
  35. //获取项CSS配置信息
  36. cssConfig.Add(ChartCssConfigService.Get(item.FuntionType, item.ChartCssId));
  37. }
  38. //各项初始化
  39. for (int i = 0; i < count; i++)
  40. {
  41. trendChartItem[i].Cid = Cid;
  42. chartItem[i].Init(cssConfig[i], trendChartItem[i]);
  43. }
  44. //大于等于term开奖数据
  45. IList<HC1Info> ListToEnd = HC1Service.GetListToEnd(term, fields);
  46. if (null == ListToEnd || 0 >= ListToEnd.Count)
  47. return new Tuple<bool, string>(false, "未找到有效开奖数据");
  48. int j = 0;
  49. TrendChartData entity = null;
  50. var ResultEntity = new TrendChartData
  51. {
  52. ChartId = chartId,
  53. Term = term,
  54. ChartType = chartType,
  55. LocalMiss = new string[count],
  56. LastMiss = new string[count],
  57. AllMaxMiss = new string[count],
  58. AllAvgMiss = new string[count],
  59. AllTimes = new string[count]
  60. };
  61. foreach (var currentData in ListToEnd)
  62. {
  63. //根据参数term期数获取近两期开奖信息TOP 2 [Term]<=term ORDER BY [Term] DESC
  64. IList<HC1Info> list = HC1Service.ToListForTrend(currentData.Term, fields);
  65. HC1Info info = null;
  66. info = list[0];
  67. if (2 == list.Count)
  68. {
  69. //取当前期数的上一期的走势图信息及遗漏数据
  70. entity = ResultEntity;
  71. if (0 == j)
  72. entity = HC1TrendChartDataService.GetTrendChartDataByTerm(chartId, chartType, list[1].Term);
  73. }
  74. bool yes = true;
  75. var sp = new StringBuilder(20000);
  76. sp.Append("<tr>");
  77. for (int i = 0; i < count; i++)
  78. {
  79. //初始化遗漏数据(根据上期结果集计算_entity)
  80. chartItem[i].MissDataInit(entity, i);
  81. //计算项值及遗漏计算
  82. yes = yes && chartItem[i].SetItemValue(info);
  83. if (yes)
  84. {
  85. //结果集赋值
  86. ResultEntity.LocalMiss[i] = chartItem[i].GetMissData(MissDataType.LocalMiss);
  87. ResultEntity.LastMiss[i] = chartItem[i].GetMissData(MissDataType.LastMiss);
  88. ResultEntity.AllMaxMiss[i] = chartItem[i].GetMissData(MissDataType.AllMaxMiss);
  89. ResultEntity.AllAvgMiss[i] = chartItem[i].GetMissData(MissDataType.AllAvgMiss);
  90. ResultEntity.AllTimes[i] = chartItem[i].GetMissData(MissDataType.AllTimes);
  91. sp.Append(chartItem[i].GetFomartString("<td {0}>{1}</td>"));
  92. }
  93. }
  94. sp.Append("</tr>");
  95. if (null != entity)
  96. ResultEntity.RecordCount = entity.RecordCount + 1;
  97. else
  98. ResultEntity.RecordCount = 1;
  99. ResultEntity.Term = currentData.Term;
  100. ResultEntity.HtmlData = sp.ToString();
  101. if (!yes)
  102. { return new Tuple<bool, string>(false, string.Format("无效开奖数据:数据生成截止期数为【term={0}】", ResultEntity.Term)); }
  103. yes = yes && DatabaseProvider.GetDbProvider<IHC1TendChartDataService>().Save(ResultEntity);
  104. if (!yes)
  105. { return new Tuple<bool, string>(false, string.Format("数据保存出错:数据保存截止期数为【term={0}】", ResultEntity.Term)); }
  106. j++;
  107. }
  108. return new Tuple<bool, string>(true, string.Format("正常生成完毕,截止期数为:Term={0}", ListToEnd[ListToEnd.Count - 1].Term));
  109. }
  110. /// <summary>
  111. /// 预览走势图,默认显示近30期数据 (实时计算生成)
  112. /// </summary>
  113. /// <param name="chartId"></param>
  114. /// <param name="chartType"></param>
  115. /// <param name="term"></param>
  116. /// <param name="fields"></param>
  117. /// <returns></returns>
  118. public static string PreViewTrendChart(int chartId, TrendChartType chartType, LotterySearchField fields = null)
  119. {
  120. var list = HC1Service.GetListToEnd(0, fields);
  121. if (null == list || 0 >= list.Count)
  122. return "";
  123. //获取走势图项及配置数据
  124. var trendChartItem = TrendChartItemService.ToListByChartId(chartId, chartType);
  125. if (null == trendChartItem || 0 >= trendChartItem.Count)
  126. return "";
  127. int count = trendChartItem.Count;
  128. IList<IChartItem<HC1Info>> chartItem = new List<IChartItem<HC1Info>>(count);
  129. IList<ChartCssConfigInfo> cssConfig = new List<ChartCssConfigInfo>(count);
  130. foreach (var item in trendChartItem)
  131. {
  132. //实例化项类型
  133. chartItem.Add(TrendChartUtils.GetTrendChartInterface<HC1Info>(item.ClassName));
  134. //获取项CSS配置信息
  135. cssConfig.Add(ChartCssConfigService.Get(item.FuntionType, item.ChartCssId));
  136. }
  137. //项初始化
  138. for (int i = 0; i < count; i++)
  139. {
  140. trendChartItem[i].Cid = Cid;
  141. chartItem[i].Init(cssConfig[i], trendChartItem[i]);
  142. }
  143. var sp = new StringBuilder(20000);
  144. int record = list.Count;
  145. int topSize = null == fields ? 30 : fields.TopSize;
  146. if (30 > topSize)
  147. topSize = 30;
  148. for (int i = 0; i < record; i++)
  149. {
  150. for (int j = count - 1; j >= 0; j--)
  151. {
  152. chartItem[j].SetItemValue(list[i]);
  153. }
  154. if (i >= record - topSize)
  155. {
  156. sp.Append("<tr>");
  157. for (int j = 0; j < count; j++)
  158. {
  159. sp.Append(chartItem[j].GetFomartString("<td {0}>{1}</td>"));
  160. }
  161. sp.Append("</tr>");
  162. }
  163. }
  164. return sp.ToString();
  165. }
  166. }
  167. }