using FCS.Common;
using FCS.Interface;
using FCS.Models;
using FCS.Models.DTO;
using FCS.Models.Entity;
using HtmlAgilityPack;
using Quartz;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FCS.Crawler.Basketball
{
///
/// 篮球让球盘路
///
public class B_MakeBallRankingJob : CommonJob, IJob
{
private List MakeBallRankingList = new List();
private List DateItem = new List();
private List TeamList = new List();
B_MakeBallRanking g;
public B_MakeBallRankingJob()
{
g = new B_MakeBallRanking();
}
public void Execute(IJobExecutionContext context)
{
Config = CommonHelper.GetConfigFromDataMap(context.JobDetail.JobDataMap);
}
#region 更新数据
///
/// 获取所有数据
///
public void GetAll()
{
GetSqlString("");
}
///
/// 更新数据
///
///
public void Click(string Year = "")
{
if (Year == "")
{
Year = DateTime.Now.Year.ToString().Substring(2, 2); ;
}
GetSqlString(Year);
}
#endregion
///
/// 解析数据
///
///
private void GetSqlString(string Year)
{
TeamList = services.Query().ToList();
var dataItem = services.GetDataItem(DataItemDetailEnum.FootBallMakeBallType);
var ds = services.Query("and Remark is not null", "", "distinct EventId,Season,Remark").ToList();
if (Year != "")
{
ds = services.Query("and Remark is not null and Season like '%" + Year + "%'", "", "distinct EventId,Season,Remark").ToList();
}
int max = ds.Count;
int num = 0;
ds.ForEach(async p =>
{
await Task.Run(() =>
{
var eventId = p.EventId;
var season = p.Season;
var url = p.Remark.ToString().Replace("saiAll.do", "1/letPlateBall.do");
GetData(url, eventId, season, dataItem.Where(o => o.ItemValue == "1").First().Id.ToString());
url = p.Remark.ToString().Replace("saiAll.do", "2/letPlateBall.do");
GetData(url, eventId, season, dataItem.Where(o => o.ItemValue == "2").First().Id.ToString());
url = p.Remark.ToString().Replace("saiAll.do", "3/letPlateBall.do");
GetData(url, eventId, season, dataItem.Where(o => o.ItemValue == "3").First().Id.ToString());
});
lock (g)
{
num++;
Monitor.Pulse(g); //完成,通知等待队列,告知已完,执行下一个。
}
});
lock (g)
{
while (num < max)
{
Monitor.Wait(g);//等待
}
}
Trace.WriteLine("获取B_MakeBallRanking 完结");
try
{
if (Year != "")
{
services.Delete(" and Season like '%" + Year + "%'");
}
services.SqlBulkCopyAdd(MakeBallRankingList);
}
catch (Exception ex)
{
throw;
}
}
///
/// 解析排行榜数据
///
///
///
///
private void GetData(string url, string eventId, string season, string makeBallType)
{
HtmlParameterDTO dtomodel = new HtmlParameterDTO();
dtomodel.Url = url;
HtmlDocument doc = CommonHelper.GetHtmlHtmlDocument(dtomodel);
if (doc.DocumentNode.InnerHtml == "Termination" || doc.DocumentNode.InnerHtml == "" || doc.DocumentNode.SelectNodes("//*[@class='paiming']") == null)
{
return;
}
var team = doc.DocumentNode.SelectNodes("//*[@class='paiming']").First();
HtmlDocument itemdoc = new HtmlDocument();
itemdoc.LoadHtml(team.InnerHtml);
var trList = itemdoc.DocumentNode.SelectNodes("//table/tr").ToList();
trList.ForEach(p =>
{
if (!p.InnerHtml.Contains(" 1)
{
B_MakeBallRanking making = new B_MakeBallRanking();
making.Id = Guid.NewGuid().ToString();
making.Sort = int.Parse(tdList[0].InnerText.Trim().ToString());
making.MakeBallType = makeBallType;
making.TeamId = TeamList.Where(o => o.Name == tdList[1].InnerText.Trim().ToString()).Count() > 0 ? TeamList.Where(o => o.Name == tdList[1].InnerText.Trim().ToString()).FirstOrDefault().Id : "";
making.EventId = eventId;
making.Season = season;
making.Sum = int.Parse(tdList[2].InnerText.Trim().ToString());
making.UpDisc = int.Parse(tdList[3].InnerText.Trim().ToString());
making.DownDisc = int.Parse(tdList[4].InnerText.Trim().ToString());
making.WinDiscNum = int.Parse(tdList[5].InnerText.Trim().ToString());
making.GoDiscNum = int.Parse(tdList[6].InnerText.Trim().ToString());
making.TransportDiscNum = int.Parse(tdList[7].InnerText.Trim().ToString());
making.NetDiscNum = int.Parse(tdList[8].InnerText.Trim().ToString());
making.WinPercentage = tdList[9].InnerText.Trim().ToString();
making.GoPercentage = tdList[10].InnerText.Trim().ToString();
making.NegativePercentage = tdList[11].InnerText.Trim().ToString();
making.Remark = tdList[1].InnerText.Trim().ToString();
MakeBallRankingList.Add(making);
}
}
});
}
}
}
|