|
@@ -18,8 +18,11 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -38,7 +41,8 @@ public class WaterAndElectricity {
|
|
|
private EnergyEnvDeviceMapper envDeviceMapper;
|
|
|
|
|
|
|
|
|
- @Scheduled(cron = "0 0/20 * * * ? ")
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 */1 * * ? ")
|
|
|
private void sendDate() throws Exception {
|
|
|
QueryWrapper<EnergyEnvDevice> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("farm_id", 26);
|
|
@@ -46,9 +50,9 @@ public class WaterAndElectricity {
|
|
|
Date date = new Date();//获取当前时间
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(date);
|
|
|
- calendar.add(Calendar.MINUTE, -20);// 20分钟前
|
|
|
+ calendar.add(Calendar.HOUR, -1);// 20分钟前
|
|
|
//获取到完整的时间
|
|
|
- SimpleDateFormat sdf= new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
|
|
for (EnergyEnvDevice device : devices) {
|
|
@@ -77,14 +81,27 @@ public class WaterAndElectricity {
|
|
|
jsonArray.add(jsonObject);
|
|
|
}
|
|
|
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
-
|
|
|
- HttpEntity<JSONArray> httpEntity = new HttpEntity<>(jsonArray, headers);
|
|
|
+// RestTemplate restTemplate = new RestTemplate();
|
|
|
+// HttpHeaders headers = new HttpHeaders();
|
|
|
+// headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+//
|
|
|
+// MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
|
|
+//// Map<String, Object> map = new HashMap<>();
|
|
|
+// map.put("result", jsonArray);
|
|
|
+//
|
|
|
+// HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(map, headers);
|
|
|
+//
|
|
|
+// String url = "https://huatong.ifarmcloud.com/huatongApi/energy-data/getData";
|
|
|
+// String responseBody = restTemplate.postForObject(url, httpEntity, String.class);
|
|
|
+// System.out.println(responseBody);
|
|
|
|
|
|
- String url = "https://huatong.ifarmcloud.com/huatongApi/energy-data/getData";
|
|
|
- String responseBody = restTemplate.postForObject(url, httpEntity, String.class);
|
|
|
- System.out.println(responseBody);
|
|
|
+ HashMap<String, String> paramsMap = new HashMap<>();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("result", jsonArray);
|
|
|
+ System.out.println(jsonObject);
|
|
|
+ paramsMap.put("Content-Type", "application/json;charset=utf-8");
|
|
|
+ String post = HttpRequest.post("https://huatong.ifarmcloud.com/huatongApi/energy-data/getData")
|
|
|
+ .headerMap(paramsMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
|
|
|
+ System.out.println(post);
|
|
|
}
|
|
|
}
|