package com.fastbee.iot.timer;

import cn.hutool.core.date.DateTime;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fastbee.deviceData.api.devlink.service.DevLinkMetDataService;
import com.fastbee.deviceData.api.devlink.service.DevLinkMiaoQingDataService;
import com.fastbee.deviceData.api.devlink.service.DevLinkMoistureDataService;
import com.fastbee.deviceData.api.devlink.service.DevLinkPhotovoltaicDataService;
import com.fastbee.deviceData.api.renke.constant.RenKeDeviceTypeConstant;
import com.fastbee.deviceData.api.renke.service.RenKeAuthorizationService;
import com.fastbee.deviceData.api.renke.service.RenkeDeviceDataService;
import com.fastbee.deviceData.domain.*;

import com.fastbee.deviceData.mapper.*;
import com.fastbee.deviceData.service.IDeviceRealtimedataWormsService;
import com.fastbee.deviceData.service.impl.DeviceRealtimedataWormsServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * @author mijiupro
 */
@Component("agricultureDeviceDateTask")
public class DeviceDateTask {
//

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

//    @Autowired
//    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private DeviceRealtimedataWormsMapper deviceRealtimedataWormsMapper;

    @Autowired
    private DeviceRealtimedataMeteorologyMapper deviceRealtimedataMeteorologyMapper;

    @Autowired
    private DeviceRealtimedataMoistureMapper deviceRealtimedataMoistureMapper;

    @Autowired
    private DeviceRealtimedataPhotovoltaicMapper deviceRealtimedataPhotovoltaicMapper;

    @Autowired
    private DeviceRealtimedataMiaoqingMapper deviceRealtimedataMiaoqingMapper;

    @Autowired
    private RenkeDeviceDataService wormsService; //虫情设备数据获取

    @Autowired
    private DevLinkMetDataService metDataService; //气象设备数据获取

    @Autowired
    private DevLinkMoistureDataService moistureDataService; //墒情设备数据获取

    @Autowired
    private DevLinkPhotovoltaicDataService photovoltaicDataService; //光伏设备数据获取

    @Autowired
    private DevLinkMiaoQingDataService miaoQingDataService; //苗情设备数据获取





    /**
     * 获取虫情设备实时数据并保存
     */
    public void getWormsDeviceRealtimeData() throws Exception{
        DeviceRealtimedataWorms deviceRealtimedataWorms = wormsService.setData("1017240042");
        int i = deviceRealtimedataWormsMapper.insert(deviceRealtimedataWorms);
        if (i<1){
            System.out.println("插入数据失败!");
        }
    }

    /**
     * 获取气象设备实时数据并保存
     */
    public void getDevLinkMetDeviceRealtimeData() throws Exception{
        DeviceRealtimedataMeteorology deviceRealtimedataMeteorology = metDataService.setData(metDataService.getMetDeviceRealData("3269"));
        int i = deviceRealtimedataMeteorologyMapper.insert(deviceRealtimedataMeteorology);
        if (i<1){
            System.out.println("插入数据失败!");
        }

    }
    /**
     * 获取墒情设备实时数据并保存
     */
    public void getDevLinkMoistureDeviceRealtimeData() throws Exception{
        DeviceRealtimedataMoisture deviceRealtimedataMoisture = moistureDataService.setData(moistureDataService.getMetDeviceRealData("3270"));
        int i = deviceRealtimedataMoistureMapper.insert(deviceRealtimedataMoisture);
        if (i<1)
            System.out.println("插入数据失败!");
    }

    /**
     * 获取光伏设备实时数据并保存
     */
    public void getDevLinkPhotovoltaicDeviceRealtimeData() throws Exception{
        DeviceRealtimedataPhotovoltaic deviceRealtimedataPhotovoltaic = photovoltaicDataService.setData(photovoltaicDataService.getMetDeviceRealData("3276"));
        int i = deviceRealtimedataPhotovoltaicMapper.insert(deviceRealtimedataPhotovoltaic);
        if (i<1)
            System.out.println("插入数据失败!");
    }

    /**
     * 获取苗情设备实时数据并保存
     */
    public void getDevLinkMiaoqingDeviceRealtimeData() throws Exception{
        DeviceRealtimedataMiaoqing deviceRealtimedataMiaoqing = miaoQingDataService.setData(miaoQingDataService.getMetDeviceRealData("3275"));
        int i = deviceRealtimedataMiaoqingMapper.insert(deviceRealtimedataMiaoqing);
        if (i<1)
            System.out.println("插入数据失败!");
    }



}

