提交 21bd8c8f 编写于 作者: M monomania

1.赛季信息获取完成

上级 65c926e2
......@@ -14,4 +14,5 @@ bin
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.idea/
logs/
\ No newline at end of file
logs/
.err
\ No newline at end of file
package main
import (
"fmt"
"tesou.io/platform/foot-parent/foot-spider/launch"
"time"
)
func main() {
launch.Spider_league()
now := time.Now()
temp_year, _ := time.ParseDuration("-8760h")
add := now.Add(temp_year)
parse:= now.Format( "2006")
parse2 := add.Format( "2006")
fmt.Println(parse)
fmt.Println(parse2)
//launch.Spider_league()
launch.Spider_leagueSeason()
}
......@@ -13,6 +13,8 @@ type League struct {
Name string `xorm:" comment('联赛名称') index"`
ShortName string `xorm:" comment('联赛名简称') index"`
ShortUrl string `xorm:" comment('联赛入口路径') index"`
Cup bool `xorm:" comment('是否是杯赛') index"`
SeasonCross bool `xorm:" comment('赛制是否跨年') index"`
//联赛级别
Level int `xorm:" comment('联赛级别') index"`
......
......@@ -5,17 +5,14 @@ import (
)
/**
联赛子表表
联赛赛季表,,
*/
//不管是从哪个平台抓取的数据,都使用win007的联赛的ID数据
type LeagueStub struct {
type LeagueSeason struct {
//联赛id
LeagueId string `xorm:" comment('LeagueId') index"`
//年份,使用,间隔
Season string `xorm:" comment('Season')"`
//subs
SubIds []string `xorm:" comment('Subs')"`
//--
//赛季
Season string `xorm:" comment('Season') index"`
//最大的回合数
Round int `xorm:" comment('最大的回合数')"`
pojo.BasePojo `xorm:"extends"`
......
package pojo
import (
"tesou.io/platform/foot-parent/foot-api/common/base/pojo"
)
/**
联赛赛季次级表,, 如联赛,升级附加赛,降级附加赛
*/
type LeagueSub struct {
//联赛id
LeagueId string `xorm:" comment('LeagueId') index"`
//赛季
Season string `xorm:" comment('Season') index"`
SubId string `xorm:" comment('SubId') index"`
SubName string `xorm:" comment('SubName') index"`
//最大的回合数
Round int `xorm:" comment('最大的回合数')"`
pojo.BasePojo `xorm:"extends"`
}
......@@ -60,7 +60,7 @@ func (this *DBOpsService) SyncTableStruct() {
}
//波菜公司,联赛其他数据表
err = engine.Sync2(new(entity3.Comp), new(entity3.League))
err = engine.Sync2(new(entity3.Comp), new(entity3.League), new(entity3.LeagueSeason), new(entity3.LeagueSub))
if nil != err {
base.Log.Error(err.Error())
}
......
package service
import (
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-core/common/base/service/mysql"
)
//联赛表
type LeagueSeasonService struct {
mysql.BaseService
}
func (this *LeagueSeasonService) Exist(e *pojo.LeagueSeason) (string, bool) {
sql_build := strings.Builder{}
sql_build.WriteString(" LeagueId = '" + e.LeagueId + "' AND Season = '" + e.Season + "'")
temp := &pojo.LeagueSeason{}
var id string
exist, err := mysql.GetEngine().Where(sql_build.String()).Get(temp)
if err != nil {
base.Log.Error("Exist:", err)
}
if exist {
id = temp.Id
}
return id, exist
}
func (this *LeagueSeasonService) FindByLeagueId(id string) []*pojo.LeagueSeason {
dataList := make([]*pojo.LeagueSeason, 0)
sql_build := strings.Builder{}
sql_build.WriteString(" LeagueId = '" + id + "'")
err := mysql.GetEngine().Where(sql_build.String()).Find(&dataList)
if err != nil {
base.Log.Error("FindByLeagueId:", err)
}
return dataList
}
package service
import (
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-core/common/base/service/mysql"
)
//联赛表
type LeagueStubService struct {
mysql.BaseService
}
func (this *LeagueStubService) Exist(e *pojo.LeagueStub) (string, bool) {
//sql_build := strings.Builder{}
//eventMatchDateStr := e.EventMatchDate.Format("2006-01-02 15:04:05")
//sql_build.WriteString(" MatchId = '" + e.MatchId + "' AND TeamId = '" + e.TeamId + "' AND EventMatchDate = '" + eventMatchDateStr + "'")
//temp := &pojo.BFFutureEvent{}
//var id string
//exist, err := mysql.GetEngine().Where(sql_build.String()).Get(temp)
//if err != nil {
// base.Log.Error("Exist:", err)
//}
//if exist {
// id = temp.Id
//}
//return id, exist
return "",false
}
func (this *LeagueStubService) FindById(id string) *pojo.League {
league := new(pojo.League)
league.Id = id
_, err := mysql.GetEngine().Get(league)
if err != nil {
base.Log.Info("FindById:", err)
}
return league
}
func (this *LeagueStubService) FindByName(name string) *pojo.League {
league := new(pojo.League)
league.Name = name
_, err := mysql.GetEngine().Get(league)
if err != nil {
base.Log.Info("FindByName:", err)
}
return league
}
package service
import (
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-core/common/base/service/mysql"
)
//联赛表
type LeagueSubService struct {
mysql.BaseService
}
func (this *LeagueSubService) Exist(e *pojo.LeagueSub) (string, bool) {
sql_build := strings.Builder{}
sql_build.WriteString(" LeagueId = '" + e.LeagueId + "' AND Season = '" + e.Season + "' AND SubId = '" + e.SubId + "'")
temp := &pojo.LeagueSub{}
var id string
exist, err := mysql.GetEngine().Where(sql_build.String()).Get(temp)
if err != nil {
base.Log.Error("Exist:", err)
}
if exist {
id = temp.Id
}
return id, exist
}
func (this *LeagueSubService) FindByLeagueId(id string) []*pojo.LeagueSub {
dataList := make([]*pojo.LeagueSub, 0)
sql_build := strings.Builder{}
sql_build.WriteString(" LeagueId = '" + id + "'")
err := mysql.GetEngine().Where(sql_build.String()).Find(&dataList)
if err != nil {
base.Log.Error("FindByLeagueId:", err)
}
return dataList
}
package launch
import (
"tesou.io/platform/foot-parent/foot-spider/module/win007/proc"
)
func Spider_leagueSeason() {
processer := proc.GetLeagueSubProcesser()
processer.Startup()
}
package launch
import (
"tesou.io/platform/foot-parent/foot-spider/module/win007/proc"
)
//抓取比赛数据
func Spider_match_his() {
processer := proc.GetMatchHisProcesser()
// /联赛时间/联赛id_联赛子id_第几轮.htm
//http://m.win007.com/info/fixture/2019-2020/36_0_1.htm
processer.MatchlastUrl = "http://m.win007.com/info/fixture/2019-2020/36_0_1.htm"
processer.Startup()
//processer := proc.GetMatchHisProcesser()
//// /联赛时间/联赛id_联赛子id_第几轮.htm
////http://m.win007.com/info/fixture/2019-2020/36_0_1.htm
//processer.MatchlastUrl = "http://m.win007.com/info/fixture/2019-2020/36_0_1.htm"
//processer.Startup()
}
......@@ -21,5 +21,10 @@ const WIN007_EUROODD_BET_URL_PATTERN = "http://m.win007.com/1x2Detail.aspx?schei
const WIN007_ASIAODD_URL_PATTERN = "http://m.win007.com/asian/${matchId}.htm"
const WIN007_ASIAODD_NEW_URL_PATTERN = "http://m.win007.com/HandicapDataInterface.ashx?scheid=${matchId}&type=1&oddskind=0&flesh=0.7215399647784261"
/**
资料库里的比赛赛程前缀
示例:http://m.win007.com/info/Fixture/2019-2020/34_0_0.htm
*/
const WIN007_MATCH_HIS_PATTERN = "http://m.win007.com/info/Fixture/${season}/${leagueId}_${subId}_${round}.htm"
......@@ -80,6 +80,13 @@ func (this *LeagueProcesser) Process(p *page.Page) {
league.Sid = sId
league.SName = sName
league.ShortUrl = lUrl
if strings.Contains(lUrl,"Cup"){
league.Cup = true
}
if strings.Contains(lUrl,"-"){
league.SeasonCross = true
}
this.league_list = append(this.league_list,league)
})
}
......
package proc
import (
"github.com/PuerkitoBio/goquery"
"github.com/hu17889/go_spider/core/common/page"
"github.com/hu17889/go_spider/core/pipeline"
"github.com/hu17889/go_spider/core/spider"
"strconv"
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
service2 "tesou.io/platform/foot-parent/foot-core/module/elem/service"
"tesou.io/platform/foot-parent/foot-spider/module/win007"
"tesou.io/platform/foot-parent/foot-spider/module/win007/down"
)
type LeagueSeasonProcesser struct {
service2.LeagueService
service2.LeagueSeasonService
service2.LeagueSubService
//联赛次级数据
leagueSeason_list []*pojo.LeagueSeason
leagueSub_list []*pojo.LeagueSub
sUrl_leagueId map[string]string
}
func GetLeagueSubProcesser() *LeagueSeasonProcesser {
return &LeagueSeasonProcesser{}
}
func (this *LeagueSeasonProcesser) Startup() {
//初始化参数值
this.leagueSeason_list = make([]*pojo.LeagueSeason, 0)
this.leagueSub_list = make([]*pojo.LeagueSub, 0)
this.sUrl_leagueId = make(map[string]string)
//1.获取所有的联赛
leaguesList := make([]*pojo.League, 0)
this.LeagueService.FindAll(&leaguesList)
//2.配置要抓取的路径
newSpider := spider.NewSpider(this, "LeagueSeasonProcesser")
//index := 0
for _, v := range leaguesList {
//先不处理杯赛....
if v.Cup{
continue
}
//index++
//if index > 10{
// break
//}
url := win007.WIN007_MATCH_HIS_PATTERN
if v.SeasonCross {
url = strings.Replace(url, "${season}", "2018-2019", 1)
} else {
url = strings.Replace(url, "${season}", "2019", 1)
}
url = strings.Replace(url, "${leagueId}", v.Id, 1)
url = strings.Replace(url, "${subId}", "0", 1)
url = strings.Replace(url, "${round}", "1", 1)
this.sUrl_leagueId[url] = v.Id
newSpider = newSpider.AddUrl(url, "html")
}
newSpider.SetDownloader(down.NewMWin007Downloader())
newSpider = newSpider.AddPipeline(pipeline.NewPipelineConsole())
newSpider.SetSleepTime("rand", 100, 2000)
newSpider.SetThreadnum(1).Run()
}
func (this *LeagueSeasonProcesser) Process(p *page.Page) {
request := p.GetRequest()
if !p.IsSucc() {
base.Log.Error("URL:,", request.Url, p.Errormsg())
return
}
rawText := p.GetBodyStr()
if rawText == "" {
base.Log.Error("rawText:为空.url:", request.Url)
return
}
leagueId := this.sUrl_leagueId[request.Url]
//1.处理season
htmlParser := p.GetHtmlParser()
htmlParser.Find("select[id='selSeason'] option").Each(func(i int, selection *goquery.Selection) {
temp_maxRound := 1
temp_season := strings.TrimSpace(selection.Text())
//2.处理sub
htmlParser.Find("select[id='selSubSclass'] option").Each(func(i int, selection *goquery.Selection) {
temp_subName := strings.TrimSpace(selection.Text())
if len(temp_subName) <= 0 {
return
}
val, exist := selection.Attr("value")
if !exist {
return
}
base.Log.Info("联赛Id:", leagueId, ",赛季:", temp_season, ",次级名称:", temp_subName, ",次级Id:", val)
leagueSub := new(pojo.LeagueSub)
leagueSub.LeagueId = leagueId
leagueSub.Season = temp_season
leagueSub.Round = temp_maxRound
leagueSub.SubId = val
leagueSub.SubName = temp_subName
this.leagueSub_list = append(this.leagueSub_list, leagueSub)
})
//3.处理round
htmlParser.Find("select[id='selRound'] option").Each(func(i int, selection *goquery.Selection) {
temp_round_str := strings.TrimSpace(selection.Text())
if len(temp_round_str) <= 0 {
return
}
temp_round, _ := strconv.Atoi(temp_round_str)
if temp_round > temp_maxRound {
temp_maxRound = temp_round
}
})
leagueSeason := new(pojo.LeagueSeason)
leagueSeason.LeagueId = leagueId
leagueSeason.Season = temp_season
leagueSeason.Round = temp_maxRound
this.leagueSeason_list = append(this.leagueSeason_list, leagueSeason)
})
}
func (this *LeagueSeasonProcesser) Finish() {
base.Log.Info("联赛次级抓取解析完成,执行入库 \r\n")
leagueSeason_list_slice := make([]interface{}, 0)
leagueSeason_modify_list_slice := make([]interface{}, 0)
for _, v := range this.leagueSeason_list {
if nil == v {
continue
}
id, exist := this.LeagueSeasonService.Exist(v)
if exist {
v.Id = id
leagueSeason_modify_list_slice = append(leagueSeason_modify_list_slice, v)
continue
}
leagueSeason_list_slice = append(leagueSeason_list_slice, v)
}
this.LeagueSeasonService.SaveList(leagueSeason_list_slice)
this.LeagueSeasonService.ModifyList(leagueSeason_modify_list_slice)
leagueSub_list_slice := make([]interface{}, 0)
leagueSub_modify_list_slice := make([]interface{}, 0)
for _, v := range this.leagueSub_list {
if nil == v {
continue
}
id, exist := this.LeagueSubService.Exist(v)
if exist {
v.Id = id
leagueSub_modify_list_slice = append(leagueSub_modify_list_slice, v)
continue
}
leagueSub_list_slice = append(leagueSub_list_slice, v)
}
this.LeagueSubService.SaveList(leagueSub_list_slice)
this.LeagueSubService.ModifyList(leagueSub_modify_list_slice)
}
package proc
import (
"github.com/PuerkitoBio/goquery"
"github.com/hu17889/go_spider/core/common/page"
"github.com/hu17889/go_spider/core/pipeline"
"github.com/hu17889/go_spider/core/spider"
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
entity2 "tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
service2 "tesou.io/platform/foot-parent/foot-core/module/elem/service"
"tesou.io/platform/foot-parent/foot-spider/module/win007"
"tesou.io/platform/foot-parent/foot-spider/module/win007/down"
)
type LeagueStubProcesser struct {
service2.LeagueService
service2.CompService
//联赛数据
league_list []*entity2.League
sUrl_Id map[string]string
sUrl_Name map[string]string
}
func GetLeagueStubProcesser() *LeagueStubProcesser {
return &LeagueStubProcesser{}
}
func (this *LeagueStubProcesser) Startup() {
//初始化参数值
this.league_list = make([]*entity2.League, 0)
this.sUrl_Id = make(map[string]string)
this.sUrl_Name = make(map[string]string)
newSpider := spider.NewSpider(this, "LeagueStubProcesser")
//sid 数据
sid_stat_url := "http://m.win007.com/info.htm#section0";
document, _ := GetDocument(sid_stat_url)
document.Find("a[href*='sid']").Each(func(i int, selection *goquery.Selection) {
sUrl, _ := selection.Attr("href")
sId := strings.Split(sUrl, "sid=")[1]
sName := strings.TrimSpace(selection.Text())
base.Log.Info("sId:", sId, ",sName:", sName, ",sUrl:"+sUrl)
this.sUrl_Id[win007.WIN007_BASE_URL+sUrl] = sId
this.sUrl_Name[win007.WIN007_BASE_URL+sUrl] = sName
newSpider = newSpider.AddUrl(win007.WIN007_BASE_URL+sUrl, "html")
})
newSpider.SetDownloader(down.NewMWin007Downloader())
newSpider = newSpider.AddPipeline(pipeline.NewPipelineConsole())
newSpider.SetSleepTime("rand",100,2000)
newSpider.SetThreadnum(1).Run()
}
func (this *LeagueStubProcesser) Process(p *page.Page) {
request := p.GetRequest()
if !p.IsSucc() {
base.Log.Error("URL:,", request.Url, p.Errormsg())
return
}
rawText := p.GetBodyStr()
if rawText == "" {
base.Log.Error("rawText:为空.url:", request.Url)
return
}
sUrl := request.Url
sId := this.sUrl_Id[sUrl]
sName := this.sUrl_Name[sUrl]
p.GetHtmlParser().Find("a.gameItem[href*='info'][href*='htm']").Each(func(i int, selection *goquery.Selection) {
lUrl, _ := selection.Attr("href")
l_arr := strings.Split(lUrl, "/")
lId_suffix := l_arr[len(l_arr)-1]
lId := strings.ReplaceAll(lId_suffix,".htm","")
lName := strings.TrimSpace(selection.Text())
base.Log.Info("lId:", lId, ",lName:", lName, ",lUrl:"+lUrl)
league := new(entity2.League)
league.Id = lId
league.Name = lName
league.Sid = sId
league.SName = sName
league.ShortUrl = lUrl
this.league_list = append(this.league_list,league)
})
}
func (this *LeagueStubProcesser) Finish() {
base.Log.Info("联赛解析完成,执行入库 \r\n")
league_list_slice := make([]interface{}, 0)
league_modify_list_slice := make([]interface{}, 0)
for _, v := range this.league_list {
if nil == v {
continue
}
exists := this.LeagueService.ExistById(v.Id)
if exists {
league_modify_list_slice = append(league_modify_list_slice,v)
continue
}
league_list_slice = append(league_list_slice, v)
}
this.LeagueService.SaveList(league_list_slice)
this.LeagueService.ModifyList(league_modify_list_slice)
}
package proc
import (
"github.com/hu17889/go_spider/core/common/page"
"github.com/hu17889/go_spider/core/pipeline"
"github.com/hu17889/go_spider/core/spider"
"math/rand"
"strconv"
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
entity2 "tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-api/module/match/pojo"
service2 "tesou.io/platform/foot-parent/foot-core/module/elem/service"
"tesou.io/platform/foot-parent/foot-core/module/match/service"
"tesou.io/platform/foot-parent/foot-spider/module/win007"
"tesou.io/platform/foot-parent/foot-spider/module/win007/down"
"time"
)
type MatchHisProcesser struct {
service.MatchLastService
service.MatchHisService
service2.LeagueService
service2.CompService
//抓取的url
MatchlastUrl string
//联赛数据
league_list []*entity2.League
win007Id_leagueId_map map[string]string
//比赛数据
matchLast_list []*pojo.MatchLast
//比赛级别
MatchLevel int
}
func GetMatchHisProcesser() *MatchHisProcesser {
return &MatchHisProcesser{}
}
func (this *MatchHisProcesser) Startup() {
//联赛数据
this.league_list = make([]*entity2.League, 0)
this.win007Id_leagueId_map = make(map[string]string)
//比赛数据
this.matchLast_list = make([]*pojo.MatchLast, 0)
if this.MatchlastUrl == "" {
this.MatchlastUrl = "http://m.win007.com/phone/Schedule_0_0.txt"
}
this.MatchlastUrl = this.MatchlastUrl + "?flesh=" + strconv.FormatFloat(rand.Float64(), 'f', -1, 64)
newSpider := spider.NewSpider(this, "MatchHisProcesser")
newSpider = newSpider.AddUrl(this.MatchlastUrl, "text")
newSpider.SetDownloader(down.NewMWin007Downloader())
newSpider = newSpider.AddPipeline(pipeline.NewPipelineConsole())
newSpider.SetSleepTime("rand",100,2000)
newSpider.SetThreadnum(1).Run()
}
func (this *MatchHisProcesser) Process(p *page.Page) {
request := p.GetRequest()
if !p.IsSucc() {
base.Log.Error("URL:,", request.Url, p.Errormsg())
return
}
rawText := p.GetBodyStr()
if rawText == "" {
base.Log.Error("rawText:为空.url:", request.Url)
return
}
rawText_arr := strings.Split(rawText, "$$")
if len(rawText_arr) < 2 {
base.Log.Error("rawText:解析失败,rawTextArr长度小于所必需要的长度2,url:", request.Url, "内容:", rawText_arr)
return
}
flag := this.findParamVal(request.Url)
var league_str string
var match_str string
if flag == "0" {
league_str = rawText_arr[0]
match_str = rawText_arr[1]
} else {
league_str = rawText_arr[1]
match_str = rawText_arr[2]
}
base.Log.Info("日期:TODAY", "联赛信息:", league_str)
this.league_process(league_str)
base.Log.Info("日期:TODAY", "比赛信息:", match_str)
this.match_process(match_str)
now := time.Now()
//获取明天赛程
h24h, _ := time.ParseDuration("24h")
t_1_date := now.Add(h24h).Format("2006-01-02")
this.futrueMatch(t_1_date)
//获取后天赛程
//h24h, _ = time.ParseDuration("48h")
//t_1_date = now.Add(h24h).Format("2006-01-02")
//this.futrueMatch(t_1_date)
}
func (this *MatchHisProcesser) futrueMatch(date string) {
url := "http://m.win007.com/ChangeDate.ashx?date=" + date
rawText := GetText(url)
//rawText := Post("http://m.win007.com/ChangeDate.ashx", &req)
if rawText == "" {
base.Log.Error("rawText:为空.url:", url)
return
}
rawText_arr := strings.Split(rawText, "$")
if len(rawText_arr) < 2 {
base.Log.Error("rawText:解析失败,rawTextArr长度小于所必需要的长度2,url:", url, "内容:", rawText_arr)
return
}
league_str := rawText_arr[0]
match_str := rawText_arr[1]
base.Log.Info("日期:", date, "联赛信息:", league_str)
this.league_process(league_str)
base.Log.Info("日期:", date, "比赛信息:", match_str)
this.match_process(match_str)
}
func (this *MatchHisProcesser) findParamVal(url string) string {
paramUrl := strings.Split(url, "_")[2]
paramArr := strings.Split(paramUrl, ".")
return paramArr[0]
}
func (this *MatchHisProcesser) league_process(rawText string) {
league_arr := strings.Split(rawText, "!")
this.league_list = make([]*entity2.League, len(league_arr))
var index int
for _, v := range league_arr {
league_info_arr := strings.Split(v, "^")
if len(league_info_arr) < 3 {
continue
}
i := 0
//联赛名称
name := league_info_arr[i]
//联赛ID
i++
win007Id := league_info_arr[i]
league := new(entity2.League)
league.Id = win007Id
league.ShortName = name
if this.MatchLevel > 0 {
//设置联赛级别
league.LevelAssist = 10000
}
//league.Ext = make(map[string]interface{})
//league.Ext["win007Id"] = win007Id
this.win007Id_leagueId_map[win007Id] = league.Id
//联赛级别
i++
level_str := league_info_arr[i]
level, _ := strconv.Atoi(level_str)
league.Level = level
//占位
i++
//赛事类别ID
i++
league.Sid = league_info_arr[i]
//赛事类别名称
i++
league.SName = league_info_arr[i]
this.league_list[index] = league
index++
}
}
/**
处理比赛信息
*/
func (this *MatchHisProcesser) match_process(rawText string) {
match_arr := strings.Split(rawText, "!")
match_len := len(match_arr)
for i := 0; i < match_len; i++ {
matchLast := new(pojo.MatchLast)
//matchLast.Ext = make(map[string]interface{})
//matchLast.Id = bson.NewObjectId().Hex()
//match_arr[0] is
//1503881^284^0^20180909170000^^町田泽维亚^水户蜀葵^0^0^0^0^0^0^0^0^0.5^181^^0^2^12^^^0^0^0^0
match_info_arr := strings.Split(match_arr[i], "^")
index := 0
win007Id := match_info_arr[index]
//matchLast.Ext["win007Id"] = win007Id
//比赛ID
matchLast.Id = win007Id
//联赛ID
index++
matchLast.LeagueId = this.win007Id_leagueId_map[match_info_arr[index]]
index++
//比赛日期
index++
match_date_str := match_info_arr[index]
matchLast.MatchDate, _ = time.ParseInLocation("20060102150405", match_date_str, time.Local)
index++
//主队客队名称
index++
matchLast.MainTeamId = match_info_arr[index]
/* if regexp.MustCompile("^\\d*$").MatchString(dataDate_or_mainTeamName) {
data_date_timestamp, _ := strconv.ParseInt(dataDate_or_mainTeamName, 10, 64)
matchLast.DataDate = time.Unix(data_date_timestamp, 0).Format("2006-01-02 15:04:05")
} else {
matchLast.MainTeamId = dataDate_or_mainTeamName
}*/
index++
matchLast.GuestTeamId = match_info_arr[index]
//全场进球
index++
mainTeamGoals_str := match_info_arr[index]
mainTeamGoals, _ := strconv.Atoi(mainTeamGoals_str)
matchLast.MainTeamGoals = mainTeamGoals
index++
guestTeamGoals_str := match_info_arr[index]
guestTeamGoals, _ := strconv.Atoi(guestTeamGoals_str)
matchLast.GuestTeamGoals = guestTeamGoals
//半场进球
index++
mainTeamHalfGoals_str := match_info_arr[index]
mainTeamHalfGoals, _ := strconv.Atoi(mainTeamHalfGoals_str)
matchLast.MainTeamHalfGoals = mainTeamHalfGoals
index++
guestTeamHalfGoals_str := match_info_arr[index]
guestTeamHalfGoals, _ := strconv.Atoi(guestTeamHalfGoals_str)
matchLast.GuestTeamHalfGoals = guestTeamHalfGoals
//最后加入数据中
this.matchLast_list = append(this.matchLast_list, matchLast)
}
}
func (this *MatchHisProcesser) Finish() {
base.Log.Info("比赛抓取解析完成,执行入库 \r\n")
league_list_slice := make([]interface{}, 0)
for _, v := range this.league_list {
if nil == v {
continue
}
/* bytes, _ := json.Marshal(v)
base.Log.Info(string(bytes))*/
exists := this.LeagueService.ExistById(v.Id)
if exists {
continue
}
league_list_slice = append(league_list_slice, v)
}
this.LeagueService.SaveList(league_list_slice)
matchLast_list_slice := make([]interface{}, 0)
matchLast_modify_list_slice := make([]interface{}, 0)
matchHis_list_slice := make([]interface{}, 0)
matchHis_modify_list_slice := make([]interface{}, 0)
for _, v := range this.matchLast_list {
if nil == v {
continue
}
//v.Id = v.Ext["win007Id"].(string);
//处理比赛配置信息
matchExt := new(pojo.MatchExt)
/* matchLast_elem := reflect.ValueOf(v).Elem()
matchExt.MatchId = matchLast_elem.FieldByName("Id").String()*/
//ext := matchLast_elem.FieldByName("Ext").Interface().(map[string]interface{})
//matchExt.Sid = ext["win007Id"].(string)
matchExt.Sid = v.Id
v.Ext = make(map[string]interface{})
v.Ext[win007.MODULE_FLAG] = matchExt
exists := this.MatchLastService.Exist(v)
if exists {
matchLast_modify_list_slice = append(matchLast_modify_list_slice, v)
} else {
matchLast_list_slice = append(matchLast_list_slice, v)
}
his := new(pojo.MatchHis)
his.MatchLast = *v
his_exists := this.MatchHisService.Exist(his)
if his_exists {
matchHis_modify_list_slice = append(matchHis_modify_list_slice, his)
} else {
matchHis_list_slice = append(matchHis_list_slice, his)
}
}
this.MatchLastService.SaveList(matchLast_list_slice)
this.MatchLastService.ModifyList(matchLast_modify_list_slice)
this.MatchHisService.SaveList(matchHis_list_slice)
this.MatchHisService.ModifyList(matchHis_modify_list_slice)
}
./logs/foot.err.20200227
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册