From bfcca60e2dbf84bce27def31f92e1c99f94a1d6e Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期四, 19 九月 2024 18:38:51 +0800
Subject: [PATCH] http tag

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpApiRespVO.java                  |   36 +++----
 /dev/null                                                                                                                          |  136 ---------------------------
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTokenServiceImpl.java |   26 -----
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java         |   12 --
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTokenService.java          |    2 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpTagRespVO.java                  |   30 +++--
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java                |    4 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/entity/HttpTokenEntity.java            |   41 +++++++
 8 files changed, 71 insertions(+), 216 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/HttpCollectorForZxzk.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/HttpCollectorForZxzk.java
deleted file mode 100644
index 1828401..0000000
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/HttpCollectorForZxzk.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package com.iailab.module.data.channel.http.collector;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.iailab.module.data.common.enums.CommonConstant;
-import com.iailab.module.data.common.enums.DataSourceType;
-import com.iailab.module.data.common.utils.HttpsRequest;
-import com.iailab.module.data.common.utils.TagUtils;
-import com.iailab.module.data.channel.http.entity.HttpApiEntity;
-import com.iailab.module.data.channel.http.service.HttpApiService;
-import lombok.extern.slf4j.Slf4j;
-import javax.annotation.Resource;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-
-import java.math.BigDecimal;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 中选时序数据采集
- * http://192.168.55.122/api/Data/CurrentData?domain=NttRslinxLogic&tagstr=[ZX1]D_113.State.KM,[ZX1]D_114.State.KM
- * domain:限定数据域,可空,为空时不限定数据域。
- * tagstr:限定标签集合,可空,为空时不限定标签。格式为英文逗号分隔的一个或多个标签名,如tag1,tag2,由于标签中可能包含特殊字符,get参数需要对此参数进行encode处理。
- * {
- *   "sta": true,
- *   "msg": null,
- *   "res": [
- *     {
- *       "Tag": "[ZX1]D_110.State.KM",//标签
- *       "Value": 0//当前值
- *     },
- *
- * @author PanZhibao
- * @Description
- * @createTime 2024年05月16日
- */
-@Slf4j
-@Component
-public class HttpCollectorForZxzk {
-
-    private Map<String, HttpApiEntity> apiMap = new HashMap<>();
-
-    @Resource
-    private HttpApiService httpApiService;
-
-    @Resource
-    HttpsRequest httpsRequest;
-
-    private final String STA_TRUE = "true";
-
-    private final int GROUP_MAX_COUNT = 50;
-
-    private HttpApiEntity getHttpApi(String id) {
-        if (apiMap.containsKey(id)) {
-            return apiMap.get(id);
-        }
-        HttpApiEntity httpApi = httpApiService.info(id);
-        apiMap.put(id, httpApi);
-        return httpApi;
-    }
-
-    public BigDecimal getTagValue(String sourceId, String tagNo) {
-        BigDecimal value = CommonConstant.BAD_VALUE;
-        HttpApiEntity httpApi = this.getHttpApi(sourceId);
-        Map<String, String> queryParams = new HashMap<>();
-        queryParams.put("tagstr", tagNo);
-        String responseStr = httpsRequest.doGet(httpApi.getUrl(), queryParams, "utf-8", "");
-        JSONObject responseObj = JSON.parseObject(responseStr);
-        if (STA_TRUE.equals(responseObj.get("sta").toString())) {
-            JSONArray tagValueList = responseObj.getJSONArray("res");
-            if (!CollectionUtils.isEmpty(tagValueList)) {
-                for (int i = 0; i < tagValueList.size(); i++) {
-                    JSONObject item = tagValueList.getJSONObject(i);
-                    value = new BigDecimal(item.get("Value").toString());
-                }
-            }
-        }
-        return value;
-    }
-
-
-    public Map<String, Object> getTagValues(List<String[]> params) {
-        if (CollectionUtils.isEmpty(params)) {
-            return new HashMap<>();
-        }
-
-        Map<Integer, List<String[]>> measurePointsCountGroup = new HashMap<>();
-        int pointListSize = params.size();
-        int groupCount  = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0);
-        log.info("groupCount=" + groupCount);
-        for (int i = 0; i < groupCount; i++) {
-            int end = (i + 1) * GROUP_MAX_COUNT;
-            if (end > pointListSize) {
-                end = pointListSize;
-            }
-            measurePointsCountGroup.put(i, params.subList(i * GROUP_MAX_COUNT, end));
-        }
-        Map<String, Object> result = new HashMap<>(params.size());
-        for(Map.Entry<Integer, List<String[]>> measurePointsItem : measurePointsCountGroup.entrySet()) {
-            try {
-                getByHtp(result, measurePointsItem.getValue());
-            } catch (Exception ex) {
-                ex.printStackTrace();
-            }
-        }
-        return result;
-    }
-
-    private void getByHtp(Map<String, Object> result, List<String[]> params) {
-        HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0]);
-        Map<String, String> queryParams = new HashMap<>();
-        StringBuilder tagSb = new StringBuilder();
-        for (int i = 0; i < params.size(); i ++) {
-            tagSb.append(params.get(i)[1]);
-            if (i < params.size() - 1) {
-                tagSb.append(",");
-            }
-        }
-        queryParams.put("tagstr", tagSb.toString());
-        String responseStr = httpsRequest.doGet(httpApi.getUrl(), queryParams, "utf-8", "");
-        JSONObject responseObj = JSON.parseObject(responseStr);
-        if (STA_TRUE.equals(responseObj.get("sta").toString())) {
-            JSONArray tagValueList = responseObj.getJSONArray("res");
-            if (!CollectionUtils.isEmpty(tagValueList)) {
-                for (int i = 0; i < tagValueList.size(); i++) {
-                    JSONObject item = tagValueList.getJSONObject(i);
-                    result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), httpApi.getCode(), item.get("Tag").toString()), item.get("Value"));
-                }
-            }
-        }
-
-    }
-}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/entity/HttpTokenEntity.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/entity/HttpTokenEntity.java
index d6cdf22..d3f4b69 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/entity/HttpTokenEntity.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/entity/HttpTokenEntity.java
@@ -10,7 +10,7 @@
 import java.util.Date;
 
 @Data
-@TableName("T_HTTP_TOKEN")
+@TableName("t_http_token")
 public class HttpTokenEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
@@ -20,16 +20,49 @@
     @Schema(description = "主键")
     @TableId(value = "id", type = IdType.INPUT)
     private String id;
+
+    /**
+     * 接口ID
+     */
     private String apiId;
+
+    /**
+     * 登录地址
+     */
     private String loginUrl;
+
+    /**
+     * ClientId
+     */
     private String clientId;
+
+    /**
+     * ClientSecret
+     */
     private String clientSecret;
+
+    /**
+     * 用户名
+     */
     private String username;
+
+    /**
+     * 密码
+     */
     private String password;
+
+    /**
+     * token
+     */
     private String token;
-    private String prvsetName;
-    private String projectName;
-    private String platform;
+
+    /**
+     * 过期时间
+     */
     private Date expireTime;
+
+    /**
+     * 更新时间
+     */
     private Date updateTime;
 }
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTokenService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTokenService.java
index 07c2e0e..d8e1478 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTokenService.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTokenService.java
@@ -21,7 +21,5 @@
 
     HttpTokenEntity getByApiId(String apiId);
 
-    void updateToken(String clientId);
-
     String queryToken(String clientId);
 }
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTokenServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTokenServiceImpl.java
index 48f459c..bd6c61d 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTokenServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTokenServiceImpl.java
@@ -65,32 +65,6 @@
         return httpTokenDao.selectOne(wrapper);
     }
 
-
-    @Override
-    public void updateToken(String clientId) {
-        Map<String, String> params = new HashMap<>(1);
-        params.put("timeout", "30000");
-        HttpTokenEntity entity = httpTokenDao.selectOne(new QueryWrapper<HttpTokenEntity>().eq("client_id", clientId));
-        Map<String, String> dataJson = new HashMap<>(2);
-        String url = entity.getLoginUrl();
-        String userName = entity.getUsername();
-        String password = entity.getPassword();
-        String prvsetName = entity.getPrvsetName();
-        String projectName = entity.getProjectName();
-        String platform = entity.getPlatform();
-        dataJson.put("username", userName);
-        dataJson.put("password", password);
-        dataJson.put("prvset_name", prvsetName);
-        dataJson.put("project_name", projectName);
-        dataJson.put("platform", platform);
-        //查询token的请求
-        String responseStr = httpsRequest.doPostToken(url, params, JSONObject.toJSONString(dataJson), "utf-8");
-        //插入token和更新时间
-        entity.setToken(responseStr);
-        entity.setUpdateTime(new Date());
-        httpTokenDao.update(entity, new QueryWrapper<HttpTokenEntity>().eq("client_id", clientId));
-    }
-
     @Override
     public String queryToken(String clientId) {
         return httpTokenDao.selectOne(new QueryWrapper<HttpTokenEntity>().eq("client_id", clientId)).getToken();
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpApiRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpApiRespVO.java
index ac6570f..9c73475 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpApiRespVO.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpApiRespVO.java
@@ -21,36 +21,32 @@
     @ExcelProperty("ID")
     private String id;
 
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
-    private String name;
-
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
+    @Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("编码")
     private String code;
 
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
+    @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("名称")
+    private String name;
+
+    @Schema(description = "URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("URL")
     private String url;
 
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
+    @Schema(description = "请求方法", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("请求方法")
     private String method;
 
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
-    private String collectType;
-
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
+    @Schema(description = "参数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("参数")
     private String param;
 
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
+    @Schema(description = "描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("描述")
     private String descp;
 
-    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("")
+    @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("状态")
     private Integer status;
 
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpTagRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpTagRespVO.java
index f196604..c8a3d5a 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpTagRespVO.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpTagRespVO.java
@@ -21,22 +21,26 @@
     @ExcelProperty("ID")
     private String id;
 
-    @Schema(description = "api编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("api编码")
-    private String httpApiCode;
+    @Schema(description = "接口ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("接口ID")
+    private String apiId;
 
-    @Schema(description = "测点类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("测点类型")
-    private String tagType;
-
-    @Schema(description = "测点编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("测点编码")
-    private String tagCode;
-
-    @Schema(description = "测点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    @ExcelProperty("测点名称")
+    @Schema(description = "标签名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("标签名称")
     private String tagName;
 
+    @Schema(description = "数据类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("数据类型")
+    private String dataType;
+
+    @Schema(description = "标签描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("标签描述")
+    private String tagDesc;
+
+    @Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @ExcelProperty("是否启用")
+    private Boolean enabled;
+
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
     @ExcelProperty("创建时间")
     private Date createTime;
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
index 7bd34be..dc4c0be 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
@@ -7,7 +7,6 @@
 import com.iailab.module.data.point.common.PointTypeEnum;
 import com.iailab.module.data.point.dto.DaPointDTO;
 import com.iailab.module.data.point.service.DaPointService;
-import com.iailab.module.data.channel.http.collector.HttpCollectorForZxzk;
 import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO;
 import com.iailab.module.data.channel.modbus.collector.ModBusCollector;
 import com.iailab.module.data.channel.opcua.collector.OpcUaCollector;
@@ -55,9 +54,6 @@
 
     @Resource
     private OpcUaCollector opcUaCollector;
-
-    @Resource
-    private HttpCollectorForZxzk httpCollectorForZxzk;
 
     /**
      * 采集
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
index a5d084e..455b836 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -12,7 +12,6 @@
 import com.iailab.module.data.point.common.PointDataTypeEnum;
 import com.iailab.module.data.point.dto.DaPointDTO;
 import com.iailab.module.data.point.service.DaPointService;
-import com.iailab.module.data.channel.http.collector.HttpCollectorForZxzk;
 import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO;
 import lombok.extern.slf4j.Slf4j;
 import javax.annotation.Resource;
@@ -50,9 +49,6 @@
 
     @Autowired
     private OpcDACollector opcDACollector;
-
-    @Resource
-    private HttpCollectorForZxzk httpCollectorForZxzk;
 
     @Resource
     private DaPointService daPointService;
@@ -95,10 +91,6 @@
         }
         if (!CollectionUtils.isEmpty(kioTagIds)) {
             tagValues.putAll(kingIOCollector.getTagValues(kioTagIds));
-        }
-        if (!CollectionUtils.isEmpty(httpTagZxzk)) {
-            tagValues.putAll(httpCollectorForZxzk.getTagValues(httpTagZxzk));
-
         }
         this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
         log.info("测量点处理结束");
@@ -175,9 +167,7 @@
                         } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) {
                             value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo());
                         } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) {
-                            if (CommonConstant.HTTP_API_ZXZK_IH.equals(item.getSourceName())) {
-                                value = httpCollectorForZxzk.getTagValue(item.getSourceId(), item.getTagNo());
-                            }
+
                         } else {
                             log.info("没有匹配的TagNo=" + item.getTagNo());
                         }

--
Gitblit v1.9.3