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

594 lines
26 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.NumberUtil;
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.exception.base.BaseException;
import com.ff.base.utils.StringUtils;
import com.ff.base.utils.bean.BeanUtils;
import com.ff.base.system.domain.TenantSecretKey;
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.GameSecretKeyCurrencyDTO;
import com.ff.game.dto.GameSecretKeyLangDTO;
import com.ff.game.service.*;
import com.ff.member.domain.Member;
import com.ff.member.service.IMemberService;
import com.github.pagehelper.PageHelper;
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.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 javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
/**
* 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 KeyConfig keyConfig;
@Resource
private IGameSecretKeyService gameSecretKeyService;
@Resource
private IMemberService memberService;
@Resource
private IGamePlatformService gamePlatformService;
@Resource
private ITenantGameQuotaService tenantGameQuotaService;
@Resource
private ITenantGameQuotaFlowService tenantGameQuotaFlowService;
@Resource
private IGameBettingDetailsService gameBettingDetailsService;
@Resource
private IGameFreeRecordService gameFreeRecordService;
@Resource
private IGameExchangeMoneyService gameExchangeMoneyService;
@Resource
private IGameSecretKeyCurrencyService gameSecretKeyCurrencyService;
@Resource
private IGameSecretKeyLangService gameSecretKeyLangService;
@Autowired
@Qualifier("threadPoolTaskExecutor")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
/**
* 列表
*
* @return {@link AjaxResult }
*/
@PostMapping("/list")
public AjaxResult list() {
List<GameResponse> gameResponses = gameService.selectGameResponseList();
for (GameResponse gameRespons : gameResponses) {
List<GameSecretKeyCurrencyDTO> gameSecretKeyCurrencies = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTOList(GameSecretKeyCurrencyDTO.builder().platformCode(gameRespons.getPlatformCode()).build());
List<String> currencyCode = gameSecretKeyCurrencies.stream().map(GameSecretKeyCurrencyDTO::getSystemCurrency).collect(Collectors.toList());
gameRespons.setCurrencyCode(currencyCode);
}
return AjaxResult.success(gameResponses);
}
/**
* 登录
*
* @param memberCreateApiRequest 成员创建api请求
* @return {@link AjaxResult }
*/
@PostMapping("/login")
public AjaxResult login(@Validated @RequestBody GameLoginRequest memberCreateApiRequest) {
Game game = gameService.selectGameById(memberCreateApiRequest.getGameId());
ApiException.notNull(game, ErrorCode.GAME_NOT_EXIST.getCode());
GamePlatform gamePlatform = gamePlatformService.selectGamePlatformById(game.getPlatformId());
ApiException.notNull(gamePlatform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(gamePlatform.getPlatformCode() + Constants.SERVICE);
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(memberCreateApiRequest.getAccount(), memberCreateApiRequest.getCurrencyCode(), gamePlatform.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
GamesLogin gamesLogin = GamesLogin.builder()
.agentId(secretKeyCurrencyDTO.getCode())
.agentKey(secretKeyCurrencyDTO.getKey())
.account(member.getGameAccount())
.gameType(game.getGameSourceType())
.currency(secretKeyCurrencyDTO.getCurrency())
.gameId(game.getGameCode())
.homeUrl(memberCreateApiRequest.getHomeUrl())
.platform(memberCreateApiRequest.getPlatform())
.disableFullScreen(memberCreateApiRequest.getDisableFullScreen())
.lang(gameSecretKeyLangDTO.getLang())
.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());
BigDecimal quota = tenantGameQuotaService.gameBalanceExchange(GameBalanceExchange.builder()
.platformCode(gameExchangeBalanceRequest.getPlatformCode())
.sourceId(gameExchangeBalanceRequest.getOrderId())
.currencyCode(gameExchangeBalanceRequest.getCurrencyCode())
.transferType(gameExchangeBalanceRequest.getTransferType())
.amount(gameExchangeBalanceRequest.getAmount())
.account(gameExchangeBalanceRequest.getAccount())
.tenantKey(tenantSecretKey.getTenantKey())
.build());
// 获取用户信息
Member member = memberService.selectMemberByAccount(gameExchangeBalanceRequest.getAccount(), gameExchangeBalanceRequest.getCurrencyCode(), gameExchangeBalanceRequest.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
//操作第三方额度接口
ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO = ExchangeTransferMoneyRequestDTO.builder()
.agentId(gameSecretKey.getCode())
.agentKey(gameSecretKey.getKey())
.orderId(gameExchangeBalanceRequest.getOrderId())
.account(member.getGameAccount())
.currency(gameSecretKey.getCurrency())
.tenantKey(tenantSecretKey.getTenantKey())
.quota(quota)
.amount(gameExchangeBalanceRequest.getAmount())
.transferType(gameExchangeBalanceRequest.getTransferType())
.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<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());
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());
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())
.agentId(gameSecretKey.getCode())
.agentKey(gameSecretKey.getKey())
.referenceId(gameCreateFreeSpinRequest.getReferenceId())
.freeSpinValidity(gameCreateFreeSpinRequest.getFreeSpinValidity())
.numberOfRounds(gameCreateFreeSpinRequest.getNumberOfRounds())
.gameIds(gameCreateFreeSpinRequest.getGameIds())
.betValue(gameCreateFreeSpinRequest.getBetValue())
.startTime(gameCreateFreeSpinRequest.getStartTime())
.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");
GameBettingDetails gameBettingDetails = GameBettingDetails.builder()
.platformCode(gameCreateFreeSpinRequest.getPlatformCode())
.currencyCode(gameCreateFreeSpinRequest.getCurrencyCode())
.tenantKey(tenantSecretKey.getTenantKey())
.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) {
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())
.agentId(gameSecretKey.getCode())
.agentKey(gameSecretKey.getKey())
.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());
Member member = memberService.selectMemberByAccount(gameKickMemeberRequest.getAccount(), gameKickMemeberRequest.getCurrencyCode(), gameKickMemeberRequest.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(gameKickMemeberRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
return AjaxResult.success(iGamesService.kickMember(KickMemberRequestDTO.builder()
.account(member.getGameAccount())
.agentId(gameSecretKey.getCode())
.agentKey(gameSecretKey.getKey())
.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());
IGamesService iGamesService = gamesService.get(gameKickMemeberAllRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
KickMemberAllDTO kickMemberAllDTO = KickMemberAllDTO.builder()
.agentId(gameSecretKey.getCode())
.agentKey(gameSecretKey.getKey())
.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 gameGetFreeSpinDashflowRequest 游戏获得免费旋转dashflow请求
* @return {@link TableDataInfo }
*/
@PostMapping("/cancel/free/spin")
public AjaxResult cancelFreeSpin(@Validated @RequestBody GameCancelFreeSpinRequest gameGetFreeSpinDashflowRequest) {
GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
.platformCode(gameGetFreeSpinDashflowRequest.getPlatformCode())
.systemCurrency(gameGetFreeSpinDashflowRequest.getCurrencyCode()).build());
ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
IGamesService iGamesService = gamesService.get(gameGetFreeSpinDashflowRequest.getPlatformCode() + Constants.SERVICE);
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
Boolean cancelFreeSpin = iGamesService.cancelFreeSpin(CancelFreeSpinRequestDTO.builder()
.agentId(gameSecretKey.getCode())
.agentKey(gameSecretKey.getKey())
.referenceId(gameGetFreeSpinDashflowRequest.getReferenceId())
.build());
return AjaxResult.success(cancelFreeSpin);
}
/**
* 信息全部
*
* @param gameExchangeBalanceAllRequest 成员信息所有api请求
* @return {@link AjaxResult }
*/
@PostMapping("/exchange/balance/all")
public AjaxResult exchangeBalanceAll(@Validated @RequestBody GameExchangeBalanceAllRequest gameExchangeBalanceAllRequest) {
TenantSecretKey tenantSecretKey = keyConfig.get();
List<GameSecretKeyCurrencyDTO> gameSecretKeys = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTOList(GameSecretKeyCurrencyDTO.builder()
.systemCurrency(gameExchangeBalanceAllRequest.getCurrencyCode()).build());
// 创建线程池
Map<String, BigDecimal> balanceMap = new LinkedHashMap<>();
CountDownLatch latch = new CountDownLatch(gameSecretKeys.size());
// 使用List存储Future对象用于获取异步执行的结果
List<Future<Long>> futures = new ArrayList<>();
// 提交异步任务到线程池
for (GameSecretKeyCurrencyDTO gameSecretKeyCurrencyDTO : gameSecretKeys) {
futures.add(threadPoolTaskExecutor.submit(() -> {
try {
IGamesService iGamesService = gamesService.get(gameSecretKeyCurrencyDTO.getPlatformCode() + Constants.SERVICE);
Member member = memberService.selectMemberByAccount(gameExchangeBalanceAllRequest.getAccount(), gameExchangeBalanceAllRequest.getCurrencyCode(), gameSecretKeyCurrencyDTO.getPlatformCode());
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
//操作第三方钱包
ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO = ExchangeTransferMoneyRequestDTO.builder()
.agentId(gameSecretKeyCurrencyDTO.getCode())
.agentKey(gameSecretKeyCurrencyDTO.getKey())
.orderId(gameExchangeBalanceAllRequest.getOrderId())
.amount(BigDecimal.ONE)
.currency(gameSecretKeyCurrencyDTO.getCurrency())
.tenantKey(tenantSecretKey.getTenantKey())
.account(member.getGameAccount())
.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(gameExchangeBalanceAllRequest.getOrderId())
.transferType(TransferType.ALL.getCode())
.amount(gameExchangeMoney.getBalance())
.account(member.getMemberAccount())
.tenantKey(tenantSecretKey.getTenantKey())
.build());
}
} catch (Exception e) {
log.error("拉回用户余额失败", e);
throw new BaseException("拉回用户余额失败");
}
balanceMap.put("balanceAll", balanceAll);
return AjaxResult.success(balanceMap);
}
}