package com.zanxiang.game.gs.data.serve.service.impl;


import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.zanxiang.game.gs.data.serve.dao.mapper.game.order.GameServerSonMergeMapper;
import com.zanxiang.game.gs.data.serve.pojo.entity.game.order.GameServerSonMerge;
import com.zanxiang.game.gs.data.serve.service.IGameServerSonMergeService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 游戏区服合服子服记录表 服务层实现。
 *
 * @author shaosong
 * @since 1.0
 */
@Service
public class GameServerSonMergeServiceImpl extends ServiceImpl<GameServerSonMergeMapper, GameServerSonMerge> implements IGameServerSonMergeService {

    @Override
    public Map<Long, Map<String, String>> gameServerMap(String sourceSystem, Collection<String> serverIdList) {
        return list(new QueryWrapper()
                .eq(GameServerSonMerge::getSourceSystem, sourceSystem)
                .in(GameServerSonMerge::getServerId, serverIdList)
                .and("main_server_id = son_server_ids"))
                .stream()
                .collect(Collectors.groupingBy(GameServerSonMerge::getGameId, Collectors.toMap(GameServerSonMerge::getServerId, GameServerSonMerge::getServerName)));
    }

    @Override
    public Map<Long, Map<String, Integer>> gameServerOriginMap(String sourceSystem, Collection<String> serverIdList) {
        return list(new QueryWrapper()
                .eq(GameServerSonMerge::getSourceSystem, sourceSystem)
                .in(GameServerSonMerge::getServerId, serverIdList)
                .and("main_server_id = son_server_ids"))
                .stream()
                .collect(Collectors.groupingBy(GameServerSonMerge::getGameId, Collectors.toMap(GameServerSonMerge::getServerId, GameServerSonMerge::getIsSourceServer)));
    }
}