package vip.xiaonuo.Timer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import vip.xiaonuo.common.timer.CommonTimerTaskRunner;
import vip.xiaonuo.modular.env.envdata.entity.EnvData;
import vip.xiaonuo.modular.env.envdata.mapper.EnvDataMapper;
import vip.xiaonuo.modular.env.envdevice.entity.EnvDevice;
import vip.xiaonuo.modular.env.envdevice.mapper.EnvDeviceMapper;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Slf4j
@Component
public class ProEnvData implements CommonTimerTaskRunner {

    @Autowired
    private EnvDeviceMapper deviceMapper;
    @Autowired
    private EnvDataMapper dataMapper;
    @Override
    public void action() {
        QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("org_id", "1543842934270394370").eq("delete_flag", "NOT_DELETE")
                .eq("status", 1);
        List<EnvDevice> devices = deviceMapper.selectList(queryWrapper);
        for (EnvDevice device : devices) {
            EnvData data = new EnvData();
            data.setAskTime(new Date());
            data.setUpdateTime(new Date());
            data.setChipCode(device.getId());
            data.setDeviceCode(device.getDeviceCode());
            data.setPigpenId(device.getInstallPosition());
            data.setOrgId(device.getOrgId());
            data.setIsShow(0);
            String tem = NumberUtils.getNumFloat(19.0, 21.0);
            String hum = NumberUtils.getNumFloat(39.0, 41.0);
            data.setTemHandleValue(new BigDecimal(tem));
            data.setTemOriginalValue(new BigDecimal(tem));
            data.setHumiHandleValue(new BigDecimal(hum));
            data.setHumiOriginalValue(new BigDecimal(hum));
            dataMapper.insert(data);
        }
    }
}
