package com.hzs.member.base.provider;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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;

/**
 * @description: 隶属团队配置
 * @author: zhang jing
 * @date: 2022/11/10 17:02
 * @param:
 * @return:
 **/
@DubboService
public class MemberTeamServiceProvider implements IMemberTeamServiceApi {

    @Autowired
    private ICuMemberTeamService memberTeamService;

    /**
     * @description: 根据国家查询隶属团队配置列表
     * @author: zhang jing
     * @date: 2022/9/29 15:17
     * @param: [pkCountry]
     * @return: com.hzs.common.core.domain.R<java.util.List < com.hzs.common.domain.system.config.BdAwards>>
     **/
    @Override
    public R<List<CuMemberTeamExt>> queryCuMemberTeam(Integer pkCountry) {
        return R.ok(memberTeamService.queryCuMemberTeam(pkCountry));
    }

    /**
     * 根据体系id 查询是否有团队占用该体系
     *
     * @param pkVertex
     * @return
     */
    @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) {
        LambdaQueryWrapper<CuMemberTeam> queryWrapper = new LambdaQueryWrapper<>();
        if (null != pkVertexList) {
            queryWrapper.in(CuMemberTeam::getPkBdVertex, pkVertexList);
        }
        queryWrapper.orderByAsc(CuMemberTeam::getPkBdVertex);
        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);
    }

}
