package com.rf.psychological.module.index.service.impl;

import com.rf.psychological.module.index.dao.dto.IndexNumDayDTO;
import com.rf.psychological.module.index.dao.dto.IndexNumMonthDTO;
import com.rf.psychological.module.index.dao.dto.IndexRecordsNumSortDTO;
import com.rf.psychological.module.index.dao.dto.IndexSortNumDTO;
import com.rf.psychological.module.index.repository.IndexRepository;
import com.rf.psychological.module.index.service.IndexService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lpf
 * @description:
 * @date 2022/3/14 17:54
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Resource
    private IndexRepository indexRepository;

    @Override
    public int findGroupCount(String institutionNo) {
        return this.indexRepository.findGroupCount(institutionNo);
    }

    @Override
    public int findInstitutionAdminCount(String institutionNo) {
        return this.indexRepository.findInstitutionAdminCount(institutionNo);
    }

    @Override
    public int findUserCount(String institutionNo) {
        return this.indexRepository.findUserCount(institutionNo);
    }

    @Override
    public List<IndexSortNumDTO> findIndexCgSort(String institutionNo) {
        if ("10006".equals(institutionNo)) {
            return this.indexRepository.findIndexCgSort();
        }
        return this.indexRepository.findIndexCgSort(institutionNo);
    }

    @Override
    public List<IndexSortNumDTO> findIndexSjSort(String institutionNo) {
        if ("10006".equals(institutionNo)) {
            return this.indexRepository.findIndexSjSort();
        }
        return this.indexRepository.findIndexSjSort(institutionNo);
    }

    @Override
    public List<IndexNumMonthDTO> finIndexNumMonth(String type, String institutionNo) {
        ArrayList<IndexNumMonthDTO> indexNumMonthDTOS = new ArrayList<>();
        if (type.equals("0") || type.equals("1")) {
            return this.indexRepository.finIndexNumMonth(type, institutionNo);
        }
        return indexNumMonthDTOS;
    }

    @Override
    public List<IndexNumDayDTO> findIndexNumberByDays(String type, String institutionNo) {
        return this.indexRepository.findIndexNumberByDays(type, institutionNo);
    }

    @Override
    public List<IndexRecordsNumSortDTO> findIndexLeaderboard(String institutionNo, int limit, String type) {

        ArrayList<IndexRecordsNumSortDTO> indexRecordsNumSortDTOS = new ArrayList<>();
        if ("0".equals(type)) {
            return this.indexRepository.findIndexSubjectLeaderboard(institutionNo, limit);
        } else if ("1".equals(type)) {
            return this.indexRepository.findIndexCognitiveLeaderboard(institutionNo, limit);
        }
        return indexRecordsNumSortDTOS;
    }
}
