调整投注方法
This commit is contained in:
@@ -43,25 +43,11 @@ public class LoginInfoResult {
|
|||||||
//1是开0是关
|
//1是开0是关
|
||||||
@Column(name = "on_off")
|
@Column(name = "on_off")
|
||||||
private Integer onOff;
|
private Integer onOff;
|
||||||
|
|
||||||
|
//登录cookie
|
||||||
|
@Column(name = "cookie")
|
||||||
|
private String cookie;
|
||||||
|
|
||||||
/* @Column(name = "current_num", nullable = false)
|
|
||||||
private Integer currentNum;*/
|
|
||||||
/*@Column(name = "create_time", nullable = false, updatable = false)
|
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
@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)
|
@Column(name = "create_time", nullable = false, updatable = false)
|
||||||
@CreationTimestamp
|
@CreationTimestamp
|
||||||
@Convert(converter = SQLiteDateConverter.class)
|
@Convert(converter = SQLiteDateConverter.class)
|
||||||
|
|||||||
@@ -6,9 +6,13 @@ import com.tem.bocai.entity.LoginInfoResult;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface CompletedTodayRepository extends JpaRepository<CompletedToday, Long> {
|
public interface CompletedTodayRepository extends JpaRepository<CompletedToday, Long> {
|
||||||
|
|
||||||
|
// 根据时间范围查询resultAmount的总和
|
||||||
|
Double sumResultAmountByCreateTimeAfter(Date startTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package com.tem.bocai.schedules;
|
package com.tem.bocai.schedules;
|
||||||
|
|
||||||
|
import com.tem.bocai.service.LoginService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@@ -11,112 +12,147 @@ import java.net.http.HttpRequest;
|
|||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
import com.tem.bocai.entity.LoginInfoResult;
|
import com.tem.bocai.entity.LoginInfoResult;
|
||||||
|
import com.tem.bocai.repository.CompletedTodayRepository;
|
||||||
import com.tem.bocai.repository.LoginInfoRepository;
|
import com.tem.bocai.repository.LoginInfoRepository;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class BetSchedule {
|
public class BetSchedule {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LoginService loginService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoginInfoRepository loginInfoRepository;
|
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)
|
// 每天早上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 * * ?")
|
// @Scheduled(cron = "0 7/5 7-23,0-6 * * ?")
|
||||||
public void placeBet() {
|
public void placeBet() {
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
int hour = now.getHour();
|
int hour = now.getHour();
|
||||||
int minute = now.getMinute();
|
int minute = now.getMinute();
|
||||||
|
|
||||||
// 检查是否在7:07到第二天6:00之间
|
// 检查是否在7:07到第二天6:00之间
|
||||||
// 如果时间在6:00到7:06之间,则跳过执行
|
// 如果时间在6:00到7:06之间,则跳过执行
|
||||||
if ((hour == 6) || (hour == 7 && minute < 7)) {
|
if ((hour == 6) || (hour == 7 && minute < 7)) {
|
||||||
String currentTime = now.format(
|
String currentTime = now.format(
|
||||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
);
|
);
|
||||||
System.out.println(currentTime + " - 不在投注时间范围内,跳过执行");
|
System.out.println(currentTime + " - 不在投注时间范围内,跳过执行");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据LoginInfoResult 中的winNum,loseNum,onOff字段判断是否执行投注
|
// 根据LoginInfoResult 中的winNum,loseNum,onOff字段判断是否执行投注
|
||||||
String currentTime = now.format(
|
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);
|
LoginInfoResult loginInfo = loginInfoRepository.findFirstByOrderByCreateTimeDesc().orElse(null);
|
||||||
if (loginInfo == null) {
|
if (loginInfo == null) {
|
||||||
System.out.println(currentTime + " - 未找到登录信息,跳过执行");
|
System.out.println(currentTime + " - 未找到登录信息,跳过执行");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查onOff字段是否为1(开启状态)
|
// 检查onOff字段是否为1(开启状态)
|
||||||
if (loginInfo.getOnOff() != 1) {
|
if (loginInfo.getOnOff() != 1) {
|
||||||
System.out.println(currentTime + " - 投注功能未开启,跳过执行");
|
System.out.println(currentTime + " - 投注功能未开启,跳过执行");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查winNum和loseNum字段是否合理
|
// 检查winNum和loseNum字段是否合理
|
||||||
Integer winNum = loginInfo.getWinNum();
|
Integer winNum = loginInfo.getWinNum();
|
||||||
Integer loseNum = loginInfo.getLoseNum();
|
Integer loseNum = loginInfo.getLoseNum();
|
||||||
if (winNum == null || loseNum == null) {
|
|
||||||
System.out.println(currentTime + " - 投注设置不完整,跳过执行");
|
if (winNum != null || loseNum != null) {
|
||||||
return;
|
// 根据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(currentTime + " - 开始执行投注...");
|
||||||
System.out.println(" - 投注设置: 止盈点=" + winNum + ", 止亏点=" + loseNum + ", 状态=" + (loginInfo.getOnOff() == 1 ? "开启" : "关闭"));
|
System.out.println(" - 投注设置: 止盈点=" + winNum + ", 止亏点=" + loseNum + ", 状态=" + (loginInfo.getOnOff() == 1 ? "开启" : "关闭"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 模拟投注逻辑
|
// 执行投注逻辑
|
||||||
executeBet();
|
executeBet(loginInfo);
|
||||||
|
|
||||||
System.out.println(currentTime + " - 投注执行完成");
|
System.out.println(currentTime + " - 投注执行完成");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(currentTime + " - 投注执行失败:");
|
System.err.println(currentTime + " - 投注执行失败:");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行投注逻辑
|
* 执行投注逻辑
|
||||||
*/
|
*/
|
||||||
private void executeBet() {
|
private void executeBet(LoginInfoResult loginInfo) {
|
||||||
// 这里实现具体的投注逻辑
|
// 这里实现具体的投注逻辑
|
||||||
// 1. 获取投注号码
|
// 1. 获取投注号码
|
||||||
// 2. 计算投注金额
|
// 2. 计算投注金额
|
||||||
// 3. 执行投注操作
|
// 3. 执行投注操作
|
||||||
// 4. 记录投注结果
|
// 4. 记录投注结果
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. 从json文件中获取投注号码
|
// 1. 从json文件中获取投注号码
|
||||||
System.out.println(" - 从json文件中获取投注号码...");
|
System.out.println(" - 从json文件中获取投注号码...");
|
||||||
JSONObject betData = readBetDataFromJson();
|
JSONObject betData = readBetDataFromJson();
|
||||||
JSONArray betNumbers = betData.getJSONArray("betNumbers");
|
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());
|
System.out.println(" - 投注号码: " + betNumbers.toString());
|
||||||
|
|
||||||
// 2. 计算投注金额
|
// 2. 计算投注金额
|
||||||
System.out.println(" - 计算投注金额...");
|
System.out.println(" - 计算投注金额...");
|
||||||
double betAmount = betData.getDouble("betAmount");
|
double betAmount = betData.getDouble("betAmount");
|
||||||
System.out.println(" - 投注金额: " + betAmount);
|
System.out.println(" - 投注金额: " + betAmount);
|
||||||
|
|
||||||
// 3. 调用投注接口
|
// 3. 调用投注接口
|
||||||
System.out.println(" - 提交投注...");
|
System.out.println(" - 提交投注...");
|
||||||
String betResult = callBetApi(betNumbers, betAmount);
|
String betResult = callBetApi(betNumbers, betAmount, loginInfo);
|
||||||
System.out.println(" - 投注结果: " + betResult);
|
System.out.println(" - 投注结果: " + betResult);
|
||||||
|
|
||||||
// 4. 记录投注结果
|
// 4. 记录投注结果
|
||||||
System.out.println(" - 记录投注结果...");
|
System.out.println(" - 记录投注结果...");
|
||||||
recordBetResult(betNumbers, betAmount, betResult);
|
recordBetResult(betNumbers, betAmount, betResult);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(" - 投注执行失败:");
|
System.err.println(" - 投注执行失败:");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从json文件中读取投注数据
|
* 从json文件中读取投注数据
|
||||||
*/
|
*/
|
||||||
@@ -129,31 +165,37 @@ public class BetSchedule {
|
|||||||
reader.close();
|
reader.close();
|
||||||
return betData;
|
return betData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用投注接口
|
* 调用投注接口
|
||||||
*/
|
*/
|
||||||
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
|
// 假设投注接口地址为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();
|
JSONObject requestBody = new JSONObject();
|
||||||
requestBody.put("betNumbers", betNumbers);
|
requestBody.put("lottery", "SGFT");
|
||||||
requestBody.put("betAmount", betAmount);
|
requestBody.put("drawNumber", betAmount);
|
||||||
requestBody.put("betTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
requestBody.put("fastBets", false);
|
||||||
|
requestBody.put("ignore", false);
|
||||||
|
requestBody.put("bets", betNumbers);
|
||||||
|
|
||||||
// 创建HTTP客户端和请求
|
// 创建HTTP客户端和请求
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||||
.uri(URI.create(apiUrl))
|
.uri(URI.create(apiUrl))
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
|
.header("cookie", "token=" + loginService.completedToday());
|
||||||
|
|
||||||
|
|
||||||
|
HttpRequest request = requestBuilder
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(requestBody.toString()))
|
.POST(HttpRequest.BodyPublishers.ofString(requestBody.toString()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// 发送请求并获取响应
|
// 发送请求并获取响应
|
||||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
// 解析响应
|
// 解析响应
|
||||||
if (response.statusCode() == 200) {
|
if (response.statusCode() == 200) {
|
||||||
JSONObject responseBody = new JSONObject(response.body());
|
JSONObject responseBody = new JSONObject(response.body());
|
||||||
@@ -162,7 +204,7 @@ public class BetSchedule {
|
|||||||
return "error: " + response.statusCode();
|
return "error: " + response.statusCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录投注结果
|
* 记录投注结果
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user