From 664bb4d0b7799328667ffc47e39da711a77ddbfa Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期一, 28 八月 2023 12:05:33 +0800 Subject: [PATCH] 更新MODBUS-TCP协议,调整配置2 --- igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java | 44 ++++++++++++++------------------------------ 1 files changed, 14 insertions(+), 30 deletions(-) diff --git a/igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java b/igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java index 7652715..0f1ff64 100644 --- a/igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java +++ b/igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Component @@ -49,13 +48,26 @@ for (DeviceModbus hibDevice : listAll) { entityDevice = new DeviceModbus(); BeanUtils.copyProperties(hibDevice, entityDevice); - key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_DEVICE_CACHE, hibDevice.getDeviceCode()); + + if (null == hibDevice.getBizType()) hibDevice.setBizType(BizType.AREATION.getCode()); + if (BizType.AREATION.getCode().equals(hibDevice.getBizType())) { + key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_DEVICE_CACHE, hibDevice.getDeviceCode()); + } else { + key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_DEVICE_CACHE, hibDevice.getDeviceCode(), hibDevice.getBizType()); + } redisUtil.set(key, entityDevice); } } public DeviceModbus getCacheDeviceModbus(String companyId, String deviceCode) { + return getCacheDeviceModbus(companyId, deviceCode, null); + } + + public DeviceModbus getCacheDeviceModbus(String companyId, String deviceCode, String bizType) { String key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_DEVICE_CACHE, deviceCode); + if (null != bizType && !BizType.AREATION.equals(bizType)) { + key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_DEVICE_CACHE, deviceCode, bizType); + } return (DeviceModbus) redisUtil.get(key); } @@ -194,32 +206,6 @@ session.update(gas); } } - flushCacheGas(null); - } - - public void flushCacheGas(String companyId) { - - List<GasModbus> listAll = this.listGasModBus(null); - - if (null == listAll || listAll.isEmpty()) return; - - if (null == companyId) companyId = ContextUtil.getDefaultCompanyId(); - - - Map<String, List<GasModbus>> collect = listAll.stream().collect(Collectors.groupingBy(GasModbus::getDepotId)); - - String key; - for (String depotId : collect.keySet()) { - key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_GAS_CACHE_LIST, depotId); - redisUtil.set(key, key); - } - } - - - public List<GasModbus> getCacheGasModbus(String companyId, String depotId) { - if (null == companyId) companyId = ContextUtil.getDefaultCompanyId(); - String key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_GAS_CACHE_LIST, depotId); - return (List<GasModbus>) redisUtil.get(key); } @@ -227,8 +213,6 @@ Session session = this.getSessionFactory().openSession(); try { session.delete(data); - - flushCacheGas(null); } catch (Exception e) { } finally { session.flush(); -- Gitblit v1.9.3