调整投注方法
This commit is contained in:
@@ -44,24 +44,10 @@ public class LoginInfoResult {
|
||||
@Column(name = "on_off")
|
||||
private Integer onOff;
|
||||
|
||||
/* @Column(name = "current_num", nullable = false)
|
||||
private Integer currentNum;*/
|
||||
/*@Column(name = "create_time", nullable = false, updatable = false)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
//登录cookie
|
||||
@Column(name = "cookie")
|
||||
private String cookie;
|
||||
|
||||
@Column(name = "update_time", nullable = false)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;*/
|
||||
|
||||
|
||||
/* @Column(name = "create_time", nullable = false, updatable = false)
|
||||
@CreationTimestamp // Hibernate注解,自动设置创建时间
|
||||
private Date createTime;
|
||||
|
||||
@Column(name = "update_time", nullable = false)
|
||||
@UpdateTimestamp // Hibernate注解,自动更新时间
|
||||
private Date updateTime;*/
|
||||
@Column(name = "create_time", nullable = false, updatable = false)
|
||||
@CreationTimestamp
|
||||
@Convert(converter = SQLiteDateConverter.class)
|
||||
|
||||
@@ -6,9 +6,13 @@ import com.tem.bocai.entity.LoginInfoResult;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CompletedTodayRepository extends JpaRepository<CompletedToday, Long> {
|
||||
|
||||
// 根据时间范围查询resultAmount的总和
|
||||
Double sumResultAmountByCreateTimeAfter(Date startTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.tem.bocai.schedules;
|
||||
|
||||
import com.tem.bocai.service.LoginService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -11,18 +12,27 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import com.tem.bocai.entity.LoginInfoResult;
|
||||
import com.tem.bocai.repository.CompletedTodayRepository;
|
||||
import com.tem.bocai.repository.LoginInfoRepository;
|
||||
|
||||
@Component
|
||||
public class BetSchedule {
|
||||
|
||||
@Autowired
|
||||
private LoginService loginService;
|
||||
|
||||
@Autowired
|
||||
private LoginInfoRepository loginInfoRepository;
|
||||
|
||||
@Autowired
|
||||
private CompletedTodayRepository completedTodayRepository;
|
||||
|
||||
// 每天早上7.07分开始,每5分钟执行一次到第二天早上6点结束(7:07, 7:12, 7:17...23:57, 0:02, 0:07...5:57)
|
||||
// @Scheduled(cron = "0 7/5 7-23,0-6 * * ?")
|
||||
public void placeBet() {
|
||||
@@ -34,7 +44,7 @@ public class BetSchedule {
|
||||
// 如果时间在6:00到7:06之间,则跳过执行
|
||||
if ((hour == 6) || (hour == 7 && minute < 7)) {
|
||||
String currentTime = now.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
);
|
||||
System.out.println(currentTime + " - 不在投注时间范围内,跳过执行");
|
||||
return;
|
||||
@@ -42,7 +52,7 @@ public class BetSchedule {
|
||||
|
||||
// 根据LoginInfoResult 中的winNum,loseNum,onOff字段判断是否执行投注
|
||||
String currentTime = now.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
);
|
||||
|
||||
LoginInfoResult loginInfo = loginInfoRepository.findFirstByOrderByCreateTimeDesc().orElse(null);
|
||||
@@ -60,17 +70,36 @@ public class BetSchedule {
|
||||
// 检查winNum和loseNum字段是否合理
|
||||
Integer winNum = loginInfo.getWinNum();
|
||||
Integer loseNum = loginInfo.getLoseNum();
|
||||
if (winNum == null || loseNum == null) {
|
||||
System.out.println(currentTime + " - 投注设置不完整,跳过执行");
|
||||
return;
|
||||
|
||||
if (winNum != null || loseNum != null) {
|
||||
// 根据LoginInfo的startTime 查询CompletedToday的resultAmount总和 判断是否达到 winNum 和 loseNum的值
|
||||
Date startTime = loginInfo.getStartTime();
|
||||
if (startTime != null) {
|
||||
Double totalResultAmount = completedTodayRepository.sumResultAmountByCreateTimeAfter(startTime);
|
||||
if (totalResultAmount != null) {
|
||||
System.out.println(" - 今日盈亏总和: " + totalResultAmount);
|
||||
|
||||
// 判断是否达到止盈点
|
||||
if (totalResultAmount >= winNum) {
|
||||
System.out.println(currentTime + " - 已达到止盈点 " + winNum + ",跳过执行");
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断是否达到止亏点
|
||||
if (totalResultAmount <= -loseNum) {
|
||||
System.out.println(currentTime + " - 已达到止亏点 " + loseNum + ",跳过执行");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(currentTime + " - 开始执行投注...");
|
||||
System.out.println(" - 投注设置: 止盈点=" + winNum + ", 止亏点=" + loseNum + ", 状态=" + (loginInfo.getOnOff() == 1 ? "开启" : "关闭"));
|
||||
|
||||
try {
|
||||
// 模拟投注逻辑
|
||||
executeBet();
|
||||
// 执行投注逻辑
|
||||
executeBet(loginInfo);
|
||||
|
||||
System.out.println(currentTime + " - 投注执行完成");
|
||||
|
||||
@@ -83,7 +112,7 @@ public class BetSchedule {
|
||||
/**
|
||||
* 执行投注逻辑
|
||||
*/
|
||||
private void executeBet() {
|
||||
private void executeBet(LoginInfoResult loginInfo) {
|
||||
// 这里实现具体的投注逻辑
|
||||
// 1. 获取投注号码
|
||||
// 2. 计算投注金额
|
||||
@@ -95,6 +124,13 @@ public class BetSchedule {
|
||||
System.out.println(" - 从json文件中获取投注号码...");
|
||||
JSONObject betData = readBetDataFromJson();
|
||||
JSONArray betNumbers = betData.getJSONArray("betNumbers");
|
||||
|
||||
JSONObject bet = betData.getJSONObject("bet");
|
||||
bet.put("game", betNumbers);
|
||||
bet.put("contents", betNumbers);
|
||||
bet.put("amount", betNumbers);
|
||||
bet.put("odds", 9.599);
|
||||
bet.put("title", betNumbers);
|
||||
System.out.println(" - 投注号码: " + betNumbers.toString());
|
||||
|
||||
// 2. 计算投注金额
|
||||
@@ -104,7 +140,7 @@ public class BetSchedule {
|
||||
|
||||
// 3. 调用投注接口
|
||||
System.out.println(" - 提交投注...");
|
||||
String betResult = callBetApi(betNumbers, betAmount);
|
||||
String betResult = callBetApi(betNumbers, betAmount, loginInfo);
|
||||
System.out.println(" - 投注结果: " + betResult);
|
||||
|
||||
// 4. 记录投注结果
|
||||
@@ -133,21 +169,27 @@ public class BetSchedule {
|
||||
/**
|
||||
* 调用投注接口
|
||||
*/
|
||||
private String callBetApi(JSONArray betNumbers, double betAmount) throws IOException, InterruptedException {
|
||||
private String callBetApi(JSONArray betNumbers, double betAmount, LoginInfoResult loginInfo) throws IOException, InterruptedException {
|
||||
// 假设投注接口地址为http://localhost:8080/api/bet
|
||||
String apiUrl = "http://localhost:8080/api/bet";
|
||||
String apiUrl = "https://4701268539-esh.qdk63ayw8g.com/member/bet";
|
||||
|
||||
// 构建请求体
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.put("betNumbers", betNumbers);
|
||||
requestBody.put("betAmount", betAmount);
|
||||
requestBody.put("betTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
requestBody.put("lottery", "SGFT");
|
||||
requestBody.put("drawNumber", betAmount);
|
||||
requestBody.put("fastBets", false);
|
||||
requestBody.put("ignore", false);
|
||||
requestBody.put("bets", betNumbers);
|
||||
|
||||
// 创建HTTP客户端和请求
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
.uri(URI.create(apiUrl))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("cookie", "token=" + loginService.completedToday());
|
||||
|
||||
|
||||
HttpRequest request = requestBuilder
|
||||
.POST(HttpRequest.BodyPublishers.ofString(requestBody.toString()))
|
||||
.build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user