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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.alarm.mapper.auto.ProEconShutdownEvent2Mapper;
import com.gyee.alarm.model.auto.ProEconShutdownEvent2;
import com.gyee.alarm.service.auto.IProEconShutdownEvent2Service;
import com.gyee.common.model.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 停机事件2 服务实现类
 * </p>
 *
 * @author shilin
 * @since 2022-10-21
 */
@Service
public class ProEconShutdownEvent2ServiceImpl extends ServiceImpl<ProEconShutdownEvent2Mapper, ProEconShutdownEvent2> implements IProEconShutdownEvent2Service {

    @Resource
    private ProEconShutdownEvent2Mapper proEconShutdownEvent2Mapper;
    public IPage<ProEconShutdownEvent2> queryShutdownEvent2(String wpId, String wtId,String description, String begin,String end, Integer pageNum, Integer pageSize,String type) {
        QueryWrapper<ProEconShutdownEvent2> qw = new QueryWrapper<>();

        if (StringUtils.notEmp(wpId)) {
            qw.eq("winpowerstation_id", wpId);
        }

        if (StringUtils.notEmp(wtId)) {
            qw.eq("windturbine_id", wtId);
        }

        if (StringUtils.notEmp(description)) {
            qw.like("fault_view", "%"+description+"%");
        }

        if (StringUtils.notEmp(begin) && StringUtils.notEmp(end)) {
            try {
                Date beginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(begin);
                Date endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(end);
                qw.ge("stop_time", beginDate);
                qw.le("stop_time", endDate);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        qw.eq("stop_type_id", type);
        qw.orderByDesc("stop_time");


        Page<ProEconShutdownEvent2> page = new Page<>(pageNum, pageSize);
        IPage<ProEconShutdownEvent2> InputPage = getBaseMapper().selectPage(page, qw);

        return InputPage;
    }
}
