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.common.util.SortUtils;
import com.gyee.generation.mapper.auto.ProEconSystemEfficiencyEquipmentMapper;
import com.gyee.generation.model.auto.ProEconSystemEfficiencyEquipment;
import com.gyee.generation.service.auto.IProEconSystemEfficiencyEquipmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 光伏系统效率-设备 服务实现类
 * </p>
 *
 * @author shilin
 * @since 2023-11-28
 */
@Service
public class ProEconSystemEfficiencyEquipmentServiceImpl extends ServiceImpl<ProEconSystemEfficiencyEquipmentMapper, ProEconSystemEfficiencyEquipment> implements IProEconSystemEfficiencyEquipmentService {
    @Override
    public boolean batchAdd(List<ProEconSystemEfficiencyEquipment> proEconStationPowers) {
        SortUtils.sort(proEconStationPowers, "orderNum", SortUtils.ASC);
        try {
            proEconStationPowers.stream().forEach(i -> {
                QueryWrapper<ProEconSystemEfficiencyEquipment> qw = new QueryWrapper<>();
                qw.lambda().eq(ProEconSystemEfficiencyEquipment::getDataDate, i.getDataDate());
                qw.lambda().eq(ProEconSystemEfficiencyEquipment::getForeignKeyId, i.getForeignKeyId());
                qw.lambda().eq(ProEconSystemEfficiencyEquipment::getStationId, i.getStationId());
                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;
    }
}
