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
19fa49b7
Commit
19fa49b7
authored
Jul 28, 2021
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新赛程
parent
a3090728
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
290 additions
and
1235 deletions
+290
-1235
UserInfoResponse.java
...java/com/live/common/domain/dto/api/UserInfoResponse.java
+1
-1
UserServiceImpl.java
...in/java/com/live/common/service/impl/UserServiceImpl.java
+1
-6
ScheduledService.java
.../src/main/java/com/live/job/service/ScheduledService.java
+287
-287
ChatTimedSendingServiceImpl.java
...om/live/job/service/impl/ChatTimedSendingServiceImpl.java
+0
-104
CrawlAlStatServiceImpl.java
...ava/com/live/job/service/impl/CrawlAlStatServiceImpl.java
+1
-1
CrawlLeYuServiceImpl.java
.../java/com/live/job/service/impl/CrawlLeYuServiceImpl.java
+0
-836
No files found.
score-common/src/main/java/com/live/common/domain/dto/api/UserInfoResponse.java
View file @
19fa49b7
...
@@ -21,7 +21,7 @@ public class UserInfoResponse {
...
@@ -21,7 +21,7 @@ public class UserInfoResponse {
private
Integer
message
;
private
Integer
message
;
private
Integer
collect
Match
;
private
Integer
collect
Article
;
private
Integer
collectTeam
;
private
Integer
collectTeam
;
...
...
score-common/src/main/java/com/live/common/service/impl/UserServiceImpl.java
View file @
19fa49b7
...
@@ -577,11 +577,6 @@ public class UserServiceImpl implements UserService {
...
@@ -577,11 +577,6 @@ public class UserServiceImpl implements UserService {
.
eq
(
UserMessage:
:
getUserId
,
account
.
getId
())
.
eq
(
UserMessage:
:
getUserId
,
account
.
getId
())
);
);
long
collectMatch
=
userReserveMapper
.
selectCount
(
Wrappers
.<
UserReserve
>
lambdaQuery
()
.
eq
(
UserReserve:
:
getDeleted
,
StatusEnum
.
ENABLE
.
getCode
())
.
eq
(
UserReserve:
:
getUserId
,
account
.
getId
())
.
eq
(
UserReserve:
:
getType
,
0
)
);
long
collectTeam
=
userReserveMapper
.
selectCount
(
Wrappers
.<
UserReserve
>
lambdaQuery
()
long
collectTeam
=
userReserveMapper
.
selectCount
(
Wrappers
.<
UserReserve
>
lambdaQuery
()
.
eq
(
UserReserve:
:
getDeleted
,
StatusEnum
.
ENABLE
.
getCode
())
.
eq
(
UserReserve:
:
getDeleted
,
StatusEnum
.
ENABLE
.
getCode
())
.
eq
(
UserReserve:
:
getUserId
,
account
.
getId
())
.
eq
(
UserReserve:
:
getUserId
,
account
.
getId
())
...
@@ -594,7 +589,7 @@ public class UserServiceImpl implements UserService {
...
@@ -594,7 +589,7 @@ public class UserServiceImpl implements UserService {
.
userName
(
account
.
getUserName
())
.
userName
(
account
.
getUserName
())
.
userDesc
(
account
.
getUserDesc
())
.
userDesc
(
account
.
getUserDesc
())
.
message
((
int
)
count
+
1
)
.
message
((
int
)
count
+
1
)
.
collect
Match
((
int
)
collectMatch
)
.
collect
Article
(
0
)
.
collectTeam
((
int
)
collectTeam
)
.
collectTeam
((
int
)
collectTeam
)
.
build
());
.
build
());
}
}
...
...
score-job/src/main/java/com/live/job/service/ScheduledService.java
View file @
19fa49b7
//package com.live.job.service;
package
com
.
live
.
job
.
service
;
//
//import com.live.common.domain.entity.ScheduledTask;
import
com.live.common.domain.entity.ScheduledTask
;
//import com.live.common.mapper.ScheduledTaskMapper;
import
com.live.common.mapper.ScheduledTaskMapper
;
//import com.live.job.constant.CrawlPlatformEnum;
import
com.live.job.constant.CrawlPlatformEnum
;
//import lombok.extern.slf4j.Slf4j;
import
lombok.extern.slf4j.Slf4j
;
//import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Autowired
;
//import org.springframework.context.annotation.Lazy;
import
org.springframework.context.annotation.Lazy
;
//import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.scheduling.annotation.Scheduled
;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
//import org.springframework.stereotype.Component;
import
org.springframework.stereotype.Component
;
//
//import javax.annotation.Resource;
import
javax.annotation.Resource
;
//import java.time.Instant;
import
java.time.Instant
;
//import java.util.Date;
import
java.util.Date
;
//import java.util.concurrent.ThreadPoolExecutor;
import
java.util.concurrent.ThreadPoolExecutor
;
//
//@Slf4j
@Slf4j
//@Component
@Component
//public class ScheduledService {
public
class
ScheduledService
{
//
// private ThreadPoolExecutor threadPoolExecutor;
private
ThreadPoolExecutor
threadPoolExecutor
;
// private CrawlStrategyFactory crawStrategyFactory;
private
CrawlStrategyFactory
crawStrategyFactory
;
// private ScheduledTaskMapper scheduledTaskMapper;
private
ScheduledTaskMapper
scheduledTaskMapper
;
// @Resource
@Resource
// private ThreadPoolTaskScheduler taskScheduler;
private
ThreadPoolTaskScheduler
taskScheduler
;
//
//
/**
* 10 分钟爬取一次 AlStat 足球盘口指数
*/
// @Scheduled(fixedRate = 10 * 60 * 1000)
// @Scheduled(cron = "01 15/10 * * * ?")
public
void
crawlIndexCompanyFootball
(){
String
desc
=
"10 分钟爬取一次 AlStat 足球盘口指数"
;
log
.
info
(
desc
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlIndexCompanyFootball"
)
.
methodDesc
(
desc
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
AlStat
.
getCode
())
.
crawlIndexCompanyFootball
(
"http://data61.aistat.cn/zhishu/mainOdds?key="
);
}
/**
* 11 分钟爬取一次 AlStat 篮球盘口指数
*/
// @Scheduled(fixedRate = 10 * 60 * 1000)
// @Scheduled(cron = "01 13/11 * * * ?")
public
void
crawlIndexCompanyBasketball
(){
String
desc
=
"11 分钟爬取一次 AlStat 篮球盘口指数"
;
log
.
info
(
desc
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlIndexCompanyBasketball"
)
.
methodDesc
(
desc
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
AlStat
.
getCode
())
.
crawlIndexCompanyBasketball
(
"http://data91.aistat.cn/basketball/zhishu/mainOdds?key="
);
}
/**
* 20 分钟爬取一次 AlStat 篮球赛程
*/
// @Scheduled(fixedRate = 2 * 60 * 60 * 1000)
@Scheduled
(
cron
=
"01 40/20 * * * ?"
)
public
void
crawlAlStatBasketball
(){
log
.
info
(
"20 分钟爬取一次 AlStat 篮球赛程"
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlAlStatBasketball"
)
.
methodDesc
(
"20 分钟爬取一次 AlStat 篮球赛程"
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
AlStat
.
getCode
())
.
crawlScheduleMatch
(
"http://data71.aistat.cn/basketball/matchs/queryFixtureByDate?key="
);
}
/**
* 篮球赛事阶段比分 -> 赛况
*/
// @Scheduled(fixedRate = 10 * 60 * 1000)
@Scheduled
(
cron
=
"01 42/10 * * * ?"
)
public
void
crawlAlStatBasketballMatchStageScore
(){
log
.
info
(
"10 分钟爬取一次 AlStat 篮球赛况"
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlAlStatBasketballMatchStageScore"
)
.
methodDesc
(
"10 分钟爬取一次 AlStat 篮球赛况"
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
AlStat
.
getCode
())
.
crawlMatchStageScore
(
"http://data71.aistat.cn/basketball/matchs/liveScores?key="
);
}
/**
* 20 分钟爬取一次 AlStat 足球赛程
*/
// @Scheduled(fixedRate = 2 * 60 * 60 * 1000)
@Scheduled
(
cron
=
"01 31/20 * * * ?"
)
public
void
crawlAlStatFootball
(){
log
.
info
(
"20 分钟爬取一次 AlStat 足球赛程"
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlAlStatFootball"
)
.
methodDesc
(
"20 分钟爬取一次 AlStat 足球赛程"
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
AlStat
.
getCode
())
.
crawlScheduleMatch
(
"http://data43.aistat.cn/competitions/queryFixtureByDate?key="
);
}
@Scheduled
(
cron
=
"01 20 01 * * ?"
)
public
void
crawlAlStatFootballEverOne
(){
String
desc
=
"每天爬取一次 3 天后的 AlStat 足球赛程"
;
log
.
info
(
desc
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlAlStatFootballEverOne"
)
.
methodDesc
(
desc
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
AlStat
.
getCode
())
.
crawlScheduleMatchByDay
(
"http://data43.aistat.cn/competitions/queryFixtureByDate?key="
,
3
);
}
@Scheduled
(
cron
=
"01 20 02 * * ?"
)
public
void
crawlAlStatBasketballEverOne
(){
String
desc
=
"每天爬取一次 3 天后的 AlStat 篮球赛程"
;
log
.
info
(
desc
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlAlStatBasketballEverOne"
)
.
methodDesc
(
desc
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
AlStat
.
getCode
())
.
crawlScheduleMatchByDay
(
"http://data71.aistat.cn/basketball/matchs/liveScores?key="
,
3
);
}
/**
* 每天爬取一次资讯
*/
// @Scheduled(fixedRate = 5 * 60 * 60 * 1000)
@Scheduled
(
cron
=
"01 10 0/05 * * ?"
)
public
void
crawlArticle
()
{
log
.
info
(
"五小时爬取资讯"
);
scheduledTaskMapper
.
insert
(
ScheduledTask
.
builder
()
.
createTime
(
new
Date
())
.
method
(
"crawlArticle"
)
.
methodDesc
(
"五小时爬取资讯"
)
.
build
());
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
ARTICLE24BWZ
.
getCode
())
.
crawlScheduleArticle
(
"https://www.24zbw.com/news/lanqiu/"
);
taskScheduler
.
schedule
(()
->
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
ARTICLE24BWZ
.
getCode
())
.
crawlScheduleArticle
(
"https://www.24zbw.com/news/zuqiu/"
),
Instant
.
now
().
plusSeconds
(
2
*
60
));
taskScheduler
.
schedule
(()
->
crawStrategyFactory
.
getCrawMatchService
(
CrawlPlatformEnum
.
ARTICLE24BWZ
.
getCode
())
.
crawlScheduleArticle
(
"https://www.24zbw.com/news/tag/shenshuiqu/"
),
Instant
.
now
().
plusSeconds
(
4
*
60
));
}
// /**
// /**
// *
10 分钟爬取一次 AlStat 足球盘口指数
// *
每 5 分钟更新 sportlive360 赛程直播源
// */
// */
//// @Scheduled(fixedRate = 10 * 60 * 1000)
// @Scheduled(cron = "50 01/5 * * * ?")
// @Scheduled(cron = "01 15/10 * * * ?")
// public void updateSportLive360List() {
// public void crawlIndexCompanyFootball(){
// String desc = "10 分钟爬取一次 AlStat 足球盘口指数";
// log.info(desc);
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("
crawlIndexCompanyFootball
")
// .method("
updateSportLive360List
")
// .methodDesc(
desc
)
// .methodDesc(
"每 5 分钟更新 sportlive360 赛程直播源"
)
// .build());
// .build());
//
//
//
crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.AlStat.getCode())
//
threadPoolExecutor.execute(() ->
//
.crawlIndexCompanyFootball("http://data61.aistat.cn/zhishu/mainOdds?key="
);
//
crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.SportLive360.getCode()).crawlScheduleMatch(null)
);
// }
// }
//
//
// /**
// /**
// *
11 分钟爬取一次 AlStat 篮球盘口指数
// *
每天爬取一次 乐鱼 赛事 篮球
// */
// */
//// @Scheduled(fixedRate = 10 * 60 * 1000)
// @Scheduled(cron = "01 01/12 * * * ?")
// @Scheduled(cron = "01 13/11 * * * ?")
// public void crawlBasketball() {
// public void crawlIndexCompanyBasketball(){
// log.info("爬取篮球赛事");
// String desc = "11 分钟爬取一次 AlStat 篮球盘口指数";
// log.info(desc);
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("crawl
IndexCompany
Basketball")
// .method("crawlBasketball")
// .methodDesc(
desc
)
// .methodDesc(
"12 分钟爬取一次 乐鱼 赛事 篮球"
)
// .build());
// .build());
//
//
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.
AlStat
.getCode())
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.
LeYu
.getCode())
// .crawl
IndexCompanyBasketball("http://data91.aistat.cn/basketball/zhishu/mainOdds?key=
");
// .crawl
ScheduleMatch("http://preview.611.com/api/Index/getLiveData?tabId=b5f013cd-777b-4b36-85b1-a0f9cbc0a5ee&tabName=%E7%AF%AE%E7%90%83&groupName=&millinsecond=&isFuture=true
");
// }
// }
//
//
// /**
// /**
// *
20 分钟爬取一次 AlStat 篮球赛程
// *
每天爬取一次 乐鱼 赛事 足球
// */
// */
//// @Scheduled(fixedRate = 2 * 60 * 60 * 1000)
// @Scheduled(cron = "10 01/11 * * * ?")
// @Scheduled(cron = "01 20/20 * * * ?")
// public void crawlFootball() {
// public void crawlAlStatBasketball(){
// log.info("爬取足球赛事");
// log.info("20 分钟爬取一次 AlStat 篮球赛程");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("crawl
AlStatBaske
tball")
// .method("crawl
Foo
tball")
// .methodDesc("
20 分钟爬取一次 AlStat 篮球赛程
")
// .methodDesc("
11 分钟爬取一次 乐鱼 赛事 足球
")
// .build());
// .build());
//
//
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.
AlStat
.getCode())
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.
LeYu
.getCode())
// .crawlScheduleMatch("http://
data71.aistat.cn/basketball/matchs/queryFixtureByDate?key=
");
// .crawlScheduleMatch("http://
preview.611.com/api/Index/getLiveData?tabId=0ecfe170-15de-4c6d-ae89-fb37920ea616&tabName=%E8%B6%B3%E7%90%83&groupName=&millinsecond=&isFuture=true
");
// }
// }
//
//
// /**
// @Scheduled(cron = "01 02/10 * * * ?")
// * 篮球赛事阶段比分 -> 赛况
// public void updateMatchSchedule() {
// */
// log.info("更新乐鱼赛程");
//// @Scheduled(fixedRate = 10 * 60 * 1000)
// @Scheduled(cron = "01 12/10 * * * ?")
// public void crawlAlStatBasketballMatchStageScore(){
// log.info("10 分钟爬取一次 AlStat 篮球赛况");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("
crawlAlStatBasketballMatchStageScor
e")
// .method("
updateMatchSchedul
e")
// .methodDesc("10
分钟爬取一次 AlStat 篮球赛况
")
// .methodDesc("10
分钟 乐鱼 赛程
")
// .build());
// .build());
//
//
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.AlStat.getCode())
// updateMatchStateService.updateStateMatch();
// .crawlMatchStageScore("http://data71.aistat.cn/basketball/matchs/liveScores?key=");
// }
// }
//
//
// /**
// /**
// *
20 分钟爬取一次 AlStat 足球
赛程
// *
每 30 分钟更新 乐鱼
赛程
// */
// */
//// @Scheduled(fixedRate = 2 * 60 * 60 * 1000)
// @Scheduled(cron = "40 30/30 * * * ?")
// @Scheduled(cron = "01 21/20 * * * ?")
// public void updateMatchList() {
// public void crawlAlStatFootball(){
// log.info("更新赛程");
// log.info("20 分钟爬取一次 AlStat 足球赛程");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("
crawlAlStatFootball
")
// .method("
updateMatchList
")
// .methodDesc("
20 分钟爬取一次 AlStat 足球
赛程")
// .methodDesc("
每 30 分钟更新 乐鱼
赛程")
// .build());
// .build());
//
//
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.AlStat.getCode())
// threadPoolExecutor.execute(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.LeYu.getCode()).updateMatchList());
// .crawlScheduleMatch("http://data43.aistat.cn/competitions/queryFixtureByDate?key=");
// }
// }
//
//
// @Scheduled(cron = "01 10 01 * * ?")
// /**
// public void crawlAlStatFootballEverOne(){
// * 每 10 分钟爬取一次 UU球 主播信息
// String desc = "每天爬取一次 3 天后的 AlStat 足球赛程";
// */
// log.info(desc);
// @Scheduled(cron = "50 10/10 * * * ?")
// public void crawlUUQiuAnchor() {
// log.info("爬取主播信息");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("crawl
AlStatFootballEverOne
")
// .method("crawl
UUQiuAnchor
")
// .methodDesc(
desc
)
// .methodDesc(
"每 10 分钟爬取一次 UU球 主播信息"
)
// .build());
// .build());
//
//
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.AlStat.getCode())
// threadPoolExecutor.execute(() ->
// .crawlScheduleMatchByDay("http://data43.aistat.cn/competitions/queryFixtureByDate?key=", 3);
// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.UUQiu.getCode()).crawlAnchor()
// );
// }
// }
//
//
// @Scheduled(cron = "01 10 02 * * ?")
// /**
// public void crawlAlStatBasketballEverOne(){
// * 每 30 分钟更新 UU球 主播
// String desc = "每天爬取一次 3 天后的 AlStat 篮球赛程";
// */
// log.info(desc);
// @Scheduled(cron = "20 30/30 * * * ?")
// public void updateUUQiuAnchor() {
// log.info("更新主播");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("
crawlAlStatBasketballEverOne
")
// .method("
updateUUQiuAnchor
")
// .methodDesc(
desc
)
// .methodDesc(
"每 30 分钟更新 UU球 主播"
)
// .build());
// .build());
//
//
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.AlStat.getCode())
// threadPoolExecutor.execute(() ->
// .crawlScheduleMatchByDay("http://data71.aistat.cn/basketball/matchs/liveScores?key=", 3);
// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.UUQiu.getCode()).updateAllAnchor()
// );
// }
// }
//
//
// /**
// /**
// * 每
天爬取一次资讯
// * 每
30 分钟更新 UU球 赛程
// */
// */
//// @Scheduled(fixedRate = 5 * 60 * 60 * 1000)
// @Scheduled(cron = "33 30/30 * * * ?")
// @Scheduled(cron = "01 01 0/05 * * ?")
// public void crawlUUQiuMatchList() {
// public void crawlArticle() {
// log.info("更新 UU球 赛程");
// log.info("五小时爬取资讯");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("crawl
Article
")
// .method("crawl
UUQiuMatchList
")
// .methodDesc("
五小时爬取资讯
")
// .methodDesc("
每 30 分钟更新 UU球 赛程
")
// .build());
// .build());
//
//
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode())
// threadPoolExecutor.execute(() ->
// .crawlScheduleArticle("https://www.24zbw.com/news/lanqiu/");
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.UUQiu.getCode()).crawlScheduleMatch("http://uuqiu.net/match/list")
//
// );
// taskScheduler.schedule(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode())
// .crawlScheduleArticle("https://www.24zbw.com/news/zuqiu/"), Instant.now().plusSeconds(2 * 60));
//
// taskScheduler.schedule(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode())
// .crawlScheduleArticle("https://www.24zbw.com/news/tag/shenshuiqu/"), Instant.now().plusSeconds(4 * 60));
// }
// }
//
//
// /**
// /**
// * 每
5 分钟更新 sportlive360 赛程直播源
// * 每
10 分钟爬取一次 红杉 主播信息
// */
// */
// @Scheduled(cron = "50 01/5 * * * ?")
// @Scheduled(cron = "10 10/10 * * * ?")
// public void updateSportLive360List() {
// public void crawlSequoiaAnchor() {
// log.info("爬取主播信息");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .createTime(new Date())
// .method("
updateSportLive360List
")
// .method("
crawlSequoiaAnchor
")
// .methodDesc("每
5 分钟更新 sportlive360 赛程直播源
")
// .methodDesc("每
10 分钟爬取一次 红杉 主播信息
")
// .build());
// .build());
//
//
// threadPoolExecutor.execute(() ->
// threadPoolExecutor.execute(() ->
// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.SportLive360.getCode()).crawlScheduleMatch(null));
// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.Sequoia.getCode()).crawlAnchor()
// );
// }
// }
//
//
//// /**
// /**
//// * 每天爬取一次 乐鱼 赛事 篮球
// * 每 30 分钟更新 红杉 主播
//// */
// */
//// @Scheduled(cron = "01 01/12 * * * ?")
// @Scheduled(cron = "30 30/30 * * * ?")
//// public void crawlBasketball() {
// public void updateSequoiaAnchor() {
//// log.info("爬取篮球赛事");
// log.info("更新主播");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
// .createTime(new Date())
//// .method("crawlBasketball")
// .method("updateSequoiaAnchor")
//// .methodDesc("12 分钟爬取一次 乐鱼 赛事 篮球")
// .methodDesc("每 30 分钟更新 红杉 主播")
//// .build());
// .build());
////
//// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.LeYu.getCode())
//// .crawlScheduleMatch("http://preview.611.com/api/Index/getLiveData?tabId=b5f013cd-777b-4b36-85b1-a0f9cbc0a5ee&tabName=%E7%AF%AE%E7%90%83&groupName=&millinsecond=&isFuture=true");
//// }
////
//// /**
//// * 每天爬取一次 乐鱼 赛事 足球
//// */
//// @Scheduled(cron = "10 01/11 * * * ?")
//// public void crawlFootball() {
//// log.info("爬取足球赛事");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("crawlFootball")
//// .methodDesc("11 分钟爬取一次 乐鱼 赛事 足球")
//// .build());
////
//// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.LeYu.getCode())
//// .crawlScheduleMatch("http://preview.611.com/api/Index/getLiveData?tabId=0ecfe170-15de-4c6d-ae89-fb37920ea616&tabName=%E8%B6%B3%E7%90%83&groupName=&millinsecond=&isFuture=true");
//// }
////
//// @Scheduled(cron = "01 02/10 * * * ?")
//// public void updateMatchSchedule() {
//// log.info("更新乐鱼赛程");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("updateMatchSchedule")
//// .methodDesc("10分钟 乐鱼 赛程")
//// .build());
////
//// updateMatchStateService.updateStateMatch();
//// }
////
//// /**
//// * 每 30 分钟更新 乐鱼 赛程
//// */
//// @Scheduled(cron = "40 30/30 * * * ?")
//// public void updateMatchList() {
//// log.info("更新赛程");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("updateMatchList")
//// .methodDesc("每 30 分钟更新 乐鱼 赛程")
//// .build());
////
//// threadPoolExecutor.execute(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.LeYu.getCode()).updateMatchList());
//// }
////
//// /**
//// * 每 10 分钟爬取一次 UU球 主播信息
//// */
//// @Scheduled(cron = "50 10/10 * * * ?")
//// public void crawlUUQiuAnchor() {
//// log.info("爬取主播信息");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("crawlUUQiuAnchor")
//// .methodDesc("每 10 分钟爬取一次 UU球 主播信息")
//// .build());
////
//// threadPoolExecutor.execute(() ->
//// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.UUQiu.getCode()).crawlAnchor()
//// );
//// }
////
//// /**
//// * 每 30 分钟更新 UU球 主播
//// */
//// @Scheduled(cron = "20 30/30 * * * ?")
//// public void updateUUQiuAnchor() {
//// log.info("更新主播");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("updateUUQiuAnchor")
//// .methodDesc("每 30 分钟更新 UU球 主播")
//// .build());
////
//// threadPoolExecutor.execute(() ->
//// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.UUQiu.getCode()).updateAllAnchor()
//// );
//// }
////
//// /**
//// * 每 30 分钟更新 UU球 赛程
//// */
//// @Scheduled(cron = "33 30/30 * * * ?")
//// public void crawlUUQiuMatchList() {
//// log.info("更新 UU球 赛程");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("crawlUUQiuMatchList")
//// .methodDesc("每 30 分钟更新 UU球 赛程")
//// .build());
////
//// threadPoolExecutor.execute(() ->
//// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.UUQiu.getCode()).crawlScheduleMatch("http://uuqiu.net/match/list")
//// );
//// }
////
//// /**
//// * 每 10 分钟爬取一次 红杉 主播信息
//// */
//// @Scheduled(cron = "10 10/10 * * * ?")
//// public void crawlSequoiaAnchor() {
//// log.info("爬取主播信息");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("crawlSequoiaAnchor")
//// .methodDesc("每 10 分钟爬取一次 红杉 主播信息")
//// .build());
////
//// threadPoolExecutor.execute(() ->
//// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.Sequoia.getCode()).crawlAnchor()
//// );
//// }
////
//// /**
//// * 每 30 分钟更新 红杉 主播
//// */
//// @Scheduled(cron = "30 30/30 * * * ?")
//// public void updateSequoiaAnchor() {
//// log.info("更新主播");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("updateSequoiaAnchor")
//// .methodDesc("每 30 分钟更新 红杉 主播")
//// .build());
////
//// threadPoolExecutor.execute(() ->
//// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.Sequoia.getCode()).updateAllAnchor()
//// );
//// }
////
//// /**
//// * 每 30 分钟更新 红杉 赛程
//// */
//// @Scheduled(cron = "01 30/30 * * * ?")
//// public void crawlSequoiaMatchList() {
//// log.info("更新 红杉 赛程");
//// scheduledTaskMapper.insert(ScheduledTask.builder()
//// .createTime(new Date())
//// .method("crawlSequoiaMatchList")
//// .methodDesc("每 30 分钟更新 红杉 赛程")
//// .build());
////
//// threadPoolExecutor.execute(() ->
//// crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.Sequoia.getCode()).crawlScheduleMatch("http://hszb.cc/match/list")
//// );
//// }
//
//
// @Lazy
// threadPoolExecutor.execute(() ->
// @Resource
// crawStrategyFactory.getCrawlAnchorService(CrawlPlatformEnum.Sequoia.getCode()).updateAllAnchor()
// public void setCrawStrategyFactory(CrawlStrategyFactory crawStrategyFactory) {
// );
// this.crawStrategyFactory = crawStrategyFactory;
// }
// }
//
//
// @Autowired
// /**
// public void setScheduledTaskMapper(ScheduledTaskMapper scheduledTaskMapper) {
// * 每 30 分钟更新 红杉 赛程
// this.scheduledTaskMapper = scheduledTaskMapper;
// */
// }
// @Scheduled(cron = "01 30/30 * * * ?")
// public void crawlSequoiaMatchList() {
// log.info("更新 红杉 赛程");
// scheduledTaskMapper.insert(ScheduledTask.builder()
// .createTime(new Date())
// .method("crawlSequoiaMatchList")
// .methodDesc("每 30 分钟更新 红杉 赛程")
// .build());
//
//
//
@Autowired
//
threadPoolExecutor.execute(() ->
//
public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) {
//
crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.Sequoia.getCode()).crawlScheduleMatch("http://hszb.cc/match/list")
//
this.threadPoolExecutor = threadPoolExecutor
;
//
)
;
// }
// }
//
//}
@Lazy
@Resource
public
void
setCrawStrategyFactory
(
CrawlStrategyFactory
crawStrategyFactory
)
{
this
.
crawStrategyFactory
=
crawStrategyFactory
;
}
@Autowired
public
void
setScheduledTaskMapper
(
ScheduledTaskMapper
scheduledTaskMapper
)
{
this
.
scheduledTaskMapper
=
scheduledTaskMapper
;
}
@Autowired
public
void
setThreadPoolExecutor
(
ThreadPoolExecutor
threadPoolExecutor
)
{
this
.
threadPoolExecutor
=
threadPoolExecutor
;
}
}
score-job/src/main/java/com/live/job/service/impl/ChatTimedSendingServiceImpl.java
deleted
100644 → 0
View file @
a3090728
package
com
.
live
.
job
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.live.common.domain.entity.RobotMsg
;
import
com.live.common.domain.entity.Room
;
import
com.live.common.domain.request.SendMessageByRoomRequest
;
import
com.live.common.mapper.RobotMsgMapper
;
import
com.live.common.mapper.RoomMapper
;
import
com.live.common.service.HuanXinIMService
;
import
com.live.common.utils.ChatFakeMsgUtils
;
import
com.live.common.utils.IdGen
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.Instant
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Slf4j
@Service
public
class
ChatTimedSendingServiceImpl
{
@Resource
private
RoomMapper
roomMapper
;
@Resource
private
RobotMsgMapper
robotMsgMapper
;
@Resource
private
HuanXinIMService
huanXinIMService
;
@Resource
private
ThreadPoolTaskScheduler
taskScheduler
;
// @Scheduled(fixedRate = 10 * 60 * 1000)
// @Scheduled(cron = "01 01/01 * * * ?")
public
void
timedSendingServiceImpl
()
{
List
<
Room
>
rooms
=
roomMapper
.
selectList
(
Wrappers
.<
Room
>
lambdaQuery
()
.
eq
(
Room:
:
getDeleted
,
0
)
.
eq
(
Room:
:
getType
,
1
)
.
eq
(
Room:
:
getEnableFakeChat
,
1
)
);
for
(
String
roomId
:
rooms
.
stream
().
map
(
Room:
:
getHuanXinRoomId
).
collect
(
Collectors
.
toList
()))
{
int
randomSeconds
=
IdGen
.
randomUtil
(
60
);
taskScheduler
.
schedule
(()
->
sendFakeMessage
(
roomId
),
Instant
.
now
().
plusSeconds
(
randomSeconds
));
}
}
private
void
sendFakeMessage
(
String
roomId
)
{
List
<
RobotMsg
>
robotMsgs
=
returnFakeMsg
();
for
(
RobotMsg
msg
:
robotMsgs
)
{
String
userName
=
StringUtils
.
isBlank
(
msg
.
getNickName
())
?
ChatFakeMsgUtils
.
generateName
()
:
msg
.
getNickName
();
huanXinIMService
.
sendMessageByRoom
(
SendMessageByRoomRequest
.
builder
()
.
ext
(
SendMessageByRoomRequest
.
Ext
.
builder
()
.
live_room_user_name
(
userName
)
.
user_level
(
getRandomLevel
())
.
user_nick
(
userName
)
.
build
())
.
from
(
userName
)
.
msg
(
SendMessageByRoomRequest
.
SendMessage
.
builder
()
.
msg
(
msg
.
getFakeMsg
())
.
type
(
"txt"
)
.
build
())
.
target_type
(
"chatrooms"
)
.
target
(
Collections
.
singletonList
(
roomId
))
.
build
());
}
}
private
List
<
RobotMsg
>
returnFakeMsg
()
{
int
random
=
IdGen
.
randomUtil
(
6
)
+
1
;
return
robotMsgMapper
.
selectList
(
Wrappers
.<
RobotMsg
>
lambdaQuery
()
.
eq
(
RobotMsg:
:
getMsgType
,
-
1
)
.
eq
(
RobotMsg:
:
getDeleted
,
0
)
.
last
(
String
.
format
(
" ORDER BY RAND() LIMIT %s"
,
random
))
);
}
private
int
getRandomLevel
()
{
int
random
=
IdGen
.
randomUtil
(
1000
)
+
1
;
if
(
random
>
950
)
{
return
7
;
}
else
if
(
random
>
880
)
{
return
6
;
}
else
if
(
random
>
800
)
{
return
5
;
}
else
if
(
random
>
650
)
{
return
4
;
}
else
if
(
random
>
550
)
{
return
3
;
}
else
if
(
random
>
350
)
{
return
2
;
}
else
{
return
1
;
}
}
}
score-job/src/main/java/com/live/job/service/impl/CrawlAlStatServiceImpl.java
View file @
19fa49b7
...
@@ -452,7 +452,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
...
@@ -452,7 +452,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
* 10 分钟爬取一次 AlStat 足球实时比分
* 10 分钟爬取一次 AlStat 足球实时比分
*/
*/
// @Scheduled(fixedRate = 2 * 60 * 60 * 1000)
// @Scheduled(fixedRate = 2 * 60 * 60 * 1000)
//
@Scheduled(cron = "11 11/10 * * * ?")
@Scheduled
(
cron
=
"11 11/10 * * * ?"
)
public
void
crawlAlStatFootballScore
()
{
public
void
crawlAlStatFootballScore
()
{
String
url
=
String
.
format
(
"http://data43.aistat.cn/matchs/liveScores?key=%s"
,
footballKey
);
String
url
=
String
.
format
(
"http://data43.aistat.cn/matchs/liveScores?key=%s"
,
footballKey
);
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
...
...
score-job/src/main/java/com/live/job/service/impl/CrawlLeYuServiceImpl.java
deleted
100644 → 0
View file @
a3090728
package
com
.
live
.
job
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.live.common.domain.entity.*
;
import
com.live.common.enums.SystemConfigEnum
;
import
com.live.common.mapper.*
;
import
com.live.common.utils.DateUtil
;
import
com.live.common.utils.IdGen
;
import
com.live.common.utils.MD5Util
;
import
com.live.job.cache.MatchManager
;
import
com.live.job.constant.CrawlPlatformEnum
;
import
com.live.job.entity.dto.*
;
import
com.live.job.event.MatchOngoingEvent
;
import
com.live.job.service.CrawlMatchService
;
import
com.live.job.service.UpdateMatchStateService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.http.*
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.time.Instant
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.stream.Collectors
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
;
@Slf4j
@Service
public
class
CrawlLeYuServiceImpl
implements
CrawlMatchService
{
@Resource
private
TeamMapper
teamMapper
;
@Resource
private
MatchMapper
matchMapper
;
@Resource
private
RestTemplate
restTemplate
;
@Resource
private
SportsMapper
sportsMapper
;
@Resource
private
MatchLiveMapper
matchLiveMapper
;
@Resource
private
TeamReportMapper
teamReportMapper
;
@Resource
private
MatchRecentMapper
matchRecentMapper
;
@Resource
private
FootballStatMapper
footballStatMapper
;
@Resource
private
ThreadPoolExecutor
threadPoolExecutor
;
@Resource
private
ThreadPoolTaskScheduler
taskScheduler
;
@Resource
private
CrawlHistoryMapper
crawlHistoryMapper
;
@Resource
private
TeamIntegralMapper
teamIntegralMapper
;
@Resource
private
FootballEventMapper
footballEventMapper
;
@Resource
private
MatchSummaryMapper
matchSummaryMapper
;
@Resource
private
TeamCompetitionMapper
teamCompetitionMapper
;
@Resource
private
PlayerCompetitionMapper
playerCompetitionMapper
;
@Resource
private
UpdateMatchStateService
updateMatchStateService
;
@Resource
private
ApplicationEventPublisher
applicationEventPublisher
;
private
final
HttpHeaders
headers
;
public
CrawlLeYuServiceImpl
()
{
headers
=
new
HttpHeaders
();
headers
.
add
(
"User-Agent"
,
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Mobile Safari/537.36"
);
headers
.
add
(
"Connection"
,
"keep-alive"
);
headers
.
add
(
"Host"
,
"preview.611.com"
);
headers
.
add
(
"Origin"
,
"http://m.611.com"
);
headers
.
add
(
"Referer"
,
"http://m.611.com"
);
headers
.
add
(
"Cookie"
,
"UM_distinctid=17868e64adf6d4-0e33987dfe691d-2f7c2e4d-54ab0-17868e64ae0cb0"
);
headers
.
setAccept
(
Collections
.
singletonList
(
APPLICATION_JSON
));
}
@Async
@Override
public
void
crawlScheduleMatch
(
String
url
)
{
log
.
info
(
"定时爬取赛事"
);
ResponseEntity
<
String
>
response
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
new
HttpEntity
<>(
null
,
headers
),
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
List
<
MatchToDayDto
>
matchToDayDto
=
JSONArray
.
parseArray
(
jsonObject
.
getString
(
"data"
),
MatchToDayDto
.
class
);
for
(
MatchToDayDto
matchToDay
:
matchToDayDto
)
{
crawlScheduleMatch
(
matchToDay
);
}
}
}
@Override
public
void
crawlScheduleMatchByDay
(
String
url
,
int
day
)
{
}
@Override
public
void
crawlIndexCompanyFootball
(
String
url
)
{
}
@Override
public
void
crawlIndexCompanyBasketball
(
String
url
)
{
}
@Override
public
void
crawlMatchStageScore
(
String
url
)
{
}
@Override
public
void
crawlScheduleArticle
(
String
url
)
{
}
@Override
public
void
updateMatchList
()
{
updateMatchStateService
.
updateStateMatch
();
}
/**
* 爬取赛程-赛事详情
*
* @param matchToDay
*/
private
void
crawlScheduleMatch
(
MatchToDayDto
matchToDay
)
{
try
{
String
time
=
matchToDay
.
getGroupName
();
log
.
info
(
"总赛事列表:{} 条"
,
matchToDay
.
getList
().
size
());
for
(
MatchToDayInfoDto
matchToDayInfo
:
matchToDay
.
getList
())
{
String
matchInfoUrl
=
"http://preview.611.com/api/Data/getMatchData?id="
+
matchToDayInfo
.
getMatchID
()
+
"&sportType="
+
matchToDayInfo
.
getSportType
();
Match
match
=
matchMapper
.
selectOne
(
Wrappers
.<
Match
>
lambdaQuery
()
.
eq
(
Match:
:
getCrawlUrl
,
matchInfoUrl
)
);
CrawlHistory
crawlHistory
=
crawlHistoryMapper
.
selectOne
(
Wrappers
.<
CrawlHistory
>
lambdaQuery
()
.
eq
(
CrawlHistory:
:
getCrawlUrl
,
matchInfoUrl
)
);
if
((
matchToDayInfo
.
getSportType
()
==
0
&&
crawlHistory
!=
null
)
||
crawlHistory
!=
null
&&
match
!=
null
&&
(
StringUtils
.
isNotBlank
(
match
.
getCompetitionAwayId
())
||
StringUtils
.
isNotBlank
(
match
.
getCompetitionHomeId
())))
{
continue
;
}
String
sportId
=
saveSports
(
matchToDayInfo
.
getCompetetionName
(),
matchToDayInfo
.
getCompetetionShortName
(),
matchToDayInfo
.
getSportType
());
Team
away
=
saveTeam
(
matchToDayInfo
.
getAway
());
Team
home
=
saveTeam
(
matchToDayInfo
.
getHome
());
String
matchId
=
IdGen
.
uuid
();
String
homeCompetitionId
=
null
;
String
awayCompetitionId
=
null
;
if
(
match
!=
null
)
{
matchId
=
match
.
getId
();
homeCompetitionId
=
match
.
getCompetitionHomeId
();
awayCompetitionId
=
match
.
getCompetitionAwayId
();
}
//比赛结束状态
if
(
matchToDayInfo
.
getStatus
()
!=
2
&&
!
matchToDayInfo
.
getHasPlayedPart
().
contains
(
"取消"
))
{
if
(
matchToDayInfo
.
getSportType
()
==
0
)
{
//足球
crawlFootball
(
matchInfoUrl
,
matchId
,
matchToDayInfo
.
getMatchID
());
}
else
if
(
matchToDayInfo
.
getSportType
()
==
1
)
{
//篮球
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
matchInfoUrl
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
TeamCompetitionDto
competitionDto
=
JSONArray
.
parseObject
(
jsonObject
.
getString
(
"data"
),
TeamCompetitionDto
.
class
);
for
(
TeamCompetitionDto
.
GameState
gameState
:
competitionDto
.
getGameStat
())
{
if
(
StringUtils
.
isNotBlank
(
gameState
.
getResult
())
&&
gameState
.
getPlayerID
()
==
null
)
{
//团队得分总计
if
(
gameState
.
getTeamID
().
equals
(
matchToDayInfo
.
getHome
().
getTeamId
()))
{
homeCompetitionId
=
competitionTeam
(
homeCompetitionId
,
home
.
getId
(),
competitionDto
.
getGameInfo
().
getAScore
(),
gameState
);
}
else
{
awayCompetitionId
=
competitionTeam
(
awayCompetitionId
,
away
.
getId
(),
competitionDto
.
getGameInfo
().
getBScore
(),
gameState
);
}
}
}
for
(
TeamCompetitionDto
.
GameState
gameState
:
competitionDto
.
getGameStat
())
{
if
(
gameState
.
getResult
()
==
null
&&
gameState
.
getPlayerID
()
!=
null
)
{
//个人得分
if
(
gameState
.
getTeamID
().
equals
(
matchToDayInfo
.
getHome
().
getTeamId
()))
{
competitionPlayer
(
home
.
getId
(),
homeCompetitionId
,
gameState
);
}
else
{
competitionPlayer
(
away
.
getId
(),
awayCompetitionId
,
gameState
);
}
}
}
}
}
}
if
(
matchToDayInfo
.
getStatus
()
==
3
)
{
try
{
crawlHistoryMapper
.
insert
(
CrawlHistory
.
builder
().
crawlUrl
(
matchInfoUrl
).
build
());
}
catch
(
DuplicateKeyException
d
)
{
//nothing
}
}
try
{
if
(
match
!=
null
)
{
match
.
setHomeScore
(
matchToDayInfo
.
getHome
().
getScore
());
match
.
setAwayScore
(
matchToDayInfo
.
getAway
().
getScore
());
match
.
setCompetitionStatus
(
matchToDayInfo
.
getStatus
());
match
.
setCompetitionAwayId
(
awayCompetitionId
);
match
.
setCompetitionHomeId
(
homeCompetitionId
);
matchMapper
.
updateById
(
match
);
}
else
{
matchMapper
.
insert
(
Match
.
builder
()
.
id
(
matchId
)
.
sportsId
(
sportId
)
.
awayId
(
away
.
getId
())
.
homeId
(
home
.
getId
())
.
awayScore
(
matchToDayInfo
.
getAway
().
getScore
())
.
homeScore
(
matchToDayInfo
.
getHome
().
getScore
())
.
matchTime
(
DateUtil
.
parse
(
time
+
" "
+
matchToDayInfo
.
getBeginTime
(),
DateUtil
.
YMDHM_
))
.
competitionName
(
matchToDayInfo
.
getCompetetionName
())
.
competitionShortName
(
matchToDayInfo
.
getCompetetionShortName
())
.
competitionStatus
(
matchToDayInfo
.
getStatus
())
.
competitionHomeId
(
homeCompetitionId
)
.
competitionAwayId
(
awayCompetitionId
)
.
crawlUrl
(
matchInfoUrl
)
.
categoryId
(
matchToDayInfo
.
getSportType
()
+
","
)
.
build
());
log
.
info
(
"抓取成功"
);
// if (matchToDayInfo.getStatus() != 3) {
// applicationEventPublisher.publishEvent(MatchOngoingEvent.builder().matchId(matchId)
// .time(System.currentTimeMillis())
// .matchTime(DateUtil.parse(time + " " + matchToDayInfo.getBeginTime(), DateUtil.YMDHM_))
// .sportsType(1).status(matchToDayInfo.getStatus()).build());
// }
}
}
catch
(
DuplicateKeyException
d
)
{
//nothing
}
String
saveMatchId
=
matchId
;
//赛前分析
taskScheduler
.
schedule
(()
->
matchBeforeAnalysis
(
saveMatchId
,
matchToDayInfo
.
getSportType
(),
matchToDayInfo
),
Instant
.
now
().
plusSeconds
(
5
));
if
(
matchToDayInfo
.
getStatus
()
!=
2
)
{
//直播地址
// taskScheduler.schedule(() ->
// matchLive(saveMatchId, matchToDayInfo.getMatchID(), matchToDayInfo.getSportType()),
// Instant.now().plusSeconds(10));
//赛事概况
taskScheduler
.
schedule
(()
->
matchSummary
(
saveMatchId
,
matchToDayInfo
.
getMatchID
(),
matchToDayInfo
.
getSportType
()),
Instant
.
now
().
plusSeconds
(
15
));
}
}
}
catch
(
RuntimeException
e
)
{
e
.
printStackTrace
();
}
}
//直播 模块 赛事概况
private
void
matchSummary
(
String
matchId
,
int
originalMatchId
,
int
sportType
)
{
Integer
sort
=
null
;
int
max
=
3
;
try
{
do
{
String
firstUrl
=
"http://preview.611.com/api/Live/GetLivingText?MatchID="
+
originalMatchId
+
"&sportType="
+
sportType
+
"&isMobile=0&Sort="
+
sort
;
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
firstUrl
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
MatchSummaryListDto
matchLiveDto
=
JSONArray
.
parseObject
(
response
.
getBody
(),
MatchSummaryListDto
.
class
);
if
(
matchLiveDto
==
null
)
return
;
for
(
MatchSummaryListDto
.
MatchSummaryDto
summaryDto
:
matchLiveDto
.
getData
())
{
try
{
matchSummaryMapper
.
insert
(
MatchSummary
.
builder
()
.
matchId
(
matchId
)
.
sort
(
summaryDto
.
getSort
())
.
sourceId
(
summaryDto
.
getID
())
.
message
(
summaryDto
.
getMsg
())
.
sourceMatchId
(
summaryDto
.
getMatchID
())
.
matchTime
(
summaryDto
.
getMatchTime
())
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
break
;
}
}
if
(
matchLiveDto
.
getData
().
size
()
<=
0
)
{
break
;
}
sort
=
matchLiveDto
.
getData
().
get
(
matchLiveDto
.
getData
().
size
()
-
1
).
getSort
();
if
(
sportType
==
1
)
{
//篮球
if
(
Math
.
min
(
max
,
sort
)
<=
1
)
break
;
max
--;
}
log
.
info
(
"爬取:{} 赛事概况成功"
,
matchId
);
}
else
{
sort
=
1
;
}
}
while
(
sort
>
1
);
}
catch
(
RuntimeException
e
)
{
e
.
printStackTrace
();
}
}
//比赛直播地址
private
void
matchLive
(
String
matchId
,
int
originalMatchId
,
int
sportType
)
{
String
matchLiveUrl
=
"http://preview.611.com/api/live/GetLiveSources?MatchID="
+
originalMatchId
+
"&sportType="
+
sportType
;
try
{
CrawlHistory
crawlHistory
=
crawlHistoryMapper
.
selectOne
(
Wrappers
.<
CrawlHistory
>
lambdaQuery
()
.
eq
(
CrawlHistory:
:
getCrawlUrl
,
matchLiveUrl
)
);
if
(
crawlHistory
!=
null
)
{
return
;
}
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
matchLiveUrl
,
new
HttpEntity
<>(
null
,
headers
),
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
MatchLiveDto
teamReportDto
=
JSONArray
.
parseObject
(
response
.
getBody
(),
MatchLiveDto
.
class
);
if
(
teamReportDto
!=
null
)
{
for
(
MatchLiveDto
.
MatchLiveResponse
matchLive
:
teamReportDto
.
getData
())
{
matchLiveMapper
.
insert
(
MatchLive
.
builder
()
.
matchId
(
matchId
)
.
sourceName
(
matchLive
.
getSourceName
())
.
sourceType
(
matchLive
.
getSourceType
())
.
sourceUrl
(
matchLive
.
getSourceUrl
())
.
build
());
}
crawlHistoryMapper
.
insert
(
CrawlHistory
.
builder
().
crawlUrl
(
matchLiveUrl
).
build
());
}
}
}
catch
(
Exception
e
)
{
log
.
warn
(
"爬取比赛直播视频地址失败 - {} - {}"
,
e
.
getMessage
(),
matchLiveUrl
);
}
}
private
void
matchBeforeAnalysis
(
String
matchId
,
Integer
sportType
,
MatchToDayInfoDto
matchToDayInfo
)
{
try
{
String
matchInfoUrl
=
"http://preview.611.com/api/Live/getLiveMatchIData?MatchID="
+
matchToDayInfo
.
getMatchID
()
+
"&SportType="
+
sportType
+
"&publishDate=&ModeType=4&page=1"
;
CrawlHistory
crawlHistory
=
crawlHistoryMapper
.
selectOne
(
Wrappers
.<
CrawlHistory
>
lambdaQuery
()
.
eq
(
CrawlHistory:
:
getCrawlUrl
,
matchInfoUrl
)
);
if
(
crawlHistory
!=
null
)
{
return
;
}
Team
away
=
saveTeam
(
matchToDayInfo
.
getAway
());
Team
home
=
saveTeam
(
matchToDayInfo
.
getHome
());
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
matchInfoUrl
,
new
HttpEntity
<>(
null
,
headers
),
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
TeamReportDto
teamReportDto
=
JSONArray
.
parseObject
(
jsonObject
.
getString
(
"data"
),
TeamReportDto
.
class
);
if
(
teamReportDto
!=
null
)
{
saveSection
(
matchToDayInfo
.
getHome
().
getTeamId
(),
home
.
getId
(),
away
.
getId
(),
matchId
,
teamReportDto
);
crawlHistoryMapper
.
insert
(
CrawlHistory
.
builder
().
crawlUrl
(
matchInfoUrl
).
build
());
}
}
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"新增{}比赛分析报错:{}"
,
sportType
==
1
?
"篮球"
:
"足球"
,
e
.
getMessage
());
}
}
private
void
crawlFootball
(
String
matchInfoUrl
,
String
matchId
,
int
originalMatchId
)
{
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
matchInfoUrl
,
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
FootballCompetitionDto
competitionDto
=
JSONArray
.
parseObject
(
jsonObject
.
getString
(
"data"
),
FootballCompetitionDto
.
class
);
//技术统计 团队得分总计
for
(
FootballCompetitionDto
.
GameState
gameState
:
competitionDto
.
getGameStat
())
{
try
{
footballStatMapper
.
insert
(
FootballStat
.
builder
()
.
matchId
(
matchId
)
.
statAway
(
gameState
.
getStatAway
())
.
statHome
(
gameState
.
getStatHome
())
.
statName
(
gameState
.
getStatName
())
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"新增足球比分统计时报错:{}"
,
e
.
getMessage
());
}
}
//赛场事件
for
(
FootballCompetitionDto
.
MatchGoal
eventGoal
:
competitionDto
.
getGameGoalData
().
getMatchGoal
())
{
for
(
FootballCompetitionDto
.
TeamGoal
teamGoal
:
eventGoal
.
getAway_Goal
())
{
saveMatchEvent
(
teamGoal
,
matchId
);
}
for
(
FootballCompetitionDto
.
TeamGoal
teamGoal
:
eventGoal
.
getHome_Goal
())
{
saveMatchEvent
(
teamGoal
,
matchId
);
}
}
}
//视频集锦 / 回放
// matchVideoCollection(matchId, originalMatchId, 0);
}
//比赛视频集锦
private
void
matchVideoCollection
(
String
matchId
,
Integer
originalId
,
int
sportsType
)
{
try
{
String
matchInfoUrl
=
"http://preview.611.com/api/Live/getLiveMatchIData?MatchID="
+
originalId
+
"&SportType="
+
sportsType
+
"&publishDate=&ModeType=6&page=1"
;
CrawlHistory
crawlHistory
=
crawlHistoryMapper
.
selectOne
(
Wrappers
.<
CrawlHistory
>
lambdaQuery
()
.
eq
(
CrawlHistory:
:
getCrawlUrl
,
matchInfoUrl
)
);
if
(
crawlHistory
!=
null
)
{
return
;
}
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
matchInfoUrl
,
new
HttpEntity
<>(
null
,
headers
),
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
TeamCompetitionDto
competitionDto
=
JSONArray
.
parseObject
(
jsonObject
.
getString
(
"data"
),
TeamCompetitionDto
.
class
);
}
crawlHistoryMapper
.
insert
(
CrawlHistory
.
builder
().
crawlUrl
(
matchInfoUrl
).
build
());
}
catch
(
RuntimeException
e
)
{
e
.
printStackTrace
();
}
}
private
void
saveSection
(
String
oldHomeId
,
String
homeId
,
String
awayId
,
String
competitionId
,
TeamReportDto
teamReportDto
)
{
for
(
TeamReportDto
.
ReportDto
reportDto
:
teamReportDto
.
getModeData
().
getListData
())
{
switch
(
reportDto
.
getSectionType
())
{
case
1
:
//一手情报
for
(
TeamReportDto
.
LeagueMatch
leagueMatch
:
reportDto
.
getLeagueMatchList
())
{
String
teamId
=
null
;
if
(
leagueMatch
.
getTeamId
().
equals
(
oldHomeId
))
{
teamId
=
homeId
;
}
else
if
(
StringUtils
.
isBlank
(
leagueMatch
.
getTeamId
()))
{
continue
;
}
else
{
teamId
=
awayId
;
}
String
badMsg
=
null
;
String
godMsg
=
null
;
for
(
TeamReportDto
.
TeamInformation
saveInfo
:
leagueMatch
.
getTeamInformation
())
{
if
(
saveInfo
.
getIntelligenceName
().
equals
(
"有利情报"
))
{
godMsg
=
saveInfo
.
getIntelligenceArr
().
stream
().
map
(
TeamReportDto
.
Text
::
getText
).
collect
(
Collectors
.
joining
(
""
));
}
else
if
(
saveInfo
.
getIntelligenceName
().
equals
(
"不利情报"
))
{
badMsg
=
saveInfo
.
getIntelligenceArr
().
stream
().
map
(
TeamReportDto
.
Text
::
getText
).
collect
(
Collectors
.
joining
(
""
));
}
}
try
{
teamReportMapper
.
insert
(
TeamReport
.
builder
()
.
teamId
(
teamId
)
.
badMsg
(
badMsg
)
.
godMsg
(
godMsg
)
.
msgMd5
(
MD5Util
.
string2MD5
(
godMsg
+
badMsg
))
.
build
());
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"新增赛事 一手情报 失败:{}"
,
e
.
getMessage
());
}
}
break
;
case
2
:
//积分榜
for
(
TeamReportDto
.
LeagueMatch
leagueMatch
:
reportDto
.
getLeagueMatchList
())
{
String
teamId
=
null
;
if
(
leagueMatch
.
getTeamId
().
equals
(
oldHomeId
))
{
teamId
=
homeId
;
}
else
{
teamId
=
awayId
;
}
String
integralAway
=
null
;
String
integralHome
=
null
;
String
integralSum
=
null
;
for
(
List
<
String
>
integ
:
leagueMatch
.
getLeagueMatchData
())
{
if
(
integ
.
stream
().
anyMatch
(
b
->
b
.
equals
(
"总"
)))
{
integralSum
=
String
.
join
(
","
,
integ
);
}
else
if
(
integ
.
stream
().
anyMatch
(
b
->
b
.
equals
(
"主"
)))
{
integralHome
=
String
.
join
(
","
,
integ
);
}
else
{
integralAway
=
String
.
join
(
","
,
integ
);
}
}
try
{
teamIntegralMapper
.
insert
(
TeamIntegral
.
builder
()
.
teamId
(
teamId
)
.
integralAway
(
integralAway
)
.
integralHeader
(
String
.
join
(
","
,
reportDto
.
getLeagueMatchHeader
()))
.
integralHome
(
integralHome
)
.
integralSum
(
integralSum
)
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"新增赛事 积分榜 失败:{}"
,
e
.
getMessage
());
}
}
break
;
case
3
:
//分析数据
for
(
TeamReportDto
.
LeagueMatch
leagueMatch
:
reportDto
.
getLeagueMatchList
())
{
try
{
matchRecentMapper
.
insert
(
MatchRecent
.
builder
()
.
matchId
(
competitionId
)
.
teamRecordLost
(
leagueMatch
.
getTeamRecordLost
())
.
teamRecordName
(
leagueMatch
.
getTeamRecordName
())
.
teamRecordTie
(
leagueMatch
.
getTeamRecordTie
())
.
teamRecordWin
(
leagueMatch
.
getTeamRecordWin
())
.
competitionData
(
JSON
.
toJSONString
(
leagueMatch
.
getCompetitionData
()))
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"新增赛事 分析数据 失败:{}"
,
e
.
getMessage
());
}
}
break
;
}
}
}
private
void
saveMatchEvent
(
FootballCompetitionDto
.
TeamGoal
teamGoal
,
String
matchId
)
{
try
{
footballEventMapper
.
insert
(
FootballEvent
.
builder
()
.
matchId
(
matchId
)
.
assistedName
(
teamGoal
.
getAssistedPname
())
.
downName
(
teamGoal
.
getDownname
())
.
eventName
(
teamGoal
.
getEname
())
.
minute
(
teamGoal
.
getMinute
())
.
pName
(
teamGoal
.
getPname
())
.
score
(
teamGoal
.
getScore
())
.
type
(
teamGoal
.
getType
())
.
upName
(
teamGoal
.
getUpname
())
.
build
());
}
catch
(
DuplicateKeyException
e
)
{
//nothing
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"新增足球事件时报错:{}"
,
e
.
getMessage
());
}
}
private
synchronized
String
competitionTeam
(
String
dbID
,
String
teamId
,
String
scoreSettle
,
TeamCompetitionDto
.
GameState
gameState
)
{
try
{
if
(
StringUtils
.
isNotBlank
(
dbID
))
{
TeamCompetition
teamCompetition
=
teamCompetitionMapper
.
selectById
(
dbID
);
teamCompetition
.
setAssists
(
gameState
.
getAssists
());
teamCompetition
.
setAttackBoard
(
gameState
.
getAttackBoard
());
teamCompetition
.
setBlocks
(
gameState
.
getBlocks
());
teamCompetition
.
setError
(
gameState
.
getError
());
teamCompetition
.
setDefensiveBoard
(
gameState
.
getDefensiveBoard
());
teamCompetition
.
setFoul
(
gameState
.
getFoul
());
teamCompetition
.
setFreeThrowNum
(
gameState
.
getFreeThrowNum
());
teamCompetition
.
setFreeThrows
(
gameState
.
getFreeThrows
());
teamCompetition
.
setHomeOrAway
(
gameState
.
getHomeOrAway
().
equals
(
"客场"
)
?
1
:
0
);
teamCompetition
.
setResult
(
gameState
.
getResult
().
equals
(
"负"
)
?
1
:
0
);
teamCompetition
.
setScore
(
gameState
.
getScore
());
teamCompetition
.
setTeamId
(
teamId
);
teamCompetition
.
setThreeShotNum
(
gameState
.
getThreeShotNum
());
teamCompetition
.
setThreeShots
(
gameState
.
getThreeShots
());
teamCompetition
.
setTotalBoards
(
gameState
.
getTotalBoards
());
teamCompetition
.
setScoreSettle
(
scoreSettle
);
teamCompetition
.
setTwoScore
(
gameState
.
getTwoScore
());
teamCompetition
.
setSteals
(
gameState
.
getSteals
());
teamCompetitionMapper
.
updateById
(
teamCompetition
);
}
else
{
dbID
=
IdGen
.
uuid
();
teamCompetitionMapper
.
insert
(
TeamCompetition
.
builder
()
.
id
(
dbID
)
.
assists
(
gameState
.
getAssists
())
.
attackBoard
(
gameState
.
getAttackBoard
())
.
blocks
(
gameState
.
getBlocks
())
.
error
(
gameState
.
getError
())
.
defensiveBoard
(
gameState
.
getDefensiveBoard
())
.
foul
(
gameState
.
getFoul
())
.
freeThrowNum
(
gameState
.
getFreeThrowNum
())
.
freeThrows
(
gameState
.
getFreeThrows
())
.
homeOrAway
(
gameState
.
getHomeOrAway
().
equals
(
"客场"
)
?
1
:
0
)
.
result
(
gameState
.
getResult
().
equals
(
"负"
)
?
1
:
0
)
.
score
(
gameState
.
getScore
())
.
shootNum
(
gameState
.
getShootNum
())
.
shots
(
gameState
.
getShots
())
.
steals
(
gameState
.
getSteals
())
.
scoreSettle
(
scoreSettle
)
.
teamId
(
teamId
)
.
threeShotNum
(
gameState
.
getThreeShotNum
())
.
threeShots
(
gameState
.
getThreeShots
())
.
totalBoards
(
gameState
.
getTotalBoards
())
.
twoScore
(
gameState
.
getTwoScore
())
.
build
());
}
}
catch
(
RuntimeException
e
)
{
e
.
printStackTrace
();
log
.
error
(
"competitionTeam ERROR:{}"
,
e
.
getMessage
());
}
return
dbID
;
}
private
synchronized
void
competitionPlayer
(
String
tempId
,
String
competitionId
,
TeamCompetitionDto
.
GameState
gameState
)
{
try
{
PlayerCompetition
playerCompetition
=
playerCompetitionMapper
.
selectOne
(
Wrappers
.<
PlayerCompetition
>
lambdaQuery
()
.
eq
(
PlayerCompetition:
:
getTeamCompetitionId
,
competitionId
)
.
eq
(
PlayerCompetition:
:
getTeamId
,
tempId
)
.
eq
(
PlayerCompetition:
:
getPlayerName
,
gameState
.
getPlayerName
())
);
if
(
playerCompetition
!=
null
)
{
playerCompetition
.
setPlayingTime
(
gameState
.
getPlayingTime
());
playerCompetition
.
setAbsentReason
(
gameState
.
getAbsentReason
());
playerCompetition
.
setAssists
(
gameState
.
getAssists
());
playerCompetition
.
setAttackBoard
(
gameState
.
getAttackBoard
());
playerCompetition
.
setBlocks
(
gameState
.
getBlocks
());
playerCompetition
.
setError
(
gameState
.
getError
());
playerCompetition
.
setFoul
(
gameState
.
getFoul
());
playerCompetition
.
setFreeThrowNum
(
gameState
.
getFreeThrowNum
());
playerCompetition
.
setFreeThrows
(
gameState
.
getFreeThrows
());
playerCompetition
.
setHomeOrAway
(
gameState
.
getHomeOrAway
().
equals
(
"客场"
)
?
1
:
0
);
playerCompetition
.
setShootNum
(
gameState
.
getShootNum
());
playerCompetition
.
setSteals
(
gameState
.
getSteals
());
playerCompetition
.
setScore
(
gameState
.
getScore
());
playerCompetition
.
setShootNum
(
gameState
.
getShootNum
());
playerCompetition
.
setThreeShotNum
(
gameState
.
getThreeShotNum
());
playerCompetition
.
setThreeShots
(
gameState
.
getThreeShots
());
playerCompetition
.
setTotalBoards
(
gameState
.
getTotalBoards
());
playerCompetitionMapper
.
updateById
(
playerCompetition
);
}
else
{
playerCompetitionMapper
.
insert
(
PlayerCompetition
.
builder
()
.
id
(
IdGen
.
uuid
())
.
playerName
(
gameState
.
getPlayerName
())
.
playingTime
(
gameState
.
getPlayingTime
())
.
teamCompetitionId
(
competitionId
)
.
absentReason
(
gameState
.
getAbsentReason
())
.
assists
(
gameState
.
getAssists
())
.
attackBoard
(
gameState
.
getAttackBoard
())
.
blocks
(
gameState
.
getBlocks
())
.
teamId
(
tempId
)
.
error
(
gameState
.
getError
())
.
foul
(
gameState
.
getFoul
())
.
freeThrowNum
(
gameState
.
getFreeThrowNum
())
.
freeThrows
(
gameState
.
getFreeThrows
())
.
homeOrAway
(
gameState
.
getHomeOrAway
().
equals
(
"客场"
)
?
1
:
0
)
.
score
(
gameState
.
getScore
())
.
shootNum
(
gameState
.
getShootNum
())
.
shots
(
gameState
.
getShots
())
.
steals
(
gameState
.
getSteals
())
.
threeShotNum
(
gameState
.
getThreeShotNum
())
.
threeShots
(
gameState
.
getThreeShots
())
.
totalBoards
(
gameState
.
getTotalBoards
())
.
build
());
}
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"competitionPlayer ERROR:{}"
,
e
.
getMessage
());
}
}
private
synchronized
String
saveSports
(
String
competitionName
,
String
competitionShortName
,
int
sportsType
)
throws
RuntimeException
{
try
{
Sports
sports
=
sportsMapper
.
selectOne
(
Wrappers
.<
Sports
>
lambdaQuery
()
.
eq
(
Sports:
:
getDeleted
,
0
)
.
eq
(
Sports:
:
getCompetitionShortName
,
competitionShortName
)
);
if
(
sports
!=
null
)
{
return
sports
.
getId
();
}
String
id
=
IdGen
.
uuid
();
sportsMapper
.
insert
(
Sports
.
builder
()
.
id
(
id
)
.
sportsId
(
sportsType
)
.
sportsName
(
sportsType
==
1
?
"篮球"
:
"足球"
)
.
competitionName
(
competitionName
)
.
competitionShortName
(
competitionShortName
)
.
build
());
return
id
;
}
catch
(
DuplicateKeyException
d
)
{
//nothing
}
catch
(
RuntimeException
e
)
{
e
.
printStackTrace
();
log
.
warn
(
"新增 Sports 时报错:{}"
,
e
.
getMessage
());
}
throw
new
RuntimeException
();
}
private
synchronized
Team
saveTeam
(
MatchToDayInfoDto
.
Team
team
)
throws
RuntimeException
{
try
{
Team
teamDb
=
teamMapper
.
selectOne
(
Wrappers
.<
Team
>
lambdaQuery
()
.
eq
(
Team:
:
getDeleted
,
0
)
.
eq
(
Team:
:
getTeamName
,
team
.
getTeamName
())
.
eq
(
Team:
:
getOriginalType
,
0
)
);
if
(
teamDb
!=
null
)
{
return
teamDb
;
}
String
id
=
IdGen
.
uuid
();
Team
saveTeam
=
Team
.
builder
()
.
id
(
id
)
.
originalId
(
team
.
getTeamId
())
.
teamIcon
(
team
.
getTeamLogo
())
.
teamName
(
team
.
getTeamName
())
.
originalType
(
0
)
.
build
();
teamMapper
.
insert
(
saveTeam
);
return
saveTeam
;
}
catch
(
RuntimeException
e
)
{
log
.
warn
(
"新增球队时报错:{}"
,
e
.
getMessage
());
}
throw
new
RuntimeException
();
}
@Override
public
void
updateFootballState
(
String
matchId
,
long
time
)
{
log
.
info
(
"{} - 更新足球比赛状态"
,
matchId
);
Match
match
=
matchMapper
.
selectById
(
matchId
);
try
{
CrawlHistory
crawlHistory
=
crawlHistoryMapper
.
selectOne
(
Wrappers
.<
CrawlHistory
>
lambdaQuery
()
.
eq
(
CrawlHistory:
:
getCrawlUrl
,
match
.
getCrawlUrl
())
);
if
(
crawlHistory
!=
null
&&
match
.
getCompetitionStatus
()
==
3
||
StringUtils
.
isBlank
(
match
.
getCrawlUrl
()))
{
return
;
}
ResponseEntity
<
String
>
response
=
restTemplate
.
exchange
(
match
.
getCrawlUrl
(),
HttpMethod
.
GET
,
new
HttpEntity
<>(
null
,
headers
),
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
FootballCompetitionDto
competitionDto
=
JSONArray
.
parseObject
(
jsonObject
.
getString
(
"data"
),
FootballCompetitionDto
.
class
);
if
(
competitionDto
.
getGameInfo
().
getStatus
()
==
0
)
{
//未开始
log
.
info
(
"{} - 未开始"
,
matchId
);
}
else
if
(
competitionDto
.
getGameInfo
().
getStatus
()
==
10
||
competitionDto
.
getGameInfo
().
getStatus
()
==
13
||
competitionDto
.
getGameInfo
().
getStatus
()
==
9
||
competitionDto
.
getGameInfo
().
getStatus
()
==
19
)
{
try
{
crawlHistoryMapper
.
insert
(
CrawlHistory
.
builder
().
crawlUrl
(
match
.
getCrawlUrl
()).
build
());
}
catch
(
DuplicateKeyException
d
)
{
//nothing
}
MatchManager
.
getInstance
().
removeMatchEvent
(
matchId
);
match
.
setCompetitionStatus
(
3
);
match
.
setAwayScore
(
competitionDto
.
getGameInfo
().
getAwayScore
());
match
.
setHomeScore
(
competitionDto
.
getGameInfo
().
getHomeScore
());
matchMapper
.
updateById
(
match
);
log
.
info
(
"更新足球比赛完成"
);
return
;
}
else
{
log
.
info
(
"足球 {} - 其它状态 - {}"
,
matchId
,
competitionDto
.
getGameInfo
().
getStatus
());
if
(
match
.
getCompetitionStatus
()
!=
1
)
{
match
.
setCompetitionStatus
(
1
);
matchMapper
.
updateById
(
match
);
}
}
}
else
{
log
.
error
(
"赛事请求异常:{}"
,
matchId
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"更新足球比赛时报错:{} - {}"
,
e
.
getMessage
(),
matchId
);
}
// applicationEventPublisher.publishEvent(MatchOngoingEvent.builder().matchId(matchId).time(time).matchTime(match.getMatchTime()).sportsType(0).status(1).build());
}
@Override
public
void
updateBasketballState
(
String
matchId
,
long
time
)
{
log
.
info
(
"更新篮球比赛状态"
);
Match
match
=
matchMapper
.
selectById
(
matchId
);
try
{
CrawlHistory
crawlHistory
=
crawlHistoryMapper
.
selectOne
(
Wrappers
.<
CrawlHistory
>
lambdaQuery
()
.
eq
(
CrawlHistory:
:
getCrawlUrl
,
match
.
getCrawlUrl
())
);
if
(
crawlHistory
!=
null
&&
match
.
getCompetitionStatus
()
==
3
||
StringUtils
.
isBlank
(
match
.
getCrawlUrl
()))
{
return
;
}
//比赛结束状态
ResponseEntity
<
String
>
response
=
restTemplate
.
exchange
(
match
.
getCrawlUrl
(),
HttpMethod
.
GET
,
new
HttpEntity
<>(
null
,
headers
),
String
.
class
);
if
(
response
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
getBody
());
TeamCompetitionDto
competitionDto
=
JSONArray
.
parseObject
(
jsonObject
.
getString
(
"data"
),
TeamCompetitionDto
.
class
);
if
(
competitionDto
.
getGameInfo
().
getStatus
()
==
0
)
{
//未开始
log
.
info
(
"{} - 未开始"
,
matchId
);
}
else
if
(
competitionDto
.
getGameInfo
().
getStatus
()
==
9
||
competitionDto
.
getGameInfo
().
getStatus
()
==
13
)
{
try
{
crawlHistoryMapper
.
insert
(
CrawlHistory
.
builder
().
crawlUrl
(
match
.
getCrawlUrl
()).
build
());
}
catch
(
DuplicateKeyException
e
)
{
//
}
MatchManager
.
getInstance
().
removeMatchEvent
(
matchId
);
log
.
info
(
"更新篮球比赛完成"
);
String
[]
homeScore
=
competitionDto
.
getGameInfo
().
getAScore
().
split
(
","
);
String
[]
awayScore
=
competitionDto
.
getGameInfo
().
getBScore
().
split
(
","
);
match
.
setAwayScore
(
Integer
.
parseInt
(
homeScore
[
0
]));
match
.
setHomeScore
(
Integer
.
parseInt
(
awayScore
[
0
]));
match
.
setCompetitionStatus
(
3
);
matchMapper
.
updateById
(
match
);
return
;
}
else
{
log
.
info
(
"篮球 {} - 其它状态 - {}"
,
matchId
,
competitionDto
.
getGameInfo
().
getStatus
());
if
(
match
.
getCompetitionStatus
()
!=
1
)
{
match
.
setCompetitionStatus
(
1
);
matchMapper
.
updateById
(
match
);
}
}
}
else
{
log
.
info
(
"赛事请求异常:{}"
,
matchId
);
}
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"更新篮球比赛时报错:{} - {}"
,
e
.
getMessage
(),
JSON
.
toJSONString
(
match
));
}
// applicationEventPublisher.publishEvent(MatchOngoingEvent.builder().matchId(matchId).time(time).matchTime(match.getMatchTime()).sportsType(1).status(1).build());
}
@Override
public
String
getPlatform
()
{
return
CrawlPlatformEnum
.
LeYu
.
getCode
();
}
}
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