game-api/ff-game/src/main/java/com/ff/api/controller/ApiGameController.java

871 lines
38 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.ff.api.controller;
import cn.hutool.core.util.IdUtil;
import com.ff.annotation.CheckHeader;
import com.ff.api.request.*;
import com.ff.api.response.*;
import com.ff.base.constant.Constants;
import com.ff.base.core.controller.BaseController;
import com.ff.base.core.domain.AjaxResult;
import com.ff.base.core.page.TableDataInfo;
import com.ff.base.enums.*;
import com.ff.base.exception.base.ApiException;
import com.ff.base.manager.AsyncManager;
import com.ff.base.system.domain.TenantSecretKey;
import com.ff.base.utils.StringUtils;
import com.ff.base.utils.bean.BeanUtils;
import com.ff.common.dto.GameBalanceExchange;
import com.ff.config.KeyConfig;
import com.ff.game.api.IGamesService;
import com.ff.game.api.exchange.StepProcessorFactory;
import com.ff.game.api.exchange.dto.GameExchangeDTO;
import com.ff.game.api.request.*;
import com.ff.game.domain.*;
import com.ff.game.dto.GameBettingDetailsDTO;
import com.ff.game.service.*;
import com.ff.member.domain.Member;
import com.ff.member.service.IMemberService;
import com.ff.tenant.service.ITenantGameQuotaBiz;
import com.ff.tenant.service.ITenantGameQuotaService;
import com.github.pagehelper.PageHelper;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
* api控制器
*
* @author shi
* @date 2025/02/10
*/
@RestController
@CheckHeader
@RequestMapping("/api/game")
@Slf4j
public class ApiGameController extends BaseController {
@Autowired
private Map<String, IGamesService> gamesService;
@Resource
private IGameService gameService;
@Resource
private IGameBiz gameBiz;
@Resource
private KeyConfig keyConfig;
@Resource
private IMemberService memberService;
@Resource
private ITenantGameQuotaBiz tenantGameQuotaService;
@Resource
private ITenantGameQuotaBiz tenantGameQuotaBiz;
@Resource
private IGameBettingDetailsService gameBettingDetailsService;
@Resource
private IGameFreeRecordService gameFreeRecordService;
@Resource
private IGameExchangeMoneyService gameExchangeMoneyService;
@Autowired
@Qualifier("threadPoolTaskExecutor")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Resource
private IPlatformBiz platformBiz;
@Resource
private IPlatformService platformService;
@Resource
private StepProcessorFactory stepProcessorFactory;
/**
* 列表
*
* @return {@link AjaxResult }
*/
@PostMapping("/list")
public AjaxResult list() {
List<GameResponse> gameResponses = gameBiz.selectGameResponseList();
for (GameResponse gameResponse : gameResponses) {
Platform platform = platformBiz.get(gameResponse.getPlatformCode());
if (null == platform) {
continue;
}
List<String> currencyCode = new ArrayList<>(platform.getCurrencyInfo().keySet());
gameResponse.setCurrencyCode(currencyCode);
}
return AjaxResult.success(gameResponses);
}
/**
* 登录
*
* @param loginRequest 登入游戏
* @return {@link AjaxResult }
*/
@PostMapping("/login")
public AjaxResult login(@Validated @RequestBody GameLoginRequest loginRequest) {
Game game = gameService.selectGameByGameId(loginRequest.getGameId());
ApiException.notNull(game, ErrorCode.GAME_NOT_EXIST.getCode());
Platform platform = platformBiz.get(game.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(platform.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(loginRequest.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(loginRequest.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(loginRequest.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
String targetLang = platform.getLangInfo().get(loginRequest.getLangCode());
ApiException.notNull(targetLang, ErrorCode.LANG_NOT_EXIST.getCode());
Member member = memberService.selectMemberByAccount(loginRequest.getAccount(), loginRequest.getCurrencyCode(), platform.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
GamesLogin gamesLogin = GamesLogin.builder()
.agentId(keyInfo.getCode())
.agentKey(keyInfo.getKey())
.account(member.getGameAccount())
.gameType(game.getGameSourceType())
.currency(/*secretKeyCurrencyDTO.getCurrency()*/targetCurrency)
.gameId(game.getGameCode())
.homeUrl(loginRequest.getHomeUrl())
.betLimit(loginRequest.getBetLimit())
.platform(loginRequest.getPlatform())
.disableFullScreen(loginRequest.getDisableFullScreen())
.lang(/*gameSecretKeyLangDTO.getLang()*/ targetLang)
.vendor(platform)
.keyInfo(keyInfo)
.systemCurrency(loginRequest.getCurrencyCode())
.build();
String login = iGamesService.loginWithoutRedirect(gamesLogin);
return AjaxResult.success("操作成功", login);
}
/**
* 汇兑差额
*
* @param gameExchangeBalanceRequest 游戏兑换余额请求
* @return {@link AjaxResult }
*/
@PostMapping("/exchange/balance")
public DeferredResult<AjaxResult> exchangeBalance(@Validated @RequestBody GameExchangeBalanceRequest gameExchangeBalanceRequest) {
IGamesService iGamesService = gamesService.get(gameExchangeBalanceRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
TenantSecretKey tenantSecretKey = keyConfig.get();
Platform platform = platformBiz.get(gameExchangeBalanceRequest.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(gameExchangeBalanceRequest.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(gameExchangeBalanceRequest.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(gameExchangeBalanceRequest.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
BigDecimal quota = BigDecimal.ZERO;
//如果是扣钱提前扣
if (TransferType.GAMES.getCode().equals(gameExchangeBalanceRequest.getTransferType())) {
quota = tenantGameQuotaService.gameBalanceExchange(GameBalanceExchange.builder()
.platformCode(gameExchangeBalanceRequest.getPlatformCode())
.sourceId(gameExchangeBalanceRequest.getOrderId())
.currencyCode(gameExchangeBalanceRequest.getCurrencyCode())
.currency(targetCurrency)
.transferType(gameExchangeBalanceRequest.getTransferType())
.amount(gameExchangeBalanceRequest.getAmount())
.account(gameExchangeBalanceRequest.getAccount())
.tenantKey(tenantSecretKey.getTenantKey())
.systemCurrency(gameExchangeBalanceRequest.getCurrencyCode())
.agentId(keyInfo.getCode())
.agentKey(keyInfo.getKey())
.build());
}
// 获取用户信息
Member member = memberService.selectMemberByAccount(gameExchangeBalanceRequest.getAccount(), gameExchangeBalanceRequest.getCurrencyCode(), gameExchangeBalanceRequest.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
List<GameExchangeMoney> gameExchangeMonies = gameExchangeMoneyService.selectGameExchangeMoneyList(
GameExchangeMoney.builder()
.tenantKey(tenantSecretKey.getTenantKey())
.orderId(gameExchangeBalanceRequest.getOrderId())
.build()
);
ApiException.isTrue(CollectionUtils.isEmpty(gameExchangeMonies), ErrorCode.DUPLICATE_ORDER_ID.getCode());
Long gameExchangeMoneyId = IdUtil.getSnowflakeNextId();
GameExchangeDTO exchangeMoney = GameExchangeDTO.builder()
.id(gameExchangeMoneyId)
.tenantKey(tenantSecretKey.getTenantKey())
.memberId(member.getId())
.gameAccount(member.getGameAccount())
.memberAccount(member.getMemberAccount())
.exchangeType(gameExchangeBalanceRequest.getTransferType())
.currencyCode(gameExchangeBalanceRequest.getCurrencyCode())
.orderId(gameExchangeBalanceRequest.getOrderId())
.balance(gameExchangeBalanceRequest.getAmount())
.triggerType(TriggerType.MANUAL.getCode())
.platformCode(gameExchangeBalanceRequest.getPlatformCode()).build();
//转出设置转出金额为0
if (TransferType.ALL.getCode().equals(gameExchangeBalanceRequest.getTransferType())){
exchangeMoney.setBalance(BigDecimal.ZERO);
}
ExtInfo extInfo = platform.getExtInfo();
Long timeout = 5000L;
if (extInfo != null) {
timeout = extInfo.getTimeout(TimeOutType.GAME_EXCHANGE_MONEY.getCode());
}
DeferredResult<AjaxResult> output = new DeferredResult<>(timeout);
AsyncManager.me().executeOrdered(
exchangeMoney.getOrderId(),
() -> {
try {
stepProcessorFactory.getStepProcessor(GameExchangeStep.CREATE_ORDER).process(exchangeMoney);
GameExchangeMoney gameExchangeMoney = gameExchangeMoneyService.selectGameExchangeMoneyById(gameExchangeMoneyId);
GameExchangeBalanceResponse gameExchangeBalanceResponse = new GameExchangeBalanceResponse();
BeanUtils.copyProperties(gameExchangeMoney, gameExchangeBalanceResponse);
output.setResult(AjaxResult.success(gameExchangeBalanceResponse));
} catch (Exception e) {
log.error("ApiGameController [exchangeBalance] 余额转移失败 gameExchangeMoneyId {}", gameExchangeMoneyId,e);
stepProcessorFactory.getStepProcessor(GameExchangeStep.getByCode(exchangeMoney.getStep())).rollBack(exchangeMoney);
output.setErrorResult(AjaxResult.error(ErrorCode.BALANCE_TRANSFER_FAILED.getCode(), ErrorCode.BALANCE_TRANSFER_FAILED.getMessage()));
}
}
);
// 超时时间处理逻辑
output.onTimeout(() -> {
GameExchangeMoney gameExchangeMoney = gameExchangeMoneyService.selectGameExchangeMoneyById(gameExchangeMoneyId);
GameExchangeBalanceResponse gameExchangeBalanceResponse = new GameExchangeBalanceResponse();
BeanUtils.copyProperties(gameExchangeMoney, gameExchangeBalanceResponse);
output.setErrorResult(AjaxResult.success(gameExchangeBalanceResponse));
});
return output;
}
/**
* 交换状态
*
* @param gameExchangeStateRequest 游戏兑换余额状态请求
* @return {@link AjaxResult }
*/
@PostMapping("/exchange/state")
@Transactional
public AjaxResult exchangeState(@Validated @RequestBody GameExchangeStateRequest gameExchangeStateRequest) {
TenantSecretKey tenantSecretKey = keyConfig.get();
GameExchangeMoney gameExchangeMoney = GameExchangeMoney.builder()
.tenantKey(tenantSecretKey.getTenantKey())
.orderId(gameExchangeStateRequest.getOrderId())
.build();
List<GameExchangeMoney> gameExchangeMonies = gameExchangeMoneyService.selectGameExchangeMoneyList(gameExchangeMoney);
ApiException.isTrue(!CollectionUtils.isEmpty(gameExchangeMonies), ErrorCode.ORDER_NOT_EXIST.getCode());
GameExchangeBalanceResponse gameExchangeBalanceResponse = new GameExchangeBalanceResponse();
BeanUtils.copyProperties(gameExchangeMonies.get(0), gameExchangeBalanceResponse);
return AjaxResult.success(gameExchangeBalanceResponse);
}
/**
* 赠送免费局数
*
* @param gameCreateFreeSpinRequest 游戏创建免费旋转请求
* @return {@link AjaxResult }
*/
@PostMapping("/create/free/spin")
public AjaxResult createFreeSpin(@Validated @RequestBody GameCreateFreeSpinRequest gameCreateFreeSpinRequest) {
IGamesService iGamesService = gamesService.get(gameCreateFreeSpinRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
Platform platform = platformBiz.get(gameCreateFreeSpinRequest.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(gameCreateFreeSpinRequest.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(gameCreateFreeSpinRequest.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(gameCreateFreeSpinRequest.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
Member member = memberService.selectMemberByAccount(gameCreateFreeSpinRequest.getAccount(), gameCreateFreeSpinRequest.getCurrencyCode(), gameCreateFreeSpinRequest.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
CreateFreeSpinRequestDTO createFreeSpinRequestDTO = CreateFreeSpinRequestDTO.builder()
.account(member.getGameAccount())
.currency(/*gameCreateFreeSpinRequest.getCurrencyCode()*/targetCurrency)
.agentId(keyInfo.getCode())
.agentKey(keyInfo.getKey())
.referenceId(gameCreateFreeSpinRequest.getReferenceId())
.freeSpinValidity(gameCreateFreeSpinRequest.getFreeSpinValidity())
.numberOfRounds(gameCreateFreeSpinRequest.getNumberOfRounds())
.gameIds(gameCreateFreeSpinRequest.getGameIds())
.betValue(gameCreateFreeSpinRequest.getBetValue())
.startTime(gameCreateFreeSpinRequest.getStartTime())
.vendor(platform)
.keyInfo(keyInfo)
.systemCurrency(gameCreateFreeSpinRequest.getCurrencyCode())
.build();
return AjaxResult.success(iGamesService.createFreeSpin(createFreeSpinRequestDTO));
}
/**
* 获取投注记录
*
* @param gameCreateFreeSpinRequest 游戏创建免费旋转请求
* @return {@link AjaxResult }
*/
@PostMapping("/get/bet/record")
public TableDataInfo getBetRecord(@Validated @RequestBody GameGetBetRecordRequest gameCreateFreeSpinRequest) {
TenantSecretKey tenantSecretKey = keyConfig.get();
startPage();
PageHelper.startPage(gameCreateFreeSpinRequest.getPageNo(), gameCreateFreeSpinRequest.getPageSize(), "wagers_time desc");
GameBettingDetailsDTO gameBettingDetails = GameBettingDetailsDTO.builder()
.platformCode(gameCreateFreeSpinRequest.getPlatformCode())
.currencyCode(gameCreateFreeSpinRequest.getCurrencyCode())
.tenantKey(tenantSecretKey.getTenantKey())
.timeType(gameCreateFreeSpinRequest.getTimeType())
.build();
Map<String, Object> params = gameBettingDetails.getParams();
params.put("beginTime", gameCreateFreeSpinRequest.getBeginTime());
params.put("endTime", gameCreateFreeSpinRequest.getEndTime());
List<GameBettingDetails> bettingDetails = gameBettingDetailsService.selectGameBettingDetailsList(gameBettingDetails);
TableDataInfo dataTable = getDataTable(bettingDetails);
List<GameBettingDetailsResponse> result = new ArrayList<>();
for (GameBettingDetails row : (List<GameBettingDetails>) dataTable.getRows()) {
GameBettingDetailsResponse gameBettingDetailsResponse = new GameBettingDetailsResponse();
BeanUtils.copyProperties(row, gameBettingDetailsResponse);
Member member = memberService.selectMemberById(row.getMemberId());
gameBettingDetailsResponse.setAccount(member.getMemberAccount());
result.add(gameBettingDetailsResponse);
}
dataTable.setRows(result);
return dataTable;
}
/**
* 获取详细信息
*
* @param gameGetDetailRequest 游戏获取详细信息请求
* @return {@link AjaxResult }
*/
@PostMapping("/get/detail")
public AjaxResult getDetail(@Validated @RequestBody GameGetDetailRequest gameGetDetailRequest) {
Platform platform = platformBiz.get(gameGetDetailRequest.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(gameGetDetailRequest.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(gameGetDetailRequest.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(gameGetDetailRequest.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
String targetLang = platform.getLangInfo().get(gameGetDetailRequest.getLangCode());
ApiException.notNull(targetLang, ErrorCode.LANG_NOT_EXIST.getCode());
// GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
// .platformCode(gameGetDetailRequest.getPlatformCode())
// .systemCurrency(gameGetDetailRequest.getCurrencyCode()).build());
// ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(gameGetDetailRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
// GameSecretKeyLangDTO gameSecretKeyLang = gameSecretKeyLangService.findGameSecretKeyLangDTO(GameSecretKeyLangDTO.builder()
// .platformCode(gameGetDetailRequest.getPlatformCode())
// .systemLangCode(gameGetDetailRequest.getLangCode())
// .build());
// ApiException.notNull(gameSecretKeyLang, ErrorCode.LANG_NOT_EXIST.getCode());
GetGameDetailResponseDTO gameDetail = iGamesService.getGameDetail(GetGameDetailRequestDTO.builder()
.wagersId(gameGetDetailRequest.getWagersId())
.lang(/*gameSecretKeyLang.getLang()*/targetLang)
.agentId(keyInfo.getCode())
.agentKey(keyInfo.getKey())
.vendor(platform)
.keyInfo(keyInfo)
.systemCurrency(gameGetDetailRequest.getCurrencyCode())
.build());
return AjaxResult.success(gameDetail);
}
/**
* 踢腿队员
*
* @param gameKickMemeberRequest 游戏踢迷请求
* @return {@link AjaxResult }
*/
@PostMapping("/kick/member")
public AjaxResult kickMember(@Validated @RequestBody GameKickMemeberRequest gameKickMemeberRequest) {
// GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
// .platformCode(gameKickMemeberRequest.getPlatformCode())
// .systemCurrency(gameKickMemeberRequest.getCurrencyCode()).build());
// ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
Platform platform = platformBiz.get(gameKickMemeberRequest.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(gameKickMemeberRequest.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(gameKickMemeberRequest.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(gameKickMemeberRequest.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(gameKickMemeberRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
Member member = memberService.selectMemberByAccount(gameKickMemeberRequest.getAccount(), gameKickMemeberRequest.getCurrencyCode(), gameKickMemeberRequest.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
return AjaxResult.success(iGamesService.kickMember(KickMemberRequestDTO.builder()
.account(member.getGameAccount())
.agentId(keyInfo.getCode())
.currency(targetCurrency)
.agentKey(keyInfo.getKey())
.vendor(platform)
.keyInfo(keyInfo)
.systemCurrency(gameKickMemeberRequest.getCurrencyCode())
.build()));
}
@PostMapping("/kick/member/all")
public AjaxResult kickMemberAll(@Validated @RequestBody GameKickMemeberAllRequest gameKickMemeberAllRequest) {
// GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
// .platformCode(gameKickMemeberAllRequest.getPlatformCode())
// .systemCurrency(gameKickMemeberAllRequest.getCurrencyCode()).build());
//
// ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
Platform platform = platformBiz.get(gameKickMemeberAllRequest.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(gameKickMemeberAllRequest.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(gameKickMemeberAllRequest.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(gameKickMemeberAllRequest.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(gameKickMemeberAllRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
KickMemberAllDTO kickMemberAllDTO = KickMemberAllDTO.builder()
.agentId(keyInfo.getCode())
.agentKey(keyInfo.getKey())
.currency(/*gameSecretKey.getCurrency()*/targetCurrency)
.vendor(platform)
.keyInfo(keyInfo)
.systemCurrency(gameKickMemeberAllRequest.getCurrencyCode())
.build();
if (!ObjectUtils.isEmpty(gameKickMemeberAllRequest.getGameId())) {
Game game = gameService.selectGameById(gameKickMemeberAllRequest.getGameId());
ApiException.notNull(game, ErrorCode.GAME_NOT_EXIST.getCode());
kickMemberAllDTO.setGameId(game.getGameCode());
}
return AjaxResult.success(iGamesService.kickMemberAll(kickMemberAllDTO));
}
/**
* 获得自由旋转气流
*
* @param gameGetFreeSpinDashflowRequest 游戏获得免费旋转dashflow请求
* @return {@link TableDataInfo }
*/
@PostMapping("/get/free/spin/dashflow")
public TableDataInfo getFreeSpinDashflow(@Validated @RequestBody GameGetFreeSpinDashflowRequest gameGetFreeSpinDashflowRequest) {
PageHelper.startPage(gameGetFreeSpinDashflowRequest.getPageNo(), gameGetFreeSpinDashflowRequest.getPageSize(), "free_update_time desc");
GameFreeRecord gameFreeRecord = GameFreeRecord.builder()
.gameId(gameGetFreeSpinDashflowRequest.getGameId())
.platformCode(gameGetFreeSpinDashflowRequest.getPlatformCode())
.currencyCode(gameGetFreeSpinDashflowRequest.getCurrencyCode())
.build();
Map<String, Object> params = gameFreeRecord.getParams();
params.put("beginTime", gameGetFreeSpinDashflowRequest.getBeginTime());
params.put("endTime", gameGetFreeSpinDashflowRequest.getEndTime());
List<GameFreeRecord> gameFreeRecords = gameFreeRecordService.selectGameFreeRecordList(gameFreeRecord);
TableDataInfo dataTable = getDataTable(gameFreeRecords);
List<GameFreeRecordResponse> result = new ArrayList<>();
for (GameFreeRecord row : (List<GameFreeRecord>) dataTable.getRows()) {
GameFreeRecordResponse gameFreeRecordResponse = new GameFreeRecordResponse();
BeanUtils.copyProperties(row, gameFreeRecordResponse);
Member member = memberService.selectMemberById(row.getMemberId());
gameFreeRecordResponse.setMemberAccount(member.getMemberAccount());
result.add(gameFreeRecordResponse);
}
dataTable.setRows(result);
return dataTable;
}
/**
* 取消自由旋转
*
* @param request 游戏获得免费旋转dashflow请求
* @return {@link TableDataInfo }
*/
@PostMapping("/cancel/free/spin")
public AjaxResult cancelFreeSpin(@Validated @RequestBody GameCancelFreeSpinRequest request) {
// GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
// .platformCode(gameGetFreeSpinDashflowRequest.getPlatformCode())
// .systemCurrency(gameGetFreeSpinDashflowRequest.getCurrencyCode()).build());
// ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
Platform platform = platformBiz.get(request.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(request.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(request.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(request.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(request.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
Boolean cancelFreeSpin = iGamesService.cancelFreeSpin(CancelFreeSpinRequestDTO.builder()
.agentId(keyInfo.getCode())
.agentKey(keyInfo.getKey())
.referenceId(request.getReferenceId())
.vendor(platform)
.keyInfo(keyInfo)
.systemCurrency(request.getCurrencyCode())
.build());
return AjaxResult.success(cancelFreeSpin);
}
/**
* 信息全部
*
* @param request 成员信息所有api请求
* @return {@link AjaxResult }
*//*
@PostMapping("/exchange/balance/all")
public AjaxResult exchangeBalanceAll(@Validated @RequestBody GameExchangeBalanceAllRequest request) {
TenantSecretKey tenantSecretKey = keyConfig.get();
// List<GameSecretKeyCurrencyDTO> gameSecretKeys = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTOList(GameSecretKeyCurrencyDTO.builder()
// .systemCurrency(gameExchangeBalanceAllRequest.getCurrencyCode()).build());
List<Key> keys = new ArrayList<>();
for (GamePlatforms platformEnum : GamePlatforms.values()) {
Platform platform = platformService.get(platformEnum.getCode());
String targetCurrency = platform.getCurrencyInfo().get(request.getCurrencyCode());
if (StringUtils.isEmpty(targetCurrency)) {
continue;
}
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(request.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(request.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
if (null == keyInfo) {
continue;
}
Key key = new Key();
key.setPlatformCode(platform.getPlatformCode());
key.setCode(keyInfo.getCode());
key.setKey(keyInfo.getKey());
key.setCurrency(targetCurrency);
key.setPlatform(platform);
key.setKeyInfo(keyInfo);
key.setSystemCurrency(request.getCurrencyCode());
keys.add(key);
}
// 创建线程池
Map<String, BigDecimal> balanceMap = new LinkedHashMap<>();
CountDownLatch latch = new CountDownLatch(keys.size());
// 使用List存储Future对象用于获取异步执行的结果
List<Future<Long>> futures = new ArrayList<>();
// 提交异步任务到线程池
// for (GameSecretKeyCurrencyDTO gameSecretKeyCurrencyDTO : gameSecretKeys) {
for (Key key : keys) {
futures.add(threadPoolTaskExecutor.submit(() -> {
try {
IGamesService iGamesService = gamesService.get(key.getPlatformCode() + Constants.SERVICE);
Member member = memberService.selectMemberByAccount(request.getAccount(), request.getCurrencyCode(), key.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
//操作第三方钱包
ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO = ExchangeTransferMoneyRequestDTO.builder()
.agentId(key.getCode())
.agentKey(key.getKey())
.orderId(request.getOrderId())
.amount(BigDecimal.ONE)
.currency(*//*gameSecretKeyCurrencyDTO.getCurrency()*//*key.currency)
.tenantKey(tenantSecretKey.getTenantKey())
.account(member.getGameAccount())
.vendor(key.getPlatform())
.keyInfo(key.getKeyInfo())
.systemCurrency(key.systemCurrency)
.transferType(TransferType.ALL.getCode())
.build();
return iGamesService.exchangeTransferByAgentId(exchangeTransferMoneyRequestDTO);
} catch (Exception e) {
return 0L;
} finally {
latch.countDown(); // 任务完成后减少计数
}
}));
}
BigDecimal balanceAll = BigDecimal.ZERO;
try {
// 等待所有线程执行完毕
latch.await();
// 获取每个Future的结果
for (Future<Long> future : futures) {
// 汇总结果
Long id = future.get();
GameExchangeMoney gameExchangeMoney = gameExchangeMoneyService.selectGameExchangeMoneyById(id);
if (ObjectUtils.isEmpty(gameExchangeMoney)) {
continue;
}
Member member = memberService.selectMemberById(gameExchangeMoney.getMemberId());
balanceMap.put(gameExchangeMoney.getPlatformCode(), gameExchangeMoney.getBalance());
BigDecimal balance = gameExchangeMoney.getBalance();
balanceAll = NumberUtil.add(balanceAll, balance);
//操作租户额度
tenantGameQuotaService.gameBalanceExchange(GameBalanceExchange.builder()
.platformCode(gameExchangeMoney.getPlatformCode())
.currencyCode(gameExchangeMoney.getCurrencyCode())
.sourceId(request.getOrderId())
.transferType(TransferType.ALL.getCode())
.amount(gameExchangeMoney.getBalance())
.account(member.getMemberAccount())
.tenantKey(tenantSecretKey.getTenantKey())
.currency()
.systemCurrency(gameExchangeMoney.getCurrencyCode())
.agentId()
.agentKey()
.build());
}
} catch (Exception e) {
log.error("拉回用户余额失败", e);
throw new BaseException("拉回用户余额失败");
}
balanceMap.put("balanceAll", balanceAll);
return AjaxResult.success(balanceMap);
}*/
/**
* 演示登录
*
* @param request 游戏演示登录请求
* @return {@link AjaxResult }
*/
@PostMapping("/demo/login")
public AjaxResult demoLogin(@Validated @RequestBody GameDemoLoginRequest request) {
Game game = gameService.selectGameById(request.getGameId());
ApiException.notNull(game, ErrorCode.GAME_NOT_EXIST.getCode());
//GamePlatform gamePlatform = gamePlatformService.selectGamePlatformById(game.getPlatformId());
//ApiException.notNull(gamePlatform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
Platform platform = platformBiz.get(game.getPlatformCode());
ApiException.notNull(platform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(platform.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
String targetCurrency = platform.getCurrencyInfo().get(request.getCurrencyCode());
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
KeyInfo keyInfo = null;
for (KeyInfo keyData : platform.getKeyInfo()) {
if (StringUtils.isNotEmpty(request.getCurrencyCode())) {
if (keyData.getCurrency().equalsIgnoreCase(request.getCurrencyCode())) {
keyInfo = keyData;
break;
}
}
}
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
String targetLang = platform.getLangInfo().get(request.getLangCode());
ApiException.notNull(targetLang, ErrorCode.LANG_NOT_EXIST.getCode());
// GameSecretKeyLangDTO gameSecretKeyLangDTO = gameSecretKeyLangService.findGameSecretKeyLangDTO(GameSecretKeyLangDTO.builder()
// .platformCode(gamePlatform.getPlatformCode())
// .systemLangCode(gameDemoLoginRequest.getLangCode())
// .build());
// ApiException.notNull(gameSecretKeyLangDTO, ErrorCode.LANG_NOT_EXIST.getCode());
GameDemoLoginRequestDTO gamesLogin = GameDemoLoginRequestDTO.builder()
.gameId(game.getGameCode())
.gameType(game.getGameSourceType())
.lang(/*gameSecretKeyLangDTO.getLang()*/targetLang)
.vendor(platform)
.keyInfo(keyInfo)
.systemCurrency(request.getCurrencyCode())
.build();
GameDemoLoginResponseDTO gameDemoLoginResponseDTO = iGamesService.gameDemoLogin(gamesLogin);
GameDemoLoginResponse gameDemoLoginResponse = new GameDemoLoginResponse();
BeanUtils.copyProperties(gameDemoLoginResponseDTO, gameDemoLoginResponse);
return AjaxResult.success(gameDemoLoginResponse);
}
@Data
class Key {
private String platformCode;
private String code;
private String currency;
private String key;
private Platform platform;
private KeyInfo keyInfo;
private String systemCurrency;
}
}