package com.cpp.web.service.overhaulplan.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cpp.web.domain.overhaulplan.OverhaulPlanRecords;
import com.cpp.web.mapper.overhaulplan.OverhaulPlanRecordsMapper;
import com.cpp.web.service.overhaulplan.OverhaulPlanRecordsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * cpp_overhaul_plan_records
 *
 * @author fxy
 * @date 2024-10-08 9:47:33
 */
@Service
@RequiredArgsConstructor
public class OverhaulPlanRecordsServiceImpl extends ServiceImpl<OverhaulPlanRecordsMapper, OverhaulPlanRecords> implements OverhaulPlanRecordsService {

    private final OverhaulPlanRecordsMapper overhaulPlanRecordsMapper;
    @Override
    public QueryWrapper<OverhaulPlanRecords> getByStationCode(String stationCode) {
        QueryWrapper<OverhaulPlanRecords> wrapper = new QueryWrapper<>();
        if (null != stationCode && !"".equals(stationCode)) {
            wrapper.eq("station_code", stationCode);
        }
        return wrapper;
    }

    @Override
    public OverhaulPlanRecords findByStationCodeAndForecastModel(String stationCode, String forecastModel, Date startTime, Date endTime) {
        QueryWrapper wrapper = new QueryWrapper<>();
        if (null != stationCode && !"".equals(stationCode)){
            wrapper.eq("station_code",stationCode);
        }
        if (null != forecastModel && !"".equals(forecastModel)){
            wrapper.eq("forecast_model",forecastModel);
        }
        if (null != startTime){
            wrapper.eq("start_time",startTime);
        }
        if (null != endTime){
            wrapper.eq("end_time",endTime);
        }
        OverhaulPlanRecords overhaulPlanRecords = overhaulPlanRecordsMapper.selectOne(wrapper);
        return overhaulPlanRecords;
    }

    @Override
    public List<OverhaulPlanRecords> findByStationCodeAndTimeBetween(String stationCode, Date startTime, Date endTime) {
        QueryWrapper<OverhaulPlanRecords> wrapper = new QueryWrapper<>();
        if (null != stationCode && !"".equals(stationCode)){
            wrapper.eq("station_code",stationCode);
        }
        if (null != startTime){
            wrapper.eq("start_time",startTime);
        }
        if (null != endTime){
            wrapper.eq("end_time",endTime);
        }
        return overhaulPlanRecordsMapper.selectList(wrapper);
    }
}
