|
@@ -1,7 +1,5 @@
|
|
package com.persagy.dmp.rwd.iot.service.impl;
|
|
package com.persagy.dmp.rwd.iot.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -11,16 +9,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
import com.persagy.dmp.basic.utils.QueryCriteriaHelper;
|
|
import com.persagy.dmp.basic.utils.QueryCriteriaHelper;
|
|
import com.persagy.dmp.common.context.AppContext;
|
|
import com.persagy.dmp.common.context.AppContext;
|
|
-import com.persagy.dmp.common.exception.BusinessException;
|
|
|
|
import com.persagy.dmp.mybatis.utils.ConditionUtil;
|
|
import com.persagy.dmp.mybatis.utils.ConditionUtil;
|
|
import com.persagy.dmp.rwd.basic.constant.IotUrlConstant;
|
|
import com.persagy.dmp.rwd.basic.constant.IotUrlConstant;
|
|
import com.persagy.dmp.rwd.basic.utils.MeterUtils;
|
|
import com.persagy.dmp.rwd.basic.utils.MeterUtils;
|
|
import com.persagy.dmp.rwd.digital.entity.ObjectDigital;
|
|
import com.persagy.dmp.rwd.digital.entity.ObjectDigital;
|
|
import com.persagy.dmp.rwd.digital.service.IObjectDigitalService;
|
|
import com.persagy.dmp.rwd.digital.service.IObjectDigitalService;
|
|
import com.persagy.dmp.rwd.iot.model.CurrentDataModel;
|
|
import com.persagy.dmp.rwd.iot.model.CurrentDataModel;
|
|
-import com.persagy.dmp.rwd.iot.service.CurrentDataService;
|
|
|
|
|
|
+import com.persagy.dmp.rwd.iot.service.CurrentIotService;
|
|
import lombok.Getter;
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
import lombok.Setter;
|
|
|
|
+
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -28,20 +26,21 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* iot-查询实时数据
|
|
* iot-查询实时数据
|
|
* @author:linhuili
|
|
* @author:linhuili
|
|
* @date:2021/8/11
|
|
* @date:2021/8/11
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
-public class CurrentDataServiceImpl implements CurrentDataService {
|
|
|
|
|
|
+public class CurrentIotServiceImpl implements CurrentIotService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private IObjectDigitalService objectDigitalService;
|
|
private IObjectDigitalService objectDigitalService;
|
|
|
|
|
|
- //@Value("${persagy.iot.data.server}")
|
|
|
|
- @Value("http://develop.persagy.com/iot-collect")
|
|
|
|
- protected String iotDataServer;
|
|
|
|
|
|
+ @Value("${persagy.iot.data.server}")
|
|
|
|
+ private String iotDataServer;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询对象绑点信息点的实时数据
|
|
* 查询对象绑点信息点的实时数据
|
|
@@ -54,6 +53,43 @@ public class CurrentDataServiceImpl implements CurrentDataService {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
//表号功能号校验
|
|
//表号功能号校验
|
|
|
|
+ List<PointParam> parameters = verifyMeterAndFunction(param);
|
|
|
|
+ if (parameters.size() == 0) {
|
|
|
|
+ return param;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询实时数据
|
|
|
|
+ String url = iotDataServer + IotUrlConstant.QUERY_CUCCRENT_DATA;
|
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
|
+ requestBody.put("building", AppContext.getContext().getProjectId().substring(2));
|
|
|
|
+ requestBody.put("points", parameters);
|
|
|
|
+ String response = HttpUtil.post(url, requestBody.toString(), 3000);
|
|
|
|
+ JSONObject result = JSONObject.parseObject(response);
|
|
|
|
+ if(result == null){
|
|
|
|
+ return param;
|
|
|
|
+ }
|
|
|
|
+ JSONArray points = result.getJSONArray("points");
|
|
|
|
+ //绑定表号功能号
|
|
|
|
+ for (Object object : points) {
|
|
|
|
+ JSONObject item = (JSONObject) object;
|
|
|
|
+ String meter = item.getString("meter");
|
|
|
|
+ String funcid = item.getString("funcid");
|
|
|
|
+ for (CurrentDataModel model : param) {
|
|
|
|
+ if (meter.equals(model.getMeter()) && funcid.equals(model.getFunction())) {
|
|
|
|
+ model.setData(item.get("data"));
|
|
|
|
+ model.setTime(item.getString("receivetime"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return param;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验表号功能号
|
|
|
|
+ * @param param
|
|
|
|
+ */
|
|
|
|
+ private List<PointParam> verifyMeterAndFunction(List<CurrentDataModel> param){
|
|
List<PointParam> parameters = new LinkedList<>();
|
|
List<PointParam> parameters = new LinkedList<>();
|
|
for (CurrentDataModel model : param) {
|
|
for (CurrentDataModel model : param) {
|
|
if (model.getObjectId() == null) {
|
|
if (model.getObjectId() == null) {
|
|
@@ -79,33 +115,10 @@ public class CurrentDataServiceImpl implements CurrentDataService {
|
|
}
|
|
}
|
|
parameters.add(new PointParam(model.getMeter(), model.getFunction()));
|
|
parameters.add(new PointParam(model.getMeter(), model.getFunction()));
|
|
}
|
|
}
|
|
- if (parameters.size() == 0) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //查询实时数据
|
|
|
|
- String url = iotDataServer + IotUrlConstant.QUERY_CUCCRENT_DATA;
|
|
|
|
- Map<String, Object> requestBody = new HashMap<>();
|
|
|
|
- requestBody.put("building", AppContext.getContext().getProjectId().substring(2));
|
|
|
|
- requestBody.put("points", parameters);
|
|
|
|
- String response = HttpUtil.post(url,requestBody);
|
|
|
|
- JSONArray result = fetchResult(response);
|
|
|
|
-
|
|
|
|
- //绑定表号功能号
|
|
|
|
- for (Object object : result) {
|
|
|
|
- JSONObject item = (JSONObject) object;
|
|
|
|
- String meter = item.getString("meter");
|
|
|
|
- String funcid = item.getString("funcid");
|
|
|
|
- for (CurrentDataModel model : param) {
|
|
|
|
- if (meter.equals(model.getMeter()) && funcid.equals(model.getFunction())) {
|
|
|
|
- model.setData(item.get("data"));
|
|
|
|
- model.setTime(item.getString("receivetime"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return param;
|
|
|
|
|
|
+ return parameters;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询信息点值
|
|
* 查询信息点值
|
|
* @param objectId
|
|
* @param objectId
|
|
@@ -113,7 +126,7 @@ public class CurrentDataServiceImpl implements CurrentDataService {
|
|
* @return
|
|
* @return
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- private String getInfoCodeValue(String objectId,String infoCode) throws Exception {
|
|
|
|
|
|
+ public String getInfoCodeValue(String objectId,String infoCode){
|
|
//查询条件封装
|
|
//查询条件封装
|
|
QueryCriteria queryCriteria = new QueryCriteria();
|
|
QueryCriteria queryCriteria = new QueryCriteria();
|
|
ObjectNode criteria = JsonNodeFactory.instance.objectNode();
|
|
ObjectNode criteria = JsonNodeFactory.instance.objectNode();
|
|
@@ -137,7 +150,7 @@ public class CurrentDataServiceImpl implements CurrentDataService {
|
|
}
|
|
}
|
|
ObjectNode jsonNodes = data.get(0).getInfos();
|
|
ObjectNode jsonNodes = data.get(0).getInfos();
|
|
if(jsonNodes.has(infoCode)){
|
|
if(jsonNodes.has(infoCode)){
|
|
- return jsonNodes.get(infoCode).toString();
|
|
|
|
|
|
+ return jsonNodes.get(infoCode).textValue();
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -156,20 +169,5 @@ public class CurrentDataServiceImpl implements CurrentDataService {
|
|
this.funcid = function;
|
|
this.funcid = function;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 提取结果
|
|
|
|
- * @param response
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private JSONArray fetchResult(String response) {
|
|
|
|
- JSONObject responseObject = JSONObject.parseObject(response);
|
|
|
|
- // 如果结果不成功,抛出失败结果
|
|
|
|
- if(!StrUtil.equals("success", responseObject.getString("result"))) {
|
|
|
|
- throw new BusinessException(responseObject.getString("message"));
|
|
|
|
- }
|
|
|
|
- JSONArray datas = responseObject.getJSONArray("data");
|
|
|
|
- return CollUtil.isEmpty(datas) ? null : datas;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|