KL12SiChuanTrend.cs 9.5 KB

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