package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.common.security.utils.SecurityUtils;
import cn.cecep.talroad.domain.SupermonitorDrainOutlet;
import cn.cecep.talroad.mapper.SupermonitorDrainOutletMapper;
import cn.cecep.talroad.service.IPcFactoryService;
import cn.cecep.talroad.service.ISupermonitorDrainOutletService;
import cn.cecep.talroad.vo.PcFactoryVo;
import cn.cecep.talroad.vo.SupermonitorDrainOutletVo;
import cn.cecep.talroad.vo.query.SupermonitorDrainOutletQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 排污口Service业务层处理
 *
 * @author szhpt
 * @date 2023-01-10*/
@Service
public class SupermonitorDrainOutletServiceImpl extends ServiceImpl<SupermonitorDrainOutletMapper,SupermonitorDrainOutlet> implements ISupermonitorDrainOutletService
{
    @Autowired
    private SupermonitorDrainOutletMapper supermonitorDrainOutletMapper;

    @Autowired
    private IPcFactoryService factoryService;

    /**
     * 查询排污口列表
     *
     * @param supermonitorDrainOutlet 排污口
     * @return 排污口
     */
    @Override
    public List<SupermonitorDrainOutlet> selectSupermonitorDrainOutletList(SupermonitorDrainOutlet supermonitorDrainOutlet)
    {
        return supermonitorDrainOutletMapper.selectSupermonitorDrainOutletList(supermonitorDrainOutlet);
    }

    @Override
    public List<SupermonitorDrainOutletVo.PwxkRh> selectRhPwxkList(Page<SupermonitorDrainOutletVo.PwxkRh> page, SupermonitorDrainOutletQuery.PwxkRh query) {
        Page<PcFactoryVo> factoryPage = new Page<>(page.getCurrent(), page.getSize());
        List<PcFactoryVo> list = factoryService.search(factoryPage, query.getSearchVo(), "list", SecurityUtils.getLoginUser().getSysUser().getRegionCode());
        page.setTotal(factoryPage.getTotal());
        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        List<String> factoryIds = list.stream().map(PcFactoryVo::getId).collect(Collectors.toList());
        List<SupermonitorDrainOutletVo.PwxkRh> dataList = baseMapper.selectRhPwxkList(factoryIds, query);
        return dataList;

    }

    @Override
    public List<SupermonitorDrainOutletVo.PwxkYs> selectYsPwxkList(Page<SupermonitorDrainOutletVo.PwxkYs> page, SupermonitorDrainOutletQuery.PwxkYs query) {
        Page<PcFactoryVo> factoryPage = new Page<>(page.getCurrent(), page.getSize());
        List<PcFactoryVo> list = factoryService.search(factoryPage, query.getSearchVo(), "list", SecurityUtils.getLoginUser().getSysUser().getRegionCode());
        page.setTotal(factoryPage.getTotal());
        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        List<String> factoryIds = list.stream().map(PcFactoryVo::getId).collect(Collectors.toList());
        List<SupermonitorDrainOutletVo.PwxkYs> dataList = baseMapper.selectYsPwxkList(factoryIds, query);
        return dataList;
    }

}
