package com.gyee.runeconomy.service.auto.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.mapper.auto.ProBasicPowerstationMapper;
import com.gyee.runeconomy.model.auto.ProBasicPowerstation;
import com.gyee.runeconomy.service.auto.IProBasicPowerstationService;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 场站表 服务实现类
 * </p>
 *
 * @author wang
 * @since 2022-11-22
 */
@Service
public class ProBasicPowerstationServiceImpl extends ServiceImpl<ProBasicPowerstationMapper, ProBasicPowerstation> implements IProBasicPowerstationService {

    @Override
    public List<ProBasicPowerstation> getProBasicPowerstationlist(String regionId, String companyId, String staType) {

        QueryWrapper<ProBasicPowerstation> qw = new QueryWrapper<>();

        //判断后缀是区域还是公司
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_ZGS")) {
            qw.lambda().eq(ProBasicPowerstation::getCompanyId, companyId);
        }
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_RGN")) {
            qw.lambda().eq(ProBasicPowerstation::getRegionId, companyId);
        }

        List<ProBasicPowerstation> list = baseMapper.selectList(qw);

        if (StringUtils.isNotEmpty(staType) && staType.equals("-1")) {

            list = list.stream().filter(i -> i.getId().indexOf("FDC") >= 0).collect(Collectors.toList());
        }
        if (StringUtils.isNotEmpty(staType) && staType.equals("-2")) {

            list = list.stream().filter(i -> i.getId().indexOf("GDC") >= 0).collect(Collectors.toList());
        }
        return list;
    }

    @Override
    public List<ProBasicPowerstation> selectList1() {
        QueryWrapper<ProBasicPowerstation> qw = new QueryWrapper<>();
        List<ProBasicPowerstation> windplants = baseMapper.selectList(qw);
        return windplants;
    }

    @Override
    public List<ProBasicPowerstation> selectwpid(String wpid) {
        QueryWrapper<ProBasicPowerstation> wrapper = new QueryWrapper();
        wrapper.lambda().eq(ProBasicPowerstation::getId, wpid);
        List<ProBasicPowerstation> list = baseMapper.selectList(wrapper);
        return list;
    }
}
