| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using CB.Common;
- using CB.Data;
- using CB.Data.Frequency;
- using CB.Data.Lottery.Frequency;
- using CB.Entity;
- using CB.Entity.Frequency;
- using CB.Interface;
- using CB.Interface.Infrastructure;
- using CB.Interface.Infrastructure.Frequency;
- using System.Collections.Concurrent;
- namespace CB.TrendChart.FrequencyTrendChart
- {
- /// <summary>
- /// 高频彩-快乐12通用走势图生成工具
- /// </summary>
- public class KL12Trend<T> where T : LotteryOpenCode, new()
- {
- //public static int Cid = 59;//Cid用于设置样式值
- private static readonly ConcurrentDictionary<string, string[]> cdict = new ConcurrentDictionary<string, string[]>();
- #region DJP
- public static Tuple<bool, string, List<TrendChartData>> CreateGPTrendChart(int cId, int chartId, TrendChartType chartType, string tableName, GpLotterySearchField fields = null)
- {
- var cacheKey = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}", cId, chartId, (int)chartType, tableName.Substring(3), fields.EndTerm, fields.SearchDate.Value.ToString("yyyyMMdd"), fields.SearchDay ? "1" : "0", fields.StartTerm, fields.TopSize, fields.Year);//缓存Key
- var t = System.Threading.Tasks.Task.Factory.StartNew(() =>
- {
- var cacheData = CB.Cache.CBCache.GetCacheService().GetObject(cacheKey);
- if (cacheData != null)
- return new Tuple<bool, string, List<TrendChartData>>(true, null, (List<TrendChartData>)cacheData);
- do
- {
- System.Threading.Thread.Sleep(1);
- } while (cdict.ContainsKey(cacheKey));
- return CreateGpTrendChart(cacheKey, cId, chartId, chartType, tableName, fields);
- });
- System.Threading.Tasks.Task.WaitAny(new System.Threading.Tasks.Task[] { t }, 1000);
- return t.Result;
- }
- /// <summary>
- /// 动态生成高频走势图,生成当前term数据及以后数据
- /// midified by djp 2016-06-08 修正传入cid用于设置样式值
- /// </summary>
- /// <param name="cId">彩种编号</param>
- /// <param name="chartId">走势图ID</param>
- /// <param name="chartType">走势图类型</param>
- /// <param name="fields">彩种开奖数据额外查询条件</param>
- /// <returns></returns>
- private static Tuple<bool, string, List<TrendChartData>> CreateGpTrendChart(string cacheKey, int cId, int chartId, TrendChartType chartType, string tableName, GpLotterySearchField fields = null)
- {
- //获取走势图项及配置数据
- //var cacheKey = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}", cId, chartId, (int)chartType, tableName.Substring(3), fields.EndTerm, fields.SearchDate.Value.ToString("yyyyMMdd"), fields.SearchDay ? "1" : "0", fields.StartTerm, fields.TopSize, fields.Year);//缓存Key
- var cacheData = CB.Cache.CBCache.GetCacheService().GetObject(cacheKey);
- if (cacheData != null)
- {
- return new Tuple<bool, string, List<TrendChartData>>(true, null, (List<TrendChartData>)cacheData);
- }
- var trendChartItem = TrendChartItemService.ToListByChartId(chartId, chartType);
- if (null == trendChartItem || 0 >= trendChartItem.Count)
- return new Tuple<bool, string, List<TrendChartData>>(false, string.Format("未找到【ChartId={0}】走势图的项配置数据", chartId), null);
- int count = trendChartItem.Count;
- IList<IChartItem<T>> chartItem = new List<IChartItem<T>>(count);
- IList<ChartCssConfigInfo> cssConfig = new List<ChartCssConfigInfo>(count);
- foreach (var item in trendChartItem)
- {
- //实例化项类型
- chartItem.Add(TrendChartUtils.GetTrendChartInterface<T>(item.ClassName));
- //获取项CSS配置信息
- cssConfig.Add(ChartCssConfigService.Get(item.FuntionType, item.ChartCssId));
- }
- //各项初始化
- for (int i = 0; i < count; i++)
- {
- trendChartItem[i].Cid = cId;
- chartItem[i].Init(cssConfig[i], trendChartItem[i]);
- }
- //大于等于term开奖数据
- IList<T> ListToEnd = GPTrendService<T>.GetListToEnd(tableName, fields);
- if (null == ListToEnd || 0 >= ListToEnd.Count)
- return new Tuple<bool, string, List<TrendChartData>>(false, "未找到有效开奖数据", null);
- int j = 0;
- TrendChartData entity = null;
- var TrendChartDataList = new List<TrendChartData>();
- foreach (var currentData in ListToEnd)
- {
- var ResultEntity = new TrendChartData
- {
- ChartId = chartId,
- ChartType = chartType,
- LocalMiss = new string[count],
- LastMiss = new string[count],
- AllMaxMiss = new string[count],
- AllAvgMiss = new string[count],
- AllTimes = new string[count]
- };
- //根据参数term期数获取近两期开奖信息TOP 2 [Term]<=term ORDER BY [Term] DESC
- IList<T> list = ListToEnd.Where(p => p.Term <= currentData.Term).OrderByDescending(p => p.Term).Take(2).ToList();
- //GP11x5SiChuanService.ToListForTrend(currentData.Term, fields);
- var info = list[0]; //ListToEnd[ListToEnd.Count - 1];
- // info = list[0];
- if (2 == list.Count)
- {
- //取当前期数的上一期的走势图信息及遗漏数据
- if (0 == j)
- {
- entity = SCKL12TrendChartDataService.GetTrendChartDataByTerm(chartId, chartType, list[1].Term);
- }
- else if (TrendChartDataList.Count > 0)
- {
- entity = TrendChartDataList[TrendChartDataList.Count - 1];
- }
- }
- bool yes = true;
- var sp = new StringBuilder(20000);
- sp.Append("<tr>");
- for (int i = 0; i < count; i++)
- {
- //初始化遗漏数据(根据上期结果集计算_entity)
- chartItem[i].MissDataInit(entity, i);
- //计算项值及遗漏计算
- yes = yes && chartItem[i].SetItemValue(info);
- if (yes)
- {
- //结果集赋值
- ResultEntity.LocalMiss[i] = chartItem[i].GetMissData(MissDataType.LocalMiss);
- ResultEntity.LastMiss[i] = chartItem[i].GetMissData(MissDataType.LastMiss);
- ResultEntity.AllMaxMiss[i] = chartItem[i].GetMissData(MissDataType.AllMaxMiss);
- ResultEntity.AllAvgMiss[i] = chartItem[i].GetMissData(MissDataType.AllAvgMiss);
- ResultEntity.AllTimes[i] = chartItem[i].GetMissData(MissDataType.AllTimes);
- sp.Append(chartItem[i].GetFomartString("<td {0}>{1}</td>"));
- }
- }
- sp.Append("</tr>");
- if (null != entity)
- ResultEntity.RecordCount = entity.RecordCount + 1;
- else
- ResultEntity.RecordCount = 1;
- ResultEntity.Term = currentData.Term;
- ResultEntity.HtmlData = sp.ToString();
- TrendChartDataList.Add(ResultEntity);
- if (!yes)
- {
- return new Tuple<bool, string, List<TrendChartData>>(false, string.Format("无效开奖数据:数据生成截止期数为【term={0}】", ResultEntity.Term), TrendChartDataList);
- }
- j++;
- }
- TrendChartDataList.Reverse();
- //加入缓存int cId, int chartId, TrendChartType chartType, string tableName, GpLotterySearchField fields = null
- CB.Cache.CBCache.GetCacheService().AddObject(cacheKey, TrendChartDataList, 240);
- return new Tuple<bool, string, List<TrendChartData>>(true, string.Format("正常生成完毕,截止期数为:Term={0}", ListToEnd[ListToEnd.Count - 1].Term), TrendChartDataList);
- }
- #endregion
- }
- }
|