12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069 |
- using Lottomat.Application.Busines.BaseManage;
- using Lottomat.Application.Busines.CommonManage;
- using Lottomat.Application.Busines.LotteryNumberManage;
- using Lottomat.Application.Cache;
- using Lottomat.Application.Code;
- using Lottomat.Application.Entity.BaseManage;
- using Lottomat.Application.Entity.BaseManage.Parameter;
- using Lottomat.Application.Entity.CommonEntity;
- using Lottomat.Application.Entity.LotteryNumberManage.Parameter;
- using Lottomat.Application.Entity.LotteryNumberManage.ViewModel;
- using Lottomat.Application.Entity.SystemManage.ViewModel;
- using Lottomat.SOA.API.Controllers.Base;
- using Lottomat.Util;
- using Lottomat.Util.Extension;
- using Lottomat.Utils;
- using Lottomat.Utils.Date;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web.Http;
- namespace Lottomat.SOA.API.Controllers.V1
- {
- /// <summary>
- /// 开奖号相关接口
- /// </summary>
- public class LotteryNumberController : BaseApiController
- {
- #region 实例
- /// <summary>
- /// 锁
- /// </summary>
- private static readonly object _lock = new Object();
- /// <summary>
- /// 公共BLL
- /// </summary>
- private static readonly CommonBLL commonBll = new CommonBLL();
- /// <summary>
- /// 字典缓存BLL
- /// </summary>
- private static readonly DataItemCache dataItemCache = new DataItemCache();
- private static QGFC3DBLL qgfc3Dbll = new QGFC3DBLL();
- private static readonly BannerBLL bannerBLL = new BannerBLL();
- /// <summary>
- /// 彩种编码
- /// </summary>
- // QGC|全国彩,DFC|地方彩,GPC11X5|11选5,GPCK3|快3,GPCKL12|快乐十二,GPCKLSF|快乐十分,GPCSSC|时时彩,GPCQTC|其他彩种
- private static readonly string LotteryTypeCodeStr = ConfigHelper.GetValue("LotteryCategoryCodingMapping");
- #endregion 实例
- #region 获取系统热门、推荐彩种列表
- /// <summary>
- /// 获取系统热门、推荐彩种列表
- /// </summary>
- /// <param name="arg"></param>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetRecommendationAndHotLottery(BaseParameterEntity arg)
- {
- BaseJson<List<RecommendationAndHotLotteryViewEntity>> resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Task task = Task.Factory.StartNew(() =>
- {
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取系统热门、推荐彩种列表-GetRecommendationAndHotLottery", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- string codeList = GetCodeList();
- //获取所有彩种
- List<DataItemModel> cache = dataItemCache.GetDataItemList(codeList).OrderBy(d => d.SortCode ?? 0).ToList();
- List<RecommendationAndHotLotteryViewEntity> res = new List<RecommendationAndHotLotteryViewEntity>();
- //筛选推荐
- List<LotteryItems> lotteryItemsesRecommend = (from model in cache
- where model.IsRecommend
- select new LotteryItems
- {
- Id = model.ItemDetailId,
- Code = model.ItemValue,
- Name = model.ItemName,
- EnumCode = model.SimpleSpelling
- }).ToList();
- RecommendationAndHotLotteryViewEntity Recommend = new RecommendationAndHotLotteryViewEntity
- {
- Type = 0,
- Desc = "推荐",
- LotteryItemses = lotteryItemsesRecommend
- };
- res.Add(Recommend);
- //筛选热门
- List<LotteryItems> lotteryItemsesHot = (from model in cache
- where model.IsHot
- select new LotteryItems
- {
- Id = model.ItemDetailId,
- Code = model.ItemValue,
- Name = model.ItemName,
- EnumCode = model.SimpleSpelling
- }).ToList();
- RecommendationAndHotLotteryViewEntity Hot = new RecommendationAndHotLotteryViewEntity
- {
- Type = 1,
- Desc = "热门",
- LotteryItemses = lotteryItemsesHot
- };
- res.Add(Hot);
- resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = res,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- });
- task.Wait();
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- #endregion 获取系统热门、推荐彩种列表
- #region 彩票大厅
- /// <summary>
- /// 彩票大厅
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetAllLotteryList(BaseParameterEntity arg)
- {
- BaseJson<List<AllLotteryListViewEntity>> resultMsg = new BaseJson<List<AllLotteryListViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Task task = Task.Factory.StartNew(() =>
- {
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "彩票大厅-GetAllLotteryList", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- List<AllLotteryListViewEntity> res = new List<AllLotteryListViewEntity>();
- string[] lotteryTypeCodeArr = LotteryTypeCodeStr.Split(",".ToCharArray());
- foreach (string code in lotteryTypeCodeArr)
- {
- string[] arr = code.Split("|".ToCharArray());
- List<LotteryItems> items = new List<LotteryItems>();
- //获取对应彩种
- List<DataItemModel> cache = dataItemCache.GetDataItemList(arr[0]);
- foreach (DataItemModel model in cache)
- {
- LotteryItems temp = new LotteryItems
- {
- Id = model.ItemDetailId,
- Code = model.ItemValue,
- Name = model.ItemName,
- EnumCode = model.SimpleSpelling
- };
- items.Add(temp);
- }
- res.Add(new AllLotteryListViewEntity
- {
- TypeCode = arr[0],
- TypeName = arr[1],
- LotteryItemses = items
- });
- }
- resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = res,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数type为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- });
- task.Wait();
- //Tasks.Add(task);
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- #endregion 彩票大厅
- #region 获取首页展示详细开奖信息的彩种
- /// <summary>
- /// 获取首页展示详细开奖信息的彩种
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetHomeLotteryList(BaseParameterEntity arg)
- {
- BaseJson<List<HomeLotteryListViewEntity>> resultMsg = new BaseJson<List<HomeLotteryListViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Task task = Task.Factory.StartNew(() =>
- {
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取首页展示详细开奖信息的彩种-GetHomeLotteryList", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- lock (_lock)
- {
- string codeList = GetCodeList();
- //获取所有彩种
- List<DataItemModel> cache = dataItemCache.GetDataItemList(codeList).OrderBy(d => d.SortCode ?? 0).ToList();
- //获取类型码-枚举码字典
- Dictionary<string, SCCLottery> dictionary = GetTypeCodeAndEnumCodeDict(cache, true);
- //结果集合
- List<HomeLotteryListViewEntity> res = GetRealData(dictionary);
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = res,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- });
- task.Wait();
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- /// <summary>
- /// 根据彩种编码获取对应推荐的彩种开奖详情
- /// </summary>
- /// <param name="arg"></param>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetHomeLotteryListByTypeCode(HomeLotteryListByTypeCodeArgEntity arg)
- {
- BaseJson<List<HomeLotteryListViewEntity>> resultMsg = new BaseJson<List<HomeLotteryListViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Task task = Task.Factory.StartNew(() =>
- {
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取首页展示详细开奖信息的彩种-GetHomeLotteryList", () =>
- {
- if (!string.IsNullOrEmpty(arg.t) && !string.IsNullOrEmpty(arg.TypeCode))
- {
- if (arg.t.CheckTimeStamp())
- {
- lock (_lock)
- {
- //获取所有彩种
- List<DataItemModel> cache = dataItemCache.GetDataItemList(arg.TypeCode).OrderBy(d => d.SortCode ?? 0).ToList();
- //获取类型码-枚举码字典
- Dictionary<string, SCCLottery> dictionary = GetTypeCodeAndEnumCodeDict(cache, false, true, false, arg.TypeCode);
- //结果集合
- List<HomeLotteryListViewEntity> res = GetRealData(dictionary);
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = res,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- });
- task.Wait();
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- /// <summary>
- /// 获取彩种编码
- /// </summary>
- /// <returns></returns>
- private static string GetCodeList()
- {
- string codeList = String.Empty;
- string[] lotteryTypeCodeArr = LotteryTypeCodeStr.Split(",".ToCharArray());
- codeList = lotteryTypeCodeArr.Select(code => code.Split("|".ToCharArray())).Aggregate(codeList, (current, arr) => current + (arr[0] + "|"));
- codeList = StringHelper.DelLastChar(codeList, "|");
- return codeList;
- }
- /// <summary>
- /// 组装开奖号
- /// </summary>
- /// <param name="data">最新一期开奖详情</param>
- /// <param name="enumCode">枚举码</param>
- /// <param name="ballItems">开奖号集合</param>
- private static void GetOpenCodeValue(DataRow data, string enumCode, out List<LotteryBallItem> ballItems)
- {
- List<LotteryBallItem> temp = new List<LotteryBallItem>();
- int[] codeArr = LotteryBallTypeDict[enumCode];
- //正常球个数
- int normal = codeArr[0];
- //蓝球个数
- int blue = codeArr[1];
- //生肖球个数
- int zodiac = codeArr[2];
- //季节球个数
- int season = codeArr[3];
- //方位球个数
- int position = codeArr[4];
- #region 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
- //总球数
- int total = normal + blue + zodiac + season + position;
- List<int> ballList = new List<int>();
- for (int i = 1; i <= total; i++)
- {
- ballList.Add(data["OpenCode" + i].TryToInt32());
- }
- //取出当前最大开奖号
- //TODO 此做法欠妥,如果当前彩种开奖号取值在0-20之间,有可能某一期开奖号全部都小于10
- int max = ballList.Max();
- //是否需要添加0
- bool hasAppendZero = (!enumCode.Equals(SCCLottery.ShanDongKLPK3.ToString()) && max >= 10) || enumCode.Equals(SCCLottery.GuangDongHC1.ToString());
- #endregion 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
- #region 正常球
- if (normal > 0)
- {
- for (int i = 1; i <= normal; i++)
- {
- int openCode = ballList[i - 1];//data["OpenCode" + i].TryToInt32();
- temp.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Normal,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- #endregion 正常球
- #region 蓝球
- if (blue > 0)
- {
- int index = normal;
- //for (int i = blue; i >= 1; i--)
- for (int i = 1; i <= blue; i++)
- {
- int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + i)].TryToInt32();
- temp.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Blue,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- #endregion 蓝球
- #region 生肖球
- if (zodiac > 0)
- {
- int index = normal + blue;
- for (int i = zodiac; i >= 1; i--)
- {
- int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + blue + i)].TryToInt32();
- temp.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Zodiac,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- #endregion 生肖球
- #region 季节球
- if (season > 0)
- {
- int index = normal + blue + zodiac;
- for (int i = season; i >= 1; i--)
- {
- int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + blue + zodiac + i)].TryToInt32();
- temp.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Season,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- #endregion 季节球
- #region 方位球
- if (position > 0)
- {
- int index = normal + blue + zodiac + season;
- for (int i = position; i >= 1; i--)
- {
- int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + blue + zodiac + season + i)].TryToInt32();
- temp.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Position,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- #endregion 方位球
- ballItems = temp;
- }
- /// <summary>
- /// 计算下一次开奖时间
- /// </summary>
- /// <param name="config">彩种配置文件</param>
- /// <param name="currentOpenTime">最新一期开奖时间</param>
- /// <param name="openThePrizeOnTheDayOfTheWeek">每周那几天开奖数组</param>
- /// <param name="now">当前时间</param>
- /// <returns></returns>
- private DateTime GetNextOpenTime(SCCConfig config, DateTime currentOpenTime, string[] openThePrizeOnTheDayOfTheWeek, DateTime now)
- {
- //今天是星期几
- string week = DateTimeHelper.Now.DayOfWeek.ToString("d");
- //今天星期在数组中的索引
- int pointer = Array.IndexOf(openThePrizeOnTheDayOfTheWeek, week);
- //间隔时间
- int interval = config.Interval;
- //每天期数
- int timesPerDay = config.TimesPerDay;
- //当前彩种今天真实开始开奖时间
- DateTime todayRealStartOpentime = (DateTimeHelper.Now.ToString("yyyy-MM-dd") + " " + config.StartHour + ":" + config.StartMinute).TryToDateTime();
- //下次开奖时间
- DateTime nextOpenTime = default(DateTime);
- //今天将要开奖,计算出将要开奖时间
- if (pointer != -1)
- {
- //如果当前时间小于将要开奖时间,说明还未开奖,返回将要开奖时间
- if (now < todayRealStartOpentime)
- {
- //Modify By 大师兄 解决高频彩问题
- if (interval > 0 && timesPerDay > 1)
- {
- //计算真实开始开奖时间到现在时间已经开了多少期
- TimeSpan span = now - todayRealStartOpentime;
- int total = (int)Math.Floor(span.TotalMinutes * 1.0 / interval) + 1;
- nextOpenTime = todayRealStartOpentime.AddMinutes(total * interval);
- }
- else
- {
- nextOpenTime = todayRealStartOpentime;
- }
- }
- else
- {
- if (interval > 0 && timesPerDay > 1)
- {
- //Modify By 大师兄 解决偶尔开奖号未抓取到,导致中间少了
- //判断当前时间是否大于数据库最新一条记录开奖时间,如果大于,说明数据正常;如果小于,则说明数据库数据存在异常
- if (now > currentOpenTime)
- {
- //计算当前时间到当前最新一期开奖时间已经开了多少期
- TimeSpan span = now - currentOpenTime;
- int total = (int)Math.Floor(Math.Abs(span.TotalMinutes) * 1.0 / interval) + 1;
- nextOpenTime = currentOpenTime.AddMinutes(total * interval);
- }
- else
- {
- //Modify By 大师兄 解决当前最新一期开奖时间大于当前时间问题
- //矫正开奖时间
- #region 此算法较粗糙,可能会出现当天开奖时间有误差的情况
- //计算真实开始开奖时间到现在时间已经开了多少期
- //TimeSpan span = now - todayRealStartOpentime;
- //int total = (int)Math.Floor(span.TotalMinutes * 1.0 / interval) + 1;
- //nextOpenTime = todayRealStartOpentime.AddMinutes(total * interval);
- #endregion 此算法较粗糙,可能会出现当天开奖时间有误差的情况
- //计算当前最新一期开奖时间到现在已经开了多少期
- TimeSpan span = currentOpenTime - now;
- int total = (int)Math.Floor(Math.Abs(span.TotalMinutes) * 1.0 / interval) + 1;
- nextOpenTime = currentOpenTime.AddMinutes(total * interval);
- }
- }
- else
- {
- if (openThePrizeOnTheDayOfTheWeek.Length > pointer + 1)
- {
- pointer++;
- }
- else
- {
- pointer = 0;
- }
- //解决星期天的问题
- int week_n = openThePrizeOnTheDayOfTheWeek[pointer].TryToInt32() == 0 ? 7 : openThePrizeOnTheDayOfTheWeek[pointer].TryToInt32();
- int days = Math.Abs(week_n - week.TryToInt32());
- nextOpenTime = todayRealStartOpentime.AddDays(days);
- }
- }
- }
- else
- {
- //今天不开奖,计算出下一次开奖时间
- int week_t = week.TryToInt32();
- for (int i = 0; i < 7; i++)
- {
- week_t++;
- week_t = week_t.TryToInt32() <= 6 ? week_t.TryToInt32() : 0;
- int index = Array.IndexOf(openThePrizeOnTheDayOfTheWeek, week_t.ToString());
- if (index >= 0)
- {
- //解决星期天的问题
- int week_n = openThePrizeOnTheDayOfTheWeek[index].TryToInt32() == 0 ? 7 : openThePrizeOnTheDayOfTheWeek[index].TryToInt32();
- int days = Math.Abs(week_n - week.TryToInt32());
- nextOpenTime = todayRealStartOpentime.AddDays(days);
- break;
- }
- }
- }
- return nextOpenTime.AddMinutes(1);
- }
- /// <summary>
- /// 组装开奖详情
- /// </summary>
- /// <param name="data">最新一期开奖详情</param>
- /// <param name="type">彩票类型</param>
- /// <param name="typeCode">类型码</param>
- /// <returns></returns>
- private HomeLotteryListViewEntity GetOpenCodeRealDataItem(DataTable data, SCCLottery type, string typeCode)
- {
- //枚举码
- string enumCode = type.ToString();
- List<LotteryBallItem> ballItems = new List<LotteryBallItem>();
- //有特殊球的情况下
- if (LotteryBallTypeDict.ContainsKey(enumCode))
- {
- GetOpenCodeValue(data.Rows[0], enumCode, out ballItems);
- }
- else
- {
- //总共球个数
- int total = type.GetEnumText().TryToInt32();
- #region 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
- List<int> ballList = new List<int>();
- for (int i = 1; i <= total; i++)
- {
- var OpenCode = data.Rows[0]["OpenCode" + i].TryToInt32();
- ballList.Add(OpenCode);
- }
- //取出当前最大开奖号
- //TODO 此做法欠妥,如果当前彩种开奖号取值在0-20之间,有可能某一期开奖号全部都小于10
- int max = ballList.Max();
- //是否需要添加0
- bool hasAppendZero = (type != SCCLottery.ShanDongKLPK3 && max >= 10) || type == SCCLottery.GuangDongHC1;
- #endregion 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
- for (int i = 1; i <= total; i++)
- {
- int openCode = ballList[i - 1];//data.Rows[0]["OpenCode" + i].TryToInt32();
- ballItems.Add(new LotteryBallItem
- {
- //山东快乐扑克3为特殊球
- BallType = type == SCCLottery.ShanDongKLPK3 ? LotteryBallType.Poker : LotteryBallType.Normal,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- //获取当前彩种配置信息
- SCCConfig config = LotteryConfig.FirstOrDefault(s => s.EnumCode.Equals(enumCode));
- //当前最新一期已经开奖时间
- DateTime currentOpenTime = data.Rows[0]["OpenTime"].TryToDateTime();
- //期数
- string term = data.Rows[0]["Term"].ToStringEx();
- //开奖详情
- string spare = data.Rows[0]["Spare"].ToString().Trim();
- //当前时间
- DateTime nowTime = DateTimeHelper.Now;
- if (config != null)
- {
- //当前彩种每周开奖时间
- string[] openThePrizeOnTheDayOfTheWeek = config.KJTime.Split(",".ToCharArray());
- //下一次开奖时间
- DateTime nextOpenTime = GetNextOpenTime(config, currentOpenTime, openThePrizeOnTheDayOfTheWeek, nowTime);
- //彩种名称
- string lotteryName = string.IsNullOrEmpty(config.LotteryName) ? type.GetEnumDescription() : config.LotteryName;
- //组装三要素,描述
- string keywords, desc;
- #region 从配置文件里面获取三要素(暂时弃用)
- ////组装三要素
- //string keywords = string.Format(ConfigHelper.GetValue("LotteryDetailElementsKeywords"), lotteryName, term);
- ////组装描述
- //string desc = string.Format(ConfigHelper.GetValue("LotteryDetailElementsDescription"), lotteryName, config.KJRate, lotteryName);
- #endregion 从配置文件里面获取三要素(暂时弃用)
- #region 从数据库获取三要素
- List<SystemTdkViewEntity> tdkData = GetTDKData();
- //Key
- string key = "LotteryTDK_" + enumCode;
- SystemTdkViewEntity tdk = tdkData.FirstOrDefault(t => t.LotteryCode.Equals(key));
- if (tdk != null)
- {
- desc = tdk.Desc;
- keywords = tdk.Title;
- }
- else
- {
- keywords = string.Format(ConfigHelper.GetValue("LotteryDetailElementsKeywords"), lotteryName, term);
- desc = string.Format(ConfigHelper.GetValue("LotteryDetailElementsDescription"), lotteryName, config.KJRate, lotteryName);
- }
- #endregion 从数据库获取三要素
- //组装最终结果
- HomeLotteryListViewEntity res = new HomeLotteryListViewEntity
- {
- TypeCode = typeCode,
- CurrentTerm = term,
- EnumCode = enumCode,
- Cid=GetCid(enumCode),
- CurrentOpenTime = currentOpenTime.ToString("yyyy-MM-dd HH:mm"),
- ServerTime = nowTime.ToString("yyyy-MM-dd HH:mm:ss"),
- NextOpenTime = nextOpenTime.ToString("yyyy-MM-dd HH:mm"),
- //CurrentTotalTerm = config.TimesPerDay,
- LotteryName = lotteryName,
- LotteryBallItems = ballItems,
- //Interval = config.Interval,
- KJRate = config.KJRate,
- //OpenThePrizeOnTheDayOfTheWeek = openThePrizeOnTheDayOfTheWeek,
- //StartThePrizeTimeEveryDay = config.StartHour.RepairZero() + ":" + config.StartMinute.RepairZero(),
- Keywords = keywords,
- Desc = desc,
- Spare = spare
- };
- return res;
- }
- else
- {
- //TODO 容错处理,仅返回开奖号、开奖时间
- //彩种名称
- string lotteryName = type.GetEnumDescription();
- //组装三要素
- string keywords = string.Format(ConfigHelper.GetValue("LotteryDetailElementsKeywords"), lotteryName, term);
- //组装描述
- string desc = string.Format(ConfigHelper.GetValue("LotteryDetailElementsDescription"), lotteryName, "", lotteryName);
- //组装最终结果
- HomeLotteryListViewEntity res = new HomeLotteryListViewEntity
- {
- TypeCode = typeCode,
- CurrentTerm = term,
- EnumCode = enumCode,
- CurrentOpenTime = currentOpenTime.ToString("yyyy-MM-dd HH:mm"),
- ServerTime = nowTime.ToString("yyyy-MM-dd HH:mm:ss"),
- NextOpenTime = nowTime.ToString("yyyy-MM-dd HH:mm"),
- //CurrentTotalTerm = 1,
- LotteryName = lotteryName,
- LotteryBallItems = ballItems,
- //Interval = 1,
- KJRate = "",
- //OpenThePrizeOnTheDayOfTheWeek = new[] { "" },
- //StartThePrizeTimeEveryDay = "",
- Keywords = keywords,
- Desc = desc,
- Spare = spare
- };
- return res;
- }
- }
- /// <summary>
- /// 组装最终数据
- /// </summary>
- /// <param name="dictionary">彩票类型码-枚举码</param>
- /// <returns></returns>
- private List<HomeLotteryListViewEntity> GetRealData(Dictionary<string, SCCLottery> dictionary)
- {
- List<HomeLotteryListViewEntity> res = new List<HomeLotteryListViewEntity>();
- foreach (KeyValuePair<string, SCCLottery> pair in dictionary)
- {
- string typeCode = pair.Key;
- SCCLottery lottery = pair.Value;
- //组装查询语句
- string sql = GetSeleteSQL(lottery);
- //查询结果
- DataTable o = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
- if (o.Rows.Count > 0)
- {
- //Trace.WriteLine(o.Rows[0].ItemArray);
- if (int.Parse(o.Rows[0]["OpenCode1"].ToString()) == -1)
- {
- sql = GetSeleteSQL(lottery,true);
- o = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
- }
- res.Add(GetOpenCodeRealDataItem(o, lottery, typeCode));
- }
- }
- return res;
- }
- /// <summary>
- /// 获取类型码-枚举码字典
- /// </summary>
- /// <param name="model">系统字典集合</param>
- /// <param name="TypeCode"></param>
- /// <returns></returns>
- private Dictionary<string, SCCLottery> GetTypeCodeAndEnumCodeDict(List<DataItemModel> model, bool IsRecommend = false, bool IsShowHomePage = false, bool IsHot = false, string TypeCode = "")
- {
- string key = IsRecommend ? "__IsRecommend___" : IsShowHomePage ? "__IsShowHomePage__" : IsHot ? "__IsHot__" : "__Public__";
- if (!string.IsNullOrEmpty(TypeCode))
- key += TypeCode + "__";
- //类型码-枚举
- //Dictionary<string, SCCLottery> dictionary = Cache.Factory.CacheFactory.Cache().GetCache<Dictionary<string, SCCLottery>>(CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key);
- Dictionary<string, SCCLottery> dictionary = webCache.GetObject<Dictionary<string, SCCLottery>>(CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key);
- if (dictionary == null || dictionary.Count == 0)
- {
- dictionary = new Dictionary<string, SCCLottery>();
- //枚举码
- List<string> enumCode = new List<string>();
- //类型码
- List<string> typeCode = new List<string>();
- //筛选推荐
- if (IsRecommend)
- {
- enumCode = model.Where(d => d.IsRecommend).Select(d => d.SimpleSpelling).ToList();
- typeCode = model.Where(d => d.IsRecommend).Select(d => d.ItemValue).ToList();
- }
- //筛选二级首页显示彩种
- if (IsShowHomePage)
- {
- enumCode = model.Where(d => d.IsShowHomePage).Select(d => d.SimpleSpelling).ToList();
- typeCode = model.Where(d => d.IsShowHomePage).Select(d => d.ItemValue).ToList();
- }
- //筛选热门
- if (IsHot)
- {
- enumCode = model.Where(d => d.IsHot).Select(d => d.SimpleSpelling).ToList();
- typeCode = model.Where(d => d.IsHot).Select(d => d.ItemValue).ToList();
- }
- //枚举列表
- List<SCCLottery> lotteryType = enumCode.Select(s => (SCCLottery)Enum.Parse(typeof(SCCLottery), s, true)).ToList();
- for (int i = 0; i < typeCode.Count; i++)
- {
- if (!dictionary.ContainsKey(typeCode[i]))
- {
- dictionary.Add(typeCode[i], lotteryType[i]);
- }
- }
- //Cache.Factory.CacheFactory.Cache().WriteCache(dictionary, CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key, DateTimeHelper.Now.AddDays(30));
- webCache.AddObject(CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key, dictionary, (int)CacheTime.Data);
- }
- return dictionary;
- }
- #endregion 获取首页展示详细开奖信息的彩种
- #region 根据彩票枚举码获取最新一期开奖详情
- /// <summary>
- /// 根据彩票枚举码获取最新一期开奖详情
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetTheLatestAwardByEnumCode(TheLatestAwardArgEntity arg)
- {
- BaseJson<HomeLotteryListViewEntity> resultMsg = new BaseJson<HomeLotteryListViewEntity> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "根据彩票枚举码获取最新一期开奖详情-GetTheLatestAwardByEnumCode", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- //通过枚举码查询
- if (!string.IsNullOrEmpty(arg.EnumCode))
- {
- bool isSucc = Enum.TryParse<SCCLottery>(arg.EnumCode, true, out SCCLottery type);
- //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
- if (!isSucc)
- {
- resultMsg = new BaseJson<HomeLotteryListViewEntity>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = $"参数值{arg.EnumCode}无效。",
- BackUrl = null
- };
- }
- else
- {
- //查询SQL
- string sql = !string.IsNullOrEmpty(arg.Term) ? GetSeleteSQL(type, arg.Term) : GetSeleteSQL(type);
- //查询结果
- DataTable o = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
- if (o.Rows.Count > 0)
- {
- HomeLotteryListViewEntity entity = GetOpenCodeRealDataItem(o, type, "");
- resultMsg = new BaseJson<HomeLotteryListViewEntity>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = entity,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<HomeLotteryListViewEntity>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = null,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- }
- }
- else
- {
- resultMsg = new BaseJson<HomeLotteryListViewEntity>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数EnumCode为空。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<HomeLotteryListViewEntity>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<HomeLotteryListViewEntity>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<HomeLotteryListViewEntity>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- #endregion 根据彩票枚举码获取最新一期开奖详情
- #region 获取开机号、试机号
- /// <summary>
- /// 获取开机号、试机号
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetLotteryKJHAndSJH(LotteryKJHAndSJHArgEntity arg)
- {
- BaseJson<List<LotteryKJHAndSJHViewEntity>> resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取开机号、试机号-GetLotteryKJHAndSJH", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- //TODO 加上缓存
- List<LotteryKJHAndSJHViewEntity> list = new List<LotteryKJHAndSJHViewEntity>();
- string[] enumArr = arg.EnumCode.Split("|".ToCharArray());
- foreach (string s in enumArr)
- {
- bool isSucc = Enum.TryParse<SCCLottery>(s, true, out SCCLottery type);
- //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
- if (!isSucc) continue;
- //组装查询语句
- string sql = GetSeleteSQL(type, arg);
- //查询结果
- DataTable data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
- if (data.Rows.Count > 0)
- {
- for (int i = 0; i < data.Rows.Count; i++)
- {
- LotteryKJHAndSJHViewEntity res = new LotteryKJHAndSJHViewEntity
- {
- EnumCode = s,
- Term = data.Rows[i]["Term"].ToStringEx(),
- Addtime = data.Rows[i]["OpenTime"].TryToDateTimeToString("yyyy-MM-dd"),
- KjhAndSjhItems = GetKjhAndSjhItems(data.Rows[i], type)
- };
- list.Add(res);
- }
- }
- }
- list = list.OrderByDescending(l => l.Term).ToList();
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = list,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- /// <summary>
- /// 查询开机号、试机号
- /// </summary>
- /// <param name="arg"></param>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage QueryLotteryKJHAndSJH(QueryLotteryKJHAndSJHArgEntity arg)
- {
- BaseJson<List<LotteryKJHAndSJHViewEntity>> resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "查询开机号、试机号-QueryLotteryKJHAndSJH", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- //TODO 加上缓存
- List<LotteryKJHAndSJHViewEntity> list = new List<LotteryKJHAndSJHViewEntity>();
- bool isSucc = Enum.TryParse<SCCLottery>(arg.EnumCode, true, out SCCLottery type);
- //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
- if (!isSucc)
- {
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = $"参数值{arg.EnumCode}无效。",
- BackUrl = null
- };
- }
- else
- {
- //组装查询语句
- string sql = GetSeleteSQL(type, arg);
- //查询结果
- DataTable data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
- if (data.Rows.Count > 0)
- {
- for (int i = 0; i < data.Rows.Count; i++)
- {
- LotteryKJHAndSJHViewEntity res = new LotteryKJHAndSJHViewEntity
- {
- Term = data.Rows[i]["Term"].ToStringEx(),
- Addtime = data.Rows[i]["Addtime"].ToStringEx(),
- KjhAndSjhItems = GetKjhAndSjhItems(data.Rows[i], type)
- };
- list.Add(res);
- }
- }
- list = list.OrderByDescending(l => l.Term).ToList();
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = list,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- private List<LotteryBallItem> AppendKJHAndSJHBall(string sjh, SCCLottery enumCode)
- {
- List<LotteryBallItem> res = new List<LotteryBallItem>();
- string[] sjhArr = sjh.Split(",".ToCharArray());
- #region 是否需要添加0的彩种
- //是否需要添加0
- bool hasAppendZero = enumCode == SCCLottery.SSQ || enumCode == SCCLottery.DLT;
- #endregion 是否需要添加0的彩种
- //有特殊球的情况下
- if (LotteryBallTypeDict.ContainsKey(enumCode.ToString()))
- {
- int[] codeArr = LotteryBallTypeDict[enumCode.ToString()];
- //正常球个数
- int normal = codeArr[0];
- //蓝球个数
- int blue = codeArr[1];
- #region 正常球
- if (normal > 0)
- {
- for (int i = 1; i <= normal; i++)
- {
- int openCode = sjhArr[i - 1].TryToInt32();
- res.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Normal,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- #endregion 正常球
- #region 蓝球
- if (blue > 0)
- {
- for (int i = blue; i >= 1; i--)
- {
- int openCode = sjhArr[normal + i - 1].TryToInt32();
- res.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Blue,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- #endregion 蓝球
- }
- else
- {
- //总共球个数
- int total = enumCode.GetEnumText().TryToInt32();
- for (int i = 1; i <= total; i++)
- {
- int openCode = sjhArr[i - 1].TryToInt32();
- res.Add(new LotteryBallItem
- {
- BallType = LotteryBallType.Normal,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- return res;
- }
- private List<KJHAndSJHItem> GetKjhAndSjhItems(DataRow data, SCCLottery type)
- {
- List<KJHAndSJHItem> res = new List<KJHAndSJHItem>();
- string sjh = data["ShiJiHao"].ToString();
- string kjh = data["KaiJiHao"].ToString();
- //开机号
- if (!string.IsNullOrEmpty(kjh) && !kjh.Contains("-1"))
- {
- //15 17 20 24 27 33 + 11
- if (kjh.Contains("+"))
- {
- kjh = kjh.Trim().Replace(" + ", ",").Replace(" ", ",");
- }
- string[] sjhArr = kjh.Split(",".ToCharArray());
- List<int> code = sjhArr.Select(s => s.TryToInt32()).ToList();
- KJHAndSJHItem item = new KJHAndSJHItem
- {
- Which = 1,
- TypeName = "开机号",
- LotteryBallItems = AppendKJHAndSJHBall(kjh, type),
- SizeRatio = LotteryUtils.GetProportionOfDX(code, GetSizeRatioSplitNumber(type)),
- ParityRatio = LotteryUtils.GetProportionOfJO(code),
- SumValue = LotteryUtils.GetSum(code, GetSumNumberCount(type)).ToString()
- };
- res.Add(item);
- }
- //试机号
- if (!string.IsNullOrEmpty(sjh) && !sjh.Contains("-1"))
- {
- if (sjh.Contains("+"))
- {
- sjh = sjh.Trim().Replace(" + ", ",").Replace(" ", ",");
- }
- string[] sjhArr = sjh.Split(",".ToCharArray());
- List<int> code = sjhArr.Select(s => s.TryToInt32()).ToList();
- KJHAndSJHItem item = new KJHAndSJHItem
- {
- Which = 2,
- TypeName = "试机号",
- LotteryBallItems = AppendKJHAndSJHBall(sjh, type),
- SizeRatio = LotteryUtils.GetProportionOfDX(code, GetSizeRatioSplitNumber(type)),
- ParityRatio = LotteryUtils.GetProportionOfJO(code),
- SumValue = LotteryUtils.GetSum(code, GetSumNumberCount(type)).ToString()
- };
- res.Add(item);
- }
- //开奖号
- res.Add(GetOpenCode(data, type));
- return res;
- }
- private KJHAndSJHItem GetOpenCode(DataRow data, SCCLottery type)
- {
- //枚举码
- string enumCode = type.ToString();
- List<LotteryBallItem> ballItems = new List<LotteryBallItem>();
- //总共球个数
- int total = type.GetEnumText().TryToInt32();
- //有特殊球的情况下
- if (LotteryBallTypeDict.ContainsKey(enumCode))
- {
- GetOpenCodeValue(data, enumCode, out ballItems);
- }
- else
- {
- #region 是否需要添加0的彩种
- //是否需要添加0
- bool hasAppendZero = type == SCCLottery.SSQ || type == SCCLottery.DLT;
- #endregion 是否需要添加0的彩种
- for (int i = 1; i <= total; i++)
- {
- int openCode = data["OpenCode" + i].TryToInt32();
- ballItems.Add(new LotteryBallItem
- {
- //山东快乐扑克3为特殊球
- BallType = type == SCCLottery.ShanDongKLPK3 ? LotteryBallType.Poker : LotteryBallType.Normal,
- OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
- });
- }
- }
- List<int> openCodeList = new List<int>();
- for (int i = 1; i <= total; i++)
- {
- int openCode = data["OpenCode" + i].TryToInt32();
- openCodeList.Add(openCode);
- }
- KJHAndSJHItem itemOpencode = new KJHAndSJHItem
- {
- Which = 3,
- TypeName = "开奖号",
- LotteryBallItems = ballItems,
- SizeRatio = LotteryUtils.GetProportionOfDX(openCodeList, GetSizeRatioSplitNumber(type)),
- ParityRatio = LotteryUtils.GetProportionOfJO(openCodeList),
- SumValue = LotteryUtils.GetSum(openCodeList, GetSumNumberCount(type)).ToString()
- };
- return itemOpencode;
- }
- #endregion 获取开机号、试机号
- /// <summary>
- /// 获取彩种id
- /// </summary>
- /// <param name="EnumCode"></param>
- /// <returns></returns>
- private int GetCid(string EnumCode)
- {
- Enum.TryParse<SCCLottery>(EnumCode, true, out SCCLottery type);
- var Cid = type.GetCid();
- return Cid;
- }
- #region 首页获取各分类的推荐彩种以及开奖信息
- /// <summary>
- /// 获取各分类的推荐彩种以及开奖信息
- /// </summary>
- /// <param name="arg"></param>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetRecommendLotteryAndAwardInformation(BaseParameterEntity arg)
- {
- BaseJson<List<LotteryRecommendViewEntity>> resultMsg = new BaseJson<List<LotteryRecommendViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取各分类的推荐彩种以及开奖信息-GetRecommendLotteryAndAwardInformation", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- var Lottery = new List<LotteryRecommendViewEntity>();
- //var Lottery = Cache.Factory.CacheFactory.Cache().GetCache<List<LotteryRecommendViewEntity>>("__RecommendLottery");
- //if (Lottery == null)
- //{
- string codeList = GetCodeList();
- //获取所有推荐的彩种
- List<DataItemModel> LotteryList = dataItemCache.GetDataItemList().Where(o => o.IsRecommend).OrderBy(d => d.SortCode ?? 0).ToList();
- //获取类型码-枚举码字典
- Dictionary<string, SCCLottery> dictionary = GetTypeCodeAndEnumCodeDict(LotteryList, false, true, false, "");
- //结果集合
- List<HomeLotteryListViewEntity> res = GetRealData(dictionary);
- //获取所有推荐彩种以及对应的信息 开奖号,期数,奖池
- List<LotteryItem> cache = res.Select(o =>
- new LotteryItem
- {
- TypeName = o.TypeCode.Substring(0, 3),
- Name = o.LotteryName,
- Cid = GetCid(o.EnumCode),
- EnumCode = o.EnumCode,
- PeriodsNum = o.CurrentTerm,
- Date = o.CurrentOpenTime,
- Spare = o.Spare,
- LotteryBallItems = o.LotteryBallItems
- }
- ).ToList();
- ///彩种分类后的信息
- Lottery = cache.GroupBy(o => o.TypeName).Select(o => new LotteryRecommendViewEntity
- {
- LotteryType = o.Key,
- LotteryItems = o.ToList().Count() < 7 ? o.ToList() : o.Take(6).ToList(),
- }).ToList();
- // Cache.Factory.CacheFactory.Cache().WriteCache<List<LotteryRecommendViewEntity>>(Lottery, "__RecommendLottery", DateTime.Now.AddMinutes(10));
- //}
- resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = Lottery,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- #endregion
- #region 获取最新一期的开机号、试机号(双色球、排列三、大乐透、福彩3D)
- /// <summary>
- /// 获取开机号、试机号(双色球、排列三、大乐透,福彩3D)
- /// TotalRecord若为空则查询最近一期的数据,若有就查询多少条
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetThisLotteryKJHAndSJH(LotteryKJHAndSJHArgEntity arg)
- {
- BaseJson<List<KJH_SJHItem>> resultMsg = new BaseJson<List<KJH_SJHItem>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Logger(typeof(LotteryNumberController), arg.TryToJson(), " 获取开机号、试机号(双色球、排列三、大乐透、福彩3D)-GetThisLotteryKJHAndSJH", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- //因为只需要最近一期的试机号开奖号,所以给默认赋值1
- arg.TotalRecord = arg.TotalRecord == 0 ? 1 : arg.TotalRecord;
- List<KJH_SJHItem> list = new List<KJH_SJHItem>();
- string[] enumArr = { SCCLottery.SSQ.ToString(), SCCLottery.PL3.ToString(), SCCLottery.DLT.ToString(), SCCLottery.FC3D.ToString() };
- foreach (string s in enumArr)
- {
- bool isSucc = Enum.TryParse<SCCLottery>(s, true, out SCCLottery type);
- if (!isSucc) continue;
- //组装查询语句
- string sql = GetSeleteSQL(type, arg);
- //查询结果
- DataTable data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
- if (data.Rows.Count > 0)
- {
- for (int i = 0; i < data.Rows.Count; i++)
- {
- var Term = data.Rows[i]["Term"].ToStringEx();
- var kjh_sjh = GetKjhAndSjhItems(data.Rows[i], type).Where(o => o.Which != 3);
- foreach (var kjhitem in kjh_sjh)
- {
- KJH_SJHItem item = new KJH_SJHItem();
- item.LotteryBallItems = kjhitem.LotteryBallItems;
- item.Which = kjhitem.Which;
- item.Term = Term;
- item.
-
- EnumCode = s;
- item.LotteryName = type.GetEnumDescription();
- list.Add(item);
- }
- }
- }
- }
- list = list.OrderByDescending(l => l.Term).ToList();
- resultMsg = new BaseJson<List<KJH_SJHItem>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = list,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<List<KJH_SJHItem>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<KJH_SJHItem>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<KJH_SJHItem>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- #endregion
- #region 获取最新一期地方彩的开奖信息
- /// <summary>
- /// 获取地方彩今日开奖信息
- /// </summary>
- /// <param name="arg"></param>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetDFCLotteryAwardInfo(BaseParameterEntity arg)
- {
- BaseJson<List<TodaysLotteryViewEntity>> resultMsg = new BaseJson<List<TodaysLotteryViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取最新一期地方彩的开奖信息-GetDFCLotteryAwardInfo", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- // var Lottery = Cache.Factory.CacheFactory.Cache().GetCache<List<TodaysLotteryViewEntity>>("__DFCRecommendLottery");
- var Lottery = webCache.GetObject<List<TodaysLotteryViewEntity>>("__DFCRecommendLottery");
-
- if (Lottery == null)
- {
- Dictionary<string, SCCConfig> dict = GetTodayLotteryDict();
- List<TodaysLotteryViewEntity> obj = new List<TodaysLotteryViewEntity>();
- foreach (KeyValuePair<string, SCCConfig> pair in dict)
- {
- SCCConfig config = pair.Value;
- SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), config.EnumCode, true);
- //当前彩种今天真实开始开奖时间
- DateTime todayRealStartOpentime = (DateTimeHelper.Now.ToString("yyyy-MM-dd") + " " + config.StartHour + ":" + config.StartMinute).TryToDateTime();
- ////如果当前时间大于当前彩种今天真实开始开奖时间,则忽略
- //if (DateTimeHelper.Now < todayRealStartOpentime)
- //{
- string lastTerm = qgfc3Dbll.GetNewTermByTableName(type.GetSCCLotteryTableName());
- obj.Add(new TodaysLotteryViewEntity
- {
- KJRate = config.KJRate,
- LotteryName = config.LotteryName,
- CurrentTerm = lastTerm,
- OpenTime = todayRealStartOpentime,
- MainUrl = config.MainUrl,
- EnumCode = config.EnumCode,
- Cid = GetCid(config.EnumCode),
- });
- //}
- }
- Lottery = obj.OrderBy(o => o.OpenTime).ToList();
- //Cache.Factory.CacheFactory.Cache().WriteCache<List<TodaysLotteryViewEntity>>(Lottery, "__DFCRecommendLottery", DateTime.Now.AddHours(1));
- webCache.AddObject("__DFCRecommendLottery", Lottery, (int)CacheTime.Data);
- }
- resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = Lottery,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- /// <summary>
- /// 获取今日开奖彩种
- /// </summary>
- /// <returns></returns>
- private static Dictionary<string, SCCConfig> GetTodayLotteryDict()
- {
- Dictionary<string, SCCConfig> dictionary = new Dictionary<string, SCCConfig>();
- //当前时间
- DateTime now = DateTimeHelper.Now;
- //今天是星期几
- string week = now.DayOfWeek.ToString("d");
- //获取当前彩种配置信息(全国彩和地方彩) || s.Name.Contains("QGC_")
- List<SCCConfig> configList = LotteryConfig.Where(s => s.Name.Contains("DFC_")).OrderBy(s => s.LotteryName.Length).ToList();
- foreach (SCCConfig config in configList)
- {
- //当前彩种每周开奖时间
- string[] openThePrizeOnTheDayOfTheWeek = config.KJTime.Split(",".ToCharArray());
- //今天星期在数组中的索引
- int pointer = Array.IndexOf(openThePrizeOnTheDayOfTheWeek, week.ToString());
- if (pointer != -1)//今天要开奖
- {
- if (!dictionary.ContainsKey(config.EnumCode))
- {
- dictionary.Add(config.EnumCode, config);
- }
- }
- }
- return dictionary;
- }
- #endregion
- #region 首页新闻滚动展示
- /// <summary>
- /// 首页新闻滚动展示内容
- /// </summary>
- /// <param name="arg"></param>
- /// <returns></returns>
- [HttpPost]
- public HttpResponseMessage GetNewsInfo(BannerParameterArgEntity arg)
- {
- BaseJson<List<BannerEntity>> resultMsg = new BaseJson<List<BannerEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
- Logger(typeof(LotteryNumberController), arg.TryToJson(), "首页新闻滚动展示-GetNewsInfo", () =>
- {
- if (!string.IsNullOrEmpty(arg.t))
- {
- if (arg.t.CheckTimeStamp())
- {
- //var Lottery = Cache.Factory.CacheFactory.Cache().GetCache<List<BannerEntity>>("__NewsInfo");
- var Lottery = webCache.GetObject<List<BannerEntity>>("__NewsInfo");
- if (Lottery == null)
- {
- Lottery = bannerBLL.GetList("").ToList().Take(arg.TotolCount).Select(o => new BannerEntity { Id = o.Id, Title = o.Title, ImageUrl = o.ImageUrl, Content = o.Content }).ToList();
- //Cache.Factory.CacheFactory.Cache().WriteCache<List<BannerEntity>>(Lottery, "__NewsInfo", DateTime.Now.AddHours(1));
- webCache.AddObject("__NewsInfo", Lottery, (int)CacheTime.Data);
- }
- resultMsg = new BaseJson<List<BannerEntity>>
- {
- Status = (int)JsonObjectStatus.Success,
- Data = Lottery,
- Message = JsonObjectStatus.Success.GetEnumText(),
- BackUrl = null
- };
- }
- else
- {
- resultMsg = new BaseJson<List<BannerEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
- BackUrl = null
- };
- }
- }
- else
- {
- resultMsg = new BaseJson<List<BannerEntity>>
- {
- Status = (int)JsonObjectStatus.Fail,
- Data = null,
- Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
- BackUrl = null
- };
- }
- }, e =>
- {
- resultMsg = new BaseJson<List<BannerEntity>>
- {
- Status = (int)JsonObjectStatus.Exception,
- Data = null,
- Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
- BackUrl = null
- };
- });
- return resultMsg.TryToJson().ToHttpResponseMessage();
- }
- #endregion
- #region 公共私有方法
- /// <summary>
- /// 组装查询语句
- /// </summary>
- /// <param name="type">枚举码</param>
- /// <returns></returns>
- private string GetSeleteSQL(SCCLottery type)
- {
- //string res = Cache.Factory.CacheFactory.Cache().GetCache<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
- string res=webCache.GetObject<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
- if (string.IsNullOrEmpty(res))
- {
- StringBuilder builder = new StringBuilder();
- int total = type.GetEnumText().TryToInt32();
- string tableName = type.GetSCCLotteryTableName();
- for (int i = 1; i <= total; i++)
- {
- builder.Append("[OpenCode" + i + "],");
- }
- res = string.Format(GetLotterySqlByTableName, StringHelper.DelLastChar(builder.ToString(), ","), tableName);
- //存入缓存
- //Cache.Factory.CacheFactory.Cache().WriteCache(res, CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), DateTimeHelper.Now.AddDays(30));
- webCache.AddObject(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), res, (int)CacheTime.Data);
- }
- return res;
- }
- /// <summary>
- /// 若是开奖号为-1的情况
- /// </summary>
- /// <param name="type"></param>
- /// <param name="again"></param>
- /// <returns></returns>
- private string GetSeleteSQL(SCCLottery type,bool again)
- {
- // string res = Cache.Factory.CacheFactory.Cache().GetCache<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
- string res = webCache.GetObject<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
- if (string.IsNullOrEmpty(res))
- {
- StringBuilder builder = new StringBuilder();
- int total = type.GetEnumText().TryToInt32();
- string tableName = type.GetSCCLotteryTableName();
- for (int i = 1; i <= total; i++)
- {
- builder.Append("[OpenCode" + i + "],");
- }
- res = string.Format(GetLotterySqlAgainByTableName, StringHelper.DelLastChar(builder.ToString(), ","), tableName);
- //存入缓存
- //Cache.Factory.CacheFactory.Cache().WriteCache(res, CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), DateTimeHelper.Now.AddDays(30));
- webCache.AddObject(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), res, (int)CacheTime.Data);
- }
- return res;
- }
- /// <summary>
- /// 组装查询语句
- /// </summary>
- /// <param name="type">枚举码</param>
- /// <param name="term">期数</param>
- /// <returns></returns>
- private string GetSeleteSQL(SCCLottery type, string term)
- {
- StringBuilder builder = new StringBuilder();
- int total = type.GetEnumText().TryToInt32();
- string tableName = type.GetSCCLotteryTableName();
- for (int i = 1; i <= total; i++)
- {
- builder.Append("[OpenCode" + i + "],");
- }
- string res = string.Format(GetLotterySqlByTerm, StringHelper.DelLastChar(builder.ToString(), ","), tableName, term);
- return res;
- }
- /// <summary>
- /// 组装查询语句
- /// </summary>
- /// <param name="type">枚举码</param>
- /// <param name="arg"></param>
- /// <returns></returns>
- private string GetSeleteSQL(SCCLottery type, LotteryKJHAndSJHArgEntity arg)
- {
- string res = String.Empty;
- string tableName = type.GetSCCLotteryTableName();
- StringBuilder builder = new StringBuilder();
- int total = type.GetEnumText().TryToInt32();
- for (int i = 1; i <= total; i++)
- {
- builder.Append("[OpenCode" + i + "],");
- }
- if (arg.TotalRecord > 0)
- {
- if (!string.IsNullOrEmpty(arg.StartTime))
- {
- string time = arg.StartTime.CheckDateTime()
- ? arg.StartTime
- : DateTimeHelper.Now.AddDays(-7).ToString("yyyy-MM-dd");
- res = string.Format(GetLotterySqlByTableNameWithStartTimeAndTop, tableName, time, StringHelper.DelLastChar(builder.ToString(), ","), arg.TotalRecord);
- }
- else
- {
- res = string.Format(GetLotterySqlByTableNameWithTop, arg.TotalRecord, tableName, StringHelper.DelLastChar(builder.ToString(), ","));
- }
- }
- else if (!string.IsNullOrEmpty(arg.StartTime))
- {
- string time = arg.StartTime.CheckDateTime()
- ? arg.StartTime
- : DateTimeHelper.Now.AddDays(-7).ToString("yyyy-MM-dd");
- res = string.Format(GetLotterySqlByTableNameWithStartTime, tableName, time, StringHelper.DelLastChar(builder.ToString(), ","));
- }
- else
- {
- res = string.Format(GetLotterySqlByTableNameWithTop, "20", tableName, StringHelper.DelLastChar(builder.ToString(), ","));
- }
- return res;
- }
- /// <summary>
- /// 组装查询语句
- /// </summary>
- /// <param name="type">枚举码</param>
- /// <param name="arg"></param>
- /// <returns></returns>
- private string GetSeleteSQL(SCCLottery type, QueryLotteryKJHAndSJHArgEntity arg)
- {
- string res = String.Empty;
- string sql = "SELECT {3} [ID],[Term],[ShiJiHao],[KaiJiHao],[Addtime],{0} FROM [dbo].[{1}] WHERE [Term] = {2} ORDER BY Term DESC";
- string tableName = type.GetSCCLotteryTableName();
- StringBuilder builder = new StringBuilder();
- int total = type.GetEnumText().TryToInt32();
- for (int i = 1; i <= total; i++)
- {
- builder.Append("[OpenCode" + i + "],");
- }
- if (!string.IsNullOrEmpty(arg.Term))
- {
- res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, arg.Term, "");
- }
- else if (!string.IsNullOrEmpty(arg.Year))
- {
- int.TryParse(arg.Year, out int year);
- year = year == 0 ? DateTime.Now.Year : year <= DateTime.Now.Year ? year : DateTime.Now.Year;
- sql = "SELECT TOP {3} [ID],[Term],[ShiJiHao],[KaiJiHao],[Addtime],{0} FROM [dbo].[{1}] WHERE [OpenTime] LIKE '%{2}%' ORDER BY Term DESC";
- res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, year.ToString(), arg.TotalRecord == 0 ? 30 : arg.TotalRecord);
- }
- else if (!string.IsNullOrEmpty(arg.StartTerm) && !string.IsNullOrEmpty(arg.EndTerm))
- {
- long start = arg.StartTerm.TryToInt64();
- long end = arg.EndTerm.TryToInt64();
- sql = "SELECT [ID],[Term],[ShiJiHao],[KaiJiHao],[Addtime],{0} FROM [dbo].[{1}] WHERE Term BETWEEN {2} AND {3} ORDER BY Term DESC";
- if (start <= end)
- {
- //WHERE Term BETWEEN 2018064 AND 2018067
- res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, start, end);
- }
- else
- {
- res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, end, start);
- }
- }
- return res;
- }
- #endregion 公共私有方法
- #region SQL语句
- /// <summary>
- /// 通过表名查询数据为校验后的最新一条数据
- /// </summary>
- private static string GetLotterySqlByTableName = @"SELECT TOP 1 [ID],[Term],[OpenTime],[Spare],{0} FROM [dbo].[{1}] ORDER BY Term DESC ";//WHERE [IsChecked] = 1 AND [IsPassed] = 1
- /// <summary>
- /// 查询最新两天数据
- /// </summary>
- private static string GetLotterySqlAgainByTableName = @"SELECT TOP 2 [ID],[Term],[OpenTime],[Spare],{0} FROM [dbo].[{1}] ORDER BY Term DESC WHERE [OpenCode1] != -1";
- /// <summary>
- /// 通过开奖时间查询数据为校验后的所有数据
- /// </summary>
- private static string GetLotterySqlByTableNameWithStartTime = @"SELECT [ID],[Term],[ShiJiHao],[KaiJiHao],[OpenTime],{2} FROM [dbo].[{0}] WHERE DATEDIFF(DAY,'{1}',OpenTime) >= 0 ORDER BY Term DESC";
- /// <summary>
- /// 通过开奖时间查询数据为校验后的所有数据
- /// </summary>
- private static string GetLotterySqlByTableNameWithStartTimeAndTop = @"SELECT TOP {3} [ID],[Term],[ShiJiHao],[KaiJiHao],[OpenTime],{2} FROM [dbo].[{0}] WHERE DATEDIFF(DAY,'{1}',OpenTime) >= 0 ORDER BY Term DESC";
- /// <summary>
- /// 通过表名查询数据为校验后的前n行数据
- /// </summary>
- private static string GetLotterySqlByTableNameWithTop = @"SELECT TOP {0} [ID],[Term],[ShiJiHao],[KaiJiHao],[OpenTime],{2} FROM [dbo].[{1}] ORDER BY Term DESC ";
- /// <summary>
- /// 通过期数查询数据为校验后的一条数据
- /// </summary>
- private static string GetLotterySqlByTerm = @"SELECT [ID],[Term],[OpenTime],[Spare],{0} FROM [dbo].[{1}] WHERE [Term]='{2}'";//[IsChecked] = 1 AND [IsPassed] = 1 AND
- #endregion SQL语句
- }
- }
|