package com.zanxiang.game.module.manage.rpc.impl;

import com.zanxiang.game.module.base.rpc.IUserRpc;
import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
import com.zanxiang.game.module.manage.service.IGameService;
import com.zanxiang.game.module.manage.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;

/**
 * @author : lingfeng
 * @time : 2025-02-13
 * @description : 玩家相关接口
 */
@Slf4j
@DubboService
public class UserRpcImpl implements IUserRpc {

    @Autowired
    private IUserService userService;

    @Autowired
    private IGameService gameService;

    @Async
    @Override
    public void appletToOther(Long userId, Long gameId, String mobile) {
        try {
            //查询游戏信息
            GameDTO gameDTO = gameService.getById(gameId);
            if (gameDTO == null) {
                return;
            }
            //判断是否存在H5端游戏
            if (gameDTO.getH5GameId() != null) {
                userService.appletToH5(userId, mobile, 1);
            }
            //判断是否存在安卓端APP游戏
            if (gameDTO.getAndroidGameId() != null) {
                userService.appletToH5(userId, mobile, 2);
            }
            //判断是否存在IOS端APP游戏
            if (gameDTO.getIosGameId() != null) {
                userService.appletToH5(userId, mobile, 3);
            }
        } catch (Exception e) {
            log.error("执行玩家导量异常, userId : {}, mobile : {}, e : {}", userId, mobile, e.getMessage());
        }
    }
}
