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.runeconomy.mapper.auto.ProEconSystemEfficiencyMapper;
import com.gyee.runeconomy.model.auto.ProEconSystemEfficiency;
import com.gyee.runeconomy.service.auto.IProEconSystemEfficiencyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 光伏系统效率 服务实现类
 * </p>
 *
 * @author wang
 * @since 2023-10-23
 */
@Service
public class ProEconSystemEfficiencyServiceImpl extends ServiceImpl<ProEconSystemEfficiencyMapper, ProEconSystemEfficiency> implements IProEconSystemEfficiencyService {

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

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

        return true;
    }
}
