Beispiel #1
0
        /// <summary>
        ///     作业执行入口
        /// </summary>
        /// <param name="context">作业执行上下文</param>
        public void Execute(IJobExecutionContext context)
        {
            Config = CommonHelper.GetConfigFromDataMap(context.JobDetail.JobDataMap);

            //预设节假日不开奖
            if (Config.SkipDate.Contains(CommonHelper.SCCSysDateTime.ToString("yyyyMMdd")))
            {
                return;
            }
            LatestItem = context.JobDetail.JobDataMap["LatestItem"] as OpenCodePL3TModel;
            try
            {
                //服务启动时配置初始数据
                if (LatestItem == null)
                {
                    LatestItem = services.GetOpenCodePL3TLastItem(currentLottery);
                    if (LatestItem == null)
                    {
                        LatestItem = new OpenCodePL3TModel
                        {
                            Term     = CommonHelper.GenerateQiHaoYYYYQQQ(0),
                            OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
                        }
                    }
                    ;
                }

                //程序时间第二天,程序根据配置检查是否昨天有开奖
                isGetData = false;
                if (CommonHelper.CheckDTIsNeedGetData(Config))
                {
                    DoMainUrl();
                }
                if (!LatestItem.Term.ToString().StartsWith(CommonHelper.SCCSysDateTime.ToString("yy")))
                {
                    LatestItem = new OpenCodePL3TModel
                    {
                        Term     = CommonHelper.GenerateQiHaoYYYYQQQ(0),
                        OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
                    }
                }
                ;
                //当今日开奖并且当前时间是晚上8点过后开始抓取
                if (CommonHelper.CheckTodayIsOpenDay(Config) && CommonHelper.SCCSysDateTime.Hour > 12)
                {
                    DoMainUrl();
                }
                CheckGetKaiJiHao();
            }
            catch (Exception ex)
            {
                log.Error(GetType(), string.Format("【{0}】抓取时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            //保存最新期号
            context.JobDetail.JobDataMap["LatestItem"] = LatestItem;
        }
Beispiel #2
0
        private void Check()
        {
            try
            {
                var dict = services.GetLast1NTerm(currentLottery, 10);
                if (dict.Count > 0)
                {
                    foreach (var dic in dict)
                    {
                        var key      = dic.Key;
                        var Spare    = dic.Value;
                        var openList = GetOpenListFromMainUrl(Config.MainUrl);
                        OpenCodePL3TModel matchItem = null;
                        matchItem = openList.FirstOrDefault(r => r.Term.ToString() == key.ToString());
                        var res = GetKaijiangDetails(key.ToString());

                        //TODO 更新数据库
                        bool isSucc = services.UpdateKJDetailP3ByTerm(currentLottery, key, res, matchItem);
                        if (isSucc)
                        {
                            Trace.WriteLine($"更新{Config.LotteryName}第{key}期开奖详情成功!");

                            log.Info(GetType(), $"更新{Config.LotteryName}第{key}期开奖详情成功!");
                        }
                        else
                        {
                            Trace.WriteLine($"更新{Config.LotteryName}第{key}期开奖详情失败!");

                            log.Error(GetType(), $"更新{Config.LotteryName}第{key}期开奖详情失败!");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Error(GetType(), e);
            }
        }
Beispiel #3
0
        /// <summary>
        ///     通过主站点爬取开奖数据
        ///     (福建体彩网)
        /// </summary>
        private void DoMainUrl()
        {
            if (!string.IsNullOrEmpty(Config.MainUrl))
            {
                var openList = GetOpenListFromMainUrl(Config.MainUrl);
                if (openList.Count == 0)
                {
                    return;                      //无抓取数据
                }
                //抓取到的最新期数
                var newestQiHao = Convert.ToInt32(openList.First().Term.ToString());
                //数据库里面最新期数
                var startQiNum = Convert.ToInt32(LatestItem.Term.ToString());

                if (startQiNum > newestQiHao)
                {
                    return;                           //无最新数据
                }
                //处理最新开奖数据
                var getQiHao = string.Empty;
                OpenCodePL3TModel matchItem = null;
                for (var i = startQiNum; i <= newestQiHao; i++)
                {
                    getQiHao  = i.ToString();
                    matchItem = openList.FirstOrDefault(r => r.Term.ToString() == getQiHao);

                    if (matchItem != null && services.AddDTOpenPL3Code(currentLottery, matchItem))
                    {
                        //Do Success Log
                        log.Info(GetType(), CommonHelper.GetJobMainLogInfo(Config, getQiHao));
                        LatestItem = matchItem;
                        isGetData  = true;
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 获取开奖号列表
        /// </summary>
        /// <param name="mainUrl"></param>
        /// <returns></returns>
        private List <OpenCodePL3TModel> GetOpenListFromMainUrl(string mainUrl)
        {
            var result = new List <OpenCodePL3TModel>();

            try
            {
                var url          = new Uri(mainUrl);
                var htmlResource = NetHelper.GetUrlResponse(mainUrl, Encoding.GetEncoding("utf-8"));
                if (htmlResource == null)
                {
                    return(result);
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectSingleNode("//table");
                if (table == null)
                {
                    return(result);
                }
                var trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
                OpenCodePL3TModel model = null;
                HtmlNode          nodeA = null;
                var optimizeUrl         = string.Empty;
                for (var i = 0; i < trs.Count; i++) //第一二行为表头
                {
                    var trstyle = trs[i].Attributes["style"];
                    if (trstyle != null && trstyle.Value == "display:none")
                    {
                        continue;
                    }
                    var tds = trs[i].ChildNodes.Where(node => node.Name == "td").ToList();
                    if (tds.Count < 6)
                    {
                        continue;
                    }
                    model = new OpenCodePL3TModel();

                    var Term = tds[0].InnerText.Trim();
                    if (Term.Length <= 7)
                    {
                        model.Term = Convert.ToInt64("20" + Term);
                    }
                    else
                    {
                        model.Term = Convert.ToInt64(Term);
                    }
                    optimizeUrl    = model.Term.ToString();
                    model.OpenTime = Convert.ToDateTime(tds[1].InnerText.Substring(0, 5));
                    var openCodeString = tds[2].InnerText.Replace("    ", "").Trim();
                    if (openCodeString == "--")
                    {
                        model.OpenCode1 = Convert.ToInt32("-1");
                        model.OpenCode2 = Convert.ToInt32("-1");
                        model.OpenCode3 = Convert.ToInt32("-1");
                    }
                    else
                    {
                        model.OpenCode1 = Convert.ToInt32(openCodeString.Substring(0, 1));
                        model.OpenCode2 = Convert.ToInt32(openCodeString.Substring(2, 1));
                        model.OpenCode3 = Convert.ToInt32(openCodeString.Substring(4, 1));
                    }


                    model.KaiJiHao = null;
                    model.ShiJiHao = tds[3].InnerText.Trim().Replace(" ", ",").Trim();
                    var details = GetKaijiangDetails(optimizeUrl);
                    model.Spare = details;
                    result.Add(model);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCodePL5TModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
                result = result.OrderByDescending(S => S.Term).ToList();
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过主站抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }