首页传动侧/操作侧取值错位+plc实时数据读取修改

This commit is contained in:
zhanghan11 2024-04-12 14:45:16 +08:00
parent 7e3e34e2b9
commit 808dcd6e49
7 changed files with 162 additions and 119 deletions

View File

@ -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
*/

View File

@ -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,30 +48,12 @@ public class IPCPlcDataSyncThread implements Runnable {
IIpcAlarmRulesConfigService iIpcAlarmRulesConfigService = SpringUtils.getBean(IIpcAlarmRulesConfigService.class);
InfluxDBService i = SpringUtils.getBean(InfluxDBService.class);
IIpcRunningStatusRecordService iIpcRunningStatusRecordService = SpringUtils.getBean(IIpcRunningStatusRecordService.class);
/* BatchRead<Integer> batch = new BatchRead<Integer>();
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<Integer> 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));
@ -78,44 +61,33 @@ public class IPCPlcDataSyncThread implements Runnable {
}
// 如果不是停机数据进行处理
if (!IpcConstant.RUNNING_STATUS_SHUTDOWN.equals(status)) {
// 温压数据
// 缓存取数据
List<IpcMonitorField> partList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.MONITOR_PART_KEY);
List<IpcMonitorField> plcList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_KEY);
List<IpcMonitorField> plcList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_READ_KEY);
// modbus批量取数
// BatchRead<String> batch = new BatchRead<String>();
// for (IpcMonitorField plcParams : plcList) {
// batch.addLocator(plcParams.getSourceField(), BaseLocator.holdingRegister(1, plcParams.getOffset(), DataType.FOUR_BYTE_FLOAT_SWAPPED));
// }
// batch.setContiguousRequests(false);
// BatchResults<String> 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<IpcAlarmRecord> alarmRecordList = new ArrayList<>();
// 字典数据列表集合
// 遍历监测部位
for (IpcMonitorField part : partList) {
// 根据监测部位获取参数
Map<String, Object> fields = plcList.stream().filter(ipcMonitorField -> part.getFieldCode().equals(ipcMonitorField.getParentCode())).collect(Collectors.toMap(IpcMonitorField::getFieldValue, IpcMonitorField::getData));;
Map<String, String> tags = new TreeMap();
tags.put("part", part.getFieldValue());
Map<String, Object> 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);

View File

@ -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,10 +144,46 @@ 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("parentCode", getParentCode())
.append("data", getData())
.append("offset", getOffset())
.append("dataType", getDataType())
.append("fieldSort", getFieldSort())
.append("fieldLabel", getFieldLabel())
.append("fieldValue", getFieldValue())

View File

@ -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();
}

View File

@ -6,10 +6,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="IpcMonitorField" id="IpcMonitorFieldResult">
<result property="fieldCode" column="field_code" />
<result property="parentCode" column="parent_code" />
<result property="fieldSort" column="field_sort" />
<result property="fieldLabel" column="field_label" />
<result property="fieldValue" column="field_value" />
<result property="fieldType" column="field_type" />
<result property="offset" column="offset" />
<result property="dataType" column="data_type" />
<result property="sourceField" column="source_field" />
<result property="unit" column="unit" />
<result property="status" column="status" />
@ -21,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectIpcMonitorFieldVo">
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
</sql>
<select id="selectIpcMonitorFieldList" parameterType="IpcMonitorField" resultMap="IpcMonitorFieldResult">

View File

@ -642,15 +642,16 @@ export default {
initData(params = []) {
this.getDataResponse(params).then(({ data }) => {
const { drive, operation } = data;
//
if (drive) {
const { vx, vy, vz } = drive;
//
if (operation) {
const { vx, vy, vz } = operation;
this.initChart2(this.xSensorData, vx, vy, vz);
const { xPlcData, pz4, pz6, pz14, pz21 } = drive;
const { xPlcData, pz4, pz6, pz14, pz21 } = operation;
this.initChart4(xPlcData, pz4, pz6, pz14, pz21);
const { pzAlarmStr, otherAlarmStr, ssat, rot, oip, ov, owc } = drive;
const { pzAlarmStr, otherAlarmStr, ssat, rot, oip, ov, owc } =
operation;
this.initBottomR1(oip);
this.initBottomR2(ov);
@ -662,16 +663,15 @@ export default {
this.rtAlarmStr = pzAlarmStr;
this.rbAlarmStr = otherAlarmStr;
}
//
if (operation) {
const { vx, vy, vz } = operation;
//
if (drive) {
const { vx, vy, vz } = drive;
this.initChart1(this.xSensorData, vx, vy, vz);
const { xPlcData, pz4, pz6, pz14, pz21 } = operation;
const { xPlcData, pz4, pz6, pz14, pz21 } = drive;
this.initChart3(xPlcData, pz4, pz6, pz14, pz21);
const { pzAlarmStr, otherAlarmStr, owc, ov, oip, rot, ssat } =
operation;
const { pzAlarmStr, otherAlarmStr, owc, ov, oip, rot, ssat } = drive;
this.initBottomL1(owc);
this.initBottomL2(ov);
this.initBottomL3(oip);

View File

@ -206,7 +206,7 @@ import { getFields } from "@/api/ipc/monitorFields";
export default {
name: "plcDataLog",
dicts: ["is_alarm"],
dicts: ["is_alarm", "running_status"],
data() {
return {
//