package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.MonDevJhReal;
import cn.cecep.talroad.mapper.MonDevJhRealMapper;
import cn.cecep.talroad.service.IMonDevJhRealService;
import cn.cecep.talroad.vo.MonDevJhRealVo;
import cn.cecep.talroad.vo.analysis.AvgValueVo;
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 MonDevJhRealServiceImpl extends ServiceImpl<MonDevJhRealMapper,MonDevJhReal> implements IMonDevJhRealService
{
    @Autowired
    private MonDevJhRealMapper monDevJhRealMapper;

    /**
     * 查询设备数据-焦化-实时 保存设备的实时数据列表
     *
     * @param monDevJhReal 设备数据-焦化-实时 保存设备的实时数据
     * @return 设备数据-焦化-实时 保存设备的实时数据
     */
    @Override
    public List<MonDevJhReal> selectMonDevJhRealList(MonDevJhReal monDevJhReal)
    {
        return monDevJhRealMapper.selectMonDevJhRealList(monDevJhReal);
    }

    @Override
    public List<MonDevJhRealVo> getDataPage(String factoryId, List<String> deviceIds, String startTime, String endTime, String orderField, String orderType, Page page) {
        QueryWrapper<MonDevJhRealVo> queryWrapper = new QueryWrapper<MonDevJhRealVo>()
                .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<MonDevJhReal> selectLastHourData(MonDevJhReal real) {
        return monDevJhRealMapper.selectLastHourData(real);
    }

    @Override
    public List<MonDevJhReal> selectLatestByParams(String industry, String deviceType, Date lastHour,Date curr) {
        return monDevJhRealMapper.selectLatestByParams(industry, deviceType, lastHour,curr);
    }

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

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

    @Override
    public List<MonDevJhReal> selectMonDevJhRealListByDataTime(DateTime queryBeginTime, DateTime queryEndTime, String deviceId){
        return monDevJhRealMapper.selectMonDevJhRealListByDataTime(queryBeginTime,queryEndTime,deviceId);
    }

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