Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sequoia_score
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mark
sequoia_score
Commits
ba4644fb
Commit
ba4644fb
authored
Jul 28, 2021
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
job
parent
19fa49b7
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
563 additions
and
24 deletions
+563
-24
Team.java
...mon/src/main/java/com/live/common/domain/entity/Team.java
+11
-5
AlStatBasketballTeamPlayerDto.java
...om/live/job/entity/dto/AlStatBasketballTeamPlayerDto.java
+50
-0
AlStatBasketballTeamsDto.java
...ava/com/live/job/entity/dto/AlStatBasketballTeamsDto.java
+53
-0
AlStatCountryDto.java
...c/main/java/com/live/job/entity/dto/AlStatCountryDto.java
+39
-0
AlStatFootballTeamPlayerDto.java
.../com/live/job/entity/dto/AlStatFootballTeamPlayerDto.java
+65
-0
AlStatSportsBasketballDto.java
...va/com/live/job/entity/dto/AlStatSportsBasketballDto.java
+2
-0
AlStatTeamsFootballDto.java
.../java/com/live/job/entity/dto/AlStatTeamsFootballDto.java
+35
-0
CrawlAlStatServiceImpl.java
...ava/com/live/job/service/impl/CrawlAlStatServiceImpl.java
+308
-19
No files found.
score-common/src/main/java/com/live/common/domain/entity/Team.java
View file @
ba4644fb
...
...
@@ -17,15 +17,21 @@ public class Team extends BaseStringIdEntity {
private
int
sportsId
;
private
String
originalId
;
//0 Leyu 1 AlStat
private
Integer
originalType
;
private
String
teamNameEn
;
private
String
teamNameEnFull
;
private
String
teamName
;
private
String
sportsName
;
private
String
teamNameFull
;
private
String
teamIcon
;
//0默认1热门
private
Integer
hotTeam
;
private
String
apiResponse
;
private
String
sportsName
;
private
String
country
;
//本地 sports.id
private
String
sportsDbId
;
//不用数据先已json存放
private
String
apiResponse
;
}
score-job/src/main/java/com/live/job/entity/dto/AlStatBasketballTeamPlayerDto.java
0 → 100644
View file @
ba4644fb
package
com
.
live
.
job
.
entity
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
AlStatBasketballTeamPlayerDto
{
private
String
state
;
private
List
<
BasketballTeamsPlayerDto
>
players
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
static
class
BasketballTeamsPlayerDto
{
private
Integer
id
;
private
String
name
;
private
String
nameEn
;
//性别(male: 男, female:女)
private
String
gender
;
private
Integer
areaId
;
private
String
birthday
;
private
Integer
birthAreaId
;
private
String
rnNumber
;
private
String
height
;
private
String
weight
;
private
String
position
;
//“id”: 37, //球员Id
// “name”: “戈登·海沃德”, //球员名称
// “nameEn”: “Gordon Hayward”, //球员英文名
// “areaId”: 193, //国籍
// “birthday”: “1990-03-23”, //出生日期
// “birthAreaId”: 193, //出生地
// “rnNumber”: “20”, //球衣号码
// “gender”: “male”, //性别(male: 男, female:女)
// “height”: “2.03m”, //身高
// “weight”: “102”, //体重
// “position”: “Small Forward” //位置
}
}
score-job/src/main/java/com/live/job/entity/dto/AlStatBasketballTeamsDto.java
0 → 100644
View file @
ba4644fb
package
com
.
live
.
job
.
entity
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
AlStatBasketballTeamsDto
{
private
String
state
;
private
List
<
BasketballTeamsDto
>
teams
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
static
class
BasketballTeamsDto
{
private
Integer
id
;
private
String
name
;
private
String
nameFull
;
private
String
nameEn
;
private
String
nameEnFull
;
private
String
teamType
;
private
String
gender
;
private
Integer
leagueId
;
private
Integer
areaId
;
private
String
city
;
private
String
founded
;
private
String
website
;
private
String
venueId
;
//“id”: 1, //球队Id
// “name”: “湖人”, //球队名称(简称)
// “nameFull”: “洛杉矶湖人”, //球队名称(全称)
// “nameEn”: “Lakers”, //球队英文名称(简称)
// “nameEnFull”: “Los Angeles Lakers”, //球队英文名称(全称)
// “teamType”: “club”, //球队类型(club: 俱乐部, national: 国家队)
// “gender”: “male”, //性别类型(male: 男子, female: 女子, youthMale: 青年男子, youthFemale: 青年女子)
// “leagueId”: 1, //参加联赛Id
// “areaId”: 193, //球队所在国家
// “city”: “洛杉矶”, //所在城市
// “website”: “”, //官网网址
// “founded”: “1964”, //成立时间
// “venueId”: 18 //主场球馆
}
}
score-job/src/main/java/com/live/job/entity/dto/AlStatCountryDto.java
0 → 100644
View file @
ba4644fb
package
com
.
live
.
job
.
entity
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
AlStatCountryDto
{
private
String
state
;
private
List
<
AlStatCountry
>
countries
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
static
class
AlStatCountry
{
private
Integer
id
;
private
String
nameZh
;
private
String
nameEn
;
private
Integer
area
;
private
Integer
fifaPoint
;
//“id”: 6, //国家Id
// “nameZh”: “法国”, //中文名
// “nameEn”: “France”, //英文名
// “area”: 1, //所在大洲(具体定义参考文件-个别名词解释)
// “fifaPoint”: 1718, //FIFA积分
// “fifaRank”: 3, //FIFA排名
// “areaRank”: 2 //所在大洲排名
}
}
score-job/src/main/java/com/live/job/entity/dto/AlStatFootballTeamPlayerDto.java
0 → 100644
View file @
ba4644fb
package
com
.
live
.
job
.
entity
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
AlStatFootballTeamPlayerDto
{
private
String
state
;
private
List
<
FootballTeamPlayerDto
>
players
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
static
class
FootballTeamPlayerDto
{
private
Integer
id
;
private
String
name
;
private
String
nameEn
;
private
String
country
;
private
String
birthday
;
private
Integer
marketValue
;
private
String
rnNumber
;
private
String
height
;
private
String
foot
;
private
String
position
;
private
String
mainPosition
;
private
String
sencondPosition1
;
private
String
sencondPosition2
;
private
Integer
nationalChosenTimes
;
private
Integer
nationalGoals
;
//“id”: 25, //球员Id
// “name”: “萨拉赫”, //球员名称
// “nameEn”: “Mohamed Salah”, //球员英文名
// “country”: “Egypt”, //国籍
// “birthday”: “1992-06-15”, //出生日期
// “marketValue”: 150000000, //球员当前身价(单位:欧元)
// “rnNumber”: 11, //球衣号码
// “height”: “1.75m”, //身高
// “foot”: “left”, //惯用脚(left左脚,right右脚,both左右脚)
// “position”: “Striker”, //位置(具体定义参考文件-个别名词解释)
// “mainPosition”: “Right Winger”, //主要位置(具体定义参考文件-个别名词解释)
// “sencondPosition1”: “Centre-Forward”, //次要位置1(具体定义参考文件-个别名词解释)
// “sencondPosition2”: “Left Wing”, //次要位置2(具体定义参考文件-个别名词解释)
// “clubId”: 13, //当前所属俱乐部id
// “inTeamSince”: “2017-07-01”, //入队日期
// “contactEnd”: “2023-06-30”, //当前合同截至
// “loanFromClubId”: null, //租借母队id
// “loanFromClubName”: null, //租借母队名称
// “loanFromClubContractEnd”: “”, //租借母队合同截至
// “nationalChosenTimes”: 67, //国家队入选次数
// “nationalChosenTeam”: “”, //为空表示成年国家队,U21、U18等表示各级青年队
// “nationalGoals”: 41 //国家队进球数
}
}
score-job/src/main/java/com/live/job/entity/dto/AlStatSportsBasketballDto.java
View file @
ba4644fb
...
...
@@ -35,6 +35,8 @@ public class AlStatSportsBasketballDto {
private
Integer
quarterNum
;
//每节比赛时间
private
String
quarterTime
;
//当前赛季Id
private
Integer
currSeasonId
;
// “id”: 1, //赛事Id
// “name”: “美职篮”, //赛事名称(简称)
...
...
score-job/src/main/java/com/live/job/entity/dto/AlStatTeamsFootballDto.java
0 → 100644
View file @
ba4644fb
package
com
.
live
.
job
.
entity
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
AlStatTeamsFootballDto
{
private
String
state
;
private
List
<
AlStatTeamFootballDto
>
teams
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
static
class
AlStatTeamFootballDto
{
private
Integer
id
;
private
String
name
;
private
String
nameFull
;
private
String
nameEn
;
private
String
nameEnFull
;
private
String
teamType
;
private
Integer
competitionId
;
private
String
country
;
}
}
score-job/src/main/java/com/live/job/service/impl/CrawlAlStatServiceImpl.java
View file @
ba4644fb
...
...
@@ -51,8 +51,12 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
@Resource
private
RestTemplate
restTemplate
;
@Resource
private
CountryMapper
countryMapper
;
@Resource
private
MatchOddsMapper
matchOddsMapper
;
@Resource
private
TeamPlayerMapper
teamPlayerMapper
;
@Resource
private
ScheduledTaskMapper
scheduledTaskMapper
;
@Resource
private
SystemConfigMapper
systemConfigMapper
;
...
...
@@ -116,7 +120,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
* 爬取赛事信息 (英超 - 等)
*/
// @Scheduled(fixedRate = 50 * 60 * 1000)
//
@Scheduled(cron = "01 10 02/6 * * ?")
@Scheduled
(
cron
=
"01 10 02/6 * * ?"
)
public
void
crawlSportsInfoFootball
()
{
log
.
info
(
"爬取赛事基本信息 -> 足球"
);
String
url
=
"http://data43.aistat.cn/competitions/infos?key="
+
footballKey
;
...
...
@@ -126,6 +130,13 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
AlStatSportsFootballDto
companyInfoDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatSportsFootballDto
.
class
);
if
(
companyInfoDto
.
getState
().
equals
(
"success"
))
{
for
(
AlStatSportsFootballDto
.
AlStatCompetition
competition
:
companyInfoDto
.
getCompetitions
())
{
saveOrUpdateFootball
(
competition
);
}
}
}
}
private
Sports
saveOrUpdateFootball
(
AlStatSportsFootballDto
.
AlStatCompetition
competition
){
Sports
sports
=
sportsMapper
.
selectOne
(
Wrappers
.<
Sports
>
lambdaQuery
()
.
eq
(
Sports:
:
getCompetitionShortName
,
competition
.
getName
())
.
eq
(
Sports:
:
getSourceType
,
1
)
...
...
@@ -152,16 +163,14 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
}
else
{
sportsMapper
.
updateById
(
sports
);
}
}
}
}
return
sports
;
}
/**
* 爬取赛事信息 (美国职业篮球赛 - 等)
*/
// @Scheduled(fixedRate = 50 * 60 * 1000)
//
@Scheduled(cron = "01 01 02/6 * * ?")
@Scheduled
(
cron
=
"01 01 02/6 * * ?"
)
public
void
crawlSportsInfoBasketball
()
{
log
.
info
(
"爬取赛事基本信息 -> 篮球"
);
String
url
=
"http://data71.aistat.cn/basketball/competitions/infos?key="
+
basketballKey
;
...
...
@@ -171,6 +180,14 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
AlStatSportsBasketballDto
companyInfoDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatSportsBasketballDto
.
class
);
if
(
companyInfoDto
.
getState
().
equals
(
"success"
))
{
for
(
AlStatSportsBasketballDto
.
AlStatBasketballCompetition
competition
:
companyInfoDto
.
getCompetitions
())
{
saveOrUpdateSports
(
competition
);
}
}
}
log
.
info
(
"爬取赛事基本信息 -> 篮球 完成"
);
}
private
Sports
saveOrUpdateSports
(
AlStatSportsBasketballDto
.
AlStatBasketballCompetition
competition
){
Sports
sports
=
sportsMapper
.
selectOne
(
Wrappers
.<
Sports
>
lambdaQuery
()
.
eq
(
Sports:
:
getCompetitionShortName
,
competition
.
getName
())
.
eq
(
Sports:
:
getSourceType
,
1
)
...
...
@@ -199,10 +216,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
}
else
{
sportsMapper
.
updateById
(
sports
);
}
}
}
}
log
.
info
(
"爬取赛事基本信息 -> 篮球 完成"
);
return
sports
;
}
/**
...
...
@@ -277,6 +291,280 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
}
/**
* 更新或新增足球队伍信息
*/
// @Scheduled(fixedRate = 50 * 60 * 1000)
public
void
updateOrInsertFootballTeam
()
{
log
.
info
(
"更新或新增足球队伍信息"
);
String
url
=
String
.
format
(
"http://data43.aistat.cn/teams/infos?key=%s"
,
footballKey
);
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
AlStatTeamsFootballDto
teamsFootballDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatTeamsFootballDto
.
class
);
if
(
teamsFootballDto
.
getState
().
equals
(
"success"
))
{
for
(
AlStatTeamsFootballDto
.
AlStatTeamFootballDto
team
:
teamsFootballDto
.
getTeams
())
{
threadPoolExecutor
.
execute
(()
->
{
try
{
Sports
sports
=
sportsMapper
.
selectOne
(
Wrappers
.<
Sports
>
lambdaQuery
()
.
eq
(
Sports:
:
getSourceId
,
team
.
getCompetitionId
())
.
eq
(
Sports:
:
getSportsId
,
0
)
.
eq
(
Sports:
:
getSourceType
,
1
)
);
Team
teamDb
=
teamMapper
.
selectOne
(
Wrappers
.<
Team
>
lambdaQuery
()
.
eq
(
Team:
:
getDeleted
,
0
)
.
eq
(
Team:
:
getTeamName
,
team
.
getName
())
.
eq
(
Team:
:
getOriginalType
,
1
)
);
if
(
teamDb
==
null
)
{
teamDb
=
new
Team
();
}
teamDb
.
setOriginalId
(
""
+
team
.
getId
());
teamDb
.
setTeamNameEn
(
team
.
getNameEn
());
teamDb
.
setTeamNameEnFull
(
team
.
getNameEnFull
());
teamDb
.
setTeamName
(
team
.
getName
());
teamDb
.
setTeamNameFull
(
team
.
getNameFull
());
teamDb
.
setCountry
(
team
.
getCountry
());
teamDb
.
setTeamIcon
(
"http://dt.aistat.cn/teams/"
+
team
.
getId
()
+
".png"
);
teamDb
.
setOriginalType
(
1
);
teamDb
.
setSportsId
(
0
);
teamDb
.
setSportsDbId
(
sports
!=
null
?
sports
.
getId
()
:
null
);
teamDb
.
setApiResponse
(
JSON
.
toJSONString
(
team
));
if
(
StringUtils
.
isBlank
(
teamDb
.
getId
()))
{
String
id
=
IdGen
.
uuid
();
teamDb
.
setId
(
id
);
teamMapper
.
insert
(
teamDb
);
}
else
{
teamMapper
.
updateById
(
teamDb
);
}
log
.
info
(
"新增或修改一个队伍信息"
);
}
catch
(
Exception
e
)
{
log
.
warn
(
e
.
getMessage
());
}
});
}
}
}
log
.
info
(
"更新或新增足球队伍信息完成"
);
}
/**
* 更新或新增篮球队伍信息
*/
@Scheduled
(
fixedRate
=
50
*
60
*
1000
)
public
void
updateOrInsertBasketballTeam
()
{
log
.
info
(
"更新或新增篮球队伍信息"
);
String
url
=
"http://data71.aistat.cn/basketball/competitions/infos?key="
+
basketballKey
;
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
AlStatSportsBasketballDto
companyInfoDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatSportsBasketballDto
.
class
);
if
(
companyInfoDto
.
getState
().
equals
(
"success"
))
{
threadPoolExecutor
.
execute
(()
->
{
try
{
for
(
AlStatSportsBasketballDto
.
AlStatBasketballCompetition
basketball
:
companyInfoDto
.
getCompetitions
())
{
Sports
sports
=
sportsMapper
.
selectOne
(
Wrappers
.<
Sports
>
lambdaQuery
()
.
eq
(
Sports:
:
getCompetitionShortName
,
basketball
.
getName
())
.
eq
(
Sports:
:
getSourceType
,
1
)
);
if
(
sports
==
null
)
{
sports
=
saveOrUpdateSports
(
basketball
);
}
requestBasketball
(
sports
.
getId
(),
basketball
.
getCurrSeasonId
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
});
}
}
log
.
info
(
"更新或新增篮球队伍信息完成"
);
}
private
void
requestBasketball
(
String
sportsDbId
,
int
seasonId
)
{
String
url
=
String
.
format
(
"http://data71.aistat.cn/basketball/teams/infos?key=%s&type=season&id=%s"
,
basketballKey
,
seasonId
);
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
AlStatBasketballTeamsDto
companyInfoDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatBasketballTeamsDto
.
class
);
if
(
companyInfoDto
.
getState
().
equals
(
"success"
))
{
for
(
AlStatBasketballTeamsDto
.
BasketballTeamsDto
team
:
companyInfoDto
.
getTeams
())
{
try
{
Team
teamDb
=
teamMapper
.
selectOne
(
Wrappers
.<
Team
>
lambdaQuery
()
.
eq
(
Team:
:
getDeleted
,
0
)
.
eq
(
Team:
:
getTeamName
,
team
.
getName
())
.
eq
(
Team:
:
getOriginalType
,
1
)
);
if
(
teamDb
==
null
)
{
teamDb
=
new
Team
();
}
teamDb
.
setOriginalId
(
""
+
team
.
getId
());
teamDb
.
setTeamNameEn
(
team
.
getNameEn
());
teamDb
.
setTeamNameEnFull
(
team
.
getNameEnFull
());
teamDb
.
setTeamName
(
team
.
getName
());
teamDb
.
setTeamNameFull
(
team
.
getNameFull
());
teamDb
.
setCountry
(
team
.
getAreaId
()
+
""
);
teamDb
.
setTeamIcon
(
"http://basketball.aistat.cn/teams/"
+
team
.
getId
()
+
".png"
);
teamDb
.
setOriginalType
(
1
);
teamDb
.
setSportsId
(
1
);
teamDb
.
setSportsDbId
(
sportsDbId
);
teamDb
.
setApiResponse
(
JSON
.
toJSONString
(
team
));
if
(
StringUtils
.
isBlank
(
teamDb
.
getId
()))
{
String
id
=
IdGen
.
uuid
();
teamDb
.
setId
(
id
);
teamMapper
.
insert
(
teamDb
);
}
else
{
teamMapper
.
updateById
(
teamDb
);
}
log
.
info
(
"新增或修改一个队伍信息"
);
}
catch
(
Exception
e
)
{
log
.
warn
(
e
.
getMessage
());
}
}
}
}
}
private
void
crawlCountry
()
{
String
url
=
"http://data43.aistat.cn/countries/infos?key="
+
footballKey
;
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
AlStatCountryDto
companyInfoDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatCountryDto
.
class
);
if
(
companyInfoDto
.
getState
().
equals
(
"success"
))
{
for
(
AlStatCountryDto
.
AlStatCountry
country
:
companyInfoDto
.
getCountries
())
{
try
{
countryMapper
.
insert
(
Country
.
builder
()
.
apiResponse
(
JSON
.
toJSONString
(
country
))
.
id
(
country
.
getId
())
.
nameEn
(
country
.
getNameEn
())
.
nameZh
(
country
.
getNameZh
())
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
/**
* 爬取球员信息
*/
// @Scheduled(fixedRate = 50 * 60 * 1000)
public
void
crawlPlayerInfo
()
{
crawlCountry
();
List
<
Team
>
teams
=
teamMapper
.
selectList
(
Wrappers
.<
Team
>
lambdaQuery
()
.
eq
(
Team:
:
getDeleted
,
0
)
.
eq
(
Team:
:
getOriginalType
,
1
)
.
orderByDesc
(
Team:
:
getCreateTime
)
);
for
(
Team
team
:
teams
)
{
threadPoolExecutor
.
execute
(()
->
{
if
(
team
.
getSportsId
()
==
0
)
{
//足球
crawlFootballPlayerInfo
(
team
.
getOriginalId
(),
team
.
getId
());
}
else
if
(
team
.
getSportsId
()
==
1
)
{
//篮球
crawlBasketballPlayerInfo
(
team
.
getOriginalId
(),
team
.
getId
());
}
});
log
.
info
(
"新增:{}"
,
team
.
getTeamName
());
try
{
Thread
.
sleep
(
500
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
log
.
info
(
"更新所有球队球员"
);
}
private
void
crawlFootballPlayerInfo
(
String
teamId
,
String
dbTeamId
)
{
String
url
=
String
.
format
(
"http://data43.aistat.cn/players/infos?key=%s&teamId=%s"
,
footballKey
,
teamId
);
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
AlStatFootballTeamPlayerDto
companyInfoDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatFootballTeamPlayerDto
.
class
);
if
(
companyInfoDto
.
getState
().
equals
(
"success"
))
{
for
(
AlStatFootballTeamPlayerDto
.
FootballTeamPlayerDto
playerDto
:
companyInfoDto
.
getPlayers
())
{
try
{
teamPlayerMapper
.
insert
(
TeamPlayer
.
builder
()
.
sourceId
(
playerDto
.
getId
())
.
sportsId
(
0
)
.
apiResponse
(
JSON
.
toJSONString
(
playerDto
))
.
country
(
playerDto
.
getCountry
())
.
birthday
(
playerDto
.
getBirthday
())
.
foot
(
playerDto
.
getFoot
())
.
name
(
playerDto
.
getName
())
.
nameEn
(
playerDto
.
getNameEn
())
.
marketValue
(
playerDto
.
getMarketValue
())
.
rnNumber
(
playerDto
.
getRnNumber
())
.
height
(
playerDto
.
getHeight
())
.
position
(
playerDto
.
getPosition
())
.
mainPosition
(
playerDto
.
getMainPosition
())
.
secondPosition1
(
playerDto
.
getSencondPosition1
())
.
secondPosition2
(
playerDto
.
getSencondPosition2
())
.
nationalChosenTimes
(
playerDto
.
getNationalChosenTimes
())
.
nationalGoals
(
playerDto
.
getNationalGoals
())
.
teamId
(
dbTeamId
)
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
()
+
"_"
+
playerDto
.
toString
());
}
}
}
}
}
private
void
crawlBasketballPlayerInfo
(
String
teamId
,
String
dbTeamId
)
{
String
url
=
String
.
format
(
"http://data71.aistat.cn/basketball/players/infos?key=%s&teamId=%s"
,
basketballKey
,
teamId
);
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
AlStatBasketballTeamPlayerDto
companyInfoDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
AlStatBasketballTeamPlayerDto
.
class
);
if
(
companyInfoDto
.
getState
().
equals
(
"success"
))
{
for
(
AlStatBasketballTeamPlayerDto
.
BasketballTeamsPlayerDto
playerDto
:
companyInfoDto
.
getPlayers
())
{
try
{
Country
country
=
countryMapper
.
selectById
(
playerDto
.
getAreaId
());
Country
birthCountry
=
countryMapper
.
selectById
(
playerDto
.
getBirthAreaId
());
teamPlayerMapper
.
insert
(
TeamPlayer
.
builder
()
.
sourceId
(
playerDto
.
getId
())
.
sportsId
(
1
)
.
apiResponse
(
JSON
.
toJSONString
(
playerDto
))
.
country
(
country
!=
null
?
country
.
getNameZh
()
:
null
)
.
birthCountry
(
birthCountry
!=
null
?
birthCountry
.
getNameZh
()
:
null
)
.
birthday
(
playerDto
.
getBirthday
())
.
name
(
playerDto
.
getName
())
.
nameEn
(
playerDto
.
getNameEn
())
.
rnNumber
(
playerDto
.
getRnNumber
())
.
height
(
playerDto
.
getHeight
())
.
weight
(
playerDto
.
getWeight
())
.
position
(
playerDto
.
getPosition
())
.
gender
(
playerDto
.
getGender
())
.
teamId
(
dbTeamId
)
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
()
+
"_"
+
playerDto
.
toString
());
}
}
}
}
}
/**
* 爬取赛事积分榜 -> 足球
*/
// @Scheduled(fixedRate = 50 * 60 * 1000)
...
...
@@ -311,7 +599,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
);
if
(
sports
==
null
)
continue
;
Team
team
=
saveTeam
(
companyInfo
.
getTeamName
(),
companyInfo
.
getTeamId
());
Team
team
=
saveTeam
(
companyInfo
.
getTeamName
(),
companyInfo
.
getTeamId
()
,
0
);
FootballLeagueRank
footballLeagueRank
=
footballLeagueRankMapper
.
selectOne
(
Wrappers
.<
FootballLeagueRank
>
lambdaQuery
()
.
eq
(
FootballLeagueRank:
:
getGroupName
,
groupNames
.
get
(
companyInfo
.
getGroupId
()))
...
...
@@ -395,7 +683,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
if
(
sports
==
null
)
continue
;
Team
team
=
saveTeam
(
standingInfo
.
getTeamName
(),
standingInfo
.
getTeamId
());
Team
team
=
saveTeam
(
standingInfo
.
getTeamName
(),
standingInfo
.
getTeamId
()
,
1
);
BasketballLeagueRank
basketballLeagueRank
=
basketballLeagueRankMapper
.
selectOne
(
Wrappers
.<
BasketballLeagueRank
>
lambdaQuery
()
.
eq
(
BasketballLeagueRank:
:
getGroupName
,
group
.
getGroupName
())
...
...
@@ -452,7 +740,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
* 10 分钟爬取一次 AlStat 足球实时比分
*/
// @Scheduled(fixedRate = 2 * 60 * 60 * 1000)
@Scheduled
(
cron
=
"
11 11/1
0 * * * ?"
)
@Scheduled
(
cron
=
"
51 11/2
0 * * * ?"
)
public
void
crawlAlStatFootballScore
()
{
String
url
=
String
.
format
(
"http://data43.aistat.cn/matchs/liveScores?key=%s"
,
footballKey
);
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
...
...
@@ -531,7 +819,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
}
}
for
(
String
uniqueUrl
:
uniqueUrls
)
{
for
(
String
uniqueUrl
:
uniqueUrls
)
{
Match
match
=
matchMapper
.
selectOne
(
Wrappers
.<
Match
>
lambdaQuery
()
.
eq
(
Match:
:
getCrawlUrl
,
uniqueUrl
)
.
eq
(
Match:
:
getSourceType
,
1
)
...
...
@@ -574,7 +862,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
}
}
for
(
String
uniqueUrl
:
uniqueUrls
)
{
for
(
String
uniqueUrl
:
uniqueUrls
)
{
Match
match
=
matchMapper
.
selectOne
(
Wrappers
.<
Match
>
lambdaQuery
()
.
eq
(
Match:
:
getCrawlUrl
,
uniqueUrl
)
.
eq
(
Match:
:
getSourceType
,
1
)
...
...
@@ -888,8 +1176,8 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
return
;
String
sportsId
=
saveSports
(
matchInfoDto
.
getCompetitionName
(),
0
);
Team
away
=
saveTeam
(
matchInfoDto
.
getAwayTeamName
(),
matchInfoDto
.
getAwayTeamId
());
Team
home
=
saveTeam
(
matchInfoDto
.
getHomeTeamName
(),
matchInfoDto
.
getHomeTeamId
());
Team
away
=
saveTeam
(
matchInfoDto
.
getAwayTeamName
(),
matchInfoDto
.
getAwayTeamId
()
,
0
);
Team
home
=
saveTeam
(
matchInfoDto
.
getHomeTeamName
(),
matchInfoDto
.
getHomeTeamId
()
,
0
);
String
matchId
=
IdGen
.
uuid
();
if
(
match
!=
null
)
...
...
@@ -1055,8 +1343,8 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
return
;
}
String
sportsId
=
saveSports
(
matchInfoDto
.
getCompetitionName
(),
1
);
Team
away
=
saveTeam
(
matchInfoDto
.
getAwayTeamName
(),
matchInfoDto
.
getAwayTeamId
());
Team
home
=
saveTeam
(
matchInfoDto
.
getHomeTeamName
(),
matchInfoDto
.
getHomeTeamId
());
Team
away
=
saveTeam
(
matchInfoDto
.
getAwayTeamName
(),
matchInfoDto
.
getAwayTeamId
()
,
1
);
Team
home
=
saveTeam
(
matchInfoDto
.
getHomeTeamName
(),
matchInfoDto
.
getHomeTeamId
()
,
1
);
String
matchId
=
IdGen
.
uuid
();
if
(
match
!=
null
)
{
...
...
@@ -1353,7 +1641,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
throw
new
RuntimeException
();
}
private
Team
saveTeam
(
String
teamName
,
Integer
originalId
)
throws
RuntimeException
{
private
Team
saveTeam
(
String
teamName
,
Integer
originalId
,
Integer
sportsId
)
throws
RuntimeException
{
lock
.
lock
();
try
{
Team
teamDb
=
teamMapper
.
selectOne
(
Wrappers
.<
Team
>
lambdaQuery
()
...
...
@@ -1372,6 +1660,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
.
teamIcon
(
"http://dt.aistat.cn/teams/"
+
originalId
+
".png"
)
.
teamName
(
teamName
)
.
originalType
(
1
)
.
sportsId
(
sportsId
)
.
build
();
teamMapper
.
insert
(
saveTeam
);
return
saveTeam
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment