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.ProEconAnalysisSubtableBottomMapper;
import com.gyee.runeconomy.model.auto.ProEconAnalysisSubtableBottom;
import com.gyee.runeconomy.service.auto.IProEconAnalysisSubtableBottomService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 风电表底 服务实现类
 * </p>
 *
 * @author wang
 * @since 2023-09-19
 */
@Service
public class ProEconAnalysisSubtableBottomServiceImpl extends ServiceImpl<ProEconAnalysisSubtableBottomMapper, ProEconAnalysisSubtableBottom> implements IProEconAnalysisSubtableBottomService {

    @Override
    public boolean batchAdd(List<ProEconAnalysisSubtableBottom> proEconStationPowers) {
        try {
            proEconStationPowers.stream().forEach(i -> {
                QueryWrapper<ProEconAnalysisSubtableBottom> qw = new QueryWrapper<>();
                qw.lambda().eq(ProEconAnalysisSubtableBottom::getRecordDate, i.getRecordDate());
                qw.lambda().eq(ProEconAnalysisSubtableBottom::getMeterId, i.getMeterId());
                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;
    }
}
