package com.gemho.meizhou.service;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.gemho.meizhou.SjzApplication;
import com.gemho.meizhou.Util.TimeUtils;
import com.gemho.meizhou.dao.UploadCloudDao;
import com.gemho.meizhou.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class UploadCloudServiceImp {

    private static final Logger logger = LoggerFactory.getLogger(UploadCloudServiceImp.class);

    private DecimalFormat dfFour = new DecimalFormat("0.0000");

    private DecimalFormat dfTwo = new DecimalFormat("0.00");

    @Autowired
    private UploadCloudDao uploadCloudDao;

    @Autowired
    private BmwyService bmwyService;

    @Autowired
    private JrxService jrxService;

    @Autowired
    private GtService gtService;

    @Autowired
    private KswService kswService;

    @Autowired
    private BmwydizhihuapoService bmwydizhihuapoService;

    // 推送其他设备采集数据
    public void other() {
        bmwyService.bmwyUpload();
        jrxService.jinrunxianUpload();
        gtService.gantanUpload();
        kswService.kushuiweiUpload();
        // bmwydizhihuapoService.bmwyhpStatusUpload();
    }

    public void hour() {
        bmwydizhihuapoService.oneHourPushBmwyhpData();
    }



    // 内部位移
  /*  public void nbwyUpload() {
        List<TabSensor> nbcjList = uploadCloudDao.findSensorDataByKind("坝体内部沉降");
        List<TabSensor> nbspList = uploadCloudDao.findSensorDataByKind("坝体内部水平位移");
        for (TabSensor sensor : nbcjList) {
            // 判断时间
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            TabNeibuchenjiang tabNeibuchenjiang = uploadCloudDao.findNbcjData(sensor.getName());
            if (sensor.getName().length() == 2) {
                if (tabNeibuchenjiang != null) {
                    String result = HttpRequest.post("")
                            .form("code", "4414018766204" + sensor.getName())
                            .form("measurementTime", sdf.format(date))
                            .form("valueX", "0")
                            .form("valueY", tabNeibuchenjiang.getValue2())
                            .execute().body();
                    System.out.println(sensor.getName() + ": " + result);
                }
            }
        }

        for (TabSensor sensor : nbspList) {
            // 判断时间
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            TabShuipingweiyi tabShuipingweiyi = uploadCloudDao.findNbspData(sensor.getName());
            if (sensor.getName().length() == 2) {
                if (tabShuipingweiyi != null) {
                    String result = HttpRequest.post("")
                            .form("code", "4414018766204" + sensor.getName())
                            .form("measurementTime", sdf.format(date))
                            .form("valueX", tabShuipingweiyi.getValue2())
                            .form("valueY", "0")
                            .execute().body();
                    System.out.println(sensor.getName() + ": " + result);
                    System.out.println("内部水平位移value2： " + tabShuipingweiyi.getValue2());
                }
            }
        }
    }*/


}
