package com.ycl.service.smoke.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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 com.ycl.dto.smoker.InTimeCountDto;
import com.ycl.entity.smoke.OdsCustomer;
import com.ycl.entity.smoke.OdsInTime;
import com.ycl.mapper.smoke.OdsInTimeMapper;
import com.ycl.service.smoke.IOdsInTimeService;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* 返回实时的设备数据 服务实现类
*
*
* @author lyq
* @since 2023-02-28
*/
@Service
public class OdsInTimeServiceImpl extends ServiceImpl implements IOdsInTimeService {
@Override
public Page findList(String owner, String onlineStatus, String startTime, String endTime, String type, String status, Integer pageSize, Integer pageNum) {
Page page = new Page<>(pageNum, pageSize);
QueryWrapper wrapper = new QueryWrapper<>();
LambdaQueryWrapper lambda = wrapper.lambda();
if (StrUtil.isNotEmpty(owner)) {
lambda.like(OdsInTime::getOwner, owner);
}
if (StrUtil.isNotEmpty(onlineStatus)) {
lambda.eq(OdsInTime::getOnlineStatus, onlineStatus);
}
if (StrUtil.isNotEmpty(startTime)) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startdate = format.parse(startTime);
Long startTimestamp = startdate.getTime() / 1000;
Date enddate = format.parse(endTime);
Long endTimestamp = enddate.getTime() / 1000;
lambda.between(OdsInTime::getLastAt, startTimestamp, endTimestamp);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
if (StrUtil.isNotEmpty(type)) {
lambda.eq(OdsInTime::getTyp, type);
}
if (StrUtil.isNotEmpty(status)) {
lambda.eq(OdsInTime::getStatus, status);
}
wrapper.orderByDesc("id");
return this.page(page, wrapper);
}
@Override
public InTimeCountDto getInTimeCount() {
return baseMapper.getInTimeCount();
}
}