diff --git a/tzipc-server/tzipc-common/src/main/java/com/inspur/common/constant/CacheConstants.java b/tzipc-server/tzipc-common/src/main/java/com/inspur/common/constant/CacheConstants.java index ee2e294..29ca2a2 100644 --- a/tzipc-server/tzipc-common/src/main/java/com/inspur/common/constant/CacheConstants.java +++ b/tzipc-server/tzipc-common/src/main/java/com/inspur/common/constant/CacheConstants.java @@ -52,6 +52,11 @@ public class CacheConstants */ public static final String PLC_MONITOR_PARAMS_KEY = "plc_monitor_params"; + /** + * plc监测参数读取用 redis key + */ + public static final String PLC_MONITOR_PARAMS_READ_KEY = "plc_monitor_params_read"; + /** * 传感器监测参数 redis key */ diff --git a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java index fb17ff8..b1ab067 100644 --- a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java +++ b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java @@ -16,6 +16,7 @@ import com.inspur.ipc.utils.IpcConstant; import com.inspur.ipc.utils.IpcUtil; import com.inspur.system.service.influx.InfluxDBService; import com.serotonin.modbus4j.BatchRead; +import com.serotonin.modbus4j.BatchResults; import com.serotonin.modbus4j.ModbusMaster; import com.serotonin.modbus4j.code.DataType; import com.serotonin.modbus4j.locator.BaseLocator; @@ -47,75 +48,46 @@ public class IPCPlcDataSyncThread implements Runnable { IIpcAlarmRulesConfigService iIpcAlarmRulesConfigService = SpringUtils.getBean(IIpcAlarmRulesConfigService.class); InfluxDBService i = SpringUtils.getBean(InfluxDBService.class); IIpcRunningStatusRecordService iIpcRunningStatusRecordService = SpringUtils.getBean(IIpcRunningStatusRecordService.class); - /* BatchRead batch = new BatchRead(); - batch.addLocator(0, BaseLocator.holdingRegister(1, 0, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 进油压力,float - batch.addLocator(1, BaseLocator.holdingRegister(1, 2, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 进油油液温度,float - batch.addLocator(2, BaseLocator.holdingRegister(1, 4, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 回油油液温度,float - batch.addLocator(3, BaseLocator.holdingRegister(1, 6, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 油水监测,float - batch.addLocator(4, BaseLocator.holdingRegister(1, 8, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 油液粘度,float - batch.addLocator(5, BaseLocator.holdingRegister(1, 10, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 力传感器,float - batch.addLocator(6, BaseLocator.holdingRegister(1, 12, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 速度传感器,float - batch.addLocator(7, BaseLocator.holdingRegister(1, 14, DataType.FOUR_BYTE_FLOAT_SWAPPED));// X1轴位置传感器一,float - batch.addLocator(8, BaseLocator.holdingRegister(1, 16, DataType.FOUR_BYTE_FLOAT_SWAPPED));// X2轴位置传感器二,float - batch.addLocator(9, BaseLocator.holdingRegister(1, 18, DataType.FOUR_BYTE_FLOAT_SWAPPED));// Y1轴位置传感器三,float - batch.addLocator(10, BaseLocator.holdingRegister(1, 20, DataType.FOUR_BYTE_FLOAT_SWAPPED));// Y2轴位置传感器四,float - batch.addLocator(11, BaseLocator.holdingRegister(1, 22, DataType.FOUR_BYTE_FLOAT_SWAPPED));// Z轴位置传感器五,float - batch.addLocator(12, BaseLocator.holdingRegister(1, 24, DataType.FOUR_BYTE_FLOAT_SWAPPED));// 油液密度,float - batch.addLocator(13, BaseLocator.holdingRegister(1, 26, DataType.TWO_BYTE_INT_UNSIGNED));// 颗粒度4um,int - batch.addLocator(14, BaseLocator.holdingRegister(1, 27, DataType.TWO_BYTE_INT_UNSIGNED));// 颗粒度6um,int - batch.addLocator(15, BaseLocator.holdingRegister(1, 28, DataType.TWO_BYTE_INT_UNSIGNED));// 颗粒度14um,int - batch.addLocator(16, BaseLocator.holdingRegister(1, 29, DataType.TWO_BYTE_INT_UNSIGNED));// 颗粒度21um,int - batch.setContiguousRequests(false); - BatchResults results = master.send(batch);*/ // 获取运行状态,不一致则新增运行状态 String status = iIpcRunningStatusRecordService.selectLatestStatus(); String sss = iIpcRunningStatusRecordService.getSSS(); - if(sss==null){sss=IpcConstant.RUNNING_STATUS_SHUTDOWN;} + if (sss == null) { + sss = IpcConstant.RUNNING_STATUS_SHUTDOWN; + } if (StringUtils.isNull(status) || !status.equals(sss)) { status = sss; iIpcRunningStatusRecordService.insertIpcRunningStatusRecord(new IpcRunningStatusRecord(status)); - System.out.println("状态更新"+status); + System.out.println("状态更新" + status); } // 如果不是停机数据,进行处理 if (!IpcConstant.RUNNING_STATUS_SHUTDOWN.equals(status)) { - // 温压数据 + // 缓存取数据 List partList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.MONITOR_PART_KEY); - List plcList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_KEY); + List plcList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_READ_KEY); + // modbus批量取数 +// BatchRead batch = new BatchRead(); +// for (IpcMonitorField plcParams : plcList) { +// batch.addLocator(plcParams.getSourceField(), BaseLocator.holdingRegister(1, plcParams.getOffset(), DataType.FOUR_BYTE_FLOAT_SWAPPED)); +// } +// batch.setContiguousRequests(false); +// BatchResults results = master.send(batch); + // 将数据与字段匹配 + for (IpcMonitorField plcParams : plcList) { + if (plcParams.getFieldValue().equals("rstatus")) { + plcParams.setData(status); + } else { + plcParams.setData(Math.random()); + } +// plcParams.setData(results.getValue(plcParams.getSourceField())); + } + // 报警数据列表 List alarmRecordList = new ArrayList<>(); - // 字典数据列表集合 + // 遍历监测部位 for (IpcMonitorField part : partList) { + // 根据监测部位获取参数 + Map fields = plcList.stream().filter(ipcMonitorField -> part.getFieldCode().equals(ipcMonitorField.getParentCode())).collect(Collectors.toMap(IpcMonitorField::getFieldValue, IpcMonitorField::getData));; Map tags = new TreeMap(); tags.put("part", part.getFieldValue()); - Map fields = new TreeMap(); - for (IpcMonitorField field : plcList) { - // 可以配置源字段,获取时通过源字段获取数据 - // field.getSourceField() - if(field.getFieldValue().equals("rstatus")){ - fields.put(field.getFieldValue(), status); - }else{ - fields.put(field.getFieldValue(), Math.random()); - } - } -// //颗粒度4μm -// fields.put("pz4", (float) 0 + Math.random()); -// //颗粒度6μm -// fields.put("pz6", (float) 0 + Math.random()); -// //颗粒度14μm -// fields.put("pz14", (float) 0 + Math.random()); -// //颗粒度21μm -// fields.put("pz21", (float) 0 + Math.random()); -// //油水含量 -// fields.put("owc", (float) 0 + Math.random()); -// //油品粘度 -// fields.put("ov", (float) 0 + Math.random()); -// //回油温度 -// fields.put("rot", (float) 0 + Math.random()); -// //进油压力 -// fields.put("oip", (float) 0 + Math.random()); -// //油液密度 -// fields.put("od", (float) 0 + Math.random()); -// // 运行状态 -// fields.put("rstatus", (float) 0 + Math.random()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); String format = simpleDateFormat.format(new Date()); fields.put("insertTime", format); diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcMonitorField.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcMonitorField.java index 1020a35..8580d61 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcMonitorField.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcMonitorField.java @@ -11,102 +11,128 @@ import org.apache.commons.lang3.builder.ToStringStyle; * @author inspur * @date 2024-03-30 */ -public class IpcMonitorField extends BaseEntity -{ +public class IpcMonitorField extends BaseEntity { private static final long serialVersionUID = 1L; - /** 字段编码 */ + /** + * 字段编码 + */ private Long fieldCode; - /** 字段排序 */ + /** + * 父级编码 + */ + private Long parentCode; + + /** + * 字段排序 + */ @Excel(name = "字段排序") private Integer fieldSort; - /** 字段描述 */ + /** + * 字段描述 + */ @Excel(name = "字段描述") private String fieldLabel; - /** 字段名 */ + /** + * 字段名 + */ @Excel(name = "字段名") private String fieldValue; - /** 字段类型 */ + /** + * 字段类型 + */ @Excel(name = "字段类型") private String fieldType; - /** 源字段 */ + /** + * 数据位置 + */ + private Integer offset; + + /** + * 数据类型 + */ + private String dataType; + + /** + * 数据 + */ + private Object data; + /** + * 源字段 + */ @Excel(name = "源字段") private String sourceField; - /** 单位 */ + /** + * 单位 + */ @Excel(name = "单位") private String unit; - /** 状态(0正常 1停用) */ + /** + * 状态(0正常 1停用) + */ @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private String status; - public void setFieldCode(Long fieldCode) - { + public void setFieldCode(Long fieldCode) { this.fieldCode = fieldCode; } - public Long getFieldCode() - { + public Long getFieldCode() { return fieldCode; } - public void setFieldSort(Integer fieldSort) - { + + public void setFieldSort(Integer fieldSort) { this.fieldSort = fieldSort; } - public Integer getFieldSort() - { + public Integer getFieldSort() { return fieldSort; } - public void setFieldLabel(String fieldLabel) - { + + public void setFieldLabel(String fieldLabel) { this.fieldLabel = fieldLabel; } - public String getFieldLabel() - { + public String getFieldLabel() { return fieldLabel; } - public void setFieldValue(String fieldValue) - { + + public void setFieldValue(String fieldValue) { this.fieldValue = fieldValue; } - public String getFieldValue() - { + public String getFieldValue() { return fieldValue; } - public void setFieldType(String fieldType) - { + + public void setFieldType(String fieldType) { this.fieldType = fieldType; } - public String getFieldType() - { + public String getFieldType() { return fieldType; } - public void setSourceField(String sourceField) - { + + public void setSourceField(String sourceField) { this.sourceField = sourceField; } - public String getSourceField() - { + public String getSourceField() { return sourceField; } - public void setStatus(String status) - { + + public void setStatus(String status) { this.status = status; } - public String getStatus() - { + public String getStatus() { return status; } @@ -118,21 +144,57 @@ public class IpcMonitorField extends BaseEntity this.unit = unit; } + public Long getParentCode() { + return parentCode; + } + + public void setParentCode(Long parentCode) { + this.parentCode = parentCode; + } + + public Integer getOffset() { + return offset; + } + + public void setOffset(Integer offset) { + this.offset = offset; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - .append("fieldCode", getFieldCode()) - .append("fieldSort", getFieldSort()) - .append("fieldLabel", getFieldLabel()) - .append("fieldValue", getFieldValue()) - .append("fieldType", getFieldType()) - .append("sourceField", getSourceField()) - .append("status", getStatus()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .toString(); + .append("fieldCode", getFieldCode()) + .append("parentCode", getParentCode()) + .append("data", getData()) + .append("offset", getOffset()) + .append("dataType", getDataType()) + .append("fieldSort", getFieldSort()) + .append("fieldLabel", getFieldLabel()) + .append("fieldValue", getFieldValue()) + .append("fieldType", getFieldType()) + .append("sourceField", getSourceField()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); } } diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java index 39c0dea..4170e90 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java @@ -29,6 +29,7 @@ public class IpcRedisCacheConfiguration { iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.MONITOR_PART_KEY); iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.SENSOR_MONITOR_PARAMS_KEY); iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_KEY); + iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_READ_KEY); iIpcAlarmRulesConfigService.updateRedisCache(); iIpcRunningStatusRecordService.selectLatestStatus(); } diff --git a/tzipc-server/tzipc-system/src/main/resources/mapper/ipc/IpcMonitorFieldMapper.xml b/tzipc-server/tzipc-system/src/main/resources/mapper/ipc/IpcMonitorFieldMapper.xml index 30a0e3b..102454e 100644 --- a/tzipc-server/tzipc-system/src/main/resources/mapper/ipc/IpcMonitorFieldMapper.xml +++ b/tzipc-server/tzipc-system/src/main/resources/mapper/ipc/IpcMonitorFieldMapper.xml @@ -6,10 +6,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -21,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select field_code, field_sort, field_label, field_value, field_type, source_field,unit, status, create_by, create_time, update_by, update_time, remark from ipc_monitor_field + select field_code,parent_code, field_sort, field_label, field_value, field_type,offset,data_type, source_field,unit, status, create_by, create_time, update_by, update_time, remark from ipc_monitor_field