package com.hzs.member.base.provider;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.member.base.CuMemberTeam;
import com.hzs.common.domain.member.ext.CuMemberTeamExt;
import com.hzs.member.base.IMemberTeamServiceApi;
import com.hzs.member.base.service.ICuMemberTeamService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 隶属团队配置
 **/
@DubboService
public class MemberTeamServiceProvider implements IMemberTeamServiceApi {

    @Autowired
    private ICuMemberTeamService memberTeamService;

    @Override
    public R<List<CuMemberTeamExt>> queryCuMemberTeam(Integer pkCountry) {
        return R.ok(memberTeamService.queryCuMemberTeam(pkCountry));
    }

    @Override
    public R<Boolean> checkVertex(Integer pkVertex) {
        return R.ok(memberTeamService.checkVertex(pkVertex));
    }

    @Override
    public R<CuMemberTeamExt> getCuMemberTeamById(Long pkMember) {
        return R.ok(memberTeamService.getCuMemberTeamById(pkMember));
    }

    @Override
    public R<Map<Long, CuMemberTeam>> getTeamByVertexIds(List<Integer> pkVertexList) {
        QueryWrapper<CuMemberTeam> queryWrapper = new QueryWrapper<>();
        if (null != pkVertexList) {
            queryWrapper.in("PK_BD_VERTEX", pkVertexList);
        }
        queryWrapper.orderByAsc("PK_BD_VERTEX");
        List<CuMemberTeam> list = memberTeamService.list(queryWrapper);

        Map<Long, CuMemberTeam> resultMap = new HashMap<>();
        if (CollectionUtil.isNotEmpty(list)) {
            resultMap = list.stream().collect(Collectors.toMap(CuMemberTeam::getPkId, t -> t));
        }
        return R.ok(resultMap);
    }

}
