-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
258 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/online/fycloud/webapi/common/entity/FreeGame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package online.fycloud.webapi.common.entity; | ||
|
||
import com.alibaba.fastjson.annotation.JSONField; | ||
import com.baomidou.mybatisplus.annotation.IdType; | ||
import com.baomidou.mybatisplus.annotation.TableField; | ||
import com.baomidou.mybatisplus.annotation.TableId; | ||
import com.baomidou.mybatisplus.annotation.TableName; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
/** | ||
* 游戏白嫖信息 | ||
* | ||
* @author VarleyT | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@TableName(value = "free_game") | ||
public class FreeGame implements Serializable { | ||
/** | ||
* | ||
*/ | ||
@TableId(type = IdType.AUTO) | ||
@JSONField(serialize = false) | ||
private Integer id; | ||
|
||
/** | ||
* 游戏名 | ||
*/ | ||
@JSONField(ordinal = 1) | ||
private String gameName; | ||
|
||
/** | ||
* 链接 | ||
*/ | ||
@JSONField(ordinal = 3) | ||
private String url; | ||
|
||
/** | ||
* 类型 | ||
*/ | ||
@JSONField(ordinal = 4) | ||
private String type; | ||
|
||
/** | ||
* 开始时间 | ||
*/ | ||
@JSONField(ordinal = 5, format = "yyyy-MM-dd HH:mm:ss") | ||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
private Date startTime; | ||
|
||
/** | ||
* 结束时间 | ||
*/ | ||
@JSONField(ordinal = 6, format = "yyyy-MM-dd HH:mm:ss") | ||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
private Date endTime; | ||
|
||
/** | ||
* 是否永久 | ||
*/ | ||
@JSONField(ordinal = 7, name = "forever") | ||
private boolean valid; | ||
|
||
/** | ||
* 游戏平台 | ||
*/ | ||
@JSONField(ordinal = 2) | ||
private String store; | ||
|
||
@TableField(exist = false) | ||
@JSONField(serialize = false) | ||
private static final long serialVersionUID = 1L; | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/online/fycloud/webapi/common/logic/FreeGameAnalyse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package online.fycloud.webapi.common.logic; | ||
|
||
import cn.hutool.core.date.DateField; | ||
import cn.hutool.core.date.DateTime; | ||
import cn.hutool.core.date.DateUtil; | ||
import cn.hutool.http.HttpRequest; | ||
import cn.hutool.http.HttpUtil; | ||
import lombok.extern.slf4j.Slf4j; | ||
import online.fycloud.webapi.common.entity.FreeGame; | ||
import online.fycloud.webapi.common.service.FreeGameService; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author VarleyT | ||
* @date 2022/10/6 | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class FreeGameAnalyse { | ||
private static final String API = "https://steamstats.cn/xi"; | ||
|
||
@Autowired | ||
private FreeGameService freeGameService; | ||
|
||
@Scheduled(cron = "0 0 1 ? * 5") | ||
public void analyse() { | ||
log.info("开始执行定时任务:{}", "获取游戏白嫖信息"); | ||
List<FreeGame> freeGameList = new LinkedList<>(); | ||
HttpRequest request = HttpUtil.createGet(API).header("accept-language", "zh-CN,zh;q=0.9") | ||
.header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9") | ||
.header("accept-language", "zh-CN,zh;q=0.9") | ||
.header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36") | ||
.setFollowRedirects(false); | ||
Document doc = Jsoup.parse(request.execute().body()); | ||
Elements datas = doc.getElementsByClass("v-data-table__wrapper"); | ||
Elements gameInfos = datas.get(0).child(0).child(1).children(); | ||
for (Element gameInfo : gameInfos) { | ||
String gameName = gameInfo.child(1).select("a").first().attr("title"); | ||
String url = gameInfo.child(1).select("a").first().attr("href"); | ||
String type = gameInfo.child(2).text(); | ||
DateTime startTime = DateUtil.parse(gameInfo.child(3).text(), "yyyy-MM-dd"); | ||
DateTime endTime = DateUtil.parse(gameInfo.child(4).text(), "yyyy-MM-dd") | ||
.offset(DateField.HOUR, 23); | ||
boolean valid = false; | ||
if (gameInfo.child(5).text().equals("是") || gameInfo.child(5).text().equals("yes")) { | ||
valid = true; | ||
} | ||
String store = gameInfo.child(6).getElementsByClass("v-btn__content").get(0).text(); | ||
freeGameList.add(new FreeGame(null, gameName, url, type, startTime, endTime, valid, store)); | ||
} | ||
freeGameService.add(freeGameList); | ||
log.info("定时任务执行完毕:{}", "获取游戏白嫖信息"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/online/fycloud/webapi/common/mapper/FreeGameMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package online.fycloud.webapi.common.mapper; | ||
|
||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
import online.fycloud.webapi.common.entity.FreeGame; | ||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
/** | ||
* @author VarleyT | ||
* @date 2022/10/6 | ||
*/ | ||
@Mapper | ||
public interface FreeGameMapper extends BaseMapper<FreeGame> { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/online/fycloud/webapi/common/service/FreeGameService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package online.fycloud.webapi.common.service; | ||
|
||
import com.baomidou.mybatisplus.extension.service.IService; | ||
import online.fycloud.webapi.common.entity.FreeGame; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author VarleyT | ||
* @date 2022/10/6 | ||
*/ | ||
public interface FreeGameService extends IService<FreeGame> { | ||
|
||
/** | ||
* 新增元素 | ||
* | ||
* @param freeGameList | ||
*/ | ||
void add(List<FreeGame> freeGameList); | ||
|
||
/** | ||
* 获取信息 | ||
* | ||
* @return | ||
*/ | ||
List<FreeGame> getInfos(); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/online/fycloud/webapi/common/service/Impl/FreeGameServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package online.fycloud.webapi.common.service.Impl; | ||
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
import online.fycloud.webapi.common.entity.FreeGame; | ||
import online.fycloud.webapi.common.mapper.FreeGameMapper; | ||
import online.fycloud.webapi.common.service.FreeGameService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* @author VarleyT | ||
* @date 2022/10/6 | ||
*/ | ||
@Service | ||
public class FreeGameServiceImpl extends ServiceImpl<FreeGameMapper, FreeGame> implements FreeGameService { | ||
@Override | ||
public void add(List<FreeGame> freeGameList) { | ||
freeGameList.forEach(freeGame -> saveOrUpdate(freeGame)); | ||
} | ||
|
||
@Override | ||
public List<FreeGame> getInfos() { | ||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
String now = sdf.format(new Date()); | ||
List<FreeGame> list = list(new QueryWrapper<FreeGame>() | ||
.apply("start_time < time({0}) and end_time > time({0})", now)); | ||
return list; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters