package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.MonDevSnReal;
import cn.cecep.talroad.mapper.MonDevSnRealMapper;
import cn.cecep.talroad.service.IMonDevSnRealService;
import cn.cecep.talroad.vo.MonDevSnRealVo;
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 MonDevSnRealServiceImpl extends ServiceImpl<MonDevSnRealMapper,MonDevSnReal> implements IMonDevSnRealService
{
    @Autowired
    private MonDevSnRealMapper monDevSnRealMapper;

    /**
     * 查询设备数据-水泥-实时 保存设备的实时数据列表
     *
     * @param monDevSnReal 设备数据-水泥-实时 保存设备的实时数据
     * @return 设备数据-水泥-实时 保存设备的实时数据
     */
    @Override
    public List<MonDevSnReal> selectMonDevSnRealList(MonDevSnReal monDevSnReal)
    {
        return monDevSnRealMapper.selectMonDevSnRealList(monDevSnReal);
    }

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

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

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

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


}
