package com.zd.system.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.zd.common.core.domain.R;
import com.zd.system.api.domain.SysUser;
import com.zd.system.api.domain.TeacherListVO;
import com.zd.system.api.laboratory.RemoteLaboratoryService;
import com.zd.system.api.laboratory.domain.LabSubjectControllerVO;
import com.zd.system.api.laboratory.domain.LabSubjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 教职工服务
 *
 * @Author: zhoupan
 * @Date: 2021/09/11/13:14
 * @Description:
 */
@Service
public class TeacherServiceImpl {

    @Autowired
    RemoteLaboratoryService laboratoryService;

    /**
     * 查询教师的实验室信息
     *
     * @param list
     * @return
     */
    public void queryTeacherSuBCount(List<SysUser> list) {
        if (CollUtil.isEmpty(list)) return ;
        final Map<Long, List<LabSubjectVO>> collect = new HashMap<>();
        if (CollUtil.isNotEmpty(list)) {
            //得到ids
            String ids = list.stream().map(a -> a.getUserId().toString()).collect(Collectors.joining(","));
            //远程获取实验室信息
            R<List<LabSubjectVO>> infoByUserIds = laboratoryService.getInfoByUserIds(ids);
            if (CollUtil.isNotEmpty(infoByUserIds.getData())) {
                collect.putAll(infoByUserIds.getData().stream().collect(Collectors.groupingBy(LabSubjectVO::getAdminId)));
            }
        }
        /*list.stream().forEach(a -> {
            if (collect.containsKey(a.getUserId())) {
                a.setManageSubCount(collect.get(a.getUserId()).size());
            } else {
                a.setManageSubCount(0);
            }
        });*/



    }


}
