فهرست منبع

iot代码迁移

linhuili 3 سال پیش
والد
کامیت
2cf094e990
15فایلهای تغییر یافته به همراه612 افزوده شده و 55 حذف شده
  1. 0 0
      dmp-business/dmp-dic/src/main/resources/mapper/HistoryIotService.xml
  2. 15 0
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/basic/constant/IotUrlConstant.java
  3. 10 0
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/IObjectDigitalService.java
  4. 20 0
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/impl/ObjectDigitalServiceImpl.java
  5. 97 2
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/controller/IotController.java
  6. 4 1
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/model/history/InfoCodeModel.java
  7. 3 1
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/CurrentDataService.java
  8. 17 0
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/HistoryIotService.java
  9. 27 0
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/SettingIotService.java
  10. 49 51
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/impl/CurrentDataServiceImpl.java
  11. 167 0
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/impl/HistoryIotServiceImpl.java
  12. 203 0
      dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/impl/SettingIotServiceImpl.java
  13. 0 0
      dmp-business/dmp-rwd/src/main/resources/mapper/HistoryIotService.xml
  14. 0 0
      dmp-cloud/dmp-file/src/main/resources/mapper/HistoryIotService.xml
  15. 0 0
      dmp-comp/dmp-mybatis/src/main/resources/mapper/HistoryIotService.xml

dmp-business/dmp-dic/src/main/resources/mapper/DictDataMapper.xml → dmp-business/dmp-dic/src/main/resources/mapper/HistoryIotService.xml


+ 15 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/basic/constant/IotUrlConstant.java

@@ -11,4 +11,19 @@ public class IotUrlConstant {
      * 查询实时数据
      */
     public static String QUERY_CUCCRENT_DATA = "/presentreportbatch_post";
+
+    /**
+     * 查询历史数据/分精度数据
+     */
+    public static String QUERY_HISTORY_DATA = "/fjd_query_batch_post";
+
+    /**
+     * 动态信息点绑定
+     */
+    public static String POINT_SET_DATA = "/pointsetbatch_post";
+
+    /**
+     * 查询指令执行结果
+     */
+    public static String QUERY_POINT_SET_DATA = "/pointsetresultbatch_post";
 }

+ 10 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/IObjectDigitalService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.persagy.dmp.rwd.digital.entity.ObjectDigital;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 对象数据 接口
@@ -54,4 +55,13 @@ public interface IObjectDigitalService {
      * @param idList 主键
      */
     void delete(List<String> idList) ;
+
+    /**
+     * 查询虚拟信息点
+     * @param projectId
+     * @param groupCode
+     * @param ids
+     * @return
+     */
+    Map<String, List<String>>  queryVirtualCodeMap(String projectId, String groupCode, List<String> ids);
 }

+ 20 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/impl/ObjectDigitalServiceImpl.java

@@ -6,12 +6,14 @@ import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ReflectUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.rwd.basic.constant.DigitalMessageConstant;
 import com.persagy.dmp.rwd.basic.utils.DigitalCommonUtils;
 import com.persagy.dmp.rwd.basic.utils.DigitalMessageHelper;
@@ -361,4 +363,22 @@ public class ObjectDigitalServiceImpl implements IObjectDigitalService {
         }
     }
 
+
+    /**
+     * 查询虚拟信息点
+     * @param projectId
+     * @param groupCode
+     * @param ids
+     * @return
+     */
+    public Map<String, List<String>> queryVirtualCodeMap(String projectId,String groupCode,List<String> ids) {
+        LambdaQueryWrapper<ObjectDigital> wrapper = new LambdaQueryWrapper<>();
+        wrapper.select(ObjectDigital::getId, ObjectDigital::getVirtualCodes);
+        wrapper.eq(ObjectDigital::getProjectId,projectId);
+        wrapper.eq(ObjectDigital::getGroupCode,groupCode);
+        wrapper.in(ObjectDigital::getId,ids);
+        wrapper.eq(ObjectDigital::getValid, ValidEnum.TRUE.getType());
+        List<ObjectDigital> objectDigitals = queryByCondition(wrapper);
+        return CollUtil.fieldValueAsMap(objectDigitals, "id", "virtual_codes");
+    }
 }

+ 97 - 2
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/controller/IotController.java

@@ -1,10 +1,17 @@
 package com.persagy.dmp.rwd.iot.controller;
 import com.persagy.dmp.common.constant.CommonConstant;
+import com.persagy.dmp.common.constant.ResponseCode;
+import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.common.utils.ParamCheckUtil;
 import com.persagy.dmp.common.utils.ResultHelper;
 import com.persagy.dmp.rwd.iot.model.CurrentDataModel;
-import com.persagy.dmp.rwd.iot.service.CurrentDataService;
+import com.persagy.dmp.rwd.iot.model.SettingDataModel;
+import com.persagy.dmp.rwd.iot.model.history.InfoCodeModel;
+import com.persagy.dmp.rwd.iot.model.history.RequestModel;
+import com.persagy.dmp.rwd.iot.service.CurrentIotService;
+import com.persagy.dmp.rwd.iot.service.HistoryIotService;
+import com.persagy.dmp.rwd.iot.service.SettingIotService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -24,7 +31,13 @@ import java.util.List;
 public class IotController {
 
 	@Autowired
-	private CurrentDataService currentDataService;
+	private CurrentIotService currentDataService;
+
+	@Autowired
+	private HistoryIotService historyDataService;
+
+	@Autowired
+	private SettingIotService settingDataService;
 
 	/**
 	 * 查询对象绑点信息点的实时数据
@@ -45,4 +58,86 @@ public class IotController {
 		return ResultHelper.multi(currentData,currentData.size());
 	}
 
+
+	/**
+	 * 查询历史数据/分精度数据
+	 * @param request
+	 * @return
+	 */
+	@PostMapping("/data/history")
+	public CommonResult<List<InfoCodeModel>> history(@RequestBody RequestModel request) throws Exception{
+		//基础参数校验
+		ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
+		checkHistoryRequest(request);
+        //查询历史数据/分精度数据
+		List<InfoCodeModel> historyData = historyDataService.getHistoryData(request);
+
+		if(historyData == null || historyData.size()<=0){
+			return ResultHelper.multi(new ArrayList<>(),0);
+		}
+		return ResultHelper.multi(historyData,historyData.size());
+	}
+
+	/**
+	 * 发送控制指令/设定动态参数
+	 * @param param
+	 * @return
+	 */
+	@PostMapping("/funcid/setting")
+	public CommonResult<List<SettingDataModel>> setting(@RequestBody List<SettingDataModel> param) {
+		//基础参数校验
+		ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
+		//发送控制指令/设定动态参数
+		List<SettingDataModel> settingData = settingDataService.settingDataService(param);
+
+		if(settingData == null || settingData.size()<=0){
+			return ResultHelper.multi(new ArrayList<>(),0);
+		}
+		return ResultHelper.multi(settingData,settingData.size());
+	}
+
+
+	/**
+	 * 查询指令执行结果
+	 * @param param
+	 * @return
+	 */
+	@PostMapping("/funcid/settingQuery")
+	public CommonResult<List<SettingDataModel>> settingQuery(@RequestBody List<String> param) {
+		//基础参数校验
+		ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE,CommonConstant.QUERY_PROJECTID);
+		//发送控制指令/设定动态参数
+		List<SettingDataModel> settingData = settingDataService.settingQuery(param);
+
+		if(settingData == null || settingData.size()<=0){
+			return ResultHelper.multi(new ArrayList<>(),0);
+		}
+		return ResultHelper.multi(settingData,settingData.size());
+	}
+
+	/**
+	 * 查询历史数据请求参数校验
+	 * @param request
+	 */
+	private void checkHistoryRequest(RequestModel request) {
+		String startTime = request.getStartTime();
+		if (startTime == null) {
+			throw new BusinessException(ResponseCode.A0400.getCode(), "startTime is required");
+		}
+		String endTime = request.getEndTime();
+		if (endTime == null) {
+			throw new BusinessException(ResponseCode.A0400.getCode(), "endTime is required");
+		}
+		String period = request.getPeriod();
+		if (period == null) {
+			throw new BusinessException(ResponseCode.A0400.getCode(), "period is required");
+		}
+		List<InfoCodeModel> params = request.getParams();
+		if (params == null || params.size() == 0) {
+			throw new BusinessException(ResponseCode.A0400.getCode(), "params is required");
+		}
+	}
+
+
+
 }

+ 4 - 1
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/model/history/InfoCodeModel.java

@@ -1,5 +1,6 @@
 package com.persagy.dmp.rwd.iot.model.history;
 
+import com.alibaba.fastjson.JSONArray;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import lombok.Getter;
 import lombok.Setter;
@@ -15,5 +16,7 @@ public class InfoCodeModel {
 	private String status;
 	private String error;
 
-	private ArrayNode data;
+	private JSONArray data;
+
+
 }

+ 3 - 1
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/CurrentDataService.java

@@ -5,7 +5,7 @@ import com.persagy.dmp.rwd.iot.model.CurrentDataModel;
 
 import java.util.List;
 
-public interface CurrentDataService {
+public interface CurrentIotService {
 
     /**
      * 查询对象绑点信息点的实时数据
@@ -13,4 +13,6 @@ public interface CurrentDataService {
      * @return
      */
     List<CurrentDataModel> getCurrentData(List<CurrentDataModel> param) throws Exception;
+
+
 }

+ 17 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/HistoryIotService.java

@@ -0,0 +1,17 @@
+package com.persagy.dmp.rwd.iot.service;
+
+import com.persagy.dmp.rwd.iot.model.CurrentDataModel;
+import com.persagy.dmp.rwd.iot.model.history.InfoCodeModel;
+import com.persagy.dmp.rwd.iot.model.history.RequestModel;
+
+import java.util.List;
+
+public interface HistoryIotService {
+
+    /**
+     * 查询对象绑点信息点的实时数据
+     * @param request
+     * @return
+     */
+    List<InfoCodeModel> getHistoryData(RequestModel request) throws Exception;
+}

+ 27 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/SettingIotService.java

@@ -0,0 +1,27 @@
+package com.persagy.dmp.rwd.iot.service;
+
+import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.rwd.iot.model.SettingDataModel;
+import com.persagy.dmp.rwd.iot.model.history.InfoCodeModel;
+import com.persagy.dmp.rwd.iot.model.history.RequestModel;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.List;
+
+public interface SettingIotService {
+
+    /**
+     * 发送控制指令/设定动态参数
+     * @param param
+     * @return
+     */
+    List<SettingDataModel> settingDataService(List<SettingDataModel> param);
+
+
+    /**
+     * 查询指令执行结果
+     * @param param
+     * @return
+     */
+    List<SettingDataModel> settingQuery(@RequestBody List<String> param);
+}

+ 49 - 51
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/impl/CurrentDataServiceImpl.java

@@ -1,7 +1,5 @@
 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;
@@ -11,16 +9,16 @@ 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.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.service.CurrentDataService;
+import com.persagy.dmp.rwd.iot.service.CurrentIotService;
 import lombok.Getter;
 import lombok.Setter;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -28,20 +26,21 @@ import org.springframework.util.StringUtils;
 
 import java.util.*;
 
+
 /**
  * iot-查询实时数据
  * @author:linhuili
  * @date:2021/8/11
  */
 @Service
-public class CurrentDataServiceImpl implements CurrentDataService {
+public class CurrentIotServiceImpl implements CurrentIotService {
 
     @Autowired
     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<>();
         }
         //表号功能号校验
+        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<>();
         for (CurrentDataModel model : param) {
             if (model.getObjectId() == null) {
@@ -79,33 +115,10 @@ public class CurrentDataServiceImpl implements CurrentDataService {
             }
             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
@@ -113,7 +126,7 @@ public class CurrentDataServiceImpl implements CurrentDataService {
      * @return
      * @throws Exception
      */
-    private String getInfoCodeValue(String objectId,String infoCode) throws Exception {
+    public String getInfoCodeValue(String objectId,String infoCode){
         //查询条件封装
         QueryCriteria queryCriteria = new QueryCriteria();
         ObjectNode criteria = JsonNodeFactory.instance.objectNode();
@@ -137,7 +150,7 @@ public class CurrentDataServiceImpl implements CurrentDataService {
         }
         ObjectNode jsonNodes = data.get(0).getInfos();
         if(jsonNodes.has(infoCode)){
-            return jsonNodes.get(infoCode).toString();
+            return jsonNodes.get(infoCode).textValue();
         }
         return null;
     }
@@ -156,20 +169,5 @@ public class CurrentDataServiceImpl implements CurrentDataService {
             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;
-    }
-
 }
+

+ 167 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/impl/HistoryIotServiceImpl.java

@@ -0,0 +1,167 @@
+package com.persagy.dmp.rwd.iot.service.impl;
+
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.rwd.basic.constant.IotUrlConstant;
+import com.persagy.dmp.rwd.basic.utils.MeterUtils;
+import com.persagy.dmp.rwd.iot.model.history.InfoCodeModel;
+import com.persagy.dmp.rwd.iot.model.history.RequestModel;
+import com.persagy.dmp.rwd.iot.service.HistoryIotService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * iot-查询历史数据/分精度数据
+ * @author:linhuili
+ * @date:2021/8/11
+ */
+@Service
+public class HistoryIotServiceImpl implements HistoryIotService {
+
+    @Autowired
+    private CurrentIotServiceImpl currentDataService;
+
+    @Value("${persagy.iot.data.server}")
+    private String iotDataServer;
+    /**
+     * 查询历史数据/分精度数据
+     * @param request
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public List<InfoCodeModel> getHistoryData(RequestModel request) throws Exception {
+        List<InfoCodeModel> params = request.getParams();
+        //信息点校验
+        ArrayNode pointList = JsonNodeFactory.instance.arrayNode();
+        for (InfoCodeModel param : params) {
+            param.setStatus("success");
+            checkParam(param, pointList);
+        }
+        if (pointList.size() == 0) {
+            return params;
+        }
+
+        //转换为iot请求参数
+        ObjectNode requestNode = JsonNodeFactory.instance.objectNode();
+        requestNode.put("building", AppContext.getContext().getProjectId().substring(2));
+        for (JsonNode jsonNode : pointList) {
+            ObjectNode item = (ObjectNode) jsonNode;
+            item.put("time_period", request.getPeriod());
+            item.put("time_from", request.getStartTime());
+            item.put("time_to", request.getEndTime());
+        }
+        requestNode.set("points", pointList);
+
+        //查询对象绑点信息点的历史数据
+        String url = iotDataServer + IotUrlConstant.QUERY_HISTORY_DATA;
+        String response = HttpUtil.post(url, requestNode.toString(), 30000);
+        JSONObject object = JSONObject.parseObject(response);
+        if(object == null){
+            return params;
+        }
+        JSONArray points = object.getJSONArray("points");
+        handleIotHisQueryReuslt(params,points);
+
+        return params;
+    }
+
+
+    /**
+     * iot历史数据查询结果封装
+     * @param params
+     * @param points
+     */
+    private void handleIotHisQueryReuslt(List<InfoCodeModel> params ,JSONArray points){
+        if(points == null || points.size()<=0){
+            return;
+        }
+        for (Object point : points) {
+            JSONObject meterItem = (JSONObject) point;
+            String meter = meterItem.getString("meter");
+            String function = meterItem.getString("funcid") + "";
+            for (InfoCodeModel param : params) {
+                if (!(meter + "-" + function).equals(param.getMeter() + "-" + param.getFunction())) {
+                    continue;
+                }
+
+                JSONArray data = new JSONArray();
+                JSONArray datas = meterItem.getJSONArray("datas");
+                if (datas != null && datas.size() > 0) {
+                    for (Object jsonNode : datas) {
+                        JSONObject dataItem = (JSONObject) jsonNode;
+                        JSONObject item = new JSONObject();
+                        item.put("time", dataItem.getString("data_time"));
+                        item.put("data", dataItem.getString("data_value"));
+                        data.add(item);
+                    }
+                }
+                param.setData(data);
+            }
+        }
+    }
+
+
+    /**
+     * 信息点校验
+     * @param param
+     * @param pointList
+     * @throws Exception
+     */
+    private void checkParam(InfoCodeModel param, ArrayNode pointList) throws Exception {
+        String objectId = param.getObjectId();
+        if (objectId == null) {
+            param.setStatus("error");
+            param.setError("objectId is not required");
+            return;
+        }
+        String infoCode = param.getInfoCode();
+        if (infoCode == null) {
+            param.setStatus("error");
+            param.setError("infoCode is not required");
+            return;
+        }
+        String classCode = currentDataService.getInfoCodeValue(objectId, "classCode");
+        if (classCode == null) {
+            param.setStatus("error");
+            param.setError("对象不存在或已失效");
+            return;
+        }
+
+        String infoCodeValue = currentDataService.getInfoCodeValue(objectId, infoCode);
+        if (infoCodeValue == null) {
+            param.setStatus("error");
+            param.setError("value of infoCode[" + objectId + ":" + infoCode + "] is null");
+            return;
+        }
+        // 判断信息点的值是不是表号-功能号格式
+        if (!MeterUtils.matchFormat(infoCodeValue)) {
+            param.setStatus("error");
+            param.setError("value of infoCode[" + objectId + ":" + infoCode + "][ " + infoCodeValue + "] 不是正确的表号功能号");
+            return;
+        }
+
+        int idx = infoCodeValue.lastIndexOf("-");
+        if (idx == -1) {
+
+        } else {
+            String meter = infoCodeValue.substring(0, idx);
+            String function = infoCodeValue.substring(idx + 1);
+            param.setMeter(meter);
+            param.setFunction(function);
+            ObjectNode point = pointList.addObject();
+            point.put("meter", meter);
+            point.put("funcid", Long.parseLong(function));
+        }
+    }
+
+}

+ 203 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/iot/service/impl/SettingIotServiceImpl.java

@@ -0,0 +1,203 @@
+package com.persagy.dmp.rwd.iot.service.impl;
+
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.rwd.basic.constant.IotUrlConstant;
+import com.persagy.dmp.rwd.basic.utils.MeterUtils;
+import com.persagy.dmp.rwd.digital.service.IObjectDigitalService;
+import com.persagy.dmp.rwd.iot.model.SettingDataModel;
+import com.persagy.dmp.rwd.iot.service.SettingIotService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * iot-动态参数设定/查询
+ * @author:linhuili
+ * @date:2021/8/11
+ */
+@Service
+public class SettingIotServiceImpl implements SettingIotService {
+
+    @Autowired
+    private CurrentIotServiceImpl currentDataService;
+
+    @Autowired
+    private IObjectDigitalService iObjectDigitalService;
+
+    @Value("${persagy.iot.data.server}")
+    private String iotDataServer;
+
+    /**
+     * 发送控制指令/设定动态参数
+     * @param param
+     * @return
+     */
+    @Override
+    public List<SettingDataModel> settingDataService(List<SettingDataModel> param) {
+        //设定动态参数
+        ArrayNode pointValueList = JsonNodeFactory.instance.arrayNode();
+        settingParam(param,pointValueList);
+
+        //绑定动态参数
+        String projectLocalId = AppContext.getContext().getProjectId().substring(2);
+        ObjectNode requestNode = JsonNodeFactory.instance.objectNode();
+        requestNode.put("building", projectLocalId);
+        requestNode.set("points", pointValueList);
+
+        String url = iotDataServer + IotUrlConstant.POINT_SET_DATA;
+        String response = HttpUtil.post(url, requestNode.toString(), 30000);
+        JSONObject object = JSONObject.parseObject(response);
+        if(object == null){
+            return param;
+        }
+
+        //返回结果封装
+        JSONArray points = object.getJSONArray("points");
+        for (Object node : points) {
+            JSONObject item = (JSONObject) node;
+            String meter = item.getString("meter");
+            String funcid = item.getString("funcid")+"";
+            for (SettingDataModel model : param) {
+                if (model.getMeter().equals(meter) && model.getFunction().equals(funcid)) {
+                    // 楼号-表号-功能号-时间作为唯一标识
+                    String exeCode = projectLocalId + ":" + meter + ":" + funcid + ":" + item.getString("receivetime");
+                    model.setExeCode(exeCode);
+                }
+            }
+        }
+        return param;
+    }
+
+    /**
+     * 动态参数设置
+     * @param param
+     * @param pointValueList
+     */
+    private void settingParam(List<SettingDataModel> param,ArrayNode pointValueList){
+        //查询虚拟信息点
+        Map<String, List<String>> virtualCodeMap = getVirtualCodeMap(param);
+
+        Map<String, Set<String>> virtualPointCache = new HashMap<>();
+        for (SettingDataModel model : param) {
+            model.setStatus("success");
+
+            //查询信息点值
+            String objectId = model.getObjectId();
+            String infoCode = model.getInfoCode();
+            String infoCodeValue = currentDataService.getInfoCodeValue(objectId, infoCode);
+
+            //信息点校验
+            if (infoCodeValue == null) {
+                model.setStatus("error");
+                model.setError("value of infoCode[" + objectId + ":" + infoCode + "] is null");
+                continue;
+            }
+
+            // 判断信息点的值是不是表号-功能号格式
+            if (!MeterUtils.matchFormat(infoCodeValue)) {
+                model.setStatus("error");
+                model.setError("value of infoCode[" + objectId + ":" + infoCode + "][ " + infoCodeValue + "] 不是正确的表号功能号");
+                continue;
+            }
+
+            //设置表号功能号
+            int idx = infoCodeValue.lastIndexOf("-");
+            String meter = infoCodeValue.substring(0, idx);
+            String function = infoCodeValue.substring(idx + 1);
+            model.setMeter(meter);
+            model.setFunction(function);
+            ObjectNode point = pointValueList.addObject();
+            point.put("meter", meter);
+            point.put("funcid", Long.parseLong(function));
+            point.put("data", model.getValue()); // TODO 要细分类型
+
+            //设置虚拟信息点
+            if (!virtualPointCache.containsKey(objectId)) {
+                List<String> virtualCode = virtualCodeMap.get(objectId);
+                if (virtualCode != null && virtualCode.size() > 0) {
+                    virtualPointCache.put(objectId, new HashSet<>(virtualCode));
+                } else {
+                    virtualPointCache.put(objectId, Collections.emptySet());
+                }
+            }
+            Set<String> virtualPointList = virtualPointCache.get(objectId);
+            point.put("virtual", virtualPointList.contains(infoCode));
+        }
+    }
+
+    /**
+     * 获取对象信息点虚拟信息点
+     * @param param
+     * @return
+     */
+    private Map<String, List<String>> getVirtualCodeMap(List<SettingDataModel> param){
+        List<String> ids = param.stream().map(SettingDataModel::getObjectId).collect(Collectors.toList());
+        String projectId = AppContext.getContext().getProjectId();
+        String groupCode = AppContext.getContext().getGroupCode();
+        Map<String, List<String>> map = iObjectDigitalService.queryVirtualCodeMap(projectId, groupCode, ids);
+        return map;
+    }
+
+    /**
+     * 查询指令执行结果
+     * @param param
+     * @return
+     */
+    @Override
+    public List<SettingDataModel> settingQuery(List<String> param) {
+        if (param == null || param.size() == 0) {
+            return null;
+        }
+
+        //设置查询参数
+        String projectLocalId = AppContext.getContext().getProjectId().substring(2);
+        ObjectNode requestNode = JsonNodeFactory.instance.objectNode();
+        requestNode.put("building", projectLocalId);
+        ArrayNode points = requestNode.putArray("points");
+        for (String str : param) {
+            ObjectNode point = points.addObject();
+            String[] split = str.split(":");
+            point.put("meter", split[1]);
+            point.put("funcid", Integer.parseInt(split[2]));
+            point.put("receivetime", split[3]);
+        }
+
+        //查询动态参数
+        String url = iotDataServer + IotUrlConstant.QUERY_POINT_SET_DATA;
+        String response = HttpUtil.post(url, requestNode.toString(), 30000);
+        JSONObject object = JSONObject.parseObject(response);
+        if(object == null){
+            return null;
+        }
+
+        //控制指令执行结果封装
+        JSONArray responseData = object.getJSONArray("points");
+        List<SettingDataModel> list = new LinkedList<>();
+        for (Object datum : responseData) {
+            JSONObject item = (JSONObject) datum;
+            //表号
+            String meter = item.getString("meter");
+            //功能号
+            String function = item.getString("funcid") + "";
+            //执行指令
+            String receivetime = item.getString("receivetime");
+            String exeCode = projectLocalId + ":" + meter + ":" + function + ":" + receivetime;
+            SettingDataModel model = new SettingDataModel();
+            model.setExeCode(exeCode);
+            //指令执行结果
+            model.setExeResult(item.getString("status"));
+            list.add(model);
+        }
+        return list;
+    }
+}

dmp-business/dmp-rwd/src/main/resources/mapper/DigitalMigrateMapper.xml → dmp-business/dmp-rwd/src/main/resources/mapper/HistoryIotService.xml


dmp-cloud/dmp-file/src/main/resources/mapper/FileMapper.xml → dmp-cloud/dmp-file/src/main/resources/mapper/HistoryIotService.xml


dmp-comp/dmp-mybatis/src/main/resources/mapper/DbDao.xml → dmp-comp/dmp-mybatis/src/main/resources/mapper/HistoryIotService.xml