package cn.sh.stc.sict.theme.hphy.service.impl;

import cn.sh.stc.sict.theme.hphy.dao.HphyDoctorDataStatisticsMapper;
import cn.sh.stc.sict.theme.hphy.model.HphyDoctorDataStatistics;
import cn.sh.stc.sict.theme.hphy.service.HphyDoctorDataStatisticsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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


@Service("hphyDoctorDataStatisticsService")
@AllArgsConstructor
public class HphyDoctorDataStatisticsServiceImpl extends ServiceImpl<HphyDoctorDataStatisticsMapper, HphyDoctorDataStatistics> implements HphyDoctorDataStatisticsService {

    private final HphyDoctorDataStatisticsMapper hphyDoctorDataStatisticsMapper;

    @Override
    public Map<String, Map<String, List<HphyDoctorDataStatistics>>> treeBydoctorId(Long doctorId, Long diseaseId) {
        LambdaQueryWrapper<HphyDoctorDataStatistics> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HphyDoctorDataStatistics::getDoctorId, doctorId)
                .eq(HphyDoctorDataStatistics::getDiseaseId, diseaseId)
                .orderByAsc(HphyDoctorDataStatistics::getSort);
        List<HphyDoctorDataStatistics> list = this.list(wrapper);
        Map<String, Map<String, List<HphyDoctorDataStatistics>>> tree = list.stream()
                .collect(
                        Collectors.groupingBy(HphyDoctorDataStatistics::getGroupType,
                                Collectors.groupingBy(HphyDoctorDataStatistics::getTypeCode)));
        return tree;
    }
}
