From 6b1c7e3fa773aa75ea34b346d4104ba70064f52c Mon Sep 17 00:00:00 2001 From: CZT <czt18638530771@163.com> Date: 星期四, 31 八月 2023 14:35:53 +0800 Subject: [PATCH] 调整设备状态解析2 --- igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java | 62 +++++++++++++++--------------- 1 files changed, 31 insertions(+), 31 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 216aad2..9ade627 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 @@ -15,11 +15,9 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Component @@ -50,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); } @@ -129,6 +140,23 @@ return null; } + /** + * 鏍规嵁绫诲瀷鑾峰彇Modbus鑳借�楄澶囬厤缃俊鎭� + * @param bizType + * @param serId + * @return + */ + public List<DeviceModbus> getDataByBizType(String bizType, String serId) { + + String hql = " from " + DeviceModbus.class.getName() + " where bizType=:bizType and serId =:serId"; + + Map<String, Object> param = new HashMap<>(); + param.put("bizType", bizType); + param.put("serId", serId); + + return this.query(hql, param); + } + public DeviceModbus getGasData(String companyId, String depotId, String bizType) { @@ -195,32 +223,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); } @@ -228,8 +230,6 @@ Session session = this.getSessionFactory().openSession(); try { session.delete(data); - - flushCacheGas(null); } catch (Exception e) { } finally { session.flush(); -- Gitblit v1.9.3