威尔普斯名称修改;统计查询修改

This commit is contained in:
wangshilong 2025-02-26 20:52:36 +08:00
parent 2b4bd351b7
commit 1a82fdd52d
8 changed files with 108 additions and 53 deletions

View File

@ -194,6 +194,7 @@ public class ModbusMessagePersistListener implements BatchMessageListener {
.ofInstant(Instant.ofEpochMilli(modbusMessage.getCollectionTime()), ZoneOffset.systemDefault()) .ofInstant(Instant.ofEpochMilli(modbusMessage.getCollectionTime()), ZoneOffset.systemDefault())
.format(LocalDateTimeDecodeHandler.OUT_FORMATTER)); .format(LocalDateTimeDecodeHandler.OUT_FORMATTER));
for (Map<String, Object> point : commandPointList) { for (Map<String, Object> point : commandPointList) {
try {
fieldName = MapUtil.getStr(point, "field"); fieldName = MapUtil.getStr(point, "field");
stepSize = MapUtil.getInt(point, "step_size"); stepSize = MapUtil.getInt(point, "step_size");
decodeName = MapUtil.getStr(point, "decode_name"); decodeName = MapUtil.getStr(point, "decode_name");
@ -216,6 +217,9 @@ public class ModbusMessagePersistListener implements BatchMessageListener {
value = decodeStepCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress, stepSize); value = decodeStepCommandPoint(modbusMessage.getMessagePointMap(), decodeName, point, startAddress, stepSize);
} }
hashOperations.put(deviceDataCacheName, fieldName, value); hashOperations.put(deviceDataCacheName, fieldName, value);
} catch (Exception e) {
log.error("数据解析失败message: {}, point: {}", JSONUtil.toJsonStr(modbusMessage), JSONUtil.toJsonStr(point), e);
}
} }
} }

View File

@ -38,6 +38,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
@Service("deviceService") @Service("deviceService")
@ -74,6 +75,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
Map<String, Dictionary> plugStatusMap = this.dictionaryService.getValueMapByType("plugStatus"); Map<String, Dictionary> plugStatusMap = this.dictionaryService.getValueMapByType("plugStatus");
Map<String, Dictionary> controlModeMap = this.dictionaryService.getValueMapByType("controlMode"); Map<String, Dictionary> controlModeMap = this.dictionaryService.getValueMapByType("controlMode");
Map<String, Dictionary> ctlModeMap = this.dictionaryService.getValueMapByType("ctlMode"); Map<String, Dictionary> ctlModeMap = this.dictionaryService.getValueMapByType("ctlMode");
Map<String, Dictionary> wepsRunMode = this.dictionaryService.getValueMapByType("wepsRunMode");
Map<String, Dictionary> miWepsRunMode = this.dictionaryService.getValueMapByType("miWepsRunMode");
Map<String, Dictionary> miWepsPlugStatus = this.dictionaryService.getValueMapByType("miWepsPlugStatus");
try { try {
for (DeviceVO deviceVO : deviceVOList) { for (DeviceVO deviceVO : deviceVOList) {
@ -93,6 +97,14 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
Object online = this.redisTemplate.opsForHash().get(deviceKey, "online"); Object online = this.redisTemplate.opsForHash().get(deviceKey, "online");
deviceVO.setOnline(online == null ? "" : online.toString()); 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())) { if (PersistenceHandler.ETC_MODBUS_TYPE.equalsIgnoreCase(deviceVO.getProduct().getCode())) {
Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "solenoidValveStatus"); Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "solenoidValveStatus");
deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString()); deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString());
@ -115,6 +127,44 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
Dictionary runMode1 = ctlModeMap.get(runMode.toString()); Dictionary runMode1 = ctlModeMap.get(runMode.toString());
deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName()); 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 { } else {
Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "wellStatus"); Object gas_status = this.redisTemplate.opsForHash().get(deviceKey, "wellStatus");
deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString()); deviceVO.setWellStatus(gas_status == null ? "" : gas_status.toString());
@ -123,20 +173,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
if (runMode == null) { if (runMode == null) {
deviceVO.setRunMode(""); deviceVO.setRunMode("");
} else { } else {
Dictionary runMode1 = runModeMap.get(runMode.toString()); Dictionary runMode1 = miWepsRunMode.get(runMode.toString());
deviceVO.setRunMode(runMode1 == null ? "" : runMode1.getName()); 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) { } catch (RedisConnectionFailureException e) {
this.log.error("redis连接失败请检查redis连接"); this.log.error("redis连接失败请检查redis连接");

View File

@ -7,16 +7,14 @@ import com.isu.gaswellwatch.vo.DeviceVO;
import com.isu.gaswellwatch.vo.summary.*; import com.isu.gaswellwatch.vo.summary.*;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.isu.gaswellwatch.modbus.data.PersistenceHandler.*; import static com.isu.gaswellwatch.modbus.data.PersistenceHandler.*;
@ -63,11 +61,10 @@ public class SummaryServiceImpl implements SummaryService {
List<PieSummaryVO> pieSummaryVOList = new ArrayList<>(); List<PieSummaryVO> 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(ETC_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "ETC");
addKNPCDeviceSummary(SCSS_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "四川双晟"); addKNPCDeviceSummary(SCSS_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "四川双晟");
addKNPCDeviceSummary(WEPS_PLUG_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "维尔普斯"); addKNPCDeviceSummary(WEPS_PLUG_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "威尔普斯");
addKNPCDeviceSummary(MI_WEPS_PLUG_MODBUS_TYPE, deviceGroup, onlineMap, pieSummaryVOList, "MI维尔普斯");
//计算总数 //计算总数
PieSummaryVO pieSummaryVO = new PieSummaryVO(); PieSummaryVO pieSummaryVO = new PieSummaryVO();
@ -241,13 +238,13 @@ public class SummaryServiceImpl implements SummaryService {
PieSummaryVO pieSummaryVO4 = new PieSummaryVO(); PieSummaryVO pieSummaryVO4 = new PieSummaryVO();
pieSummaryVO4.setChartName(WEPS_PLUG_MODBUS_TYPE); pieSummaryVO4.setChartName(WEPS_PLUG_MODBUS_TYPE);
pieSummaryVO4.setTitle("尔普斯"); pieSummaryVO4.setTitle("尔普斯");
pieSummaryVO4.setData(List.of()); pieSummaryVO4.setData(List.of());
result.add(pieSummaryVO4); result.add(pieSummaryVO4);
PieSummaryVO pieSummaryVO5 = new PieSummaryVO(); PieSummaryVO pieSummaryVO5 = new PieSummaryVO();
pieSummaryVO5.setChartName(MI_WEPS_PLUG_MODBUS_TYPE); pieSummaryVO5.setChartName(MI_WEPS_PLUG_MODBUS_TYPE);
pieSummaryVO5.setTitle("MI尔普斯"); pieSummaryVO5.setTitle("MI尔普斯");
pieSummaryVO5.setData(List.of()); pieSummaryVO5.setData(List.of());
result.add(pieSummaryVO5); result.add(pieSummaryVO5);
@ -256,13 +253,19 @@ public class SummaryServiceImpl implements SummaryService {
private static void addKNPCDeviceSummary(String productName, Map<String, List<DeviceVO>> deviceGroup, Map<String, String> onlineMap, List<PieSummaryVO> pieSummaryVOList, String title) { private static void addKNPCDeviceSummary(String productName, Map<String, List<DeviceVO>> deviceGroup, Map<String, String> onlineMap, List<PieSummaryVO> pieSummaryVOList, String title) {
List<DeviceVO> knpcDeviceList = deviceGroup.get(productName); List<DeviceVO> 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 pieSummaryVO = new PieSummaryVO();
pieSummaryVO.setChartName(productName); pieSummaryVO.setChartName(productName);
pieSummaryVO.setTitle(title); pieSummaryVO.setTitle(title);
if (knpcDeviceList != null) { if (Objects.isNull(knpcDeviceList)) {
//根据设备列表查找在线map中的状态进行统计在线数量 //根据设备列表查找在线map中的状态进行统计在线数量
Integer onLineCount = 0; int onLineCount = 0, offLineCount = 0;
Integer offLineCount = 0;
for (DeviceVO deviceVO : knpcDeviceList) { for (DeviceVO deviceVO : knpcDeviceList) {
if ("true".equalsIgnoreCase(onlineMap.get(deviceVO.getId().toString()))) { if ("true".equalsIgnoreCase(onlineMap.get(deviceVO.getId().toString()))) {
onLineCount++; onLineCount++;
@ -270,9 +273,8 @@ public class SummaryServiceImpl implements SummaryService {
offLineCount++; offLineCount++;
} }
} }
PieDataVO onlinePieDataVO = new PieDataVO("在线", onLineCount); pieSummaryVO.setData(List.of(new PieDataVO("在线", onLineCount),
PieDataVO offlinePieDataVO = new PieDataVO("离线", offLineCount); new PieDataVO("离线", offLineCount)));
pieSummaryVO.setData(List.of(onlinePieDataVO, offlinePieDataVO));
} else { } else {
//无值时需要构建空值结构 //无值时需要构建空值结构
pieSummaryVO.setData(new ArrayList<>()); pieSummaryVO.setData(new ArrayList<>());

View File

@ -1,5 +1,5 @@
INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) 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`) INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`)
VALUES (30, 'wepsRunMode', 'unknow', '未知', '0', 1, now(), now()); 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`, INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`,
`start_address`, `message_length`, `details`) `start_address`, `message_length`, `details`)
VALUES (10301, 'DEVICE_PRODUCT_CODE', 29, '采集实时数据地址表', 'READ_REAL_TIME_DATA', 'COLLECTION', 30, '010300000016', 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`, INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`,
`start_address`, `message_length`, `details`) `start_address`, `message_length`, `details`)
VALUES (10302, 'DEVICE_PRODUCT_CODE', 29, '采集控制器参数地址表', 'READ_CONTROL_PARAM_DATA', 'COLLECTION', 30, 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`, 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', `command` = '010303EC0048',
`start_address` = 1004, `start_address` = 1004,
`message_length` = 202, `message_length` = 202,
`details` = '(老板)尔普斯控制器参数地址表数据采集' `details` = '(老板)尔普斯控制器参数地址表数据采集'
WHERE `id` = 10302; WHERE `id` = 10302;
ALTER TABLE `command_points` ALTER TABLE `command_points`
@ -333,7 +333,7 @@ WHERE `id` = 13104;
update command_points update command_points
set `precision` = 2 set `precision` = 2
where decode_name like '%IEEE754Double%'; where decode_name like '%IEEE754Float%';
UPDATE `gas_well_watch`.`command_points` UPDATE `gas_well_watch`.`command_points`
SET `command_id` = 10302, SET `command_id` = 10302,

View File

@ -1,10 +1,10 @@
INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) 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`, INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`,
`start_address`, `message_length`, `details`) `start_address`, `message_length`, `details`)
VALUES (10300, 'DEVICE_PRODUCT_CODE', 28, '采集柱塞模式数据', 'READ_DATA', 'COLLECTION', 30, '010300320020', 32, 138, 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`, INSERT INTO `command_points` (`id`, `command_id`, `field`, `name`, `details`, `start_address`, `step_size`, `factor`,
`precision`, `format`, `decode_name`) `precision`, `format`, `decode_name`)

View File

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

View File

@ -61,4 +61,4 @@ CREATE TABLE `$TableName$`
`protection_pressure` decimal(12, 4) NULL DEFAULT NULL COMMENT '保护压力 - 单位MPa', `protection_pressure` decimal(12, 4) NULL DEFAULT NULL COMMENT '保护压力 - 单位MPa',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `udx_device_create_time` (`device_id` ASC, `collection_time` ASC) USING BTREE COMMENT '设备采集数据唯一键' UNIQUE INDEX `udx_device_create_time` (`device_id` ASC, `collection_time` ASC) USING BTREE COMMENT '设备采集数据唯一键'
) ENGINE = InnoDB COMMENT = '尔普斯设备ID$DeviceId$的采集数据' ) ENGINE = InnoDB COMMENT = '尔普斯设备ID$DeviceId$的采集数据'

View File

@ -39,4 +39,4 @@ CREATE TABLE `$TableName$`
`produce_mode` int NULL DEFAULT NULL COMMENT '生产制度1-常开2-常关3-柱塞气举', `produce_mode` int NULL DEFAULT NULL COMMENT '生产制度1-常开2-常关3-柱塞气举',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `udx_device_create_time` (`device_id` ASC, `collection_time` ASC) USING BTREE COMMENT '设备采集数据唯一键' UNIQUE INDEX `udx_device_create_time` (`device_id` ASC, `collection_time` ASC) USING BTREE COMMENT '设备采集数据唯一键'
) ENGINE = InnoDB COMMENT = '尔普斯设备ID$DeviceId$的采集数据' ) ENGINE = InnoDB COMMENT = '尔普斯设备ID$DeviceId$的采集数据'