RemoteCUserService.java 3.47 KB
package cn.com.glsx.admin.modules.remote;

import cn.com.glsx.usercenter.api.dto.response.CUser;
import cn.com.glsx.usercenter.api.feign.CUserService;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
public class RemoteCUserService {

    @Autowired
    private CUserService cUserService;

    /**
     * 根据C端用户id获取本地C端账号用户信息
     *
     * @param cuserIds
     * @return
     */
    public List<CUser> getLocalUsers(Collection<Long> cuserIds) {
        if (CollectionUtils.isEmpty(cuserIds)) {
            return Lists.newArrayList();
        }
        R<List<CUser>> listR = cUserService.getLocalCUsers(cuserIds);
        if (listR == null || !listR.isSuccess()) {
            return Lists.newArrayList();
        }

        List<CUser> cuserList = listR.getDataList(new TypeToken<List<CUser>>() {
        }.getType());
        return cuserList;
    }

    /**
     * 根据C端用户id获取本地C端账号用户信息
     *
     * @param cuserIds
     * @return
     */
    public Map<Long, CUser> getLocalUserMap(Collection<Long> cuserIds) {
        List<CUser> userModelList = this.getLocalUsers(cuserIds);

        return userModelList.stream().collect(Collectors.toMap(CUser::getUserId, Function.identity()));
    }

    /**
     * 根据后台账号用户id获取对应C端用户信息(实际同后台账号信息)
     *
     * @param relUserIds
     * @return
     */
    public List<CUser> getLocalRelUsers(Collection<Long> relUserIds) {
        if (CollectionUtils.isEmpty(relUserIds)) {
            return Lists.newArrayList();
        }
        R<List<CUser>> listR = cUserService.getLocalRelCUsers(relUserIds);
        if (listR == null || !listR.isSuccess()) {
            return Lists.newArrayList();
        }

        List<CUser> cuserList = listR.getDataList(new TypeToken<List<CUser>>() {
        }.getType());
        return cuserList;
    }

    public Map<Long, CUser> getLocalRelUserMap(Collection<Long> relUserIds) {
        List<CUser> userModelList = this.getLocalRelUsers(relUserIds);

        return userModelList.stream().filter(um -> um.getRelUserId() != null).collect(Collectors.toMap(CUser::getRelUserId, Function.identity()));
    }

    /**
     * 根据C端用户id获取微信账号用户信息
     *
     * @param cuserIds
     * @return
     */
    public List<CUser> getWechatUsers(Collection<Long> cuserIds) {
        if (CollectionUtils.isEmpty(cuserIds)) {
            return Lists.newArrayList();
        }
        R<List<CUser>> listR = cUserService.getLocalCUsers(cuserIds);
        if (listR == null || !listR.isSuccess()) {
            return Lists.newArrayList();
        }
        return listR.getDataList(new TypeToken<List<CUser>>() {
        }.getType());
    }

    /**
     * 根据C端用户id获取微信账号用户信息
     *
     * @param cuserIds
     * @return
     */
    public Map<Long, CUser> getWechatUserMap(Collection<Long> cuserIds) {
        List<CUser> userModelList = this.getWechatUsers(cuserIds);

        return userModelList.stream().collect(Collectors.toMap(CUser::getUserId, Function.identity()));
    }

}