2025-02-11 15:27:15 +08:00
|
|
|
|
package com.ff.api.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.ff.annotation.CheckHeader;
|
|
|
|
|
import com.ff.api.request.MemberCreateApiRequest;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import com.ff.api.request.MemberInfoAllApiRequest;
|
|
|
|
|
import com.ff.api.request.MemberInfoApiRequest;
|
|
|
|
|
import com.ff.api.response.MemberInfoAllResponse;
|
|
|
|
|
import com.ff.api.response.MemberInfoResponse;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import com.ff.base.constant.Constants;
|
|
|
|
|
import com.ff.base.core.controller.BaseController;
|
|
|
|
|
import com.ff.base.core.domain.AjaxResult;
|
2025-02-19 16:41:44 +08:00
|
|
|
|
import com.ff.base.enums.ErrorCode;
|
2025-04-03 14:34:49 +08:00
|
|
|
|
import com.ff.base.enums.GamePlatforms;
|
2025-02-19 16:41:44 +08:00
|
|
|
|
import com.ff.base.exception.base.ApiException;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import com.ff.base.exception.base.BaseException;
|
2025-02-25 10:05:13 +08:00
|
|
|
|
import com.ff.base.system.domain.TenantSecretKey;
|
2025-04-03 14:34:49 +08:00
|
|
|
|
import com.ff.base.utils.StringUtils;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import com.ff.config.KeyConfig;
|
|
|
|
|
import com.ff.game.api.IGamesService;
|
2025-04-03 14:34:49 +08:00
|
|
|
|
import com.ff.game.api.request.CreateMemberRequestDTO;
|
|
|
|
|
import com.ff.game.api.request.MemberInfoRequestDTO;
|
|
|
|
|
import com.ff.game.api.request.MemberInfoResponseDTO;
|
|
|
|
|
import com.ff.game.domain.KeyInfo;
|
|
|
|
|
import com.ff.game.domain.Platform;
|
|
|
|
|
import com.ff.game.service.IPlatformService;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import com.ff.member.domain.Member;
|
|
|
|
|
import com.ff.member.service.IMemberService;
|
2025-04-03 14:34:49 +08:00
|
|
|
|
import lombok.Data;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
2025-02-18 16:09:21 +08:00
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import org.springframework.util.Assert;
|
2025-03-17 18:16:42 +08:00
|
|
|
|
import org.springframework.util.ObjectUtils;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
2025-04-03 14:34:49 +08:00
|
|
|
|
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;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.LinkedHashMap;
|
2025-02-13 15:43:13 +08:00
|
|
|
|
import java.util.List;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import java.util.Map;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
|
import java.util.concurrent.Future;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* api控制器
|
|
|
|
|
*
|
|
|
|
|
* @author shi
|
|
|
|
|
* @date 2025/02/10
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@CheckHeader
|
|
|
|
|
@RequestMapping("/api/member")
|
2025-02-14 17:31:52 +08:00
|
|
|
|
@Slf4j
|
2025-02-11 15:27:15 +08:00
|
|
|
|
public class ApiMemberController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private Map<String, IGamesService> gamesService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private KeyConfig keyConfig;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private IMemberService memberService;
|
|
|
|
|
|
2025-02-14 17:31:52 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
@Qualifier("threadPoolTaskExecutor")
|
|
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
|
|
|
2025-03-14 13:31:17 +08:00
|
|
|
|
@Resource
|
2025-04-03 14:34:49 +08:00
|
|
|
|
private IPlatformService platformService;
|
2025-03-14 13:31:17 +08:00
|
|
|
|
|
2025-02-11 15:27:15 +08:00
|
|
|
|
/**
|
|
|
|
|
* 创建成员
|
|
|
|
|
*
|
|
|
|
|
* @param memberCreateApiRequest 创建成员api请求
|
|
|
|
|
* @return {@link AjaxResult }
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/create")
|
2025-03-24 14:27:45 +08:00
|
|
|
|
@Transactional
|
|
|
|
|
public synchronized AjaxResult createMember(@Validated @RequestBody MemberCreateApiRequest memberCreateApiRequest) {
|
|
|
|
|
|
|
|
|
|
IGamesService iGamesService = gamesService.get(memberCreateApiRequest.getPlatformCode() + Constants.SERVICE);
|
|
|
|
|
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
|
|
|
|
|
|
2025-02-11 15:27:15 +08:00
|
|
|
|
TenantSecretKey tenantSecretKey = keyConfig.get();
|
2025-03-24 14:27:45 +08:00
|
|
|
|
|
2025-04-03 14:34:49 +08:00
|
|
|
|
Platform platform = platformService.get(memberCreateApiRequest.getPlatformCode());
|
|
|
|
|
ApiException.notNull(platform, ErrorCode.CURRENCY_NOT_EXIST.getCode());
|
|
|
|
|
String targetCurrency = platform.getCurrencyInfo().get(memberCreateApiRequest.getCurrencyCode());
|
|
|
|
|
ApiException.notNull(targetCurrency, ErrorCode.CURRENCY_NOT_EXIST.getCode());
|
|
|
|
|
|
|
|
|
|
KeyInfo keyInfo = null;
|
|
|
|
|
for (KeyInfo keyData : platform.getKeyInfo()) {
|
|
|
|
|
if (StringUtils.isNotEmpty(memberCreateApiRequest.getCurrencyCode())) {
|
|
|
|
|
if (keyData.getCurrency().equalsIgnoreCase(memberCreateApiRequest.getCurrencyCode())) {
|
|
|
|
|
keyInfo = keyData;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ApiException.notNull(keyInfo, ErrorCode.CURRENCY_NOT_EXIST.getCode());
|
|
|
|
|
// GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
|
|
|
|
|
// .platformCode(memberCreateApiRequest.getPlatformCode())
|
|
|
|
|
// .systemCurrency(memberCreateApiRequest.getCurrencyCode()).build());
|
|
|
|
|
|
|
|
|
|
// ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
|
2025-03-24 14:27:45 +08:00
|
|
|
|
|
2025-03-27 14:36:05 +08:00
|
|
|
|
String gameAccount = StringUtils.addSuffix(memberService.getMemberGameAccount(memberCreateApiRequest.getPlatformCode()), tenantSecretKey.getTenantSn());
|
2025-03-24 14:27:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取用户信息
|
|
|
|
|
Member gameMember = memberService.selectMemberByAccount(memberCreateApiRequest.getAccount(), memberCreateApiRequest.getCurrencyCode(), memberCreateApiRequest.getPlatformCode());
|
2025-04-03 14:34:49 +08:00
|
|
|
|
if (!ObjectUtils.isEmpty(gameMember)) {
|
2025-03-24 14:27:45 +08:00
|
|
|
|
throw new ApiException(ErrorCode.GAME_ACCOUNT_CREATION_FAILED.getCode());
|
2025-02-13 15:43:13 +08:00
|
|
|
|
}
|
2025-03-24 14:27:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//注册本地账号
|
|
|
|
|
Member member = Member.builder()
|
|
|
|
|
.tenantKey(tenantSecretKey.getTenantKey())
|
|
|
|
|
.memberAccount(memberCreateApiRequest.getAccount())
|
|
|
|
|
.gameAccount(gameAccount)
|
|
|
|
|
.platformCode(memberCreateApiRequest.getPlatformCode())
|
|
|
|
|
.currencyCode(memberCreateApiRequest.getCurrencyCode())
|
|
|
|
|
.build();
|
|
|
|
|
int insertMember = memberService.insertMember(member);
|
|
|
|
|
Assert.isTrue(insertMember > 0, "建立游戏账号失败");
|
|
|
|
|
|
|
|
|
|
//向第三方注册账号
|
|
|
|
|
CreateMemberRequestDTO gamesBaseRequestDTO = CreateMemberRequestDTO.builder()
|
|
|
|
|
.account(gameAccount)
|
2025-04-03 14:34:49 +08:00
|
|
|
|
.agentId(keyInfo.getCode())
|
|
|
|
|
.agentKey(keyInfo.getKey())
|
2025-03-31 15:23:56 +08:00
|
|
|
|
.betLimit(memberCreateApiRequest.getBetLimit())
|
2025-04-03 09:50:51 +08:00
|
|
|
|
.platformType(memberCreateApiRequest.getPlatformType())
|
2025-04-03 14:34:49 +08:00
|
|
|
|
.currency(targetCurrency)
|
|
|
|
|
.vendor(platform)
|
|
|
|
|
.keyInfo(keyInfo)
|
2025-03-24 14:27:45 +08:00
|
|
|
|
.build();
|
|
|
|
|
Boolean result = iGamesService.createMember(gamesBaseRequestDTO);
|
|
|
|
|
Assert.isTrue(result, "建立游戏账号失败");
|
|
|
|
|
return toAjax(Boolean.TRUE);
|
|
|
|
|
|
2025-02-11 15:27:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取会员信息
|
|
|
|
|
*
|
2025-04-03 14:34:49 +08:00
|
|
|
|
* @param request 成员信息api请求
|
2025-02-11 15:27:15 +08:00
|
|
|
|
* @return {@link AjaxResult }
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/info")
|
2025-04-03 14:34:49 +08:00
|
|
|
|
public AjaxResult getMemberInfo(@Validated @RequestBody MemberInfoApiRequest request) {
|
|
|
|
|
IGamesService iGamesService = gamesService.get(request.getPlatformCode() + Constants.SERVICE);
|
2025-02-19 16:41:44 +08:00
|
|
|
|
ApiException.notNull(iGamesService, ErrorCode.PLATFORM_NOT_EXIST.getCode());
|
2025-02-11 15:27:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TenantSecretKey tenantSecretKey = keyConfig.get();
|
2025-04-03 14:34:49 +08:00
|
|
|
|
// GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
|
|
|
|
|
// .platformCode(memberInfoApiRequest.getPlatformCode())
|
|
|
|
|
// .systemCurrency(memberInfoApiRequest.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());
|
2025-03-17 18:16:42 +08:00
|
|
|
|
|
|
|
|
|
// 获取用户信息
|
2025-04-03 14:34:49 +08:00
|
|
|
|
Member member = memberService.selectMemberByAccount(request.getAccount(), request.getCurrencyCode(), request.getPlatformCode());
|
2025-02-19 16:41:44 +08:00
|
|
|
|
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
|
2025-02-12 13:42:52 +08:00
|
|
|
|
|
2025-03-17 18:16:42 +08:00
|
|
|
|
|
2025-02-11 15:27:15 +08:00
|
|
|
|
//向第三方查询账号
|
|
|
|
|
MemberInfoRequestDTO gamesBaseRequestDTO = MemberInfoRequestDTO.builder()
|
|
|
|
|
.accounts(member.getGameAccount())
|
2025-04-03 14:34:49 +08:00
|
|
|
|
.agentId(keyInfo.getCode())
|
|
|
|
|
.currency(targetCurrency)
|
|
|
|
|
.agentKey(keyInfo.getKey())
|
|
|
|
|
.vendor(platform)
|
|
|
|
|
.keyInfo(keyInfo)
|
2025-02-11 15:27:15 +08:00
|
|
|
|
.build();
|
2025-02-14 17:31:52 +08:00
|
|
|
|
MemberInfoResponseDTO memberInfo = iGamesService.getMemberInfo(gamesBaseRequestDTO);
|
2025-02-25 10:05:13 +08:00
|
|
|
|
MemberInfoResponse memberInfoResponse = new MemberInfoResponse();
|
|
|
|
|
BeanUtils.copyProperties(memberInfo, memberInfoResponse);
|
2025-02-14 17:31:52 +08:00
|
|
|
|
return AjaxResult.success(memberInfoResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 信息全部
|
|
|
|
|
*
|
|
|
|
|
* @param memberInfoAllApiRequest 成员信息所有api请求
|
|
|
|
|
* @return {@link AjaxResult }
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/info/all")
|
|
|
|
|
public AjaxResult infoAll(@Validated @RequestBody MemberInfoAllApiRequest memberInfoAllApiRequest) {
|
|
|
|
|
|
2025-03-17 18:16:42 +08:00
|
|
|
|
|
2025-04-03 14:34:49 +08:00
|
|
|
|
// List<GameSecretKeyCurrencyDTO> gameSecretKeys = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTOList(
|
|
|
|
|
// GameSecretKeyCurrencyDTO.builder()
|
|
|
|
|
// .systemCurrency(memberInfoAllApiRequest.getCurrencyCode()).build());
|
|
|
|
|
List<Key> keys = new ArrayList<>();
|
|
|
|
|
for (GamePlatforms platformEnum : GamePlatforms.values()) {
|
2025-03-24 14:27:45 +08:00
|
|
|
|
|
2025-04-03 14:34:49 +08:00
|
|
|
|
Platform platform = platformService.get(platformEnum.getCode());
|
|
|
|
|
String targetCurrency = platform.getCurrencyInfo().get(memberInfoAllApiRequest.getCurrencyCode());
|
|
|
|
|
if (StringUtils.isEmpty(targetCurrency)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
KeyInfo keyInfo = null;
|
|
|
|
|
for (KeyInfo keyData : platform.getKeyInfo()) {
|
|
|
|
|
if (StringUtils.isNotEmpty(memberInfoAllApiRequest.getCurrencyCode())) {
|
|
|
|
|
if (keyData.getCurrency().equalsIgnoreCase(memberInfoAllApiRequest.getCurrencyCode())) {
|
|
|
|
|
keyInfo = keyData;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (null == keyInfo) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-03-24 14:27:45 +08:00
|
|
|
|
|
2025-04-03 14:34:49 +08:00
|
|
|
|
Key key = new Key();
|
|
|
|
|
key.setPlatformCode(platform.getPlatformCode());
|
|
|
|
|
key.setCode(keyInfo.getCode());
|
|
|
|
|
key.setKey(keyInfo.getKey());
|
|
|
|
|
key.setCurrency(targetCurrency);
|
|
|
|
|
keys.add(key);
|
|
|
|
|
}
|
2025-02-14 17:31:52 +08:00
|
|
|
|
// 创建线程池
|
|
|
|
|
Map<String, BigDecimal> balanceMap = new LinkedHashMap<>();
|
2025-04-03 14:34:49 +08:00
|
|
|
|
CountDownLatch latch = new CountDownLatch(keys.size());
|
2025-02-14 17:31:52 +08:00
|
|
|
|
|
|
|
|
|
// 使用List存储Future对象,用于获取异步执行的结果
|
|
|
|
|
List<Future<MemberInfoAllResponse>> futures = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 提交异步任务到线程池
|
2025-04-03 14:34:49 +08:00
|
|
|
|
for (Key gameSecretKey : keys) {
|
|
|
|
|
|
2025-02-14 17:31:52 +08:00
|
|
|
|
futures.add(threadPoolTaskExecutor.submit(() -> {
|
2025-04-03 14:34:49 +08:00
|
|
|
|
|
2025-02-14 17:31:52 +08:00
|
|
|
|
try {
|
2025-03-14 13:31:17 +08:00
|
|
|
|
IGamesService iGamesService = gamesService.get(gameSecretKey.getPlatformCode() + Constants.SERVICE);
|
2025-03-17 18:16:42 +08:00
|
|
|
|
|
|
|
|
|
// 获取用户信息
|
|
|
|
|
Member member = memberService.selectMemberByAccount(memberInfoAllApiRequest.getAccount(), memberInfoAllApiRequest.getCurrencyCode(), gameSecretKey.getPlatformCode());
|
|
|
|
|
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
|
|
|
|
|
|
|
|
|
|
|
2025-02-14 17:31:52 +08:00
|
|
|
|
MemberInfoRequestDTO gamesBaseRequestDTO = MemberInfoRequestDTO.builder()
|
|
|
|
|
.accounts(member.getGameAccount())
|
|
|
|
|
.agentId(gameSecretKey.getCode())
|
2025-03-14 13:31:17 +08:00
|
|
|
|
.currency(gameSecretKey.getCurrency())
|
2025-02-14 17:31:52 +08:00
|
|
|
|
.agentKey(gameSecretKey.getKey())
|
|
|
|
|
.build();
|
|
|
|
|
//查询余额
|
|
|
|
|
MemberInfoResponseDTO memberInfo = iGamesService.getMemberInfo(gamesBaseRequestDTO);
|
|
|
|
|
return MemberInfoAllResponse.builder()
|
|
|
|
|
.account(member.getGameAccount())
|
|
|
|
|
.balance(memberInfo.getBalance())
|
|
|
|
|
.status(memberInfo.getStatus())
|
2025-03-14 13:31:17 +08:00
|
|
|
|
.platformCode(gameSecretKey.getPlatformCode())
|
2025-02-14 17:31:52 +08:00
|
|
|
|
.build();
|
|
|
|
|
} finally {
|
|
|
|
|
latch.countDown(); // 任务完成后减少计数
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 等待所有线程执行完毕
|
|
|
|
|
try {
|
|
|
|
|
latch.await();
|
|
|
|
|
// 获取每个Future的结果
|
|
|
|
|
for (Future<MemberInfoAllResponse> future : futures) {
|
|
|
|
|
// 汇总结果
|
|
|
|
|
MemberInfoAllResponse memberInfoAllResponse = future.get();
|
|
|
|
|
balanceMap.put(memberInfoAllResponse.getPlatformCode(), memberInfoAllResponse.getBalance());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("获取会员信息失败", e);
|
|
|
|
|
throw new BaseException("获取会员信息失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success(balanceMap);
|
2025-02-11 15:27:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-03 14:34:49 +08:00
|
|
|
|
@Data
|
|
|
|
|
class Key {
|
|
|
|
|
private String platformCode;
|
|
|
|
|
private String code;
|
|
|
|
|
private String currency;
|
|
|
|
|
private String key;
|
|
|
|
|
}
|
2025-02-11 15:27:15 +08:00
|
|
|
|
|
|
|
|
|
}
|