package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.MonDevDlReal;
import cn.cecep.talroad.mapper.MonDevDlRealMapper;
import cn.cecep.talroad.service.IMonDevDlRealService;
import cn.cecep.talroad.vo.MonDevDlRealVo;
import cn.cecep.talroad.vo.analysis.AvgValueVo;
import cn.cecep.talroad.vo.analysis.PumpStateVo;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Date;




/**
 * 设备数据-电力-实时 保存设备的实时数据Service业务层处理
 *
 * @author szhpt
 * @date 2023-01-10*/
@Service
public class MonDevDlRealServiceImpl extends ServiceImpl<MonDevDlRealMapper,MonDevDlReal> implements IMonDevDlRealService
{
    @Autowired
    private MonDevDlRealMapper monDevDlRealMapper;

    /**
     * 查询设备数据-电力-实时 保存设备的实时数据列表
     *
     * @param monDevDlReal 设备数据-电力-实时 保存设备的实时数据
     * @return 设备数据-电力-实时 保存设备的实时数据
     */
    @Override
    public List<MonDevDlReal> selectMonDevDlRealList(MonDevDlReal monDevDlReal)
    {
        return monDevDlRealMapper.selectMonDevDlRealList(monDevDlReal);
    }

    @Override
    public List<MonDevDlRealVo> getDataPage(String factoryId, List<String> deviceIds, String startTime, String endTime, String orderField, String orderType, Page page) {
        QueryWrapper<MonDevDlRealVo> queryWrapper = new QueryWrapper<MonDevDlRealVo>()
                .eq("r.factory_id", factoryId)
                .in("r.device_id", deviceIds)
                .ge("r.data_time", Timestamp.valueOf(startTime))
                .le("r.data_time", Timestamp.valueOf(endTime))
                .orderBy(StringUtils.isNotEmpty(orderField), "asc".equals(orderType), orderField, "r.data_id");
        return baseMapper.getDataPage(page, queryWrapper);
    }

    @Override
    public List<MonDevDlReal> selectLatestByParams(String industry, String deviceType, Date lastHour,Date currDate) {
        return monDevDlRealMapper.selectLatestByParams(industry,deviceType,lastHour,currDate);
    }

    @Override
    public List<AvgValueVo> selectAvgPhByParams(Date lastDayBegin, Date lastDayEnd) {
        return monDevDlRealMapper.selectAvgPhByParams(lastDayBegin,lastDayEnd);
    }

    @Override
    public List<PumpStateVo> selectPumpStateByParams(Date lastHourBegin, Date lastHourEnd) {
        return monDevDlRealMapper.selectPumpStateByParams(lastHourBegin,lastHourEnd);
    }

    @Override
    public List<PumpStateVo> selectOxFanStateByParams(Date lastHourBegin, Date lastHourEnd) {
        return monDevDlRealMapper.selectOxFanStateByParams(lastHourBegin,lastHourEnd);
    }

    @Override
    public List<AvgValueVo> selectLastDayData(DateTime queryBeginTime, DateTime queryEndTime) {
        return monDevDlRealMapper.selectLastDayData(queryBeginTime,queryEndTime);
    }

}
