|
@@ -0,0 +1,60 @@
|
|
|
+package com.ruoyi.monitorInterface.inserctpests.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.framework.web.service.ConfigService;
|
|
|
+import com.ruoyi.monitorInterface.inserctpests.service.PlantDiseasesAndInsectPestsService;
|
|
|
+import com.ruoyi.monitorInterface.sennor.api.API;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.swing.plaf.nimbus.State;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class PlantDiseasesAndInsectPestsServiceImpl implements PlantDiseasesAndInsectPestsService {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(PlantDiseasesAndInsectPestsServiceImpl.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ConfigService configService;
|
|
|
+
|
|
|
+ private String secretKey;
|
|
|
+ private String userName;
|
|
|
+
|
|
|
+ public AjaxResult plantDiseasesAndInsectPestsMessageReceiver(String deviceNumber) {
|
|
|
+ secretKey = configService.getKey("insectToken");
|
|
|
+ userName = configService.getKey("insectName");
|
|
|
+ //先请求
|
|
|
+ StringBuffer URI = new StringBuffer(configService.getKey("sennorInsectURL") + API.getInsectNewCollectionResult);
|
|
|
+ URI.append("?token=").append(secretKey);
|
|
|
+ URI.append("&userName=").append(userName);
|
|
|
+ URI.append("&deviceNumber=").append(deviceNumber);
|
|
|
+ String result = HttpRequest.post(URI.toString())
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .execute().body();
|
|
|
+ log.info("plantDiseasesAndInsectPestsMessageReceiver 收到数据 ==> {}", result);
|
|
|
+ //后推送
|
|
|
+ JSONObject object;
|
|
|
+ String res;
|
|
|
+ try {
|
|
|
+ object = JSONObject.parseObject(result);
|
|
|
+
|
|
|
+ if (object.get("state") != null && object.getString("state").equals("success")){
|
|
|
+ res = HttpRequest.post(configService.getKey("centerMonitorURL") + "device/saveInsectPestsDeviceData")
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .body(object.toJSONString())
|
|
|
+ .execute().body();
|
|
|
+ log.info("数据推送成功! data ===> {} , result ===> {}", result, res);
|
|
|
+ return AjaxResult.success("数据推送成功!", res);
|
|
|
+ }
|
|
|
+ return AjaxResult.error("数据推送失败!", result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("数据推送失败! data ===> {} , result ===> {}", result, e.getMessage());
|
|
|
+ return AjaxResult.error("数据推送失败!", result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|