JLK3Trend.cs 5.6 KB

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