package org.jeecg.modules.sensor.entity;

import org.jeecg.modules.device.service.IBuDeviceService;
import org.jeecg.modules.sensor.service.IBuSensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.Date;

@Component
public class ScheduledTest {
    @Autowired
    private IBuSensorService buSensorService;
    @Autowired
    private IBuDeviceService buDeviceService;

//    @Scheduled(cron="*/1 * * * * ?")
//    public void executeFileDownLoadTask() {
//        Random random=new Random();
//        List<BuSensor> buSensorList=buSensorService.list();
//        for(BuSensor buSensor:buSensorList){
//            BuSensorCurrentData buSensorCurrentData=buSensorCurrentDataService.getOne(new LambdaQueryWrapper<BuSensorCurrentData>().eq(BuSensorCurrentData::getSensorId, buSensor.getId()));
//            if(buSensorCurrentData==null){
//                buSensorCurrentData=new BuSensorCurrentData();
//                buSensorCurrentData.setTime(new Date());
//                buSensorCurrentData.setSensorId(buSensor.getId());
//                buSensorCurrentData.setData1(String.valueOf(random.nextInt(Integer.parseInt(buSensor.getAlarmLimit()))+5));
//                buSensorCurrentDataService.save(buSensorCurrentData);
//            }else{
//                buSensorCurrentData.setTime(new Date());
//                buSensorCurrentData.setData1(String.valueOf(random.nextInt(Integer.parseInt(buSensor.getAlarmLimit()))+5));
//                buSensorCurrentDataService.updateById(buSensorCurrentData);
//            }
//        }

//        IdentifierGenerator identifierGenerator=new DefaultIdentifierGenerator();
//        System.out.println(identifierGenerator.nextId(new Object()));
//        List<BuDevice> buDeviceList=buDeviceService.list();
//        BuRepairRecord buRepairRecord=new BuRepairRecord();
//        for(BuDevice buDevice:buDeviceList){
//            buRepairRecord=new BuRepairRecord();
//            buRepairRecord.setSubmitTime(randomHireday());
//            buRepairRecord.setDeviceName(buDevice.getId());
//            buRepairRecordService.save(buRepairRecord);
//        }
//    }

    public static Date randomHireday() {
        int startYear=2020;									//指定随机日期开始年份
        int endYear=2021;									//指定随机日期开始年份(含)
        long start = Timestamp.valueOf(startYear+"-1-1 0:0:0").getTime();
        long end = Timestamp.valueOf(endYear+"-1-1 0:0:0").getTime();
        long ms=(long) ((end-start)*Math.random()+start);	//获得了符合条件的13位毫秒数
        Date hireday=new Date(ms);
        return hireday;
    }
}
