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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.runeconomy.model.ReliabilityIssues;
import com.gyee.runeconomy.mapper.ReliabilityIssuesMapper;
import com.gyee.runeconomy.service.auto.ReliabilityIssuesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wang
 * @since 2024-11-27
 */
@Service
public class ReliabilityIssuesServiceImpl extends ServiceImpl<ReliabilityIssuesMapper, ReliabilityIssues> implements ReliabilityIssuesService {

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

    @Override
    public List<ReliabilityIssues> getReliabilityIssues(String wpid, String time) {
        QueryWrapper<ReliabilityIssues> qw = new QueryWrapper<>();
        qw.lambda().eq(ReliabilityIssues::getStationId, wpid);
        qw.lambda().eq(ReliabilityIssues::getRecordDate, time);
        List<ReliabilityIssues> ReliabilityIssues = baseMapper.selectList(qw);
        return ReliabilityIssues;
    }
}
