/// <summary> /// 获取前一天失败列表 /// 期号格式形如YYMMDDQQQ /// </summary> /// <param name="lottery">彩种名称</param> /// <param name="Terms">当前彩种当天期数列表</param> /// <returns></returns> public List <string> GetYesterdayFailQQQList(SCCLottery lottery, List <string> Terms) { List <string> result = new List <string>(); var TableName = EnumHelper.GetSCCLotteryTableName(lottery); var sqlString = string.Format(YesterdayListSql, TableName, CommonHelper.SCCSysDateTime.AddDays(-1).ToString("yyyyMMdd")); var ds = SqlHelper.ExecuteDataset(CommandType.Text, sqlString); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { var data = LoadDataList <OpenCode21Model>(ds.Tables[0]); OpenCode21Model item = null; foreach (var term in Terms) { item = data.Where(R => R.Term == Convert.ToInt64(term)).FirstOrDefault(); if (item == null) { result.Add(term); } } return(result); } else { return(Terms); } }
/// <summary> /// 新增彩种开奖数据 /// </summary> /// <param name="lottery">彩种名称</param> /// <param name="model">开奖数据模型</param> /// <returns></returns> public bool AddOpen21Code(SCCLottery lottery, OpenCode21Model model) { var TableName = EnumHelper.GetSCCLotteryTableName(lottery); var sqlString = string.Format(AddItemSql, TableName); var param = new SqlParameter[] { new SqlParameter("@Term", model.Term), new SqlParameter("@OpenCode1", model.OpenCode1), new SqlParameter("@OpenCode2", model.OpenCode2), new SqlParameter("@OpenCode3", model.OpenCode3), new SqlParameter("@OpenCode4", model.OpenCode4), new SqlParameter("@OpenCode5", model.OpenCode5), new SqlParameter("@OpenCode6", model.OpenCode6), new SqlParameter("@OpenCode7", model.OpenCode7), new SqlParameter("@OpenCode8", model.OpenCode8), new SqlParameter("@OpenCode9", model.OpenCode9), new SqlParameter("@OpenCode10", model.OpenCode10), new SqlParameter("@OpenCode11", model.OpenCode11), new SqlParameter("@OpenCode12", model.OpenCode12), new SqlParameter("@OpenCode13", model.OpenCode13), new SqlParameter("@OpenCode14", model.OpenCode14), new SqlParameter("@OpenCode15", model.OpenCode15), new SqlParameter("@OpenCode16", model.OpenCode16), new SqlParameter("@OpenCode17", model.OpenCode17), new SqlParameter("@OpenCode18", model.OpenCode18), new SqlParameter("@OpenCode19", model.OpenCode19), new SqlParameter("@OpenCode20", model.OpenCode20), new SqlParameter("@OpenCode21", model.OpenCode21), new SqlParameter("@OpenTime", model.OpenTime), new SqlParameter("@ID", Guid.NewGuid().ToString().Replace("-", "")) }; var result = SqlHelper.ExecuteNonQuery(CommandType.Text, sqlString, param); return(result > 0); }
/// <summary> /// 新增彩种开奖数据 /// </summary> /// <param name="lottery">彩种名称</param> /// <param name="model">开奖数据模型</param> /// <returns></returns> public bool AddOpen21Code(SCCLottery lottery, OpenCode21Model model) { var TableName = lottery.GetSCCLotteryTableName(); var sqlString = string.Format(AddItemSql, TableName); DbParameter[] param = new DbParameter[] { new SqlParameter("@Term", model.Term), new SqlParameter("@OpenCode1", model.OpenCode1), new SqlParameter("@OpenCode2", model.OpenCode2), new SqlParameter("@OpenCode3", model.OpenCode3), new SqlParameter("@OpenCode4", model.OpenCode4), new SqlParameter("@OpenCode5", model.OpenCode5), new SqlParameter("@OpenCode6", model.OpenCode6), new SqlParameter("@OpenCode7", model.OpenCode7), new SqlParameter("@OpenCode8", model.OpenCode8), new SqlParameter("@OpenCode9", model.OpenCode9), new SqlParameter("@OpenCode10", model.OpenCode10), new SqlParameter("@OpenCode11", model.OpenCode11), new SqlParameter("@OpenCode12", model.OpenCode12), new SqlParameter("@OpenCode13", model.OpenCode13), new SqlParameter("@OpenCode14", model.OpenCode14), new SqlParameter("@OpenCode15", model.OpenCode15), new SqlParameter("@OpenCode16", model.OpenCode16), new SqlParameter("@OpenCode17", model.OpenCode17), new SqlParameter("@OpenCode18", model.OpenCode18), new SqlParameter("@OpenCode19", model.OpenCode19), new SqlParameter("@OpenCode20", model.OpenCode20), new SqlParameter("@OpenCode21", model.OpenCode21), new SqlParameter("@OpenTime", model.OpenTime), new SqlParameter("@ID", Guid.NewGuid().ToString().Replace("-", "")) }; var result = this.BaseRepository(DatabaseLinksEnum.LotteryNumber).ExecuteBySql(sqlString, param); return(result > 0); }
/// <summary> /// 生成今日第一期记录 /// </summary> /// <returns></returns> private OpenCode21Model GenerateTodayFirstItem() { var item = new OpenCode21Model(); var currentDateTime = CommonHelper.SCCSysDateTime; var datepart = currentDateTime - new DateTime(2018, 1, 1); var t = Config.SkipDate.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); item.Term = (datepart.Days - t.Length) * Config.TimesPerDay + LastTermLastYear; //期号使用昨日最后一期期号,便于计算使用 item.OpenTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day, Config.StartHour, Config.StartMinute, 0); return(item); }
/// <summary> /// 从主要链接查询开奖号码 昨天/今天 /// </summary> /// <param name="IsToday"></param> /// <returns></returns> private List <OpenCode21Model> GetDocByMainUrl(bool IsToday = true) { var list = new List <OpenCode21Model>(); try { var time = DateTime.Now; var arg = new OpenCaiApiArg { code = EnumHelper.GetLotteryCode(SCCLottery.BeiJingKL8), date = time.ToString("yyyy-MM-dd") }; if (!IsToday) { arg.date = time.AddDays(-1).ToString("yyyy-MM-dd"); } var data = OpenCaiApiServices.GetOpenCaiApiData(arg); if (data == null) { return(list); } if (data.data != null) { if (data.data.Count == 0) { return(list); } for (var i = 0; i < data.data.Count; i++) { var tmp = new OpenCode21Model(); var codeAry = data.data[i].GetOpenCodeStr().Split(','); if (codeAry.Length == 21) { tmp.Term = long.Parse(data.data[i].expect); tmp.OpenTime = DateTime.Parse(data.data[i].opentime); tmp.OpenCode1 = int.Parse(codeAry[0]); tmp.OpenCode2 = int.Parse(codeAry[1]); tmp.OpenCode3 = int.Parse(codeAry[2]); tmp.OpenCode4 = int.Parse(codeAry[3]); tmp.OpenCode5 = int.Parse(codeAry[4]); tmp.OpenCode6 = int.Parse(codeAry[5]); tmp.OpenCode7 = int.Parse(codeAry[6]); tmp.OpenCode8 = int.Parse(codeAry[7]); tmp.OpenCode9 = int.Parse(codeAry[8]); tmp.OpenCode10 = int.Parse(codeAry[9]); tmp.OpenCode11 = int.Parse(codeAry[10]); tmp.OpenCode12 = int.Parse(codeAry[11]); tmp.OpenCode13 = int.Parse(codeAry[12]); tmp.OpenCode14 = int.Parse(codeAry[13]); tmp.OpenCode15 = int.Parse(codeAry[14]); tmp.OpenCode16 = int.Parse(codeAry[15]); tmp.OpenCode17 = int.Parse(codeAry[16]); tmp.OpenCode18 = int.Parse(codeAry[17]); tmp.OpenCode19 = int.Parse(codeAry[18]); tmp.OpenCode20 = int.Parse(codeAry[19]); tmp.OpenCode21 = int.Parse(codeAry[20]); } list.Add(tmp); } var checkDataHelper = new CheckDataHelper(); var dbdata = services.GetListIn(currentLottery, IsToday); if (dbdata == null) { return(list); } var DATA = dbdata.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()); checkDataHelper.CheckData(DATA, list.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()), Config.Area, currentLottery); } } catch (Exception ee) { log.Error(GetType(), string.Format("【{0}】通过主要站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ee.Message)); } return(list); }
/// <summary> /// 抓取备用站点开奖数据 /// 由于北京福彩官网分页30条数据一页,而此彩种每天开179期,如果去跑6页,负荷太大,只有通过主站点来保证数据完整性 /// </summary> /// <param name="url">备用站点</param> /// <returns></returns> private List <OpenCode21Model> GetOpenListFromBackUrl(string url, bool IsToday = true) { var result = new List <OpenCode21Model>(); try { var HtmlResource = string.Empty; HtmlResource = NetHelper.GetUrlResponse(url); if (HtmlResource == null) { return(result); } var doc = new HtmlDocument(); doc.LoadHtml(HtmlResource); var table = doc.DocumentNode.SelectNodes("//table"); if (table == null || table.Count < 2) { return(result); } var trs = table[1].ChildNodes.Where(R => R.Name.ToLower() == "tr").ToList(); if (trs.Count < 2) { return(result); } List <HtmlNode> tds = null; OpenCode21Model model = null; string[] openCodeList = null; var openTime = string.Empty; var todayDateString = CommonHelper.SCCSysDateTime.ToString("yyyy-MM-dd"); for (var i = 1; i < trs.Count; i++) //第一行是表头 { tds = trs[i].ChildNodes.Where(R => R.Name.ToLower() == "td").ToList(); if (tds.Count < 4) { continue; } openTime = tds[3].InnerText.Trim(); model = new OpenCode21Model(); model.Term = Convert.ToInt64(tds[0].InnerText.Trim()); model.OpenCode21 = Convert.ToInt32(tds[2].InnerText.Trim()); //飞盘 openCodeList = tds[1].InnerText.Trim().Split(','); if (openCodeList.Length < 20) { continue; } model.OpenCode1 = Convert.ToInt32(openCodeList[0]); model.OpenCode2 = Convert.ToInt32(openCodeList[1]); model.OpenCode3 = Convert.ToInt32(openCodeList[2]); model.OpenCode4 = Convert.ToInt32(openCodeList[3]); model.OpenCode5 = Convert.ToInt32(openCodeList[4]); model.OpenCode6 = Convert.ToInt32(openCodeList[5]); model.OpenCode7 = Convert.ToInt32(openCodeList[6]); model.OpenCode8 = Convert.ToInt32(openCodeList[7]); model.OpenCode9 = Convert.ToInt32(openCodeList[8]); model.OpenCode10 = Convert.ToInt32(openCodeList[9]); model.OpenCode11 = Convert.ToInt32(openCodeList[10]); model.OpenCode12 = Convert.ToInt32(openCodeList[11]); model.OpenCode13 = Convert.ToInt32(openCodeList[12]); model.OpenCode14 = Convert.ToInt32(openCodeList[13]); model.OpenCode15 = Convert.ToInt32(openCodeList[14]); model.OpenCode16 = Convert.ToInt32(openCodeList[15]); model.OpenCode17 = Convert.ToInt32(openCodeList[16]); model.OpenCode18 = Convert.ToInt32(openCodeList[17]); model.OpenCode19 = Convert.ToInt32(openCodeList[18]); model.OpenCode20 = Convert.ToInt32(openCodeList[19]); model.OpenTime = Convert.ToDateTime(openTime); if (!result.Contains(model)) { result.Add(model); } } var checkDataHelper = new CheckDataHelper(); var data = services.GetListIn(currentLottery, IsToday); if (data != null) { var dbdata = services.GetListIn(currentLottery, IsToday) .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()); checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()), Config.Area, currentLottery); } else { log.Warn(GetType(), $"{Config.LotteryName}没有最新数据!"); } } catch (Exception ex) { log.Error(GetType(), string.Format("【{0}】通过备用站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message)); } return(result); }
/// <summary> /// 新增彩种开奖数据 /// </summary> /// <param name="lottery">彩种名称</param> /// <param name="model">开奖数据模型</param> /// <returns></returns> public bool AddOpen21Code(SCCLottery lottery, OpenCode21Model model) { return(iOpen21Code.AddOpen21Code(lottery, model)); }