From db184afd0c5bf3359b44eb0251fa5b07386eb3ff Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期三, 06 十一月 2024 09:48:13 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/controller/admin/ChannelOPCUATagController.java | 26 +++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagPageReqVO.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTagService.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java | 75 +++++++++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagRespVO.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/controller/admin/ChannelKioTagController.java | 28 +++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusTagController.java | 22 ++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagPageReqVO.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/vo/OpcDaTagRespVO.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTagServiceImpl.java | 8 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/controller/admin/HttpTagController.java | 29 ++++- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagRespVO.java | 10 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpTagRespVO.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagPageReqVO.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagRespVO.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/admin/ChannelOPCDATagController.java | 32 ++++++ 17 files changed, 240 insertions(+), 16 deletions(-) diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java index 8b1ad12..3743b24 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java @@ -3,20 +3,31 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.iailab.framework.common.constant.CommonConstant; import com.iailab.module.data.channel.http.entity.HttpApiEntity; +import com.iailab.module.data.channel.http.entity.HttpTagEntity; import com.iailab.module.data.channel.http.service.HttpApiService; +import com.iailab.module.data.channel.http.service.HttpTagService; import com.iailab.module.data.common.enums.DataSourceType; import com.iailab.module.data.common.utils.DateUtils; import com.iailab.module.data.common.utils.HttpRequest; import com.iailab.module.data.common.utils.TagUtils; +import com.iailab.module.data.influxdb.pojo.InfluxPointValueBoolPOJO; +import com.iailab.module.data.influxdb.pojo.InfluxPointValueDigPOJO; +import com.iailab.module.data.influxdb.pojo.InfluxPointValueSimPOJO; +import com.iailab.module.data.influxdb.pojo.InfluxPointValueStrPOJO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.BoundHashOperations; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; +import java.util.concurrent.TimeUnit; /** * iHyperDB采集 @@ -32,6 +43,12 @@ @Autowired private HttpApiService httpApiService; + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private HttpTagService httpTagService; private static final String STA_TRUE = "true"; @@ -74,6 +91,64 @@ return value; } + public Map<String, Object> getLastValues(List<String> tagNames) { + Map<String, Object> result = new HashMap<>(); + try { + if (CollectionUtils.isEmpty(tagNames)) { + return result; + } + List<String> noCacheTagNames = new ArrayList<>();//未缓存的tag + for (int i = 0; i < tagNames.size(); i++) { + //先查缓存 + BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(tagNames.get(i)); + if (ops.get("value") != null) { + BigDecimal value = new BigDecimal(ops.get("value").toString()); + result.put(tagNames.get(i), value.setScale(3, RoundingMode.HALF_UP)); + } else { + noCacheTagNames.add(tagNames.get(i)); + } + } + if (CollectionUtils.isEmpty(noCacheTagNames)) { + log.info("全部读取缓存"); + return result; + } + log.info("查询未缓存的数据"); + Gson gson = new Gson(); + String tagSb = gson.toJson(noCacheTagNames); + log.info("body=====" + tagSb); + String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); + String responseStr = ""; + responseStr = HttpRequest.sendPost("http://172.16.59.105:9082/api/IHD/getPointslast" + "/" + currentDate, tagSb); + JSONObject responseObj = JSON.parseObject(responseStr); + if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { + JSONArray tagValueList = responseObj.getJSONArray("data"); + if (!CollectionUtils.isEmpty(tagValueList)) { + for (int i = 0; i < tagValueList.size(); i++) { + JSONObject item = tagValueList.getJSONObject(i); + if (item.get("value") != null) { + //存缓存 + BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(item.get("tagname").toString()); + ops.put("value", item.get("value").toString()); + //设置过期时间 + redisTemplate.expire(item.get("tagname").toString(), 10, TimeUnit.SECONDS); + //把查询到的数据插入结果集 + BigDecimal value = new BigDecimal(item.get("value").toString()); + result.put(item.get("tagname").toString(), value.setScale(3, RoundingMode.HALF_UP)); + } else { + result.put(item.get("tagname").toString(), CommonConstant.BAD_VALUE); + } + } + } + } + + } catch (Exception ex) { + log.info("getCurrentValue异常"); + ex.printStackTrace(); + throw ex; + } + return result; + } + public Map<String, Object> getTagValues(List<Object[]> params) { if (CollectionUtils.isEmpty(params)) { return new HashMap<>(); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/controller/admin/HttpTagController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/controller/admin/HttpTagController.java index ceeac7b..e4079de 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/controller/admin/HttpTagController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/controller/admin/HttpTagController.java @@ -7,6 +7,7 @@ import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.framework.excel.core.util.ExcelUtils; +import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; import com.iailab.module.data.channel.http.entity.HttpTagEntity; import com.iailab.module.data.channel.http.service.HttpTagService; import com.iailab.module.data.channel.http.vo.HttpTagPageReqVO; @@ -26,11 +27,8 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.UUID; - +import java.util.*; +import java.util.stream.Collectors; import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.iailab.framework.common.pojo.CommonResult.success; @@ -47,11 +45,30 @@ @Resource private HttpTagService tagService; + @Resource + private HttpCollectorForIhd httpCollectorForIhd; + @PreAuthorize("@ss.hasPermission('data:channel-http:query')") @GetMapping("page") public CommonResult<PageResult<HttpTagRespVO>> page(@Valid HttpTagPageReqVO reqVO) { + PageResult<HttpTagEntity> page = tagService.queryPage(reqVO); - return success(BeanUtils.toBean(page, HttpTagRespVO.class)); + PageResult<HttpTagRespVO> pageResultVO = new PageResult<>(); + List<String> tagNames = page.getList().stream() + .map(HttpTagEntity::getTagName) + .collect(Collectors.toList()); + Map<String, Object> dataMap = httpCollectorForIhd.getLastValues(tagNames); + + List<HttpTagRespVO> vos = page.getList().stream().map(entity -> { + + HttpTagRespVO vo = BeanUtils.toBean(entity,HttpTagRespVO.class); + vo.setDataValue(Double.parseDouble(dataMap.get(entity.getTagName()).toString())); + return vo; + }).collect(Collectors.toList()); + + pageResultVO.setList(vos); + + return success(pageResultVO); } @PreAuthorize("@ss.hasPermission('data:channel-http:query')") diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTagService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTagService.java index 9adccbb..9890920 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTagService.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpTagService.java @@ -26,5 +26,7 @@ List<HttpTagEntity> getApiId(String code); + List<HttpTagEntity> getInfoByTagNoAndSourceId(String sourceId, String tagNo); + TagImportRespVO importHttpTagList(List<TagImportExcelVO> importTags, boolean isUpdateSupport, String apiId); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTagServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTagServiceImpl.java index 841706d..c9a82ba 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTagServiceImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpTagServiceImpl.java @@ -82,6 +82,14 @@ } @Override + public List<HttpTagEntity> getInfoByTagNoAndSourceId(String sourceId, String tagName) { + return httpTagDao.selectList(new QueryWrapper<HttpTagEntity>() + .eq("api_id",sourceId) + .eq("tag_name",tagName) + ); + } + + @Override public TagImportRespVO importHttpTagList(List<TagImportExcelVO> importTags, boolean isUpdateSupport, String apiId) { // 1.1 参数校验 if (CollUtil.isEmpty(importTags)) { 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 fbac91a..2baca7c 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 @@ -41,6 +41,10 @@ @ExcelProperty("是否启用") private Integer enabled; + @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("数据值") + private Double dataValue; + @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/channel/kio/controller/admin/ChannelKioTagController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/controller/admin/ChannelKioTagController.java index b4ed847..e9f8e5b 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/controller/admin/ChannelKioTagController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/controller/admin/ChannelKioTagController.java @@ -7,6 +7,9 @@ import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.framework.excel.core.util.ExcelUtils; +import com.iailab.module.data.channel.kio.collector.KingIOCollector; +import com.iailab.framework.common.util.object.ConvertUtils; +import com.iailab.framework.excel.core.util.ExcelUtils; import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity; import com.iailab.module.data.channel.kio.service.ChannelKioTagService; import com.iailab.module.data.channel.kio.vo.KioTagPageReqVO; @@ -30,6 +33,7 @@ import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.iailab.framework.common.pojo.CommonResult.success; @@ -43,14 +47,34 @@ @Resource private ChannelKioTagService channelKioTagService; + @Resource + private KingIOCollector kingIOCollector; + /** * 分页查询tag * */ @PreAuthorize("@ss.hasPermission('data:channel-kio:query')") @GetMapping("page") public CommonResult<PageResult<KioTagRespVO>> page(@Valid KioTagPageReqVO reqVO){ + PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO); - return success(BeanUtils.toBean(page, KioTagRespVO.class)); + PageResult<KioTagRespVO> pageResultVO = new PageResult<>(); + pageResultVO.setTotal(page.getTotal()); + + List<KioTagRespVO> vos = page.getList().stream().map(entity -> { + + KioTagRespVO vo = BeanUtils.toBean(entity,KioTagRespVO.class); + try { + vo.setDataValue(Double.parseDouble(kingIOCollector.getTagValue(reqVO.getDeviceId(), entity.getTagName()))); + }catch (Exception e){ + e.printStackTrace(); + } + return vo; + }).collect(Collectors.toList()); + + pageResultVO.setList(vos); + + return success(pageResultVO); } @PreAuthorize("@ss.hasPermission('data:channel-kio:query')") @@ -96,7 +120,7 @@ List<TagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), TagExportExcelVO.class); ExcelUtils.write(response, "tag列表.xls", "数据", TagExportExcelVO.class, list, true); } - + @GetMapping("/get-import-template") @Operation(summary = "获得tag导入模板") public void importTemplate(HttpServletResponse response) throws IOException { diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagPageReqVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagPageReqVO.java index 36ac970..8e8331f 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagPageReqVO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagPageReqVO.java @@ -20,4 +20,6 @@ private String tagName; private String device; + + private String deviceId; } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagRespVO.java index a1db769..e80a47a 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagRespVO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagRespVO.java @@ -37,9 +37,13 @@ @ExcelProperty("测点描述") private String tagDesc; - @Schema(description = "是否可以tag", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @ExcelProperty("是否可以tag") - private Integer enabled; + @Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("是否启用") + private Boolean enabled; + + @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("数据值") + private Double dataValue; @Schema(description = "关联设备", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("关联设备") diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusTagController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusTagController.java index 16f7080..366cd2f 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusTagController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusTagController.java @@ -7,6 +7,8 @@ import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.framework.excel.core.util.ExcelUtils; +import com.iailab.module.data.channel.modbus.collector.ModBusCollector; +import com.iailab.module.data.channel.modbus.entity.ChannelModBusTagEntity; import com.iailab.module.data.channel.modbus.entity.ChannelModBusTagEntity; import com.iailab.module.data.channel.modbus.service.ChannelModbusTagService; import com.iailab.module.data.channel.modbus.vo.ModBusTagExportExcelVO; @@ -25,11 +27,13 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.util.ArrayList; import java.io.IOException; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.iailab.framework.common.pojo.CommonResult.success; @@ -45,12 +49,26 @@ @Resource private ChannelModbusTagService channelModbusTagService; + @Resource + private ModBusCollector modBusCollector; + @GetMapping("/page") public CommonResult<PageResult<ModBusTagRespVO>> list(@Valid ModBusTagPageReqVO reqVO) { PageResult<ChannelModBusTagEntity> page = channelModbusTagService.queryPage(reqVO); - return success(BeanUtils.toBean(page, ModBusTagRespVO.class)); - } + PageResult<ModBusTagRespVO> pageResultVO = new PageResult<>(); + pageResultVO.setTotal(page.getTotal()); + List<ModBusTagRespVO> vos = page.getList().stream().map(entity -> { + + ModBusTagRespVO vo = BeanUtils.toBean(entity,ModBusTagRespVO.class); + vo.setDataValue(modBusCollector.getTagValue(entity.getDevice(),entity.getTagName())); + return vo; + }).collect(Collectors.toList()); + + pageResultVO.setList(vos); + + return success(pageResultVO); + } /** * 根据id查询设备详情 * diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagPageReqVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagPageReqVO.java index fc5ca7f..44b9858 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagPageReqVO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagPageReqVO.java @@ -24,4 +24,6 @@ private String tagDesc; private String device; + + private String deviceId; } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagRespVO.java index ef9c2a0..6596d7a 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagRespVO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagRespVO.java @@ -33,6 +33,10 @@ @ExcelProperty("是否启用") private Integer enabled; + @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("数据值") + private Double dataValue; + @Schema(description = "大小端", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("大小端") private String format; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/admin/ChannelOPCDATagController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/admin/ChannelOPCDATagController.java index d3e5a94..7f47f41 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/admin/ChannelOPCDATagController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/admin/ChannelOPCDATagController.java @@ -5,16 +5,21 @@ import com.iailab.framework.common.pojo.PageParam; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.util.object.BeanUtils; +import com.iailab.module.data.channel.opcda.collector.OpcDACollector; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.framework.excel.core.util.ExcelUtils; import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity; +import com.iailab.module.data.channel.opcda.service.ChannelOPCDADeviceService; import com.iailab.module.data.channel.opcda.service.ChannelOPCDATagService; import com.iailab.module.data.channel.opcda.vo.OpcDaTagExportExcelVO; import com.iailab.module.data.channel.opcda.vo.OpcDaTagImportExcelVO; import com.iailab.module.data.channel.opcda.vo.OpcDaTagPageReqVO; import com.iailab.module.data.channel.opcda.vo.OpcDaTagRespVO; +import com.iailab.module.data.common.enums.DataSourceType; import com.iailab.module.data.channel.tag.vo.TagImportRespVO; import com.iailab.module.data.common.exception.RRException; +import com.iailab.module.data.common.utils.TagUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -26,11 +31,13 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.util.ArrayList; import java.io.IOException; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.iailab.framework.common.pojo.CommonResult.success; @@ -47,11 +54,34 @@ @Autowired private ChannelOPCDATagService channelOPCDATagService; + @Autowired + private OpcDACollector opcDACollector; + + @Autowired + private ChannelOPCDADeviceService channelOPCDADeviceService; + @PreAuthorize("@ss.hasPermission('data:channel-opcda:query')") @GetMapping("page") public CommonResult<PageResult<OpcDaTagRespVO>> list(@Valid OpcDaTagPageReqVO reqVO) { + PageResult<ChannelOPCDATagEntity> page = channelOPCDATagService.queryPage(reqVO); - return success(BeanUtils.toBean(page, OpcDaTagRespVO.class)); + PageResult<OpcDaTagRespVO> pageResultVO = new PageResult<>(); + pageResultVO.setTotal(page.getTotal()); + + List<OpcDaTagRespVO> vos = page.getList().stream().map(entity -> { + + OpcDaTagRespVO vo = BeanUtils.toBean(entity,OpcDaTagRespVO.class); + List<String[]> tags = new ArrayList<>(); + String[] array = {reqVO.getServerId(),entity.getTagName()}; + tags.add(array); + ChannelOPCDADeviceEntity OPCDADevice = channelOPCDADeviceService.info(reqVO.getServerId()); + vo.setDataValue(Double.parseDouble(opcDACollector.getTagValues(tags).get(TagUtils.genTagId(DataSourceType.OPCDA.getCode(), OPCDADevice.getServerName(),entity.getTagName())).toString())); + return vo; + }).collect(Collectors.toList()); + + pageResultVO.setList(vos); + + return success(pageResultVO); } @PreAuthorize("@ss.hasPermission('data:channel-opcda:query')") diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/vo/OpcDaTagRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/vo/OpcDaTagRespVO.java index c4a263a..f8c0ea7 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/vo/OpcDaTagRespVO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/vo/OpcDaTagRespVO.java @@ -37,6 +37,10 @@ @ExcelProperty("是否启用") private Integer enabled; + @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("数据值") + private Double dataValue; + @Schema(description = "itemID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("itemID") private String itemId; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/controller/admin/ChannelOPCUATagController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/controller/admin/ChannelOPCUATagController.java index 365bcc2..b4f579d 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/controller/admin/ChannelOPCUATagController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/controller/admin/ChannelOPCUATagController.java @@ -7,6 +7,9 @@ import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.framework.excel.core.util.ExcelUtils; +import com.iailab.module.data.channel.opcua.collector.OpcUaCollector; +import com.iailab.framework.common.util.object.ConvertUtils; +import com.iailab.framework.excel.core.util.ExcelUtils; import com.iailab.module.data.channel.opcua.entity.ChannelOPCUATagEntity; import com.iailab.module.data.channel.opcua.service.ChannelOPCUATagService; import com.iailab.module.data.channel.opcua.vo.OpcUaTagExportExcelVO; @@ -30,6 +33,7 @@ import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.iailab.framework.common.pojo.CommonResult.success; @@ -46,11 +50,31 @@ @Resource private ChannelOPCUATagService channelOpcuaTagService; + @Resource + private OpcUaCollector opcUaCollector; + @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')") @GetMapping("page") public CommonResult<PageResult<OpcUaTagRespVO>> list(@Valid OpcUaTagPageReqVO reqVO) { + PageResult<ChannelOPCUATagEntity> page = channelOpcuaTagService.queryPage(reqVO); - return success(BeanUtils.toBean(page, OpcUaTagRespVO.class)); + PageResult<OpcUaTagRespVO> pageResultVO = new PageResult<>(); + pageResultVO.setTotal(page.getTotal()); + + List<OpcUaTagRespVO> vos = page.getList().stream().map(entity -> { + + OpcUaTagRespVO vo = BeanUtils.toBean(entity,OpcUaTagRespVO.class); + try{ + vo.setDataValue( Double.parseDouble(opcUaCollector.getTagValue(reqVO.getDeviceId(),entity.getTagName()))); + }catch (Exception e){ + e.printStackTrace(); + } + return vo; + }).collect(Collectors.toList()); + + pageResultVO.setList(vos); + + return success(pageResultVO); } @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')") diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagPageReqVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagPageReqVO.java index 4641af1..cc91622 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagPageReqVO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagPageReqVO.java @@ -20,4 +20,6 @@ private String tagName; private String device; + + private String deviceId; } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagRespVO.java index feeac98..bf91151 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagRespVO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagRespVO.java @@ -33,6 +33,10 @@ @ExcelProperty("是否启用") private Integer enabled; + @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("数据值") + private Double dataValue; + @Schema(description = "关联设备", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("关联设备") private String device; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java index 9770ce1..005363a 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java @@ -23,7 +23,7 @@ public class PointCollectTaskNet60 implements ITask { private final Logger logger = LoggerFactory.getLogger(getClass()); - private static final String NET = "1min"; + private static final String NET = "NET60"; @Resource private PointCollector pointCollector; -- Gitblit v1.9.3