|
@@ -1,11 +1,30 @@
|
|
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 com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
+import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
|
+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.rwd.basic.constant.IotUrlConstant;
|
|
|
|
+import com.persagy.dmp.rwd.basic.utils.MeterUtils;
|
|
|
|
+import com.persagy.dmp.rwd.digital.entity.ObjectDigital;
|
|
|
|
+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.CurrentDataService;
|
|
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.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@@ -17,21 +36,24 @@ import java.util.*;
|
|
@Service
|
|
@Service
|
|
public class CurrentDataServiceImpl implements CurrentDataService {
|
|
public class CurrentDataServiceImpl implements CurrentDataService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IObjectDigitalService objectDigitalService;
|
|
|
|
+
|
|
|
|
+ //@Value("${persagy.iot.data.server}")
|
|
|
|
+ @Value("http://develop.persagy.com/iot-collect")
|
|
|
|
+ protected String iotDataServer;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 查询实时数据
|
|
|
|
|
|
+ * 查询对象绑点信息点的实时数据
|
|
* @param param
|
|
* @param param
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<CurrentDataModel> getCurrentData(List<CurrentDataModel> param) {
|
|
|
|
|
|
+ public List<CurrentDataModel> getCurrentData(List<CurrentDataModel> param) throws Exception{
|
|
if(param == null || param.size()<=0){
|
|
if(param == null || param.size()<=0){
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
-
|
|
|
|
- String groupCode = AppContext.getContext().getGroupCode();
|
|
|
|
- String projectId = AppContext.getContext().getProjectId();
|
|
|
|
-
|
|
|
|
- //查询对象绑点信息点的实时数据
|
|
|
|
|
|
+ //表号功能号校验
|
|
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) {
|
|
@@ -43,11 +65,80 @@ public class CurrentDataServiceImpl implements CurrentDataService {
|
|
model.setError("信息点编码不可为空");
|
|
model.setError("信息点编码不可为空");
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
-
|
|
|
|
- //表号功能号校验
|
|
|
|
- // String infoCodeValue = getInfoCodeValue(groupCode, projectId, model.getObjectId(), infoCode);
|
|
|
|
|
|
+ //校验表号功能号是否存在
|
|
|
|
+ String infoCodeValue = getInfoCodeValue(model.getObjectId(), infoCode);
|
|
|
|
+ if(StringUtils.isEmpty(infoCodeValue)){
|
|
|
|
+ model.setError("value of infoCode[" + model.getObjectId() + ":" + infoCode + "] is null");
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 判断信息点的值是不是表号-功能号格式
|
|
|
|
+ model.setInfoValue(infoCodeValue);
|
|
|
|
+ if (!MeterUtils.matchFormat(infoCodeValue)) {
|
|
|
|
+ model.setError("value of infoCode[" + model.getObjectId() + ":" + infoCode + "][ " + infoCodeValue + "] 不是正确的表号功能号");
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询信息点值
|
|
|
|
+ * @param objectId
|
|
|
|
+ * @param infoCode
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private String getInfoCodeValue(String objectId,String infoCode) throws Exception {
|
|
|
|
+ //查询条件封装
|
|
|
|
+ QueryCriteria queryCriteria = new QueryCriteria();
|
|
|
|
+ ObjectNode criteria = JsonNodeFactory.instance.objectNode();
|
|
|
|
+ criteria.put("id",objectId);
|
|
|
|
+ criteria.put("valid",1);
|
|
|
|
+ queryCriteria.setCriteria(criteria);
|
|
|
|
+
|
|
|
|
+ //查询object对象
|
|
|
|
+ QueryWrapper<ObjectDigital> wrapper = new QueryWrapper<>();
|
|
|
|
+ // 添加所属项目条件
|
|
|
|
+ ConditionUtil.ensureProjectCriteria(wrapper);
|
|
|
|
+ // 转换查询条件
|
|
|
|
+ QueryCriteriaHelper.toWrapper(wrapper,queryCriteria);
|
|
|
|
+ List<ObjectDigital> data = objectDigitalService.queryByCondition(wrapper);
|
|
|
|
+
|
|
|
|
+ if(data == null || data.size()<=0){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if("classCode".equals(infoCode)){
|
|
|
|
+ return data.get(0).getClassCode();
|
|
|
|
+ }
|
|
|
|
+ ObjectNode jsonNodes = data.get(0).getInfos();
|
|
|
|
+ if(jsonNodes.has(infoCode)){
|
|
|
|
+ return jsonNodes.get(infoCode).toString();
|
|
|
|
+ }
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -65,4 +156,20 @@ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|