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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.generation.mapper.auto.ProEconStationPowerMapper;
import com.gyee.generation.model.auto.ProEconStationPower;
import com.gyee.generation.service.auto.IProEconStationPowerService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 预测功率合格 服务实现类
 * </p>
 *
 * @author xieshengjie
 * @since 2023-09-13
 */
@Service
public class ProEconStationPowerServiceImpl extends ServiceImpl<ProEconStationPowerMapper, ProEconStationPower> implements IProEconStationPowerService {

    @Override
    public boolean batchAdd(List<ProEconStationPower> proEconStationPowers) {
        try {
            proEconStationPowers.stream().forEach(i -> {
                QueryWrapper<ProEconStationPower> qw = new QueryWrapper<>();
                qw.lambda().eq(ProEconStationPower::getRecordDate, i.getRecordDate());
                qw.lambda().eq(ProEconStationPower::getWindpowerstationId, i.getWindpowerstationId());
                long count = baseMapper.selectCount(qw);
                if (count <= 0) {
                    baseMapper.insert(i);
                } else if (count > 0) {
                    baseMapper.update(i, qw);
                }

            });
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }
}
