refactor(game): 重构 AE 和 SV388 的投注记录获取逻辑
- 为 GamesAEServiceImpl 和 SV388GamesServiceImpl 类添加 DelayService 依赖 - 实现 GetRealtimeRecordTask 和 GetHistoryRecordTask 类继承 DelayTask - 重写 getBetRecordByTime 和 getBetRecordByHistoryTime 方法,使用延迟任务处理大量数据 - 优化 batchInsert 方法,增加空数据判断和日志记录 - 调整 kickMember 方法,移除不必要的日志输出main-meitian
parent
b0c058345d
commit
fb6138f9a0
|
@ -16,10 +16,13 @@ import com.ff.base.utils.uuid.IdUtils;
|
||||||
import com.ff.common.dto.GameBalanceExchange;
|
import com.ff.common.dto.GameBalanceExchange;
|
||||||
import com.ff.common.service.ITenantGameQuotaService;
|
import com.ff.common.service.ITenantGameQuotaService;
|
||||||
import com.ff.config.KeyConfig;
|
import com.ff.config.KeyConfig;
|
||||||
|
import com.ff.delay.DelayService;
|
||||||
|
import com.ff.delay.DelayTask;
|
||||||
import com.ff.game.api.IGamesService;
|
import com.ff.game.api.IGamesService;
|
||||||
import com.ff.game.api.ae.client.AEClient;
|
import com.ff.game.api.ae.client.AEClient;
|
||||||
import com.ff.game.api.ae.dto.*;
|
import com.ff.game.api.ae.dto.*;
|
||||||
import com.ff.game.api.request.*;
|
import com.ff.game.api.request.*;
|
||||||
|
import com.ff.game.api.sv388.impl.SV388GamesServiceImpl;
|
||||||
import com.ff.game.api.xk.dto.XKKickMemberDTO;
|
import com.ff.game.api.xk.dto.XKKickMemberDTO;
|
||||||
import com.ff.game.domain.*;
|
import com.ff.game.domain.*;
|
||||||
import com.ff.game.service.IGameBettingDetailsService;
|
import com.ff.game.service.IGameBettingDetailsService;
|
||||||
|
@ -79,6 +82,9 @@ public class GamesAEServiceImpl implements IGamesService {
|
||||||
@Resource
|
@Resource
|
||||||
private IGameBettingDetailsService gameBettingDetailsService;
|
private IGameBettingDetailsService gameBettingDetailsService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DelayService delayService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 游戏id
|
* 游戏id
|
||||||
*/
|
*/
|
||||||
|
@ -345,15 +351,20 @@ public class GamesAEServiceImpl implements IGamesService {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GetRealtimeRecordTask extends DelayTask {
|
||||||
|
BetRecordByTimeDTO betRecordByTimeDTO;
|
||||||
|
|
||||||
|
public GetRealtimeRecordTask(BetRecordByTimeDTO betRecordByTimeDTO) {
|
||||||
|
this.betRecordByTimeDTO = betRecordByTimeDTO;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 按时间获取投注记录
|
|
||||||
*
|
|
||||||
* @param betRecordByTimeDTO 按时间dto投注记录
|
|
||||||
* @return {@link List }<{@link GameBettingDetails }>
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean getBetRecordByTime(BetRecordByTimeDTO betRecordByTimeDTO) {
|
public void execute() {
|
||||||
|
getRealtimeRecord(betRecordByTimeDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getRealtimeRecord(BetRecordByTimeDTO betRecordByTimeDTO) {
|
||||||
//请求参数
|
//请求参数
|
||||||
log.info("GamesAEServiceImpl [getBetRecordByTime] 请求参数 {}", betRecordByTimeDTO);
|
log.info("GamesAEServiceImpl [getBetRecordByTime] 请求参数 {}", betRecordByTimeDTO);
|
||||||
Map<String, Object> params = this.getKey(betRecordByTimeDTO);
|
Map<String, Object> params = this.getKey(betRecordByTimeDTO);
|
||||||
|
@ -373,23 +384,32 @@ public class GamesAEServiceImpl implements IGamesService {
|
||||||
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
||||||
//数据组装
|
//数据组装
|
||||||
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
||||||
return Boolean.TRUE;
|
if (aeBetRecordResponse.getTransactions().size() >= 20000) {
|
||||||
|
delayService.addTask(new GetRealtimeRecordTask(betRecordByTimeDTO));
|
||||||
|
}
|
||||||
|
//return Boolean.TRUE;
|
||||||
} else {
|
} else {
|
||||||
redisCache.deleteObject(CacheConstants.AE_TIME_FROM);
|
redisCache.deleteObject(CacheConstants.AE_TIME_FROM);
|
||||||
log.error("GamesAEServiceImpl [getBetRecordByTime] 获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
log.error("GamesAEServiceImpl [getBetRecordByTime] 获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
||||||
throw new BaseException(aeBetRecordResponse.getDesc());
|
//throw new BaseException(aeBetRecordResponse.getDesc());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
class GetHistoryRecordTask extends DelayTask {
|
||||||
* 按历史时间获取投注记录
|
BetRecordByTimeDTO betRecordByTimeDTO;
|
||||||
*
|
|
||||||
* @param betRecordByTimeDTO 按时间dto投注记录
|
public GetHistoryRecordTask(BetRecordByTimeDTO betRecordByTimeDTO) {
|
||||||
* @return {@link Boolean }
|
this.betRecordByTimeDTO = betRecordByTimeDTO;
|
||||||
*/
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean getBetRecordByHistoryTime(BetRecordByTimeDTO betRecordByTimeDTO) {
|
public void execute() {
|
||||||
|
getHistoryRecord(betRecordByTimeDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getHistoryRecord(BetRecordByTimeDTO betRecordByTimeDTO) {
|
||||||
log.info("GamesAEServiceImpl [getBetRecordByHistoryTime] 请求参数 {}", betRecordByTimeDTO);
|
log.info("GamesAEServiceImpl [getBetRecordByHistoryTime] 请求参数 {}", betRecordByTimeDTO);
|
||||||
Map<String, Object> params = this.getKey(betRecordByTimeDTO);
|
Map<String, Object> params = this.getKey(betRecordByTimeDTO);
|
||||||
String startTime = DateUtils.convertTimestampToFormattedDate(betRecordByTimeDTO.getStartTime(), DateUtils.ISO_8601_FORMAT, "GMT+8") + "+08:00";
|
String startTime = DateUtils.convertTimestampToFormattedDate(betRecordByTimeDTO.getStartTime(), DateUtils.ISO_8601_FORMAT, "GMT+8") + "+08:00";
|
||||||
|
@ -405,13 +425,40 @@ public class GamesAEServiceImpl implements IGamesService {
|
||||||
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
||||||
//数据组装
|
//数据组装
|
||||||
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
||||||
return Boolean.TRUE;
|
if (aeBetRecordResponse.getTransactions().size() >= 20000) {
|
||||||
|
delayService.addTask(new GetHistoryRecordTask(betRecordByTimeDTO));
|
||||||
|
}
|
||||||
|
// return Boolean.TRUE;
|
||||||
} else {
|
} else {
|
||||||
log.error("GamesAEServiceImpl [getBetRecordByHistoryTime] 获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
log.error("GamesAEServiceImpl [getBetRecordByHistoryTime] 获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
||||||
throw new BaseException(aeBetRecordResponse.getDesc());
|
// throw new BaseException(aeBetRecordResponse.getDesc());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按时间获取投注记录
|
||||||
|
*
|
||||||
|
* @param betRecordByTimeDTO 按时间dto投注记录
|
||||||
|
* @return {@link List }<{@link GameBettingDetails }>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean getBetRecordByTime(BetRecordByTimeDTO betRecordByTimeDTO) {
|
||||||
|
delayService.addTask(new GetRealtimeRecordTask(betRecordByTimeDTO));
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按历史时间获取投注记录
|
||||||
|
*
|
||||||
|
* @param betRecordByTimeDTO 按时间dto投注记录
|
||||||
|
* @return {@link Boolean }
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean getBetRecordByHistoryTime(BetRecordByTimeDTO betRecordByTimeDTO) {
|
||||||
|
delayService.addTask(new GetHistoryRecordTask(betRecordByTimeDTO));
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 赠送免费局数
|
* 赠送免费局数
|
||||||
*
|
*
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class SV388GamesServiceImpl implements IGamesService {
|
||||||
//不存在这个游戏
|
//不存在这个游戏
|
||||||
if (ObjectUtils.isEmpty(gameList)) {
|
if (ObjectUtils.isEmpty(gameList)) {
|
||||||
Game game = new Game();
|
Game game = new Game();
|
||||||
game.setId(IdUtil.getSnowflakeNextId());
|
game.setId(/*IdUtil.getSnowflakeNextId()*/GAME_ID);
|
||||||
game.setSortNo(gameService.selectMaxSortNo(platformType, GamePlatforms.SV388.getCode()) + 1);
|
game.setSortNo(gameService.selectMaxSortNo(platformType, GamePlatforms.SV388.getCode()) + 1);
|
||||||
game.setPlatformCode(platform.getPlatformCode());
|
game.setPlatformCode(platform.getPlatformCode());
|
||||||
game.setPlatformType(platformType);
|
game.setPlatformType(platformType);
|
||||||
|
@ -373,6 +373,9 @@ public class SV388GamesServiceImpl implements IGamesService {
|
||||||
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
||||||
//数据组装
|
//数据组装
|
||||||
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
||||||
|
if (aeBetRecordResponse.getTransactions().size() >= 20000) {
|
||||||
|
delayService.addTask(new GetRealtimeRecordTask(betRecordByTimeDTO));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
redisCache.deleteObject(CacheConstants.SV388_TIME_FROM);
|
redisCache.deleteObject(CacheConstants.SV388_TIME_FROM);
|
||||||
log.error("获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
log.error("获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
||||||
|
@ -394,6 +397,9 @@ public class SV388GamesServiceImpl implements IGamesService {
|
||||||
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
if (this.getIsSuccess(aeBetRecordResponse.getStatus())) {
|
||||||
//数据组装
|
//数据组装
|
||||||
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
this.batchInsert(aeBetRecordResponse, betRecordByTimeDTO);
|
||||||
|
if (aeBetRecordResponse.getTransactions().size() >= 20000) {
|
||||||
|
delayService.addTask(new GetHistoryRecordTask(betRecordByTimeDTO));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
log.error("获取投注记录失败,错误代码{},错误信息{}", aeBetRecordResponse.getStatus(), aeBetRecordResponse.getDesc());
|
||||||
}
|
}
|
||||||
|
@ -466,7 +472,6 @@ public class SV388GamesServiceImpl implements IGamesService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean kickMember(KickMemberRequestDTO kickMemberRequestDTO) {
|
public Boolean kickMember(KickMemberRequestDTO kickMemberRequestDTO) {
|
||||||
log.info("GamesAEServiceImpl [kickMember] 请求参数 {}", kickMemberRequestDTO);
|
|
||||||
Map<String, Object> params = this.getKey(kickMemberRequestDTO);
|
Map<String, Object> params = this.getKey(kickMemberRequestDTO);
|
||||||
params.put("userIds", kickMemberRequestDTO.getAccount());
|
params.put("userIds", kickMemberRequestDTO.getAccount());
|
||||||
XKKickMemberDTO xkKickMemberDTO = sv388Client.kickMember(params);
|
XKKickMemberDTO xkKickMemberDTO = sv388Client.kickMember(params);
|
||||||
|
@ -528,12 +533,16 @@ public class SV388GamesServiceImpl implements IGamesService {
|
||||||
*
|
*
|
||||||
* @param aeBetRecordResponse ae下注记录响应dto
|
* @param aeBetRecordResponse ae下注记录响应dto
|
||||||
*/
|
*/
|
||||||
private synchronized void batchInsert(SV388BetRecordResponse aeBetRecordResponse, BetRecordByTimeDTO betRecordByTimeDTO) {
|
private void batchInsert(SV388BetRecordResponse aeBetRecordResponse, BetRecordByTimeDTO betRecordByTimeDTO) {
|
||||||
List<GameBettingDetails> gameBettingDetails = new ArrayList<>();
|
List<GameBettingDetails> gameBettingDetails = new ArrayList<>();
|
||||||
List<String> wagersIds = new ArrayList<>();
|
List<String> wagersIds = new ArrayList<>();
|
||||||
//数据组装
|
//数据组装
|
||||||
List<SV388BetRecordResponse.Transaction> dataBean = aeBetRecordResponse.getTransactions();
|
List<SV388BetRecordResponse.Transaction> dataBean = aeBetRecordResponse.getTransactions();
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(dataBean)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String timeFrom = null;
|
String timeFrom = null;
|
||||||
//数据转化
|
//数据转化
|
||||||
for (SV388BetRecordResponse.Transaction bean : dataBean) {
|
for (SV388BetRecordResponse.Transaction bean : dataBean) {
|
||||||
|
@ -562,6 +571,7 @@ public class SV388GamesServiceImpl implements IGamesService {
|
||||||
timeFrom = DateUtils.convertTimestampToFormattedDate(DateUtils.getNowDate(), DateUtils.ISO_8601_FORMAT, "UTC+8") + "+08:00";
|
timeFrom = DateUtils.convertTimestampToFormattedDate(DateUtils.getNowDate(), DateUtils.ISO_8601_FORMAT, "UTC+8") + "+08:00";
|
||||||
}
|
}
|
||||||
redisCache.setCacheObject(CacheConstants.SV388_TIME_FROM, timeFrom);
|
redisCache.setCacheObject(CacheConstants.SV388_TIME_FROM, timeFrom);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue