package com.nantian.cloud.ggjg.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.ggjg.entity.Mlk;
import com.nantian.cloud.ggjg.entity.Quota;
import com.nantian.cloud.ggjg.mapper.QuotaMapper;
import com.nantian.cloud.ggjg.mapper.SkMapper;
import com.nantian.cloud.ggjg.service.QuotaService;
import com.nantian.cloud.ggjg.service.SkService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("quotaService")
public class QuotaServiceImpl extends ServiceImpl<QuotaMapper, Quota> implements QuotaService {


    @Override
    public List<Map<String, Object>> queryList(Map para) {
        return baseMapper.queryList(para);
    }

    @Override
    public List<Map<String, Object>> getQuotaTjb(Map map) {
        return baseMapper.queryTjb(map);
    }

    @Override
    public List<Map<String, Object>> getOverstretch(Quota quota) {
        String area = quota.getAreaCode();
        if (area.contains("0000")) { //省
            quota.setAreaCode(StrUtil.subWithLength(area, 0, 2));
        } else if (area.contains("00")) {  //州市
            quota.setAreaCode(StrUtil.subWithLength(area, 0, 4));
        }
        if (quota.getType() != null && !"".equals(quota.getType())) {
            return baseMapper.getOverstretch(quota);
        }else{
            List<Map<String, Object>> list = new ArrayList<>();
            quota.setType("01"); //党政机关
            list.addAll(baseMapper.getOverstretch(quota));
            quota.setType("021"); //教育
            list.addAll(baseMapper.getOverstretch(quota));
            quota.setType("024"); //卫生
            list.addAll(baseMapper.getOverstretch(quota));
            quota.setType("025"); //体育
            list.addAll(baseMapper.getOverstretch(quota));
            return list;
        }
    }
}
