|  |  |  | 
|---|
|  |  |  | Device device = getDeviceFromRedis(mac); | 
|---|
|  |  |  | if(device==null) { | 
|---|
|  |  |  | device = deviceMapper.selectWithOrgIdsByMac(mac); | 
|---|
|  |  |  | if(device!=null){ | 
|---|
|  |  |  | setDeviceToRedis(mac,device); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return  device; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | 
|---|
|  |  |  | private String getDeviceKey(String mac) { | 
|---|
|  |  |  | return keysConnect(DEVICE,mac); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 将校正值存入redis方法组 开始 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void setDeviceToRedis(String mac,Device device){ | 
|---|
|  |  |  | String key = getDeviceKey(mac); | 
|---|
|  |  |  | Device simpleDevice = new Device(); | 
|---|
|  |  |  | simpleDevice.setId(device.getId());// id | 
|---|
|  |  |  | simpleDevice.setName(device.getName());// name | 
|---|
|  |  |  | simpleDevice.setAddress(device.getAddress());// address | 
|---|
|  |  |  | simpleDevice.setDeviceVersionId(device.getDeviceVersionId());// version | 
|---|
|  |  |  | simpleDevice.setMac(device.getMac()); // mac | 
|---|
|  |  |  | simpleDevice.setMonitorPointId(device.getMonitorPointId());// 监控地id | 
|---|
|  |  |  | simpleDevice.setOrganizationIds(device.getOrganizationIds());// 组织数组 | 
|---|
|  |  |  | simpleDevice.setDeviceVersion(device.getDeviceVersion()); | 
|---|
|  |  |  | redisUtils.set(key,simpleDevice); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    /* | 
|---|
|  |  |  | //     * 将校正值存入redis方法组 开始 | 
|---|
|  |  |  | //     */ | 
|---|
|  |  |  | //    private void setDeviceToRedis(String mac,Device device){ | 
|---|
|  |  |  | //        String key = getDeviceKey(mac); | 
|---|
|  |  |  | //        Device simpleDevice = new Device(); | 
|---|
|  |  |  | //        simpleDevice.setId(device.getId());// id | 
|---|
|  |  |  | //        simpleDevice.setName(device.getName());// name | 
|---|
|  |  |  | //        simpleDevice.setAddress(device.getAddress());// address | 
|---|
|  |  |  | //        simpleDevice.setDeviceVersionId(device.getDeviceVersionId());// version | 
|---|
|  |  |  | //        simpleDevice.setMac(device.getMac()); // mac | 
|---|
|  |  |  | //        simpleDevice.setMonitorPointId(device.getMonitorPointId());// 监控地id | 
|---|
|  |  |  | //        simpleDevice.setOrganizationIds(device.getOrganizationIds());// 组织数组 | 
|---|
|  |  |  | //        simpleDevice.setDeviceVersion(device.getDeviceVersion()); | 
|---|
|  |  |  | //        redisUtils.set(key,simpleDevice); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | private Device getDeviceFromRedis(String mac) { | 
|---|
|  |  |  | String key = getDeviceKey(mac); | 
|---|
|  |  |  | return redisUtils.get(key,Device.class); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 要在数据库更改后刷新 | 
|---|
|  |  |  | * 刷新 redis 设备的信息 | 
|---|
|  |  |  | * 刷新 redis 设备的信息,注意此处指删除不做更新。更新由task完成 | 
|---|
|  |  |  | * @param mac | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void refreshDeviceInRedis(String mac){ | 
|---|
|  |  |  | if(!StringUtils.isBlank(mac)){ | 
|---|
|  |  |  | Device device = deviceMapper.selectWithOrgIdsByMac(mac); | 
|---|
|  |  |  | setDeviceToRedis(mac,device); | 
|---|
|  |  |  | String key = getDeviceKey(device.getMac()); | 
|---|
|  |  |  | redisUtils.remove(key); | 
|---|
|  |  |  | }else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | log.warn("param mac is null in method [refreshDeviceInRedis]"); | 
|---|