package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.MonDevReal;
import cn.cecep.talroad.mapper.MonDevRealMapper;
import cn.cecep.talroad.service.IMonDevRealService;
import cn.cecep.talroad.vo.MonDevGtRealVO;
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;




/**
 * 设备数据(有组织)-实时 保存有组织设备的实时数据。p1~pn字段对应各设备的生产过程类参数Service业务层处理
 *
 * @author szhpt
 * @date 2023-01-10*/
@Service
public class MonDevRealServiceImpl extends ServiceImpl<MonDevRealMapper,MonDevReal> implements IMonDevRealService
{
    @Autowired
    private MonDevRealMapper monDevRealMapper;

    /**
     * 查询设备数据(有组织)-实时 保存有组织设备的实时数据。p1~pn字段对应各设备的生产过程类参数列表
     *
     * @param monDevReal 设备数据(有组织)-实时 保存有组织设备的实时数据。p1~pn字段对应各设备的生产过程类参数
     * @return 设备数据(有组织)-实时 保存有组织设备的实时数据。p1~pn字段对应各设备的生产过程类参数
     */
    @Override
    public List<MonDevReal> selectMonDevRealList(MonDevReal monDevReal)
    {
        return monDevRealMapper.selectMonDevRealList(monDevReal);
    }

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

    public List<MonDevReal> selectLatestByCondition(String industry,String deviceType, Date startDate,Date currDate) {
        return monDevRealMapper.selectLatestByCondition(industry, deviceType, startDate,currDate);
    }

    @Override
    public List<MonDevReal> selectLatestByParam(String industry, String deviceType, Date lastHour,Date currDate) {
        return monDevRealMapper.selectLatestByParam(industry, deviceType, lastHour,currDate);
    }


    @Override
    public List<MonDevReal> selectLastHourData(MonDevReal real) {
        return monDevRealMapper.selectLastHourData(real);
    }

    @Override
    public List<MonDevReal> selectLastHourDataOne(MonDevReal real) {
        return monDevRealMapper.selectLastHourDataOne(real);
    }

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

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

    @Override
    public List<MonDevReal> selectLatestMqgwByParam(String industry, String deviceType, Date lastHour, Date curr) {
        return monDevRealMapper.selectLatestMqgwByParam(industry, deviceType, lastHour,curr);
    }

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

}
