package com.ff.game.api.xk.service.impl;

import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson2.JSON;
import com.ff.base.constant.CacheConstants;
import com.ff.base.constant.Constants;
import com.ff.base.core.redis.RedisCache;
import com.ff.base.enums.GamePlatforms;
import com.ff.base.enums.GameStatus;
import com.ff.base.enums.XKGameType;
import com.ff.base.exception.base.BaseException;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.utils.DateUtils;
import com.ff.base.utils.JsonUtil;
import com.ff.base.utils.MessageUtils;
import com.ff.base.utils.StringUtils;
import com.ff.base.utils.http.HttpClientSslUtils;
import com.ff.base.utils.sign.Md5Utils;
import com.ff.base.utils.uuid.IdUtils;
import com.ff.game.api.IGamesService;
import com.ff.game.api.request.*;
import com.ff.game.api.xk.dto.*;
import com.ff.game.domain.*;
import com.ff.game.service.*;
import com.ff.member.domain.Member;
import com.ff.member.service.IMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;


/**
 * XK 游戏 impl
 *
 * @author shi
 * @date 2024/11/12
 */
@Service("XKService")
@Slf4j
public class GamesXKServiceImpl implements IGamesService {


    @Resource
    private ISysConfigService configService;

    @Resource
    private RedisCache redisCache;

    @Resource
    private IGameExchangeMoneyService gameExchangeMoneyService;


    @Resource
    private IGamePlatformService gamePlatformService;


    @Resource
    private IGameService gameService;




    @Resource
    private IMemberService memberService;

    @Resource
    private IGameFreeRecordService gameFreeRecordService;
    @Resource
    private IGameSecretKeyService gameSecretKeyService;
    /**
     * 获得就是成功
     *
     * @param errorCode 错误代码
     * @return {@link Boolean }
     */
    private Boolean getIsSuccess(Integer errorCode) {
        return 0 == errorCode;
    }


    /**
     * 获取密钥
     *
     * @param gamesBaseRequestDTO 游戏请求dto
     * @return {@link String }
     */
    @Override
    public String getKey(GamesBaseRequestDTO gamesBaseRequestDTO) {
        Random random = new Random();
        //取出对应的key跟密钥跟请求参数
        String agentKey = gamesBaseRequestDTO.getAgentKey();
        String agentId = gamesBaseRequestDTO.getAgentId();
        String query = gamesBaseRequestDTO.getQuery();

        String now = DateUtils.getFormattedDate();
        String keyG = Md5Utils.md5New(now + agentId + agentKey);

        String md5string = Md5Utils.md5New(query + keyG);
        Integer randomText1 = 100000 + random.nextInt(900000);
        Integer randomText2 = 100000 + random.nextInt(900000);
        String key = randomText1 + md5string + randomText2;
        return key;
    }

    /**
     * 创建成员
     *
     * @param createMemberRequestDTO 创建成员请求dto
     * @return {@link Boolean }
     */
    @Override
    public Boolean createMember(CreateMemberRequestDTO createMemberRequestDTO) {
        log.info("GamesXKServiceImpl [createMember] 请求参数 {}", createMemberRequestDTO);

        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("account", createMemberRequestDTO.getAccount());
        params.put("agentId", createMemberRequestDTO.getAgentId());
        String query = JsonUtil.mapToQueryString(params);
        createMemberRequestDTO.setQuery(query);
        String key = this.getKey(createMemberRequestDTO);
        params.put("key", key);
        try {
            String result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/createMember", JsonUtil.objToPrettyString(params));
            XKCreateMemberResponseDTO xkCreateMemberResponseDTO = JsonUtil.stringToObj(result, XKCreateMemberResponseDTO.class);
            //判断是否获取成功
            return !this.getIsSuccess(xkCreateMemberResponseDTO.getCode());

        } catch (Exception e) {
            log.error("GamesXKServiceImpl [createMember] 建立游戏账号,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.account.create.failed"));
        }
    }


    /**
     * 获取会员信息
     *
     * @param memberInfoRequestDTO 会员信息请求dto
     * @return {@link MemberInfoResponseDTO }
     */
    @Override
    public MemberInfoResponseDTO getMemberInfo(MemberInfoRequestDTO memberInfoRequestDTO) {
        log.info("GamesXKServiceImpl [getMemberInfo] 请求参数 {}", memberInfoRequestDTO);
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("accounts", memberInfoRequestDTO.getAccounts());
        params.put("agentId", memberInfoRequestDTO.getAgentId());
        String query = JsonUtil.mapToQueryString(params);
        memberInfoRequestDTO.setQuery(query);
        String key = this.getKey(memberInfoRequestDTO);
        params.put("key", key);
        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        try {
            String result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/getMemberInfo", JsonUtil.objToPrettyString(params));
            XKMemberInfoDTO xkMemberInfoDTO = JsonUtil.stringToObj(result, XKMemberInfoDTO.class);
            //判断是否获取成功
            if (this.getIsSuccess(xkMemberInfoDTO.getCode())) {
                List<MemberInfoResponseDTO> memberInfoResponseDTOS = new ArrayList<>();
                xkMemberInfoDTO.getData().forEach(e -> {
                    memberInfoResponseDTOS.add(MemberInfoResponseDTO.builder()
                            .status(e.getStatus())
                            .balance(e.getBalance())
                            .account(e.getAccount())
                            .build());
                });
                return memberInfoResponseDTOS.get(0);
            } else {
                log.error("GamesXKServiceImpl [getMemberInfo] 查询游戏账号信息失败,错误代码{},错误信息{}", xkMemberInfoDTO.getCode(), xkMemberInfoDTO.getMsg());
                throw new BaseException(MessageUtils.message("game.account.query.failed"));
            }

        } catch (Exception e) {
            log.error("GamesXKServiceImpl [getMemberInfo] 查询游戏账号信息失败,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.account.query.failed"));
        }

    }

    /**
     * 无重定向登录
     *
     * @param gamesLogin 游戏登录
     * @return {@link String }
     */
    @Override
    public String loginWithoutRedirect(GamesLogin gamesLogin) {
        log.info("GamesXKServiceImpl [loginWithoutRedirect] 请求参数 {}", gamesLogin);

        Map<String, Object> params = new LinkedHashMap<>();
        params.put("account", gamesLogin.getAccount());
        params.put("gameId", gamesLogin.getGameId());
        params.put("lang", gamesLogin.getLang());
        params.put("agentId", gamesLogin.getAgentId());
        String query = JsonUtil.mapToQueryString(params);
        gamesLogin.setQuery(query);
        String key = this.getKey(gamesLogin);
        params.put("key", key);
        params.put("disableFullScreen", gamesLogin.getDisableFullScreen());
        params.put("homeUrl", gamesLogin.getHomeUrl());
        params.put("platform", gamesLogin.getPlatform());
        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        try {

            String result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/loginWithoutRedirect", JsonUtil.objToPrettyString(params));
            XKLoginWithoutRedirectResponseDTO xkLoginWithoutRedirectResponseDTO = JsonUtil.stringToObj(result, XKLoginWithoutRedirectResponseDTO.class);
            //判断是否获取成功
            if (this.getIsSuccess(xkLoginWithoutRedirectResponseDTO.getCode())) {
                return xkLoginWithoutRedirectResponseDTO.getData();
            } else {
                log.error("GamesXKServiceImpl [loginWithoutRedirect] 游戏登录失败,错误代码{},错误信息{}", xkLoginWithoutRedirectResponseDTO.getCode(), xkLoginWithoutRedirectResponseDTO.getMsg());
                throw new BaseException(MessageUtils.message("game.login.failed"));
            }
        } catch (Exception e) {
            log.error("GamesXKServiceImpl [loginWithoutRedirect] 游戏登录失败,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.login.failed"));
        }
    }


    /**
     * 获取游戏列表
     *
     * @param gamesBaseRequestDTO 游戏请求dto
     * @return {@link String }
     */
    @Transactional
    @Override
    public String getGameList(GamesBaseRequestDTO gamesBaseRequestDTO) {
        List<XKGamesDTO.DataBean> gamesDatas = redisCache.getCacheList(CacheConstants.XK_GAMES);
        if (!CollectionUtils.isEmpty(gamesDatas)) {
            return CacheConstants.XK_GAMES;
        }

        Map<String, Object> params = new LinkedHashMap<>();
        params.put("agentId", gamesBaseRequestDTO.getAgentId());
        String query = JsonUtil.mapToQueryString(params);
        gamesBaseRequestDTO.setQuery(query);
        String key = this.getKey(gamesBaseRequestDTO);
        params.put("key", key);
        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        try {


            String result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/getGameList", JsonUtil.objToPrettyString(params));
            XKGamesDTO xkGamesDTO = JsonUtil.stringToObj(result, XKGamesDTO.class);
            //判断是否获取成功
            if (this.getIsSuccess(xkGamesDTO.getCode())) {

                Map<Long, GamePlatform> gamePlatformMap = new HashMap<>();

                for (XKGamesDTO.DataBean gamesDataDTO : xkGamesDTO.getData()) {
                    if (XKGameType.GAME_HALL.getCode().equals(gamesDataDTO.getGameCategoryId())) {
                        continue;
                    }

                    GamePlatform gamePlatform = GamePlatform.builder()
                            .platformType(XKGameType.findSystemByCode(gamesDataDTO.getGameCategoryId()))
                            .platformCode(GamePlatforms.XK.getCode())
                            .build();
                    List<GamePlatform> gamePlatforms = gamePlatformService.selectGamePlatformList(gamePlatform);
                    //没有此平台就新增一个平台
                    if (CollectionUtils.isEmpty(gamePlatforms)) {
                        gamePlatform.setPlatformName(GamePlatforms.XK.getInfo() + XKGameType.findInfoByCode(gamesDataDTO.getGameCategoryId()));
                        gamePlatform.setSortNo(gamePlatformService.selectMaxSortNo() + 1);
                        gamePlatform.setCreateBy(Constants.SYSTEM);
                        gamePlatformService.insertGamePlatform(gamePlatform);
                    } else {
                        gamePlatform = gamePlatforms.get(0);
                    }
                    Game game = Game.builder()
                            .platformId(gamePlatform.getId())
                            .gameCode(gamesDataDTO.getGameId())
                            .build();
                    List<Game> games = gameService.selectGameList(game);
                    //不存在这个游戏
                    if (CollectionUtils.isEmpty(games)) {
                        game.setFreespin(gamesDataDTO.isFreeSpin());
                        game.setSortNo(gameService.selectMaxSortNoByPlatformId(gamePlatform.getId()) + 1);
                        game.setGameName(gamesDataDTO.getName());
                        game.setCreateBy(Constants.SYSTEM);
                        gameService.insertGame(game);
                    } else {
                        game = games.get(0);
                    }
                    gamesDataDTO.setSystemGameId(game.getId());


                }



                redisCache.deleteObject(CacheConstants.XK_GAMES);
                redisCache.setCacheList(CacheConstants.XK_GAMES, xkGamesDTO.getData());
                redisCache.expire(CacheConstants.XK_GAMES, 5L, TimeUnit.HOURS);
            } else {
                log.error("GamesXKServiceImpl [getGameList] 获取游戏列表失败,错误代码{},错误信息{}", xkGamesDTO.getCode(), xkGamesDTO.getMsg());
                throw new BaseException(MessageUtils.message("game.list.retrieve.failed"));
            }
        } catch (Exception e) {
            log.error("GamesXKServiceImpl [getGameList] 获取游戏列表失败,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.list.retrieve.failed"));
        }
        return CacheConstants.JILI_GAMES;
    }

    /**
     * 按代理id进行交换转账
     *
     * @param exchangeTransferMoneyRequestDTO 外汇转账moeny dto
     * @return {@link Long }
     */
    @Override
    @Transactional
    public Long exchangeTransferByAgentId(ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO) {
        log.info("GamesXKServiceImpl [exchangeTransferByAgentId] 请求参数 {}", exchangeTransferMoneyRequestDTO);
        String systemByCode = gameSecretKeyService.findSystemByCode(exchangeTransferMoneyRequestDTO.getAgentId(),GamePlatforms.XK.getInfo());
        Member member = memberService.selectMemberByMemberAccount(exchangeTransferMoneyRequestDTO.getAccount());
        //获取下一个自增id
        GameExchangeMoney exchangeMoney = GameExchangeMoney
                .builder()
                .quota(exchangeTransferMoneyRequestDTO.getQuota())
                .platformId(exchangeTransferMoneyRequestDTO.getPlatformId())
                .balance(exchangeTransferMoneyRequestDTO.getAmount())
                .exchangeType(exchangeTransferMoneyRequestDTO.getTransferType())
                .currencyCode(systemByCode)
                .memberId(member.getId())
                .platformCode(GamePlatforms.XK.getCode())
                .build();
        exchangeMoney.setCreateBy(Constants.SYSTEM);
        //接口限制限制50字符
        exchangeMoney.setTransactionId(GamePlatforms.XK.getCode() + IdUtils.simpleUUID());
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("account", exchangeTransferMoneyRequestDTO.getAccount());
        params.put("transactionId", exchangeMoney.getTransactionId());
        params.put("amount", exchangeTransferMoneyRequestDTO.getAmount().stripTrailingZeros().toString());
        params.put("transferType", exchangeTransferMoneyRequestDTO.getTransferType());
        params.put("agentId", exchangeTransferMoneyRequestDTO.getAgentId());
        String query = JsonUtil.mapToQueryString(params);
        exchangeTransferMoneyRequestDTO.setQuery(query);
        String key = this.getKey(exchangeTransferMoneyRequestDTO);
        params.put("key", key);
        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        try {
            String result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/exchangeTransferByAgentId", JsonUtil.objToPrettyString(params));

            XKExchangeMoneyResponseDTO exchangeMoneyResponse = JsonUtil.stringToObj(result, XKExchangeMoneyResponseDTO.class);
            //判断是否转移成功
            if (this.getIsSuccess(exchangeMoneyResponse.getCode())) {
                XKExchangeMoneyResponseDTO.DataBean exchangeMoneyResponseData = exchangeMoneyResponse.getData();
                //更新数据
                exchangeMoney.setBalance(NumberUtil.sub(exchangeMoneyResponseData.getCurrencyAfter(), exchangeMoneyResponseData.getCurrencyBefore()).abs());
                exchangeMoney.setCoinBefore(exchangeMoneyResponseData.getCoinBefore());
                exchangeMoney.setCoinAfter(exchangeMoneyResponseData.getCoinAfter());
                exchangeMoney.setCurrencyBefore(exchangeMoneyResponseData.getCurrencyBefore());
                exchangeMoney.setCurrencyAfter(exchangeMoneyResponseData.getCurrencyAfter());
                exchangeMoney.setStatus(exchangeMoneyResponseData.getStatus());
                gameExchangeMoneyService.insertGameExchangeMoney(exchangeMoney);
            } else {
                log.error("GamesXKServiceImpl [exchangeTransferByAgentId] 金额转移失败,错误代码{},错误信息{}", exchangeMoneyResponse.getCode(), exchangeMoneyResponse.getMsg());
                throw new BaseException(MessageUtils.message("game.account.balance.transfer.failed"));
            }
        } catch (Exception e) {
            log.error("GamesXKServiceImpl [exchangeTransferByAgentId] 金额转移失败,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.account.balance.transfer.failed"));
        }

        return exchangeMoney.getId();
    }


    /**
     * 按时间获取投注记录
     *
     * @param betRecordByTimeDTO 按时间dto投注记录
     * @return {@link List }<{@link GameBettingDetails }>
     */
    @Override
    public List<GameBettingDetails> getBetRecordByTime(BetRecordByTimeDTO betRecordByTimeDTO) {
        List<GameBettingDetails> gameBettingDetails = new ArrayList<>();
        //请求参数
        log.info("GamesXKServiceImpl [getBetRecordByTime] 请求参数 {}", betRecordByTimeDTO);
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("startTime", betRecordByTimeDTO.getStartTime());
        params.put("endTime", betRecordByTimeDTO.getEndTime());
        params.put("page", betRecordByTimeDTO.getPage());
        params.put("pageLimit", betRecordByTimeDTO.getPageLimit());
        params.put("agentId", betRecordByTimeDTO.getAgentId());
        String query = JsonUtil.mapToQueryString(params);
        betRecordByTimeDTO.setQuery(query);
        String key = this.getKey(betRecordByTimeDTO);
        params.put("key", key);
        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        String result = null;
        try {
            result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/getGameRecordByTime", JsonUtil.objToPrettyString(params));

            XKBetRecordResponseDTO betRecordJILIResponse = JSON.parseObject(result, XKBetRecordResponseDTO.class);

            //判断是否获取成功
            if (this.getIsSuccess(betRecordJILIResponse.getCode())) {
                //数据组装
                XKBetRecordResponseDTO.DataBean dataBean = betRecordJILIResponse.getData();
                for (XKBetRecordResponseDTO.DataBean.ResultBean bean : dataBean.getResult()) {
                    GameBettingDetails bettingDetails = this.dataBuild(GamesDataBuildDTO.builder().data(bean).gamesKey(key).build());
                    gameBettingDetails.add(bettingDetails);
                }

                //获取下一页数据
                while (!Objects.equals(dataBean.getCurrentPage(), dataBean.getTotalPages())&&dataBean.getTotalPages()>0) {
                    betRecordByTimeDTO.setPage(dataBean.getCurrentPage() + 1);
                    //请求参数
                    params = new LinkedHashMap<>();
                    params.put("startTime", betRecordByTimeDTO.getStartTime());
                    params.put("endTime", betRecordByTimeDTO.getEndTime());
                    params.put("page", betRecordByTimeDTO.getPage());
                    params.put("pageLimit", betRecordByTimeDTO.getPageLimit());
                    params.put("agentId", betRecordByTimeDTO.getAgentId());
                    query = JsonUtil.mapToQueryString(params);
                    betRecordByTimeDTO.setQuery(query);
                    key = this.getKey(betRecordByTimeDTO);
                    params.put("key", key);
                    result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/getGameRecordByTime", JsonUtil.objToPrettyString(params));
                    betRecordJILIResponse = JsonUtil.stringToObj(result, XKBetRecordResponseDTO.class);
                    dataBean = betRecordJILIResponse.getData();
                    for (XKBetRecordResponseDTO.DataBean.ResultBean bean : dataBean.getResult()) {
                        GameBettingDetails bettingDetails = this.dataBuild(GamesDataBuildDTO.builder().data(bean).gamesKey(key).build());
                        gameBettingDetails.add(bettingDetails);
                    }
                }


                return gameBettingDetails;
            } else {
                log.error("GamesXKServiceImpl [getBetRecordByTime] 获取投注记录失败,错误代码{},错误信息{}", betRecordJILIResponse.getCode(), betRecordJILIResponse.getMsg());
                throw new BaseException(MessageUtils.message("game.bet.record.retrieve.failed"));
            }
        } catch (Exception e) {
            log.error("GamesXKServiceImpl [getBetRecordByTime] 获取投注记录失败,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.bet.record.retrieve.failed"));
        }

    }

    /**
     * 赠送免费局数
     *
     * @param createFreeSpinRequest 创建自由旋转请求
     * @return {@link Boolean }
     */
    @Override
    public Boolean createFreeSpin(CreateFreeSpinRequestDTO createFreeSpinRequest) {
        return Boolean.FALSE;
    }

    /**
     * 获取游戏详细信息
     *
     * @param getGameDetailRequestDTO 获取游戏详细信息请求dto
     * @return {@link GetGameDetailResponseDTO }
     */
    @Override
    public GetGameDetailResponseDTO getGameDetail(GetGameDetailRequestDTO getGameDetailRequestDTO) {
        return new GetGameDetailResponseDTO();
    }

    /**
     * 强制会员从游戏注销
     *
     * @param kickMemberRequestDTO 踢会员请求dto
     * @return {@link Boolean }
     */
    @Override
    public Boolean kickMember(KickMemberRequestDTO kickMemberRequestDTO) {
        log.info("GamesXKServiceImpl [kickMember] 请求参数 {}", kickMemberRequestDTO);
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("account", kickMemberRequestDTO.getAccount());
        params.put("agentId", kickMemberRequestDTO.getAgentId());
        String query = JsonUtil.mapToQueryString(params);
        kickMemberRequestDTO.setQuery(query);
        String key = this.getKey(kickMemberRequestDTO);
        params.put("key", key);

        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        try {

            String result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/kickMember", JsonUtil.objToPrettyString(params));
            XKKickMemberDTO xkKickMemberDTO = JsonUtil.stringToObj(result, XKKickMemberDTO.class);
            //判断是否获取成功
            if (this.getIsSuccess(xkKickMemberDTO.getCode())) {
                return Boolean.TRUE;
            } else {
                log.error("GamesXKServiceImpl [kickMember] 强制会员从游戏注销失败,错误代码{},错误信息{}", xkKickMemberDTO.getCode(), xkKickMemberDTO.getMsg());
                throw new BaseException(MessageUtils.message("game.member.force.logout.failed"));
            }
        } catch (Exception e) {
            log.error("GamesXKServiceImpl [kickMember] 强制会员从游戏注销失败,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.member.force.logout.failed"));
        }
    }

    /**
     * 踢成员全部
     *
     * @param kickMemberAllDTO 踢成员全部dto
     * @return {@link Boolean }
     */
    @Override
    public Boolean kickMemberAll(KickMemberAllDTO kickMemberAllDTO) {
        log.info("GamesXKServiceImpl [kickMemberAll] 请求参数 {}", kickMemberAllDTO);
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("agentId", kickMemberAllDTO.getAgentId());
        if (!ObjectUtils.isEmpty(kickMemberAllDTO.getGameId())) {
            params.put("gameId", kickMemberAllDTO.getGameId());
        }
        String query = JsonUtil.mapToQueryString(params);
        kickMemberAllDTO.setQuery(query);
        String key = this.getKey(kickMemberAllDTO);
        params.put("key", key);
        kickMemberAllDTO.setQuery(query);
        String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
        try {

            String result = HttpClientSslUtils.doPost(apiBaseUrl + "/api/kickMemberAll", JsonUtil.objToPrettyString(params));
            XKKickMemberAllDTO xkKickMemberAllDTO = JsonUtil.stringToObj(result, XKKickMemberAllDTO.class);
            //判断是否获取成功
            if (this.getIsSuccess(xkKickMemberAllDTO.getCode())) {
                return Boolean.TRUE;
            } else {
                log.error("GamesXKServiceImpl [kickMemberAll] 强制全部会员从游戏注销失败,错误代码{},错误信息{}", xkKickMemberAllDTO.getCode(), xkKickMemberAllDTO.getMsg());
                throw new BaseException(MessageUtils.message("game.members.force.logout.failed"));
            }
        } catch (Exception e) {
            log.error("GamesXKServiceImpl [kickMemberAll] 强制全部会员从游戏注销失败,错误信息{}", e);
            throw new BaseException(MessageUtils.message("game.members.force.logout.failed"));
        }
    }

    /**
     * 免费游戏玩家使用的纪录
     *
     * @param getFreeSpinDashflowRequestDTO 获取自由旋转dashflow请求dto
     * @return {@link List }<{@link GameFreeRecord }>
     */
    @Override
    public List<GameFreeRecord> getFreeSpinDashflow(GetFreeSpinDashflowRequestDTO getFreeSpinDashflowRequestDTO) {
        return new ArrayList<>();
    }

    /**
     * 取消赠送免费局数
     *
     * @param cancelFreeSpinRequestDTO 取消免费旋转请求
     * @return {@link Boolean }
     */
    @Override
    public Boolean cancelFreeSpin(CancelFreeSpinRequestDTO cancelFreeSpinRequestDTO) {
        return Boolean.TRUE;
    }


    /**
     * 数据构建
     *
     * @param gamesDataBuildDTO 数据
     * @return {@link GameBettingDetails }
     */
    @Override
    public GameBettingDetails dataBuild(GamesDataBuildDTO gamesDataBuildDTO) {
        //转化类
        XKBetRecordResponseDTO.DataBean.ResultBean resultBean = (XKBetRecordResponseDTO.DataBean.ResultBean) gamesDataBuildDTO.getData();
        String systemByCode = gameSecretKeyService.findSystemByCode(resultBean.getAgentId(),GamePlatforms.XK.getInfo());
        Member member = memberService.selectMemberByMemberAccount(resultBean.getAccount());
        List<XKGamesDTO.DataBean> gamesDatas = redisCache.getCacheList(CacheConstants.XK_GAMES);
        Map<Integer, XKGamesDTO.DataBean> dataDTOMap = gamesDatas.stream().collect(Collectors.toMap(XKGamesDTO.DataBean::getGameId, e -> e));
        XKGamesDTO.DataBean gamesDataDTO = dataDTOMap.get(resultBean.getGameId());
        BigDecimal payoffAmount=BigDecimal.ZERO;

        if (GameStatus.WIN.getCode().equals(resultBean.getStatus())) {
            payoffAmount = NumberUtil.sub(resultBean.getPayoffAmount(), resultBean.getTurnover());
        } else if (GameStatus.FAIL.getCode().equals(resultBean.getStatus())){
            payoffAmount = NumberUtil.sub(resultBean.getPayoffAmount(), resultBean.getTurnover()).negate();
        }
        //数据构造
        GameBettingDetails gameBettingDetails = GameBettingDetails.builder()
                //保存我们的币种id
                .currencyCode(systemByCode)
                .memberId(member.getId())
                .gameCode(resultBean.getGameId())
                .gameType(XKGameType.findSystemByCode(resultBean.getGameCategoryId()))
                .platformCode(GamePlatforms.XK.getCode())
                .gameId(gamesDataDTO.getSystemGameId())
                .gameName(gamesDataDTO.getName())
                .gameStatus(resultBean.getStatus())
                .gameStatusType(resultBean.getType())
                .gameCurrencyCode(resultBean.getAgentId())
                .account(String.valueOf(resultBean.getAccount()))
                .wagersId(resultBean.getWagersId())
                .wagersTime(resultBean.getWagersTime())
                .betAmount(resultBean.getBetAmount().abs())
                .payoffTime(resultBean.getPayoffTime())
                .payoffAmount(payoffAmount)
                .settlementTime(resultBean.getSettlementTime())
                .turnover(resultBean.getTurnover())
                .orderNo(String.valueOf(resultBean.getRoundIndex()))
                .build();
        gameBettingDetails.setCreateBy(Constants.SYSTEM);
        gameBettingDetails.setCreateTime(DateUtils.getNowDate());
        return gameBettingDetails;
    }
}
