| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Component |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | Session session = this.getSessionFactory().openSession(); |
| | | try { |
| | | session.delete(data); |
| | | |
| | | flushCacheGas(null); |
| | | } catch (Exception e) { |
| | | } finally { |
| | | session.flush(); |