调整表格数据及折线图数据

This commit is contained in:
2026-01-23 15:35:54 +08:00
parent 2ff8fec4b0
commit 2f8bdf99ed
2 changed files with 132 additions and 23 deletions

View File

@@ -83,7 +83,7 @@ function updateChart1() {
const option = {
title: {
text: '折线图1',
text: '今日盈亏数据',
left: 'center'
},
tooltip: {
@@ -106,7 +106,7 @@ function updateChart1() {
data: chartLabels.value,
axisLabel: {
rotate: 45,
interval: 11, // 每12个标签显示一个避免重叠
interval: chartLabels.value.length > 12 ? Math.floor(chartLabels.value.length / 12) : 0, // 根据标签数量动态调整间隔,确保至少显示一些标签
fontSize: 10
}
},
@@ -163,8 +163,15 @@ async function fetchChartData() {
console.log('获取折线图数据');
const response = await axios.get('http://localhost:8080/api/charts/line1');
console.log('折线图数据响应:', response.data);
if (response.data && response.data.data) {
chartData1.value = response.data.data;
if (response.data) {
// 更新数据
if (response.data.data) {
chartData1.value = response.data.data;
}
// 更新标签
if (response.data.labels) {
chartLabels.value = response.data.labels;
}
// 确保数据长度与标签长度一致
if (chartData1.value.length !== chartLabels.value.length) {
console.warn('数据长度与标签长度不一致,使用默认数据');

View File

@@ -1,27 +1,38 @@
package com.tem.bocai.schedules;
import com.tem.bocai.service.CompletedTodayService;
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;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import com.tem.bocai.entity.LoginInfoResult;
import com.tem.bocai.repository.LoginInfoRepository;
@Component
public class BetSchedule {
@Autowired
CompletedTodayService completedTodayService;
// 从6:15分开始每隔5分钟投注一次6:15, 6:20, 6:25...23:25
// @Scheduled(cron = "0 15/5 6-23 * * ?")
@Scheduled(cron = "*/9 * * * * ?")
private LoginInfoRepository loginInfoRepository;
// 每天早上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() {
LocalDateTime now = LocalDateTime.now();
int hour = now.getHour();
int minute = now.getMinute();
completedTodayService.sumResultAmount();
// 检查是否在6:15到23:25之间
if ((hour < 6) || (hour == 6 && minute < 15) ||
(hour > 23) || (hour == 23 && minute > 25)) {
// 检查是否在7:07到第二天6:00之间
// 如果时间在6:00到7:06之间则跳过执行
if ((hour == 6) || (hour == 7 && minute < 7)) {
String currentTime = now.format(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
);
@@ -29,11 +40,33 @@ public class BetSchedule {
return;
}
// 根据LoginInfoResult 中的winNumloseNumonOff字段判断是否执行投注
String currentTime = now.format(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
);
LoginInfoResult loginInfo = loginInfoRepository.findFirstByOrderByCreateTimeDesc().orElse(null);
if (loginInfo == null) {
System.out.println(currentTime + " - 未找到登录信息,跳过执行");
return;
}
// 检查onOff字段是否为1开启状态
if (loginInfo.getOnOff() != 1) {
System.out.println(currentTime + " - 投注功能未开启,跳过执行");
return;
}
// 检查winNum和loseNum字段是否合理
Integer winNum = loginInfo.getWinNum();
Integer loseNum = loginInfo.getLoseNum();
if (winNum == null || loseNum == null) {
System.out.println(currentTime + " - 投注设置不完整,跳过执行");
return;
}
System.out.println(currentTime + " - 开始执行投注...");
System.out.println(" - 投注设置: 止盈点=" + winNum + ", 止亏点=" + loseNum + ", 状态=" + (loginInfo.getOnOff() == 1 ? "开启" : "关闭"));
try {
// 模拟投注逻辑
@@ -57,17 +90,86 @@ public class BetSchedule {
// 3. 执行投注操作
// 4. 记录投注结果
// 模拟投注过程
System.out.println(" - 生成投注号码...");
System.out.println(" - 计算投注金额...");
System.out.println(" - 提交投注...");
System.out.println(" - 记录投注结果...");
// 模拟网络延迟
try {
Thread.sleep(1000); // 模拟1秒的处理时间
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// 1. 从json文件中获取投注号码
System.out.println(" - 从json文件中获取投注号码...");
JSONObject betData = readBetDataFromJson();
JSONArray betNumbers = betData.getJSONArray("betNumbers");
System.out.println(" - 投注号码: " + betNumbers.toString());
// 2. 计算投注金额
System.out.println(" - 计算投注金额...");
double betAmount = betData.getDouble("betAmount");
System.out.println(" - 投注金额: " + betAmount);
// 3. 调用投注接口
System.out.println(" - 提交投注...");
String betResult = callBetApi(betNumbers, betAmount);
System.out.println(" - 投注结果: " + betResult);
// 4. 记录投注结果
System.out.println(" - 记录投注结果...");
recordBetResult(betNumbers, betAmount, betResult);
} catch (Exception e) {
System.err.println(" - 投注执行失败:");
e.printStackTrace();
}
}
/**
* 从json文件中读取投注数据
*/
private JSONObject readBetDataFromJson() throws IOException {
// 假设json文件位于项目根目录的bet-data.json
String filePath = "bet-data.json";
FileReader reader = new FileReader(filePath);
JSONTokener tokener = new JSONTokener(reader);
JSONObject betData = new JSONObject(tokener);
reader.close();
return betData;
}
/**
* 调用投注接口
*/
private String callBetApi(JSONArray betNumbers, double betAmount) throws IOException, InterruptedException {
// 假设投注接口地址为http://localhost:8080/api/bet
String apiUrl = "http://localhost:8080/api/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")));
// 创建HTTP客户端和请求
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(apiUrl))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody.toString()))
.build();
// 发送请求并获取响应
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// 解析响应
if (response.statusCode() == 200) {
JSONObject responseBody = new JSONObject(response.body());
return responseBody.getString("result");
} else {
return "error: " + response.statusCode();
}
}
/**
* 记录投注结果
*/
private void recordBetResult(JSONArray betNumbers, double betAmount, String betResult) {
// 这里可以实现将投注结果记录到数据库或日志文件的逻辑
// 为了简单起见,我们这里只打印日志
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(" - 投注记录: [" + currentTime + "] 号码: " + betNumbers.toString() + ", 金额: " + betAmount + ", 结果: " + betResult);
}
}