package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.MonDevFsReal;
import cn.cecep.talroad.mapper.MonDevFsRealMapper;
import cn.cecep.talroad.service.IMonDevFsRealService;
import cn.cecep.talroad.vo.MonDevFsRealVo;
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 java.util.Date;
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;




/**
 * 设备数据-垃圾焚烧-实时 保存设备的实时数据Service业务层处理
 *
 * @author szhpt
 * @date 2023-01-10*/
@Service
public class MonDevFsRealServiceImpl extends ServiceImpl<MonDevFsRealMapper,MonDevFsReal> implements IMonDevFsRealService
{
    @Autowired
    private MonDevFsRealMapper monDevFsRealMapper;

    /**
     * 查询设备数据-垃圾焚烧-实时 保存设备的实时数据列表
     *
     * @param monDevFsReal 设备数据-垃圾焚烧-实时 保存设备的实时数据
     * @return 设备数据-垃圾焚烧-实时 保存设备的实时数据
     */
    @Override
    public List<MonDevFsReal> selectMonDevFsRealList(MonDevFsReal monDevFsReal)
    {
        return monDevFsRealMapper.selectMonDevFsRealList(monDevFsReal);
    }

    @Override
    public List<MonDevFsRealVo> getDataPage(String factoryId, List<String> deviceIds, String startTime, String endTime, String orderField, String orderType, Page page) {
        QueryWrapper<MonDevFsRealVo> queryWrapper = new QueryWrapper<MonDevFsRealVo>()
                .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<MonDevFsReal> selectLatestByParams(String industry, String deviceType, Date lastHour,Date currDate) {
        return monDevFsRealMapper.selectLatestByParams(industry,deviceType, lastHour,currDate);
    }

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

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

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

    @Override
    public List<AvgValueVo> selectAvgTempByParams(Date lastHourBegin, Date lastHourEnd) {
        return monDevFsRealMapper.selectAvgTempByParams(lastHourBegin,lastHourEnd);
    }

    @Override
    public List<MonDevFsReal> selectLatestHourDataByParams(String factoryId, String deviceId, Date lastHour) {
        return monDevFsRealMapper.selectLatestHourDataByParams(factoryId,deviceId,lastHour);
    }

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

}
