package com.srs.stureg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.srs.common.core.domain.entity.SysDictData;
import com.srs.comprehensive.domain.Vo.DataScreen;
import com.srs.stureg.domain.SrsStuReg;
import com.srs.stureg.mapper.SrsStuCheckMapper;
import com.srs.stureg.mapper.SrsStuDormMapper;
import com.srs.stureg.mapper.SrsStuRegCountMapper;
import com.srs.stureg.mapper.SrsStuRegMapper;
import com.srs.stureg.service.ISrsStuRegCountService;
import com.srs.system.mapper.SysDictDataMapper;
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.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class SrsStuRegCountServiceImpl implements ISrsStuRegCountService {
    @Autowired
    private SrsStuRegCountMapper srsStuRegCountMapper;

    @Autowired
    private SrsStuRegMapper srsStuRegMapper;
    @Autowired
    private SrsStuCheckMapper srsStuCheckMapper;
    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    @Override
    public List<Map<String, Object>> countDept() {
        return srsStuRegCountMapper.countDept();
    }
    @Override
    public List<Map<String, Object>> countClass() {
        return srsStuRegCountMapper.countClass();
    }

    @Override
    public List<DataScreen> countArea() {
        SrsStuReg srs=new SrsStuReg();
        srs.setRegStatus("1");
        List<SrsStuReg> regs=srsStuRegMapper.selectSrsStuRegList(srs);
        return srsStuRegCountMapper.countArea(regs);
    }

    @Override
    public List<Map<String,Object>> countMajorTop10() {
        return srsStuRegCountMapper.countMajorTop10();
    }

    @Override
    public Map<String, Object> countNowAt() {
        Map<String, Object> list=srsStuRegCountMapper.countNowAt();
        Map<String, Object> check=srsStuCheckMapper.countCheckTotal();
        list.putAll(check);
        return list;
    }

    @Override
    public List<DataScreen> countGender() {
        return srsStuRegCountMapper.countGender();
    }

    @Override
    public Map<String, Integer> selectCountByRegStatus() {
        HashMap<String, Integer> map = new HashMap<>();
        List<SysDictData> srs_stu_reg_status = sysDictDataMapper.selectDictDataByType("srs_stu_reg_status");
        for (SysDictData srsStuRegStatus : srs_stu_reg_status) {
            Integer count = srsStuRegCountMapper.selectCountByRegStatus(srsStuRegStatus.getDictValue());
            map.put(srsStuRegStatus.getDictValue(), count);
        }
        return map;
    }

    @Override
    public List<Map> atStationCount() {
        return srsStuRegCountMapper.atStationCount();
    }

    @Override
    public List<Map> atStationByCampusCount() {
        return srsStuRegCountMapper.atStationByCampusCount();
    }

    @Override
    public List<Map<String, Object>> countHour() {
        return srsStuRegCountMapper.countHour();
    }



    // 定义一个方法，输入详细地址，返回省份信息
    public static String getProvince(String address) {
        String province = "";
        // 正则表达式匹配省份信息
        Pattern pattern = Pattern.compile("省|自治区|特别行政区");
        if (address==null){
            address="未知";
        }
        Matcher matcher = pattern.matcher(address);
        // 找到匹配的省份信息
        if (matcher.find()) {
            province = address.substring(matcher.start(), matcher.end());
        }
        return province;
    }
}

