diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java b/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java index b286666..7045421 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java @@ -194,28 +194,32 @@ public class ModbusMessagePersistListener implements BatchMessageListener { .ofInstant(Instant.ofEpochMilli(modbusMessage.getCollectionTime()), ZoneOffset.systemDefault()) .format(LocalDateTimeDecodeHandler.OUT_FORMATTER)); for (Map point : commandPointList) { - fieldName = MapUtil.getStr(point, "field"); - stepSize = MapUtil.getInt(point, "step_size"); - decodeName = MapUtil.getStr(point, "decode_name"); - startAddress = MapUtil.getInt(point, "start_address"); - String value; - if (StringUtils.equals(decodeName, HighLowBinDecodeHandler.NAME)) { - value = decodeHighLowCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress); - } else if (StringUtils.contains(decodeName, ",") && StringUtils.startsWith(decodeName, HighLowBinDecodeHandler.NAME)) { - value = decodeHighLowStepCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress, stepSize / 2); - } else if (stepSize <= 1) { - messagePoint = modbusMessage.getMessagePointMap() - .get(StringUtils.leftPad(String.valueOf(startAddress), 4, '0')); - if (Objects.isNull(messagePoint)) { - value = StringUtils.EMPTY; + try { + fieldName = MapUtil.getStr(point, "field"); + stepSize = MapUtil.getInt(point, "step_size"); + decodeName = MapUtil.getStr(point, "decode_name"); + startAddress = MapUtil.getInt(point, "start_address"); + String value; + if (StringUtils.equals(decodeName, HighLowBinDecodeHandler.NAME)) { + value = decodeHighLowCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress); + } else if (StringUtils.contains(decodeName, ",") && StringUtils.startsWith(decodeName, HighLowBinDecodeHandler.NAME)) { + value = decodeHighLowStepCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress, stepSize / 2); + } else if (stepSize <= 1) { + messagePoint = modbusMessage.getMessagePointMap() + .get(StringUtils.leftPad(String.valueOf(startAddress), 4, '0')); + if (Objects.isNull(messagePoint)) { + value = StringUtils.EMPTY; + } else { + decodeMessage(decodeName, point, messagePoint); + value = messagePoint.getValue(); + } } else { - decodeMessage(decodeName, point, messagePoint); - value = messagePoint.getValue(); + value = decodeStepCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress, stepSize); } - } else { - value = decodeStepCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress, stepSize); + hashOperations.put(deviceDataCacheName, fieldName, value); + } catch (Exception e) { + log.error("数据解析失败,message: {}, point: {}", JSONUtil.toJsonStr(modbusMessage), JSONUtil.toJsonStr(point), e); } - hashOperations.put(deviceDataCacheName, fieldName, value); } } diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java index 33b8777..18ba0f7 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java @@ -38,6 +38,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Objects; @Service("deviceService") @@ -74,6 +75,9 @@ public class DeviceServiceImpl extends ServiceImpl implements Map plugStatusMap = this.dictionaryService.getValueMapByType("plugStatus"); Map controlModeMap = this.dictionaryService.getValueMapByType("controlMode"); Map ctlModeMap = this.dictionaryService.getValueMapByType("ctlMode"); + Map wepsRunMode = this.dictionaryService.getValueMapByType("wepsRunMode"); + Map miWepsRunMode = this.dictionaryService.getValueMapByType("miWepsRunMode"); + Map miWepsPlugStatus = this.dictionaryService.getValueMapByType("miWepsPlugStatus"); try { for (DeviceVO deviceVO : deviceVOList) { @@ -93,6 +97,14 @@ public class DeviceServiceImpl extends ServiceImpl implements Object online = this.redisTemplate.opsForHash().get(deviceKey, "online"); deviceVO.setOnline(online == null ? "" : online.toString()); + Object plugStatus = this.redisTemplate.opsForHash().get(deviceKey, "plugStatus"); + if (plugStatus == null) { + deviceVO.setPlugStatus(""); + } else { + Dictionary plugStatus1 = plugStatusMap.get(plugStatus.toString()); + deviceVO.setPlugStatus(plugStatus1 == null ? "" : plugStatus1.getName()); + } + if (PersistenceHandler.ETC_MODBUS_TYPE.equalsIgnoreCase(deviceVO.getProduct().getCode())) { Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "solenoidValveStatus"); deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString()); @@ -115,6 +127,44 @@ public class DeviceServiceImpl extends ServiceImpl implements Dictionary runMode1 = ctlModeMap.get(runMode.toString()); deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName()); } + } else if (PersistenceHandler.WEPS_PLUG_MODBUS_TYPE.equalsIgnoreCase(deviceVO.getProduct().getCode())) { + Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "solenoidValveStatus"); + String wellStatus = ""; + if (Objects.nonNull(gas_status)) { + if (StringUtils.equals("2", gas_status.toString())) { + wellStatus = "1"; + } else if (StringUtils.equals("1", gas_status.toString())) { + wellStatus = "0"; + } + } + deviceVO.setWellStatus(wellStatus); + + Object runMode = this.redisTemplate.opsForHash().get(deviceKey, "runMode"); + if (runMode == null) { + deviceVO.setRunMode(""); + } else { + Dictionary runMode1 = wepsRunMode.get(runMode.toString()); + deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName()); + } + } else if (PersistenceHandler.MI_WEPS_PLUG_MODBUS_TYPE.equalsIgnoreCase(deviceVO.getProduct().getCode())) { + Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "currentStatus"); + deviceVO.setWellStatus(gas_status == null ? "" : Objects.equals("0", gas_status.toString()) ? "0" : "1"); + + Object runMode = this.redisTemplate.opsForHash().get(deviceKey, "produceMode"); + if (runMode == null) { + deviceVO.setRunMode(""); + } else { + Dictionary runMode1 = miWepsRunMode.get(runMode.toString()); + deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName()); + } + + plugStatus = this.redisTemplate.opsForHash().get(deviceKey, "currentStatus"); + if (plugStatus == null) { + deviceVO.setPlugStatus(""); + } else { + Dictionary plugStatus1 = miWepsPlugStatus.get(plugStatus.toString()); + deviceVO.setPlugStatus(plugStatus1 == null ? "" : plugStatus1.getName()); + } } else { Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "wellStatus"); deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString()); @@ -123,20 +173,11 @@ public class DeviceServiceImpl extends ServiceImpl implements if (runMode == null) { deviceVO.setRunMode(""); } else { - Dictionary runMode1 = runModeMap.get(runMode.toString()); + Dictionary runMode1 = miWepsRunMode.get(runMode.toString()); deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName()); } } - - Object plugStatus = this.redisTemplate.opsForHash().get(deviceKey, "plugStatus"); - if (plugStatus == null) { - deviceVO.setPlugStatus(""); - } else { - Dictionary plugStatus1 = plugStatusMap.get(plugStatus.toString()); - deviceVO.setPlugStatus(plugStatus1 == null ? "" : plugStatus1.getName()); - } - } } catch (RedisConnectionFailureException e) { this.log.error("redis连接失败,请检查redis连接"); diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java index 4af471b..ed6a5a9 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/SummaryServiceImpl.java @@ -7,16 +7,14 @@ import com.isu.gaswellwatch.vo.DeviceVO; import com.isu.gaswellwatch.vo.summary.*; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static com.isu.gaswellwatch.modbus.data.PersistenceHandler.*; @@ -63,11 +61,10 @@ public class SummaryServiceImpl implements SummaryService { List pieSummaryVOList = new ArrayList<>(); - addKNPCDeviceSummary(KNPCV1_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "KNPCV1"); + addKNPCDeviceSummary(KNPCV1_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "KNPC"); addKNPCDeviceSummary(ETC_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "ETC"); addKNPCDeviceSummary(SCSS_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "四川双晟"); - addKNPCDeviceSummary(WEPS_PLUG_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "维尔普斯"); - addKNPCDeviceSummary(MI_WEPS_PLUG_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "MI维尔普斯"); + addKNPCDeviceSummary(WEPS_PLUG_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "威尔普斯"); //计算总数 PieSummaryVO pieSummaryVO = new PieSummaryVO(); @@ -241,13 +238,13 @@ public class SummaryServiceImpl implements SummaryService { PieSummaryVO pieSummaryVO4 = new PieSummaryVO(); pieSummaryVO4.setChartName(WEPS_PLUG_MODBUS_TYPE); - pieSummaryVO4.setTitle("维尔普斯"); + pieSummaryVO4.setTitle("威尔普斯"); pieSummaryVO4.setData(List.of()); result.add(pieSummaryVO4); PieSummaryVO pieSummaryVO5 = new PieSummaryVO(); pieSummaryVO5.setChartName(MI_WEPS_PLUG_MODBUS_TYPE); - pieSummaryVO5.setTitle("MI维尔普斯"); + pieSummaryVO5.setTitle("MI威尔普斯"); pieSummaryVO5.setData(List.of()); result.add(pieSummaryVO5); @@ -256,13 +253,19 @@ public class SummaryServiceImpl implements SummaryService { private static void addKNPCDeviceSummary(String productName, Map> deviceGroup, Map onlineMap, List pieSummaryVOList, String title) { List knpcDeviceList = deviceGroup.get(productName); + if (Objects.equals(WEPS_PLUG_MODBUS_TYPE, productName)) { + if (ObjectUtils.isNotEmpty(knpcDeviceList)) { + knpcDeviceList = deviceGroup.get(MI_WEPS_PLUG_MODBUS_TYPE); + } else { + knpcDeviceList.addAll(Optional.ofNullable(deviceGroup.get(MI_WEPS_PLUG_MODBUS_TYPE)).orElse(List.of())); + } + } PieSummaryVO pieSummaryVO = new PieSummaryVO(); pieSummaryVO.setChartName(productName); pieSummaryVO.setTitle(title); - if (knpcDeviceList != null) { + if (Objects.isNull(knpcDeviceList)) { //根据设备列表查找在线map中的状态进行统计在线数量 - Integer onLineCount = 0; - Integer offLineCount = 0; + int onLineCount = 0, offLineCount = 0; for (DeviceVO deviceVO : knpcDeviceList) { if ("true".equalsIgnoreCase(onlineMap.get(deviceVO.getId().toString()))) { onLineCount++; @@ -270,9 +273,8 @@ public class SummaryServiceImpl implements SummaryService { offLineCount++; } } - PieDataVO onlinePieDataVO = new PieDataVO("在线", onLineCount); - PieDataVO offlinePieDataVO = new PieDataVO("离线", offLineCount); - pieSummaryVO.setData(List.of(onlinePieDataVO, offlinePieDataVO)); + pieSummaryVO.setData(List.of(new PieDataVO("在线", onLineCount), + new PieDataVO("离线", offLineCount))); } else { //无值时需要构建空值结构 pieSummaryVO.setData(new ArrayList<>()); diff --git a/src/main/resources/change_2020220.sql b/src/main/resources/change_2020220.sql index e7506d6..12ced64 100644 --- a/src/main/resources/change_2020220.sql +++ b/src/main/resources/change_2020220.sql @@ -1,5 +1,5 @@ INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) -VALUES (29, 'deviceProduct', 'mi_weps_plug', 'MI维尔普斯', '5', 5, now(), now()); +VALUES (29, 'deviceProduct', 'mi_weps_plug', 'MI威尔普斯', '5', 5, now(), now()); INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) VALUES (30, 'wepsRunMode', 'unknow', '未知', '0', 1, now(), now()); @@ -23,11 +23,11 @@ VALUES (38, 'miWepsRunMode', 'yldlms', '压力跌落模式', '4', 5, now(), now( INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`, `start_address`, `message_length`, `details`) VALUES (10301, 'DEVICE_PRODUCT_CODE', 29, '采集实时数据地址表', 'READ_REAL_TIME_DATA', 'COLLECTION', 30, '010300000016', - 0, 98, '(老板)维尔普斯控制器实时数据地址表'); + 0, 98, '(老板)威尔普斯控制器实时数据地址表'); INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`, `start_address`, `message_length`, `details`) VALUES (10302, 'DEVICE_PRODUCT_CODE', 29, '采集控制器参数地址表', 'READ_CONTROL_PARAM_DATA', 'COLLECTION', 30, - '010303EC0047', 1004, 294, '(老板)维尔普斯控制器参数地址表数据采集'); + '010303EC0047', 1004, 294, '(老板)威尔普斯控制器参数地址表数据采集'); INSERT INTO `command_points` (`id`, `command_id`, `field`, `name`, `details`, `start_address`, `step_size`, `factor`, @@ -230,7 +230,7 @@ SET `ref_type` = 'DEVICE_PRODUCT_CODE', `command` = '010303EC0048', `start_address` = 1004, `message_length` = 202, - `details` = '(老板)维尔普斯控制器参数地址表数据采集' + `details` = '(老板)威尔普斯控制器参数地址表数据采集' WHERE `id` = 10302; ALTER TABLE `command_points` @@ -333,7 +333,7 @@ WHERE `id` = 13104; update command_points set `precision` = 2 -where decode_name like '%IEEE754Double%'; +where decode_name like '%IEEE754Float%'; UPDATE `gas_well_watch`.`command_points` SET `command_id` = 10302, diff --git a/src/main/resources/change_20250217.sql b/src/main/resources/change_20250217.sql index 956c043..a026670 100644 --- a/src/main/resources/change_20250217.sql +++ b/src/main/resources/change_20250217.sql @@ -1,10 +1,10 @@ INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) -VALUES (28, 'deviceProduct', 'weps_plug', '维尔普斯', '4', 4, now(), now()); +VALUES (28, 'deviceProduct', 'weps_plug', '威尔普斯', '4', 4, now(), now()); INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`, `start_address`, `message_length`, `details`) VALUES (10300, 'DEVICE_PRODUCT_CODE', 28, '采集柱塞模式数据', 'READ_DATA', 'COLLECTION', 30, '010300320020', 32, 138, - '(新版)维尔普斯控制器柱塞模式数据全量采集'); + '(新版)威尔普斯控制器柱塞模式数据全量采集'); INSERT INTO `command_points` (`id`, `command_id`, `field`, `name`, `details`, `start_address`, `step_size`, `factor`, `precision`, `format`, `decode_name`) diff --git a/src/main/resources/change_202502_26.sql b/src/main/resources/change_202502_26.sql new file mode 100644 index 0000000..ed4ceb6 --- /dev/null +++ b/src/main/resources/change_202502_26.sql @@ -0,0 +1,8 @@ +INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) +VALUES (39, 'miWepsPlugStatus', 'gj', '关井', '0', 0, now(), now()); +INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) +VALUES (40, 'miWepsPlugStatus', 'ss', '上升', '1', 1, now(), now()); +INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) +VALUES (41, 'miWepsPlugStatus', 'xl', '续流', '2', 2, now(), now()); +INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) +VALUES (42, 'miWepsPlugStatus', 'tj', '停机', '3', 3, now(), now()); \ No newline at end of file diff --git a/src/main/resources/sql/CREATE_MI_WEPS_PLUG.sql b/src/main/resources/sql/CREATE_MI_WEPS_PLUG.sql index 075d85b..fcead1c 100644 --- a/src/main/resources/sql/CREATE_MI_WEPS_PLUG.sql +++ b/src/main/resources/sql/CREATE_MI_WEPS_PLUG.sql @@ -61,4 +61,4 @@ CREATE TABLE `$TableName$` `protection_pressure` decimal(12, 4) NULL DEFAULT NULL COMMENT '保护压力 - 单位:MPa', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `udx_device_create_time` (`device_id` ASC, `collection_time` ASC) USING BTREE COMMENT '设备采集数据唯一键' -) ENGINE = InnoDB COMMENT = '维尔普斯设备ID:$DeviceId$的采集数据' \ No newline at end of file +) ENGINE = InnoDB COMMENT = '威尔普斯设备ID:$DeviceId$的采集数据' \ No newline at end of file diff --git a/src/main/resources/sql/CREATE_WEPS_PLUG.sql b/src/main/resources/sql/CREATE_WEPS_PLUG.sql index 2c00452..63a54eb 100644 --- a/src/main/resources/sql/CREATE_WEPS_PLUG.sql +++ b/src/main/resources/sql/CREATE_WEPS_PLUG.sql @@ -39,4 +39,4 @@ CREATE TABLE `$TableName$` `produce_mode` int NULL DEFAULT NULL COMMENT '生产制度;1-常开;2-常关;3-柱塞气举', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `udx_device_create_time` (`device_id` ASC, `collection_time` ASC) USING BTREE COMMENT '设备采集数据唯一键' -) ENGINE = InnoDB COMMENT = '维尔普斯设备ID:$DeviceId$的采集数据' \ No newline at end of file +) ENGINE = InnoDB COMMENT = '威尔普斯设备ID:$DeviceId$的采集数据' \ No newline at end of file