package cn.cecep.talroad.service.impl.analysis;

import cn.cecep.talroad.common.core.domain.R;
import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.common.security.utils.SecurityUtils;
import cn.cecep.talroad.domain.analysis.SRaOverRateWater;
import cn.cecep.talroad.feign.BaseRegionService;
import cn.cecep.talroad.mapper.analysis.SRaOverRateWaterMapper;
import cn.cecep.talroad.service.analysis.ISRaOverRateWaterService;
import cn.cecep.talroad.vo.analysis.SRaOverRateWaterVo;
import cn.cecep.talroad.vo.query.analysis.SRaOverRateWaterQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;


/**
 * 超标率分析-水污染要素Service业务层处理
 *
 * @author szhpt
 * @date 2023-03-24
 */
@Service
public class SRaOverRateWaterServiceImpl extends ServiceImpl<SRaOverRateWaterMapper, SRaOverRateWater> implements ISRaOverRateWaterService
{

    @Autowired
    @Qualifier("baseRegionService")
    private BaseRegionService baseRegionService;
    @Autowired
    private SRaOverRateWaterMapper sRaOverRateWaterMapper;


    @Override
    public List<SRaOverRateWaterVo> selectOverRateWaterPage(Page<SRaOverRateWaterVo> page, SRaOverRateWaterQuery query) {
        // 若未指定，查询当前用户区域下的数据
        if (StringUtils.isEmpty(query.getRegionCode())) {
            String userRegionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();

            if (StringUtils.isEmpty(userRegionCode)) {
                return new ArrayList<>();
            }
            R<List<String>> r = baseRegionService.getRegionCodeListChild(userRegionCode);
            if (r.getCode() == R.SUCCESS) {
                query.setRegionCodeList(r.getData());
            } else {
                return new ArrayList<>();
            }
        }

        List<SRaOverRateWaterVo> vos = baseMapper.selectOverRateWaterPage(page, query);
        page.setRecords(vos);
        return vos;
    }

    @Override
    public List<SRaOverRateWater> selectWaterDataByMonth(List<String> monthList) {
        return sRaOverRateWaterMapper.selectWaterDataByMonth(monthList);
    }


}
