package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.MonDevBlReal;
import cn.cecep.talroad.mapper.MonDevBlRealMapper;
import cn.cecep.talroad.service.IMonDevBlRealService;
import cn.cecep.talroad.vo.MonDevBlRealVo;
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 MonDevBlRealServiceImpl extends ServiceImpl<MonDevBlRealMapper,MonDevBlReal> implements IMonDevBlRealService
{
    @Autowired
    private MonDevBlRealMapper monDevBlRealMapper;

    /**
     * 查询设备数据-玻璃-实时 保存设备的实时数据列表
     *
     * @param monDevBlReal 设备数据-玻璃-实时 保存设备的实时数据
     * @return 设备数据-玻璃-实时 保存设备的实时数据
     */
    @Override
    public List<MonDevBlReal> selectMonDevBlRealList(MonDevBlReal monDevBlReal)
    {
        return monDevBlRealMapper.selectMonDevBlRealList(monDevBlReal);
    }

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

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

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

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

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

}
