package com.xjrsoft.module.outint.service.impl;

import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.module.outint.entity.StudentOutInRecord;
import com.xjrsoft.module.outint.mapper.StudentOutInRecordMapper;
import com.xjrsoft.module.outint.service.IStudentOutInRecordService;
import com.xjrsoft.module.outint.vo.IdCountVo;
import com.xjrsoft.module.outint.vo.StudentOutInRecordVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @title: 学生出入记录
* @Author dzx
* @Date: 2024-05-14
* @Version 1.0
*/
@Service
@AllArgsConstructor
public class StudentOutInRecordServiceImpl extends MPJBaseServiceImpl<StudentOutInRecordMapper, StudentOutInRecord> implements IStudentOutInRecordService {
    @Override
    public Map<Long, Integer> getNotStayClassCount(LocalDateTime startTime, LocalDateTime endTime) {
        List<IdCountVo> classCount = this.baseMapper.getNotStayClassCount(startTime, endTime);
        Map<Long, Integer> result = new HashMap<>();
        for (IdCountVo idCountVo : classCount) {
            result.put(idCountVo.getId(), idCountVo.getCount());
        }

        return result;
    }

    @Override
    public Map<Long, Integer> getStayClassCount(LocalDateTime startTime, LocalDateTime endTime) {
        List<IdCountVo> classCount = this.baseMapper.getStayClassCount(startTime, endTime);
        Map<Long, Integer> result = new HashMap<>();
        for (IdCountVo idCountVo : classCount) {
            result.put(idCountVo.getId(), idCountVo.getCount());
        }

        return result;
    }

    @Override
    public Map<Long, List<StudentOutInRecordVo>> getNotStayList(LocalDateTime startTime, LocalDateTime endTime, List<Long> classIds) {
        List<StudentOutInRecordVo> notStayList = this.baseMapper.getNotStayList(startTime, endTime);
        Map<Long, List<StudentOutInRecordVo>> result = new HashMap<>();
        for (Long classId : classIds) {
            List<StudentOutInRecordVo> dataList = new ArrayList<>();
            for (StudentOutInRecordVo recordVo : notStayList) {
                if(!classId.equals(recordVo.getClassId())){
                    continue;
                }
                dataList.add(recordVo);
            }
            result.put(classId, dataList);
        }

        return result;
    }

    @Override
    public Map<Long, List<StudentOutInRecordVo>> getStayList(LocalDateTime startTime, LocalDateTime endTime, List<Long> classIds) {
        List<StudentOutInRecordVo> notStayList = this.baseMapper.getStayList(startTime, endTime);
        Map<Long, List<StudentOutInRecordVo>> result = new HashMap<>();
        for (Long classId : classIds) {
            List<StudentOutInRecordVo> dataList = new ArrayList<>();
            for (StudentOutInRecordVo recordVo : notStayList) {
                if(!classId.equals(recordVo.getClassId())){
                    continue;
                }
                dataList.add(recordVo);
            }
            result.put(classId, dataList);
        }

        return result;
    }

    @Override
    public Map<Long, List<StudentOutInRecordVo>> getList(LocalDateTime startTime, LocalDateTime endTime, List<Long> classIds) {
        List<StudentOutInRecordVo> notStayList = this.baseMapper.getList(startTime, endTime);
        Map<Long, List<StudentOutInRecordVo>> result = new HashMap<>();
        for (Long classId : classIds) {
            List<StudentOutInRecordVo> dataList = new ArrayList<>();
            for (StudentOutInRecordVo recordVo : notStayList) {
                if(!classId.equals(recordVo.getClassId())){
                    continue;
                }
                dataList.add(recordVo);
            }
            result.put(classId, dataList);
        }

        return result;
    }
}
