/// <summary> /// 核实最新一期期号是否为今天的期号 /// </summary> /// <returns></returns> private bool CheckLatestQiHaoIsTodayTerm() { var datepart = CommonHelper.SCCSysDateTime - new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1); var t = Config.SkipDate.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var todayPrefix = CommonHelper.SCCSysDateTime.Year + (datepart.Days - t.Length + 1).ToString().PadLeft(3, '0'); return(LatestQiHao.StartsWith(todayPrefix)); }
/// <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; } LatestQiHao = context.JobDetail.JobDataMap.GetString("LatestQiHao"); try { //服务启动时配置初始数据 if (string.IsNullOrEmpty(LatestQiHao)) { var lastItem = services.GetLastItem(currentLottery); if (lastItem != null) { LatestQiHao = lastItem.Term.ToString(); } } //第一次启动服务或最新期号为昨天的开奖期号,则自检昨天开奖数据是否抓取完毕(否则插入邮件数据),并重置当天期号和失败列表 if (string.IsNullOrEmpty(LatestQiHao) || !LatestQiHao.StartsWith(CommonHelper.SCCSysDateTime.ToString("yyMMdd"))) { CheckingYesterdayTheLotteryData(); LatestQiHao = CommonHelper.GenerateTodayQiHaoYYMMDDQQ(0); } //当最新期号不符合当天总期数,执行当天作业 if (Convert.ToInt32(LatestQiHao.Substring(6)) != Config.TimesPerDay) { DoTodayJobByMainUrl(); DoTodayJobByBackUrl(); } } catch (Exception ex) { log.Error(GetType(), string.Format("【{0}】抓取时发生错误,错误信息【{1}】", Config.Area + Config.LotteryName, ex.Message)); } //保存最新期号和失败期号列表 context.JobDetail.JobDataMap["LatestQiHao"] = LatestQiHao; }