diff --git a/src/main/java/com/ifish/helper/DeviceHelper.java b/src/main/java/com/ifish/helper/DeviceHelper.java index d8ba482..a75d3ad 100644 --- a/src/main/java/com/ifish/helper/DeviceHelper.java +++ b/src/main/java/com/ifish/helper/DeviceHelper.java @@ -251,6 +251,7 @@ public class DeviceHelper implements DeviceHelperI { * @return * @throws Exception */ + @Override public Tbl_Device_Statistics getDeviceStatisticsByDeviceId(Integer deviceId) throws Exception { Tbl_Device_Statistics device = null; String key = redisKeyHelperI.getTbl_Device_StatisticsRedisKeyByDeviceId(deviceId); @@ -287,4 +288,28 @@ public class DeviceHelper implements DeviceHelperI { } return device; } + + /** + * 根据设备Id获取设备详情 + * + * @param deviceId + * @return + * @throws Exception + */ + @Override + public Tbl_Device getDeviceById(Integer deviceId) throws Exception { + Tbl_Device device = null; + String key = redisKeyHelperI.getTbl_DeviceRedisKeyByDeviceId(deviceId); + String redisString = redisHelperI.getRedis(key); + if (StringUtils.isNotBlank(redisString)) { + device = (Tbl_Device) IfishUtil.JsonToBean(redisString, Tbl_Device.class); + } else { + device = tbl_Device_Mapper.getDeviceById(deviceId); + if (device != null && device.getDeviceId() > 0) { + redisHelperI.setRedis(key, IfishUtil.ObjectToJson(device)); + } + } + return device; + } + } diff --git a/src/main/java/com/ifish/helper/DeviceHelperI.java b/src/main/java/com/ifish/helper/DeviceHelperI.java index 64324b5..57d8b8e 100644 --- a/src/main/java/com/ifish/helper/DeviceHelperI.java +++ b/src/main/java/com/ifish/helper/DeviceHelperI.java @@ -68,4 +68,22 @@ public interface DeviceHelperI { * @return */ public List getTbl_Device_UsersListByDeviceId(Integer deviceId); + + /** + * 根据设备Id获取设备详情 + * + * @param deviceId + * @return + * @throws Exception + */ + Tbl_Device getDeviceById(Integer deviceId) throws Exception; + + /** + * 根据设备ID获取设备统计信息 + * + * @param deviceId + * @return + * @throws Exception + */ + public Tbl_Device_Statistics getDeviceStatisticsByDeviceId(Integer deviceId) throws Exception; } diff --git a/src/main/java/com/ifish/helper/RedisKeyHelper.java b/src/main/java/com/ifish/helper/RedisKeyHelper.java index a452e88..8edc4fc 100644 --- a/src/main/java/com/ifish/helper/RedisKeyHelper.java +++ b/src/main/java/com/ifish/helper/RedisKeyHelper.java @@ -26,6 +26,9 @@ public class RedisKeyHelper implements RedisKeyHelperI { @Autowired private RedisHelperI redisHelperI; + @Autowired + private DeviceHelperI deviceHelper; + /** * 根据phoneNumber获取Tbl_User用户信息的Redis缓存key键值 * @@ -373,6 +376,15 @@ public class RedisKeyHelper implements RedisKeyHelperI { */ @Override public void deleteRedisByTbl_Device(Tbl_Device device) { + deleteTbl_DeviceInfo(device); + try { + Tbl_Device_Statistics device_Statistics = deviceHelper.getDeviceStatisticsByDeviceId(device.getDeviceId()); + deleteRedisByTbl_Device_Statistics(device_Statistics); + } catch (Exception e) { + } + } + + public void deleteTbl_DeviceInfo(Tbl_Device device) { if (device.getDeviceId() != null && device.getDeviceId() > 0) { redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId())); } @@ -392,12 +404,22 @@ public class RedisKeyHelper implements RedisKeyHelperI { */ @Override public void deleteRedisByTbl_Device_Statistics(Tbl_Device_Statistics device) { + deleteTbl_Device_StatisticsInfo(device); + try { + Tbl_Device device1 = deviceHelper.getDeviceById(device.getDeviceId()); + deleteRedisByTbl_Device(device1); + } catch (Exception e) { + } + } + + public void deleteTbl_Device_StatisticsInfo(Tbl_Device_Statistics device) { if (device.getDeviceId() != null && device.getDeviceId() > 0) { redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId())); } if (StringUtils.isNotBlank(device.getMacAddress())) { redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByMacAddress(device.getMacAddress())); } + } /** @@ -407,12 +429,26 @@ public class RedisKeyHelper implements RedisKeyHelperI { */ @Override public void deleteRedisByTbl_Device_User(Tbl_Device_User tbl_Device_User) { + deleteTbl_Device_UserInfo(tbl_Device_User); + try { + Tbl_Device device1 = deviceHelper.getDeviceById(tbl_Device_User.getDeviceId()); + deleteRedisByTbl_Device(device1); + Tbl_Device_Statistics device_Statistics = deviceHelper.getDeviceStatisticsByDeviceId(tbl_Device_User.getDeviceId()); + deleteRedisByTbl_Device_Statistics(device_Statistics); + } catch (Exception e) { + } + } + + public void deleteTbl_Device_UserInfo(Tbl_Device_User tbl_Device_User) { if (tbl_Device_User.getDeviceId() != null && tbl_Device_User.getUserId() != null && tbl_Device_User.getDeviceId() > 0 && tbl_Device_User.getUserId() > 0) { redisHelperI.deleteRedis(getTbl_Device_UserRedisKeyByDeviceIdAndUserId(tbl_Device_User.getUserId(), tbl_Device_User.getDeviceId())); } if (tbl_Device_User.getDeviceId() != null && tbl_Device_User.getDeviceId() > 0) { redisHelperI.deleteRedis(getListTbl_Device_UserKeyByDeviceId(tbl_Device_User.getDeviceId())); } + if (tbl_Device_User.getUserId() != null) { + redisHelperI.delRedisByTagKey(getListTbl_Device_UserKeyByUserId(tbl_Device_User.getUserId())); + } } /** @@ -477,5 +513,4 @@ public class RedisKeyHelper implements RedisKeyHelperI { redisHelperI.delRedisByTagKey(RedisKey.LIVEMESSAGE_ROOMID + tbl_Live_Message.getRoomId()); redisHelperI.deleteRedis(RedisKey.LIVEMESSAGE_COUNT + tbl_Live_Message.getRoomId()); } - }