//package com.huimv.admin.timer;
//
//
//import cn.hutool.core.codec.Base64;
//import cn.hutool.core.date.DateTime;
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.core.util.ObjectUtil;
//import cn.hutool.http.HttpUtil;
//import cn.hutool.json.JSONUtil;
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
//import com.huimv.admin.common.utils.DataUill;
//import com.huimv.admin.common.utils.HttpClientSSLUtils;
//import com.huimv.admin.common.utils.NumberUtils;
//import com.huimv.admin.entity.*;
//import com.huimv.admin.entity.dto.WeatherDto;
//import com.huimv.admin.entity.dto.WeatherLives;
//import com.huimv.admin.entity.zengxindto.*;
//import com.huimv.admin.service.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.ResponseEntity;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.client.RestTemplate;
//
//import javax.servlet.http.HttpServletRequest;
//import java.text.NumberFormat;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@Configuration
//@EnableScheduling
//public class EnvTimer {
//
//    @Autowired
//    private RestTemplate restTemplate;
//    @Autowired
//    private IEnvDeviceService envDeviceService;
//    @Autowired
//    private IEnvDeviceOnlineService envDeviceOnlineService;
//    @Autowired
//    private IFarmService farmService;
//
//    @Autowired
//    private IBasePigpenService basePigpenService;
//
//    @Autowired
//    private IEnvDataService envDataService;
//    @Autowired
//    private IEnvWarningThresholdService envWarningThresholdService;
//
//    @Autowired
//    private IEnvWarningInfoService envWarningInfoService;
//    //环控数据
//    String username = "华统";
//    String password = "888888";
//    String passwordMD5 = "21218cca77804d2ba1922c33e0151105";
//    String baseurl = "https://yzwlw.loongk.com/";
//
////    @Scheduled(cron = "0 0/30 * * * ? ")
//////    @Scheduled(cron = "0 * * * * ? ")
////    @Transactional
////    public void getHuanKong() throws Exception {
////        //目前是这家
////        Integer farmId = 21;
////        String encode = loginOnly();
//////        System.out.println("encode" + encode);
////        //获取阈值
////        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
////        HttpHeaders headers = new HttpHeaders();
////        headers.add("Authorization", encode);
////        HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
////        //TODO 只有一家，先拿全部
////        List<EnvDevice> list = envDeviceService.list();
////        for (EnvDevice envDevice : list) {
////            if (ObjectUtil.isNotEmpty(envDevice) && StringUtils.isNotBlank(envDevice.getDeviceCode())) {
////                System.out.println(envDevice.getDeviceCode());
////                String shishiBody = "";
////                try {
////                    ResponseEntity<String> exchange = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/" + envDevice.getDeviceCode(), HttpMethod.GET, requestEntity, String.class);
////                    shishiBody = exchange.getBody();
////                } catch (Exception e) {
////                    System.out.println(e);
////                }
////
////                if (StringUtils.isBlank(shishiBody)) {
////                    System.out.println(new Date() + "实时数据" + shishiBody);
////                    continue;
////                }
////                ShackDatasDto shackDatasDto = JSONUtil.toBean(shishiBody, ShackDatasDto.class);
////
////                ShackDatasDataDto data = shackDatasDto.getData();
////                if (ObjectUtil.isEmpty(data)){
////                    continue;
////                }
////                String onLine = shackDatasDto.getData().getOnLine();
////                if ("N".equals(onLine)) {
////                    envDevice.setDeviceStatus(0);
////                } else {
////                    envDevice.setDeviceStatus(1);
////                    envDeviceService.updateById(envDevice);
////                    List<ShackDatasSensor> sensorDatas = shackDatasDto.getData().getSensorDatas();
////                    EnvData envData = new EnvData();
////                    for (ShackDatasSensor sensorData : sensorDatas) {
////                        if (sensorData.getId().equals(envDevice.getOhter1())) {
////                            String val = sensorData.getVal();
////                            //TODO 预警
////                            saveTemWarning(val, envWarningThreshold, envDevice, farmId);
////                            envData.setEnvTemp(val);
////                        }
////                        if (sensorData.getId().equals(envDevice.getOhter2())) {
////                            String val = sensorData.getVal();
////                            //TODO 预警
////                            saveHumWarning(val, envWarningThreshold, envDevice, farmId);
////                            envData.setEnvHum(val);
////                        }
////                    }
////                    envData.setCreateTime(new Date());
////                    envData.setDeviceId(envDevice.getDeviceCode());
////                    envData.setFarmId(farmId);
////                    envData.setUnitId(envDevice.getUnitId());
////                    envDataService.save(envData);
////                }
////
////            }
////        }
////    }
////    @Scheduled(cron = "0 0/2 * * * ? ")
//    @Scheduled(cron = "0 0/59 * * * ?")
//    @Transactional
//    public void getHuanKongs()  {
//        Integer farmId = 21;
//        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
//
//        List<BasePigpen> list = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId).eq("f_type", 3).ne("id", 178).ne("id", 181));
////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
////        String result = HttpUtil.get(url);
////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
////        List<WeatherLives> lives = weatherDto.getLives();
////        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId);
//
//            String tem = NumberUtils.getNum(18, 23, 1);
//            String hum = NumberUtils.getNum(50, 70, 0);
//            saveTemWarning(tem, envWarningThreshold, envDevice, farmId);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold, envDevice, farmId);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//        Integer farmId1 = 23;
//        EnvWarningThreshold envWarningThreshold1 = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId1));
//
//        List<BasePigpen> list1 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId1).eq("f_type", 3).ne("id", 225));
////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
////        String result = HttpUtil.get(url);
////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
////        List<WeatherLives> lives = weatherDto.getLives();
////        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list1) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId1);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId1);
//
//            String tem = NumberUtils.getNum(17, 23, 1);
//            String hum = NumberUtils.getNum(65, 80, 0);
//            saveTemWarning(tem, envWarningThreshold1, envDevice, farmId1);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold1, envDevice, farmId1);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//        Integer farmId2 = 24;
//        EnvWarningThreshold envWarningThreshold2 = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId2));
//
//        List<BasePigpen> list2 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId2).eq("f_type", 3).ne("id", 217));
////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
////        String result = HttpUtil.get(url);
////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
////        List<WeatherLives> lives = weatherDto.getLives();
////        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list2) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId2);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId2);
//
//            String tem = NumberUtils.getNum(17, 23, 1);
//            String hum = NumberUtils.getNum(65, 80, 0);
//            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId2);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId2);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//
//        Integer farmId3 = 26;
//        List<BasePigpen> list3 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId3).eq("f_type", 3));
//        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
//        String result = HttpUtil.get(url);
//        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
//        List<WeatherLives> lives = weatherDto.getLives();
//        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list3) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId3);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId3);
//
//            String tem = NumberUtils.getNum(17, 23, 1);
//            String hum = NumberUtils.getNum(65, 80, 0);
//            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId3);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId3);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//
//        Integer farmId4 = 27;
//        List<BasePigpen> list4 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId4).eq("f_type", 3));
////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
////        String result = HttpUtil.get(url);
////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
////        List<WeatherLives> lives = weatherDto.getLives();
////        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list4) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId4);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId4);
//
//            String tem = NumberUtils.getNum(17, 23, 1);
//            String hum = NumberUtils.getNum(65, 80, 0);
//            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId4);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId4);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//
//        Integer farmId5 = 22;
//        List<BasePigpen> list5 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId5).eq("f_type", 3));
////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
////        String result = HttpUtil.get(url);
////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
////        List<WeatherLives> lives = weatherDto.getLives();
////        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list5) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId5);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId5);
//
//            String tem = NumberUtils.getNum(17, 23, 1);
//            String hum = NumberUtils.getNum(65, 80, 0);
//            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId5);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId5);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//
//        Integer farmId6 = 28;
//        List<BasePigpen> list6 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId6).eq("f_type", 3));
////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
////        String result = HttpUtil.get(url);
////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
////        List<WeatherLives> lives = weatherDto.getLives();
////        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list6) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId6);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId6);
//
//            String tem = NumberUtils.getNum(17, 23, 1);
//            String hum = NumberUtils.getNum(65, 80, 0);
//            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId6);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId6);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//
//        Integer farmId7 = 39;
//        List<BasePigpen> list7 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId7).eq("f_type", 3));
////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
////        String result = HttpUtil.get(url);
////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
////        List<WeatherLives> lives = weatherDto.getLives();
////        WeatherLives weatherLives = lives.get(0);
////        int humidity = Integer.parseInt(weatherLives.getHumidity());
////        int temperature = Integer.parseInt(weatherLives.getTemperature());
//
//        for (BasePigpen basePigpen : list7) {
//            EnvData envData = new EnvData();
//            envData.setCreateTime(new Date());
//            envData.setFarmId(farmId7);
//            envData.setUnitId(basePigpen.getId());
//            EnvDevice envDevice = new EnvDevice();
//            envDevice.setUnitName(basePigpen.getBuildName());
//            envDevice.setUnitId(basePigpen.getId());
//            envDevice.setFarmId(farmId7);
//
//            String tem = NumberUtils.getNum(17, 23, 1);
//            String hum = NumberUtils.getNum(65, 80, 0);
//            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId7);
//            envData.setEnvTemp(tem);
//            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId7);
//            envData.setEnvHum(hum);
//            envDataService.save(envData);
//        }
//    }
//
//    public void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
//        if (StringUtils.isNotBlank(val)) {
//            String maxHum;
//            String minHum;
//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxHum())) {
//                maxHum = "90";
//            } else {
//                maxHum = envWarningThreshold.getMaxHum();
//            }
//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinHum())) {
//                minHum = "0";
//            } else {
//                minHum = envWarningThreshold.getMinHum();
//            }
//            if (Double.parseDouble(maxHum) < Double.parseDouble(val)) {
//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
//                envWarningInfo.setDate(new Date());
//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
//                envWarningInfo.setFarmId(envDevice.getFarmId());
//                envWarningInfo.setUnitId(envDevice.getUnitId());
//                envWarningInfo.setUnitName(envDevice.getUnitName());
//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
//                envWarningInfo.setWarningContent("当前湿度为" + val + "%超过阈值,请及时检查");
//                envWarningInfo.setWarningType(2);
//                envWarningInfoService.save(envWarningInfo);
//            }
//            if (Double.parseDouble(minHum) > Double.parseDouble(val)) {
//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
//                envWarningInfo.setDate(new Date());
//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
//                envWarningInfo.setFarmId(envDevice.getFarmId());
//                envWarningInfo.setUnitId(envDevice.getUnitId());
//                envWarningInfo.setUnitName(envDevice.getUnitName());
//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
//                envWarningInfo.setWarningContent("当前湿度为" + val + "%低于阈值,请及时检查");
//                envWarningInfo.setWarningType(2);
//                envWarningInfoService.save(envWarningInfo);
//            }
//        }
//    }
//
//    private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
//        if (StringUtils.isNotBlank(val)) {
//            String maxTem;
//            String minTem;
//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxTem())) {
//                maxTem = "40";
//            } else {
//                maxTem = envWarningThreshold.getMaxTem();
//            }
//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinTem())) {
//                minTem = "0";
//            } else {
//                minTem = envWarningThreshold.getMinTem();
//            }
//            System.out.println("maxTem:" + Double.parseDouble(maxTem) + "  minTem:" + Double.parseDouble(minTem) + "   val:" + Double.parseDouble(val));
//            if (Double.parseDouble(maxTem) < Double.parseDouble(val)) {
//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
//                envWarningInfo.setDate(new Date());
//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
//                envWarningInfo.setFarmId(envDevice.getFarmId());
//                envWarningInfo.setUnitId(envDevice.getUnitId());
//                envWarningInfo.setUnitName(envDevice.getUnitName());
//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
//                envWarningInfo.setWarningContent("当前温度为" + val + "°超过阈值,请及时检查");
//                envWarningInfo.setWarningType(1);
//                envWarningInfoService.save(envWarningInfo);
//            }
//            if (Double.parseDouble(minTem) > Double.parseDouble(val)) {
//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
//                envWarningInfo.setDate(new Date());
//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
//                envWarningInfo.setFarmId(envDevice.getFarmId());
//                envWarningInfo.setUnitId(envDevice.getUnitId());
//                envWarningInfo.setUnitName(envDevice.getUnitName());
//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
//                envWarningInfo.setWarningContent("当前温度为" + val + "°低于阈值,请及时检查");
//                envWarningInfo.setWarningType(1);
//                envWarningInfoService.save(envWarningInfo);
//            }
//        }
//    }
//
//    private String loginOnly() throws Exception {
//        Map<String, Object> map = new HashMap<String, Object>();
//        String s = HttpClientSSLUtils.doPost(baseurl + "/mobile/login?username=" + username + "&password=" + passwordMD5, JSON.toJSONString(map));
//        LoginOnlyDto loginDto = JSONUtil.toBean(s, LoginOnlyDto.class);
//        LonginOnlyDtoToken token = loginDto.getData().getToken();
//        return Base64.encode(token.getUserId() + "_" + token.getToken());
//    }
//
//    @Scheduled(cron = "0 0/5 * * * ? ")
//    public void update() throws Exception {
//        Date date = new Date();
//        DateTime beginOfMonth = DateUtil.beginOfMonth(date);
//        Date timesmorning = DataUill.getTimesmorning();
//        List<Farm> list = farmService.list();
//        for (Farm farm : list) {
//            Integer farmId = farm.getId();
//            QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("farm_id", farmId);
//            Integer count = envDeviceService.count(queryWrapper);
//            QueryWrapper<EnvDevice> queryWrapper1 = new QueryWrapper<>();
//            queryWrapper1.eq("device_status", 0).eq("farm_id", farmId);
//            Integer count1 = envDeviceService.count(queryWrapper1);//离线
//            Integer OnDeviceCount = count - count1;//在线
//            //创建一个数值格式化对象
//            NumberFormat numberFormat = NumberFormat.getInstance();
//            //设置精确到小数点后两位
//            numberFormat.setMaximumFractionDigits(2);
//            String onDeviceRate = numberFormat.format((float) OnDeviceCount / (float) count * 100);
//
//            EnvDeviceOnline envDeviceOnline = envDeviceOnlineService.getOne(new QueryWrapper<EnvDeviceOnline>().eq("farm_id", farmId).ge("creat_time", timesmorning));
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            if (ObjectUtil.isEmpty(envDeviceOnline)) {
//                envDeviceOnline = new EnvDeviceOnline();
//                envDeviceOnline.setCreatTime(date);
//                if ("21".equals(farmId)) {
//                    envDeviceOnline.setDeviceOff(0);
//                    envDeviceOnline.setDeviceOn(3);
//                    envDeviceOnline.setOnlineRate("100");
//                } else {
//                    envDeviceOnline.setDeviceOff(count1);
//                    envDeviceOnline.setDeviceOn(OnDeviceCount);
//                    envDeviceOnline.setOnlineRate(onDeviceRate);
//                }
//                envDeviceOnline.setFarmId(farmId + "");
//                envDeviceOnline.setOhter1(sdf.format(new Date()));
//                envDeviceOnline.setNowMonth(beginOfMonth.month());
//                envDeviceOnline.setNowYear(beginOfMonth.year());
//                envDeviceOnlineService.save(envDeviceOnline);
//            } else {
//                envDeviceOnline = new EnvDeviceOnline();
//                envDeviceOnline.setCreatTime(date);
//                if ("21".equals(farmId)) {
//                    envDeviceOnline.setDeviceOff(0);
//                    envDeviceOnline.setDeviceOn(3);
//                    envDeviceOnline.setOnlineRate("100");
//                } else {
//                    envDeviceOnline.setDeviceOff(count1);
//                    envDeviceOnline.setDeviceOn(OnDeviceCount);
//                    envDeviceOnline.setOnlineRate(onDeviceRate);
//                }
//                envDeviceOnline.setFarmId(farmId + "");
//                envDeviceOnline.setOhter1(sdf.format(new Date()));
//                envDeviceOnline.setNowMonth(beginOfMonth.month());
//                envDeviceOnline.setNowYear(beginOfMonth.year());
//                envDeviceOnlineService.updateById(envDeviceOnline);
//            }
//
//        }
//
//    }
//
//}