iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/HttpCollector.java
对比新文件 @@ -0,0 +1,48 @@ package com.iailab.module.data.channel.http.collector; /** * @author PanZhibao * @Description * @createTime 2024年11月20日 */ import com.iailab.framework.common.constant.CommonConstant; import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; import com.iailab.module.data.channel.http.entity.HttpApiEntity; import com.iailab.module.data.channel.http.service.HttpApiService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Slf4j @Component public class HttpCollector { @Autowired private HttpApiService httpApiService; @Autowired private HttpCollectorForIhd httpCollectorForIhd; public Object getTagValue(String apiId, String tag) { HttpApiEntity httpApi = httpApiService.getFromCatch(apiId); if (httpApi == null) { return CommonConstant.BAD_VALUE; } List<String> tagNames = new ArrayList<>(); tagNames.add(tag); Map<String, Object> valueMap = new HashMap<String, Object>(); if (SourceApiEnum.iHyperDB.getCode().equals(httpApi.getCode())) { valueMap = httpCollectorForIhd.getLastValues(apiId, tagNames); } if (valueMap.get(tag) == null) { return CommonConstant.BAD_VALUE; } return valueMap.get(tag); } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/SourceApiEnum.java
对比新文件 @@ -0,0 +1,18 @@ package com.iailab.module.data.channel.http.collector; import lombok.AllArgsConstructor; import lombok.Getter; /** * @author PanZhibao * @Description * @createTime 2024年11月20日 */ @Getter @AllArgsConstructor public enum SourceApiEnum { iHyperDB("iHyperDB", "宝信IHD"); private String code; private String desc; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java
@@ -6,17 +6,11 @@ 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; @@ -47,12 +41,38 @@ @Autowired private RedisTemplate redisTemplate; @Autowired private HttpTagService httpTagService; private static final String STA_TRUE = "true"; private static final int GROUP_MAX_COUNT = 50; private static final String pattern = "yyyyMMddHHmm00"; private static final String IS_SUCCESS = "isSuccess"; /** * tagName */ private static final String N = "n"; /** * dimension */ private static final String D = "d"; /** * 类型 */ private static final String P = "p"; /** * dataValue */ private static final String V = "v"; /** * dataTime */ private static final String T = "t"; private HttpApiEntity getHttpApi(String id) { if (apiMap.containsKey(id)) { @@ -69,29 +89,30 @@ StringBuilder tagSb = new StringBuilder(); tagSb.append("["); Map<String, Object> queryParams = new HashMap<>(); queryParams.put("datatype", valueType); queryParams.put("dimension", dimension); queryParams.put("tagname", tagNo); queryParams.put(P, valueType); queryParams.put(D, dimension); queryParams.put(N, tagNo); String jsonString = JSON.toJSONString(queryParams); tagSb.append(jsonString); tagSb.append("]"); String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); String currentDate = DateUtils.format(new Date(), pattern); String responseStr = HttpRequest.sendPost(httpApi.getUrl() + "/" + currentDate, tagSb.toString()); JSONObject responseObj = JSON.parseObject(responseStr); if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { if (STA_TRUE.equals(responseObj.get(IS_SUCCESS).toString())) { JSONArray tagValueList = responseObj.getJSONArray("data"); if (!CollectionUtils.isEmpty(tagValueList)) { for (int i = 0; i < tagValueList.size(); i++) { JSONObject item = tagValueList.getJSONObject(i); value = new BigDecimal(item.get("value").toString()); value = new BigDecimal(item.get(V).toString()); } } } return value; } public Map<String, Object> getLastValues(List<String> tagNames) { public Map<String, Object> getLastValues(String sourceId, List<String> tagNames) { Map<String, Object> result = new HashMap<>(); HttpApiEntity httpApi = this.getHttpApi(sourceId); try { if (CollectionUtils.isEmpty(tagNames)) { return result; @@ -100,8 +121,8 @@ 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()); if (ops.get(V) != null) { BigDecimal value = new BigDecimal(ops.get(V).toString()); result.put(tagNames.get(i), value.setScale(3, RoundingMode.HALF_UP)); } else { noCacheTagNames.add(tagNames.get(i)); @@ -115,26 +136,26 @@ Gson gson = new Gson(); String tagSb = gson.toJson(noCacheTagNames); log.info("body=====" + tagSb); String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); String currentDate = DateUtils.format(new Date(), pattern); String responseStr = ""; responseStr = HttpRequest.sendPost("http://172.16.59.105:9082/api/IHD/getPointslast" + "/" + currentDate, tagSb); responseStr = HttpRequest.sendPost(httpApi.getUrl().replace("getPointdatasAvg", "getPointslast") + "/" + currentDate, tagSb); JSONObject responseObj = JSON.parseObject(responseStr); if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { if (STA_TRUE.equals(responseObj.get(IS_SUCCESS).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) { if (item.get(V) != null) { //存缓存 BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(item.get("tagname").toString()); ops.put("value", item.get("value").toString()); BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(item.get(V).toString()); ops.put(V, item.get(V).toString()); //设置过期时间 redisTemplate.expire(item.get("tagname").toString(), 10, TimeUnit.SECONDS); redisTemplate.expire(item.get(N).toString(), 10, TimeUnit.SECONDS); //把查询到的数据插入结果集 BigDecimal value = new BigDecimal(item.get("value").toString()); result.put(item.get("tagname").toString(), value.setScale(3, RoundingMode.HALF_UP)); BigDecimal value = new BigDecimal(item.get(V).toString()); result.put(item.get(N).toString(), value.setScale(3, RoundingMode.HALF_UP)); } else { result.put(item.get("tagname").toString(), CommonConstant.BAD_VALUE); result.put(item.get(N).toString(), CommonConstant.BAD_VALUE); } } } @@ -181,9 +202,9 @@ tagSb.append("["); for (int i = 0; i < params.size(); i++) { Map<String, Object> queryParams = new HashMap<>(); queryParams.put("tagname", params.get(i)[1]); queryParams.put("dimension", params.get(i)[2]); queryParams.put("datatype", params.get(i)[3]); queryParams.put(N, params.get(i)[1]); queryParams.put(D, params.get(i)[2]); queryParams.put(P, params.get(i)[3]); String jsonString = JSON.toJSONString(queryParams); tagSb.append(jsonString); if (i < params.size() - 1) { @@ -192,16 +213,16 @@ } tagSb.append("]"); log.info("body=====" + tagSb.toString()); String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); String currentDate = DateUtils.format(new Date(), pattern); String responseStr = HttpRequest.sendPost(httpApi.getUrl() + "/" + currentDate, tagSb.toString()); JSONObject responseObj = JSON.parseObject(responseStr); log.info("responseObj=====" + responseObj.toJSONString()); if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { if (STA_TRUE.equals(responseObj.get(IS_SUCCESS).toString())) { JSONArray tagValueList = responseObj.getJSONArray("data"); 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("tagname").toString()), item.get("value")); result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), httpApi.getCode(), item.get(N).toString()), item.get(V)); } } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/package-info.java
文件已删除 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/controller/admin/HttpTagController.java
@@ -7,7 +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.collector.HttpCollector; 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; @@ -15,6 +15,7 @@ import com.iailab.module.data.channel.tag.vo.TagExportExcelVO; import com.iailab.module.data.channel.tag.vo.TagImportExcelVO; import com.iailab.module.data.channel.tag.vo.TagImportRespVO; import com.iailab.module.data.common.enums.DataQualityEnum; import com.iailab.module.data.common.enums.IsEnableEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -29,7 +30,6 @@ import javax.validation.Valid; import java.io.IOException; 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,29 +47,19 @@ private HttpTagService tagService; @Resource private HttpCollectorForIhd httpCollectorForIhd; private HttpCollector httpCollector; @PreAuthorize("@ss.hasPermission('data:channel-http:query')") @GetMapping("page") public CommonResult<PageResult<HttpTagRespVO>> page(@Valid HttpTagPageReqVO reqVO) { PageResult<HttpTagEntity> page = tagService.queryPage(reqVO); 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); PageResult<HttpTagRespVO> pageResult = BeanUtils.toBean(page, HttpTagRespVO.class); pageResult.getList().forEach(item -> { item.setDataValue(httpCollector.getTagValue(item.getApiId(), item.getTagName())); item.setDataTime(new Date()); item.setDataQuality(DataQualityEnum.getEumByValue(item.getDataValue()).getDesc()); }); return success(pageResult); } @PreAuthorize("@ss.hasPermission('data:channel-http:query')") iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/HttpApiService.java
@@ -19,5 +19,7 @@ HttpApiEntity getByCode(String code); HttpApiEntity getFromCatch(String id); List<HttpApiEntity> list(); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/service/impl/HttpApiServiceImpl.java
@@ -11,12 +11,17 @@ import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @Service public class HttpApiServiceImpl extends ServiceImpl<HttpApiDao, HttpApiEntity> implements HttpApiService { @Resource private HttpApiDao httpApiDao; private static Map<String, HttpApiEntity> idMap = new ConcurrentHashMap<>(); @Override public PageResult<HttpApiEntity> queryPage(HttpApiPageReqVO reqVO) { @@ -49,6 +54,19 @@ } @Override public HttpApiEntity getFromCatch(String id) { if (idMap.containsKey(id)) { return idMap.get(id); } HttpApiEntity entity = httpApiDao.selectById(id); if (entity == null) { return null; } idMap.put(id, entity); return idMap.get(id); } @Override public List<HttpApiEntity> list() { return httpApiDao.selectList(new QueryWrapper<>()); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/vo/HttpTagRespVO.java
@@ -2,6 +2,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -43,7 +44,16 @@ @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据值") private Double dataValue; private Object dataValue; @Schema(description = "数据质量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据质量") private String dataQuality; @Schema(description = "数据时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date dataTime; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("创建时间") iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/controller/admin/ChannelKioTagController.java
@@ -8,8 +8,6 @@ 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; @@ -17,6 +15,7 @@ import com.iailab.module.data.channel.tag.vo.TagExportExcelVO; import com.iailab.module.data.channel.tag.vo.TagImportExcelVO; import com.iailab.module.data.channel.tag.vo.TagImportRespVO; import com.iailab.module.data.common.enums.DataQualityEnum; import com.iailab.module.data.common.enums.IsEnableEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -34,7 +33,6 @@ 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; @@ -57,25 +55,14 @@ @PreAuthorize("@ss.hasPermission('data:channel-kio:query')") @GetMapping("page") public CommonResult<PageResult<KioTagRespVO>> page(@Valid KioTagPageReqVO reqVO){ PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO); 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); PageResult<KioTagRespVO> pageResult = BeanUtils.toBean(page, KioTagRespVO.class); pageResult.getList().forEach(item -> { item.setDataValue(kingIOCollector.getTagValue(item.getDevice(), item.getTagName())); item.setDataTime(new Date()); item.setDataQuality(DataQualityEnum.getEumByValue(item.getDataValue()).getDesc()); }); return success(pageResult); } @PreAuthorize("@ss.hasPermission('data:channel-kio:query')") iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/vo/KioTagRespVO.java
@@ -2,6 +2,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -43,7 +44,16 @@ @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据值") private Double dataValue; private Object dataValue; @Schema(description = "数据质量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据质量") private String dataQuality; @Schema(description = "数据时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date dataTime; @Schema(description = "关联设备", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("关联设备") iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusTagController.java
@@ -9,13 +9,13 @@ 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; import com.iailab.module.data.channel.modbus.vo.ModBusTagImportExcelVO; import com.iailab.module.data.channel.modbus.vo.ModBusTagPageReqVO; import com.iailab.module.data.channel.modbus.vo.ModBusTagRespVO; import com.iailab.module.data.channel.tag.vo.TagImportRespVO; import com.iailab.module.data.common.enums.DataQualityEnum; import com.iailab.module.data.common.enums.IsEnableEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -28,13 +28,11 @@ 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; @@ -56,20 +54,15 @@ @GetMapping("/page") public CommonResult<PageResult<ModBusTagRespVO>> list(@Valid ModBusTagPageReqVO reqVO) { PageResult<ChannelModBusTagEntity> page = channelModbusTagService.queryPage(reqVO); 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); PageResult<ModBusTagRespVO> pageResult = BeanUtils.toBean(page, ModBusTagRespVO.class); pageResult.getList().forEach(item -> { item.setDataValue(modBusCollector.getTagValue(reqVO.getDeviceId(), item.getTagName())); item.setDataTime(new Date()); item.setDataQuality(DataQualityEnum.getEumByValue(item.getDataValue()).getDesc()); }); return success(pageResult); } /** * 根据id查询设备详情 * @@ -141,7 +134,7 @@ .build() ); // 输出 ExcelUtils.write(response, "tag导入模板.xls", "tag列表", ModBusTagImportExcelVO.class, list,true); ExcelUtils.write(response, "tag导入模板.xls", "tag列表", ModBusTagImportExcelVO.class, list, true); } @PostMapping("/import") @@ -155,6 +148,6 @@ @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport, @RequestParam("device") String device) throws Exception { List<ModBusTagImportExcelVO> list = ExcelUtils.read(file, ModBusTagImportExcelVO.class); return success(channelModbusTagService.importModBusTagList(list, updateSupport,device)); return success(channelModbusTagService.importModBusTagList(list, updateSupport, device)); } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/vo/ModBusTagRespVO.java
@@ -2,6 +2,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -64,4 +65,13 @@ @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("更新时间") private Date updateTime; @Schema(description = "数据质量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据质量") private String dataQuality; @Schema(description = "数据时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date dataTime; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/admin/ChannelOPCDATagController.java
@@ -5,22 +5,17 @@ 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.enums.IsEnableEnum; 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; @@ -32,13 +27,11 @@ 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; @@ -55,34 +48,12 @@ @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); 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); PageResult<OpcDaTagRespVO> pageResult = BeanUtils.toBean(page, OpcDaTagRespVO.class); return success(pageResult); } @PreAuthorize("@ss.hasPermission('data:channel-opcda:query')") iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/vo/OpcDaTagRespVO.java
@@ -2,6 +2,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -52,4 +53,13 @@ @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("更新时间") private Date updateTime; @Schema(description = "数据质量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据质量") private String dataQuality; @Schema(description = "数据时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date dataTime; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/controller/admin/ChannelOPCUATagController.java
@@ -8,8 +8,6 @@ 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; @@ -17,6 +15,7 @@ import com.iailab.module.data.channel.opcua.vo.OpcUaTagPageReqVO; import com.iailab.module.data.channel.opcua.vo.OpcUaTagRespVO; import com.iailab.module.data.channel.tag.vo.TagImportRespVO; import com.iailab.module.data.common.enums.DataQualityEnum; import com.iailab.module.data.common.enums.IsEnableEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -34,13 +33,13 @@ 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; /** * 操作opcua tag配置 * * @author lirm * @Description * @createTime 2024年08月26日 @@ -57,25 +56,14 @@ @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')") @GetMapping("page") public CommonResult<PageResult<OpcUaTagRespVO>> list(@Valid OpcUaTagPageReqVO reqVO) { PageResult<ChannelOPCUATagEntity> page = channelOpcuaTagService.queryPage(reqVO); 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); PageResult<OpcUaTagRespVO> pageResult = BeanUtils.toBean(page, OpcUaTagRespVO.class); pageResult.getList().forEach(item -> { item.setDataValue(opcUaCollector.getTagValue(reqVO.getDeviceId(), item.getTagName())); item.setDataTime(new Date()); item.setDataQuality(DataQualityEnum.getEumByValue(item.getDataValue()).getDesc()); }); return success(pageResult); } @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')") @@ -130,7 +118,7 @@ .build() ); // 输出 ExcelUtils.write(response, "tag导入模板.xls", "tag列表", OpcUaTagImportExcelVO.class, list,true); ExcelUtils.write(response, "tag导入模板.xls", "tag列表", OpcUaTagImportExcelVO.class, list, true); } @PostMapping("/import") @@ -144,6 +132,6 @@ @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport, @RequestParam("device") String device) throws Exception { List<OpcUaTagImportExcelVO> list = ExcelUtils.read(file, OpcUaTagImportExcelVO.class); return success(channelOpcuaTagService.importOpcUaTagList(list, updateSupport,device)); return success(channelOpcuaTagService.importOpcUaTagList(list, updateSupport, device)); } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/vo/OpcUaTagRespVO.java
@@ -2,6 +2,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -35,7 +36,16 @@ @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据值") private Double dataValue; private Object dataValue; @Schema(description = "数据质量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据质量") private String dataQuality; @Schema(description = "数据时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("数据时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date dataTime; @Schema(description = "关联设备", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("关联设备") iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/CommonConstant.java
@@ -14,5 +14,6 @@ BigDecimal ZERO_VALUE = new BigDecimal("0"); // 宝信IHD String iHyperDB = "iHyperDB"; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/DataQualityEnum.java
对比新文件 @@ -0,0 +1,37 @@ package com.iailab.module.data.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; import java.math.BigDecimal; /** * @author PanZhibao * @Description * @createTime 2024年11月20日 */ @Getter @AllArgsConstructor public enum DataQualityEnum { GOOD("Good", "Good"), BAD("Bad", "Bad"); private String code; private String desc; public static DataQualityEnum getEumByValue(Object value) { if (value == null) { return BAD; } else if (value instanceof Number) { if (new BigDecimal(((Number) value).doubleValue()).compareTo(CommonConstant.BAD_VALUE) == 0) { return BAD; } } else if (value instanceof String) { if (value.toString().equals(CommonConstant.BAD_VALUE.toString())) { return BAD; } } return GOOD; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -1,5 +1,6 @@ package com.iailab.module.data.point.collection.handler; import com.iailab.module.data.channel.http.collector.SourceApiEnum; import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; import com.iailab.module.data.channel.opcda.collector.OpcDACollector; import com.iailab.module.data.common.enums.CommonConstant; @@ -81,7 +82,7 @@ } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) { kioTagIds.add(new String[]{item.getSourceId(), item.getTagNo()}); } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) { if (CommonConstant.iHyperDB.equals(item.getSourceName())) { if (SourceApiEnum.iHyperDB.getCode().equals(item.getSourceName())) { httpTagIhd.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()}); } }