/// <summary> /// 获取计算和值球个数 /// </summary> /// <param name="type"></param> /// <returns></returns> protected int GetSumNumberCount(SCCLottery type) { int res = type.GetEnumText().TryToInt32(); //有特殊球的情况下 if (LotteryBallTypeDict.ContainsKey(type.ToString())) { res = LotteryBallTypeDict[type.ToString()][0]; } return(res); }
/// <summary> /// 纠错参数 /// </summary> /// <param name="dbData"></param> /// <param name="newData"></param> public void CheckData(Dictionary <string, string> dbData, Dictionary <string, string> newData, string Area, SCCLottery Lottery) { try { Dictionary <int, int> result = new Dictionary <int, int>(); foreach (var item in dbData) { var data = newData.SingleOrDefault(w => w.Key == item.Key); if (data.Key != null) { var dbdata = Array.ConvertAll <string, int>(data.Value.Split(','), s => int.Parse(s)).ToList(); var newdata = Array.ConvertAll <string, int>(item.Value.Split(','), s => int.Parse(s)).ToList(); dbdata.Sort(); newdata.Sort(); var dbcode = string.Join(",", dbdata); var newcode = string.Join(",", newdata); if (dbcode != newcode) { result.Add(int.Parse(item.Key), 0); email.AddEmail(Area + Lottery.ToString(), data.Key, DateTime.Now, "数据验证失败" + string.Format("数据库:{0},爬取:{1}", item.Value, data.Value)); } else { result.Add(int.Parse(item.Key), 1); } } } var tableName = EnumHelper.GetSCCLotteryTableName(Lottery); int rt = resultServices.ExecuteResult(tableName, result); if (rt < 0) { email.AddEmail(Area + Lottery.ToString(), "0", DateTime.Now, "执行验证结果结果失败"); } } catch (Exception ex) { log.Error(this.GetType(), string.Format("【{0}】数据验证发生错误,错误信息【{1}】", Area + Lottery.ToString(), ex.Message)); } }
/// <summary> /// 获取抓取地址以及XPath /// </summary> /// <param name="scc"></param> /// <returns></returns> public static string[] GetRequestUrlAndXPath(SCCLottery scc) { if (!cacheDictionary.ContainsKey(scc.ToString())) { cacheDictionary.Add(scc.ToString(), new[] { ConfigHelper.GetValue("__" + scc.ToString() + "__URL__"), ConfigHelper.GetValue("__" + scc.ToString() + "__XPATH__") }); } else { cacheDictionary[scc.ToString()] = new[] { ConfigHelper.GetValue("__" + scc.ToString() + "__URL__"), ConfigHelper.GetValue("__" + scc.ToString() + "__XPATH__") }; } return(cacheDictionary[scc.ToString()]); }
/// <summary> /// 获取开奖号模板 /// </summary> /// <param name="type"></param> /// <param name="openCodeList">开奖号集合</param> /// <returns></returns> protected string GetOpenCodeTemplate(SCCLottery type, List <int> openCodeList) { StringBuilder res = new StringBuilder(); string blueTemplate = "<span class='ball-list blue'>{0}</span>"; string redTemplate = "<span class='ball-list red'>{0}</span>"; //快乐扑克3为特殊彩种 if (type == SCCLottery.ShanDongKLPK3) { return(GetKLPK3OpenCodeTemplate(openCodeList)); } #region 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0 //取出当前最大开奖号 //TODO 此做法欠妥,如果当前彩种开奖号取值在0-20之间,有可能某一期开奖号全部都小于10 int max = openCodeList.Max(); //是否需要添加0 bool hasAppendZero = (type != SCCLottery.ShanDongKLPK3 && max >= 10) || type == SCCLottery.GuangDongHC1; #endregion //其他彩 string typeCode = type.ToString(); if (LotteryBallTypeDict.ContainsKey(typeCode)) { int[] codeArr = LotteryBallTypeDict[typeCode]; //正常球个数 int normal = codeArr[0]; //蓝球个数 int blue = codeArr[1]; //生肖球个数 int zodiac = codeArr[2]; //季节球个数 int season = codeArr[3]; //方位球个数 int position = codeArr[4]; #region 正常球 if (normal > 0) { for (int i = 1; i <= normal; i++) { int openCode = openCodeList[i - 1].TryToInt32(); res.Append(string.Format(redTemplate, 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 = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, hasAppendZero ? openCode.RepairZero() : openCode.ToString())); } } #endregion #region 生肖球 if (zodiac > 0) { int index = normal + blue; for (int i = zodiac; i >= 1; i--) { int openCode = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, LotteryUtils.GetZodiacByOpenCode(openCode))); } } #endregion #region 季节球 if (season > 0) { int index = normal + blue + zodiac; for (int i = season; i >= 1; i--) { int openCode = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, LotteryUtils.GetSeasonByOpenCode(openCode))); } } #endregion #region 方位球 if (position > 0) { int index = normal + blue + zodiac + season; for (int i = position; i >= 1; i--) { int openCode = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, LotteryUtils.GetPositionByOpenCode(openCode))); } } #endregion } else { //总共球个数 int total = type.GetEnumText().TryToInt32(); for (int i = 1; i <= total; i++) { int openCode = openCodeList[i - 1].TryToInt32(); res.Append(string.Format(redTemplate, hasAppendZero ? openCode.RepairZero() : openCode.ToString())); } } return(res.ToString()); }