package com.ff.api.controller; 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.ErrorCode; import com.ff.base.exception.base.ApiException; 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.common.service.ITenantGameQuotaFlowService; import com.ff.common.service.ITenantGameQuotaService; import com.ff.config.KeyConfig; import com.ff.game.api.IGamesService; 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.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.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.transaction.annotation.Transactional; 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 javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * api控制器 * * @author shi * @date 2025/02/10 */ @RestController @CheckHeader @RequestMapping("/api/game") @Slf4j public class ApiGameController extends BaseController { @Autowired private Map gamesService; @Resource private IGameService gameService; @Resource private KeyConfig keyConfig; @Resource private IMemberService memberService; @Resource private ITenantGameQuotaService tenantGameQuotaService; @Resource private ITenantGameQuotaFlowService tenantGameQuotaFlowService; @Resource private IGameBettingDetailsService gameBettingDetailsService; @Resource private IGameFreeRecordService gameFreeRecordService; @Resource private IGameExchangeMoneyService gameExchangeMoneyService; @Autowired @Qualifier("threadPoolTaskExecutor") private ThreadPoolTaskExecutor threadPoolTaskExecutor; @Resource private IPlatformService platformService; /** * 列表 * * @return {@link AjaxResult } */ @PostMapping("/list") public AjaxResult list() { List gameResponses = gameService.selectGameResponseList(); for (GameResponse gameResponse : gameResponses) { Platform platform = platformService.get(gameResponse.getPlatformCode()); if (null == platform) { continue; } // List gameSecretKeyCurrencies = // gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTOList( // GameSecretKeyCurrencyDTO.builder().platformCode(gameResponse.getPlatformCode()) // .build() // ); // List currencyCode = gameSecretKeyCurrencies.stream().map(GameSecretKeyCurrencyDTO::getSystemCurrency).collect(Collectors.toList()); List 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.selectGameById(loginRequest.getGameId()); ApiException.notNull(game, ErrorCode.GAME_NOT_EXIST.getCode()); Platform platform = platformService.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()); // TenantSecretKey tenantSecretKey = keyConfig.get(); // GameSecretKeyCurrencyDTO secretKeyCurrencyDTO = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder() // .platformCode(gamePlatform.getPlatformCode()) // .systemCurrency(memberCreateApiRequest.getCurrencyCode()).build()); // ApiException.notNull(secretKeyCurrencyDTO, ErrorCode.CURRENCY_NOT_EXIST.getCode()); // GameSecretKeyLangDTO gameSecretKeyLangDTO = gameSecretKeyLangService.findGameSecretKeyLangDTO(GameSecretKeyLangDTO.builder() // .platformCode(gamePlatform.getPlatformCode()) // .systemLangCode(memberCreateApiRequest.getLangCode()) // .build()); // ApiException.notNull(gameSecretKeyLangDTO, 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") @Transactional public 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(); // GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder() // .platformCode(gameExchangeBalanceRequest.getPlatformCode()) // .systemCurrency(gameExchangeBalanceRequest.getCurrencyCode()).build()); // // ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode()); Platform platform = platformService.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 = 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()); //操作第三方额度接口 ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO = ExchangeTransferMoneyRequestDTO.builder() .agentId(keyInfo.getCode()) .agentKey(keyInfo.getKey()) .orderId(gameExchangeBalanceRequest.getOrderId()) .account(member.getGameAccount()) .currency(/*gameSecretKey.getCurrency()*/targetCurrency) .tenantKey(tenantSecretKey.getTenantKey()) .quota(quota) .amount(gameExchangeBalanceRequest.getAmount()) .transferType(gameExchangeBalanceRequest.getTransferType()) .vendor(platform) .keyInfo(keyInfo) .systemCurrency(gameExchangeBalanceRequest.getCurrencyCode()) .build(); Long exchangeTransferId = iGamesService.exchangeTransferByAgentId(exchangeTransferMoneyRequestDTO); GameExchangeMoney gameExchangeMoney = gameExchangeMoneyService.selectGameExchangeMoneyById(exchangeTransferId); GameExchangeBalanceResponse gameExchangeBalanceResponse = new GameExchangeBalanceResponse(); BeanUtils.copyProperties(gameExchangeMoney, gameExchangeBalanceResponse); return AjaxResult.success(gameExchangeBalanceResponse); } /** * 交换状态 * * @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 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()); // TenantSecretKey tenantSecretKey = keyConfig.get(); // GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder() // .platformCode(gameCreateFreeSpinRequest.getPlatformCode()) // .systemCurrency(gameCreateFreeSpinRequest.getCurrencyCode()).build()); // ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode()); Platform platform = platformService.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 params = gameBettingDetails.getParams(); params.put("beginTime", gameCreateFreeSpinRequest.getBeginTime()); params.put("endTime", gameCreateFreeSpinRequest.getEndTime()); List bettingDetails = gameBettingDetailsService.selectGameBettingDetailsList(gameBettingDetails); TableDataInfo dataTable = getDataTable(bettingDetails); List result = new ArrayList<>(); for (GameBettingDetails row : (List) 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 = platformService.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 = platformService.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 = platformService.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 params = gameFreeRecord.getParams(); params.put("beginTime", gameGetFreeSpinDashflowRequest.getBeginTime()); params.put("endTime", gameGetFreeSpinDashflowRequest.getEndTime()); List gameFreeRecords = gameFreeRecordService.selectGameFreeRecordList(gameFreeRecord); TableDataInfo dataTable = getDataTable(gameFreeRecords); List result = new ArrayList<>(); for (GameFreeRecord row : (List) 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 = platformService.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 gameSecretKeys = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTOList(GameSecretKeyCurrencyDTO.builder() // .systemCurrency(gameExchangeBalanceAllRequest.getCurrencyCode()).build()); List 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 balanceMap = new LinkedHashMap<>(); CountDownLatch latch = new CountDownLatch(keys.size()); // 使用List存储Future对象,用于获取异步执行的结果 List> 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 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 = platformService.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; } }