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;
|
|
|
|
|
import com.ff.base.exception.base.ApiException;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import com.ff.base.exception.base.BaseException;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import com.ff.base.utils.StringUtils;
|
2025-02-25 10:05:13 +08:00
|
|
|
|
import com.ff.base.system.domain.TenantSecretKey;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import com.ff.config.KeyConfig;
|
|
|
|
|
import com.ff.game.api.IGamesService;
|
2025-02-14 17:31:52 +08:00
|
|
|
|
import com.ff.game.api.request.*;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import com.ff.game.domain.GameSecretKey;
|
2025-03-14 13:31:17 +08:00
|
|
|
|
import com.ff.game.dto.GameSecretKeyCurrencyDTO;
|
|
|
|
|
import com.ff.game.service.IGameSecretKeyCurrencyService;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import com.ff.game.service.IGameSecretKeyService;
|
|
|
|
|
import com.ff.game.service.IGameService;
|
|
|
|
|
import com.ff.member.domain.Member;
|
|
|
|
|
import com.ff.member.service.IMemberService;
|
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-02-13 15:43:13 +08:00
|
|
|
|
import org.springframework.util.CollectionUtils;
|
2025-02-11 15:27:15 +08:00
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
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 IGameService gameService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private KeyConfig keyConfig;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private IGameSecretKeyService gameSecretKeyService;
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
private IGameSecretKeyCurrencyService gameSecretKeyCurrencyService;
|
|
|
|
|
|
2025-02-11 15:27:15 +08:00
|
|
|
|
/**
|
|
|
|
|
* 创建成员
|
|
|
|
|
*
|
|
|
|
|
* @param memberCreateApiRequest 创建成员api请求
|
|
|
|
|
* @return {@link AjaxResult }
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/create")
|
2025-02-18 16:09:21 +08:00
|
|
|
|
@Transactional
|
2025-02-11 15:27:15 +08:00
|
|
|
|
public AjaxResult createMember(@Validated @RequestBody MemberCreateApiRequest memberCreateApiRequest) {
|
|
|
|
|
|
|
|
|
|
IGamesService iGamesService = gamesService.get(memberCreateApiRequest.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-03-14 13:31:17 +08:00
|
|
|
|
GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
|
|
|
|
|
.platformCode(memberCreateApiRequest.getPlatformCode())
|
|
|
|
|
.systemCurrency(memberCreateApiRequest.getCurrencyCode()).build());
|
|
|
|
|
|
2025-02-19 16:41:44 +08:00
|
|
|
|
ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
|
2025-02-11 15:27:15 +08:00
|
|
|
|
|
2025-03-14 19:30:40 +08:00
|
|
|
|
String gameAccount = StringUtils.addSuffix(memberService.getMemberGameAccount(), tenantSecretKey.getTenantSn());
|
2025-02-25 10:05:13 +08:00
|
|
|
|
|
2025-02-13 15:43:13 +08:00
|
|
|
|
|
|
|
|
|
List<Member> members = memberService.selectMemberList(Member.builder()
|
2025-02-18 16:37:16 +08:00
|
|
|
|
.tenantKey(tenantSecretKey.getTenantKey()).gameAccount(gameAccount).build());
|
2025-02-13 15:43:13 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(members)) {
|
|
|
|
|
//注册本地账号
|
|
|
|
|
Member member = Member.builder()
|
|
|
|
|
.tenantKey(tenantSecretKey.getTenantKey())
|
|
|
|
|
.memberAccount(memberCreateApiRequest.getAccount())
|
|
|
|
|
.gameAccount(gameAccount)
|
|
|
|
|
.platformCode(memberCreateApiRequest.getPlatformCode())
|
|
|
|
|
.currencyCode(memberCreateApiRequest.getCurrencyCode())
|
|
|
|
|
.build();
|
2025-02-25 10:05:13 +08:00
|
|
|
|
int insertMember = memberService.insertMember(member);
|
2025-03-14 13:31:17 +08:00
|
|
|
|
Assert.isTrue(insertMember > 0, "建立游戏账号失败");
|
2025-02-13 15:43:13 +08:00
|
|
|
|
}
|
2025-02-25 10:05:13 +08:00
|
|
|
|
//向第三方注册账号
|
|
|
|
|
CreateMemberRequestDTO gamesBaseRequestDTO = CreateMemberRequestDTO.builder()
|
|
|
|
|
.account(gameAccount)
|
|
|
|
|
.agentId(gameSecretKey.getCode())
|
|
|
|
|
.agentKey(gameSecretKey.getKey())
|
2025-03-14 13:31:17 +08:00
|
|
|
|
.currency(gameSecretKey.getCurrency())
|
2025-02-25 10:05:13 +08:00
|
|
|
|
.build();
|
|
|
|
|
Boolean result = iGamesService.createMember(gamesBaseRequestDTO);
|
|
|
|
|
Assert.isTrue(result, "建立游戏账号失败");
|
2025-02-13 15:43:13 +08:00
|
|
|
|
return toAjax(Boolean.TRUE);
|
|
|
|
|
|
2025-02-11 15:27:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取会员信息
|
|
|
|
|
*
|
2025-02-14 17:31:52 +08:00
|
|
|
|
* @param memberInfoApiRequest 成员信息api请求
|
2025-02-11 15:27:15 +08:00
|
|
|
|
* @return {@link AjaxResult }
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/info")
|
2025-02-14 17:31:52 +08:00
|
|
|
|
public AjaxResult getMemberInfo(@Validated @RequestBody MemberInfoApiRequest memberInfoApiRequest) {
|
|
|
|
|
IGamesService iGamesService = gamesService.get(memberInfoApiRequest.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-03-14 13:31:17 +08:00
|
|
|
|
GameSecretKeyCurrencyDTO gameSecretKey = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTO(GameSecretKeyCurrencyDTO.builder()
|
|
|
|
|
.platformCode(memberInfoApiRequest.getPlatformCode())
|
|
|
|
|
.systemCurrency(memberInfoApiRequest.getCurrencyCode()).build());
|
|
|
|
|
|
2025-02-19 16:41:44 +08:00
|
|
|
|
ApiException.notNull(gameSecretKey, ErrorCode.CURRENCY_NOT_EXIST.getCode());
|
2025-02-11 15:27:15 +08:00
|
|
|
|
|
2025-02-14 17:31:52 +08:00
|
|
|
|
Member member = memberService.selectMemberByGameAccount(StringUtils.addSuffix(memberInfoApiRequest.getAccount(), memberInfoApiRequest.getCurrencyCode() + tenantSecretKey.getTenantSn()));
|
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-02-11 15:27:15 +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-11 15:27:15 +08:00
|
|
|
|
.agentKey(gameSecretKey.getKey())
|
|
|
|
|
.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) {
|
|
|
|
|
|
|
|
|
|
TenantSecretKey tenantSecretKey = keyConfig.get();
|
|
|
|
|
Member member = memberService.selectMemberByGameAccount(StringUtils.addSuffix(memberInfoAllApiRequest.getAccount(), memberInfoAllApiRequest.getCurrencyCode() + tenantSecretKey.getTenantSn()));
|
2025-02-19 16:41:44 +08:00
|
|
|
|
ApiException.notNull(member, ErrorCode.ACCOUNT_NOT_EXIST.getCode());
|
2025-02-14 17:31:52 +08:00
|
|
|
|
|
|
|
|
|
|
2025-03-14 13:31:17 +08:00
|
|
|
|
List<GameSecretKeyCurrencyDTO> gameSecretKeys = gameSecretKeyCurrencyService.findByGameSecretKeyCurrencyDTOList(GameSecretKeyCurrencyDTO.builder()
|
|
|
|
|
.systemCurrency(memberInfoAllApiRequest.getCurrencyCode()).build());
|
2025-02-14 17:31:52 +08:00
|
|
|
|
|
|
|
|
|
// 创建线程池
|
|
|
|
|
Map<String, BigDecimal> balanceMap = new LinkedHashMap<>();
|
|
|
|
|
CountDownLatch latch = new CountDownLatch(gameSecretKeys.size());
|
|
|
|
|
|
|
|
|
|
// 使用List存储Future对象,用于获取异步执行的结果
|
|
|
|
|
List<Future<MemberInfoAllResponse>> futures = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 提交异步任务到线程池
|
2025-03-14 13:31:17 +08:00
|
|
|
|
for (GameSecretKeyCurrencyDTO gameSecretKey : gameSecretKeys) {
|
2025-02-14 17:31:52 +08:00
|
|
|
|
futures.add(threadPoolTaskExecutor.submit(() -> {
|
|
|
|
|
try {
|
2025-03-14 13:31:17 +08:00
|
|
|
|
IGamesService iGamesService = gamesService.get(gameSecretKey.getPlatformCode() + Constants.SERVICE);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|