新增投注记录到数据库
This commit is contained in:
@@ -54,4 +54,6 @@ public class LotteryResult {
|
||||
@Column(name = "glh_result", nullable = false)
|
||||
private String glh_result; //[ "龙", "龙", "龙", "虎", "虎" ] 龙虎
|
||||
|
||||
@Column(name = "bet_result")
|
||||
private String betResult;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.tem.bocai.schedules;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.tem.bocai.util.TokenCacheService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -20,9 +21,11 @@ import java.util.Optional;
|
||||
import org.json.JSONObject;
|
||||
import com.tem.bocai.entity.LoginInfoResult;
|
||||
import com.tem.bocai.entity.BetRecord;
|
||||
import com.tem.bocai.entity.LotteryResult;
|
||||
import com.tem.bocai.repository.CompletedTodayRepository;
|
||||
import com.tem.bocai.repository.LoginInfoRepository;
|
||||
import com.tem.bocai.repository.BetRecordRepository;
|
||||
import com.tem.bocai.repository.LotteryResultRepository;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -40,6 +43,9 @@ public class BetSchedule {
|
||||
@Autowired
|
||||
private BetRecordRepository betRecordRepository;
|
||||
|
||||
@Autowired
|
||||
private LotteryResultRepository lotteryResultRepository;
|
||||
|
||||
// 从7:02分钟起每5分钟执行一次
|
||||
@Scheduled(cron = "30 2/5 * * * ?")
|
||||
public void placeBet() {
|
||||
@@ -202,9 +208,27 @@ public class BetSchedule {
|
||||
* 记录投注结果
|
||||
*/
|
||||
private void recordBetResult(String betData, String betResult) {
|
||||
// 这里可以实现将投注结果记录到数据库或日志文件的逻辑
|
||||
// 为了简单起见,我们这里只打印日志
|
||||
// 这里实现将投注结果记录到LotteryResult的betResult字段的逻辑
|
||||
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
log.info(" - 投注记录: [{}] 数据: {}, 结果: {}", currentTime, betData, betResult);
|
||||
|
||||
try {
|
||||
// 解析betData获取drawNumber(term)
|
||||
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(betData);
|
||||
String drawNumber = jsonObject.getString("drawNumber");
|
||||
if (StringUtils.isBlank(drawNumber)){
|
||||
log.error(" - 新增LotteryResult记录失败:");
|
||||
return;
|
||||
}
|
||||
// 创建新的LotteryResult记录
|
||||
LotteryResult newLotteryResult = new LotteryResult();
|
||||
newLotteryResult.setIssue(drawNumber);
|
||||
newLotteryResult.setBetResult(betData);
|
||||
// 保存新记录
|
||||
lotteryResultRepository.save(newLotteryResult);
|
||||
log.info(" - 已新增LotteryResult记录,期号: {}", drawNumber);
|
||||
} catch (Exception e) {
|
||||
log.error(" - 新增LotteryResult记录失败:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user