FCDF6J1Trend.cs 5.6 KB

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