设备缓存删除修改

This commit is contained in:
谢洪龙 2017-08-01 13:47:07 +08:00
parent 13ee810461
commit af6ac0c002
3 changed files with 79 additions and 1 deletions

View File

@ -251,6 +251,7 @@ public class DeviceHelper implements DeviceHelperI {
* @return * @return
* @throws Exception * @throws Exception
*/ */
@Override
public Tbl_Device_Statistics getDeviceStatisticsByDeviceId(Integer deviceId) throws Exception { public Tbl_Device_Statistics getDeviceStatisticsByDeviceId(Integer deviceId) throws Exception {
Tbl_Device_Statistics device = null; Tbl_Device_Statistics device = null;
String key = redisKeyHelperI.getTbl_Device_StatisticsRedisKeyByDeviceId(deviceId); String key = redisKeyHelperI.getTbl_Device_StatisticsRedisKeyByDeviceId(deviceId);
@ -287,4 +288,28 @@ public class DeviceHelper implements DeviceHelperI {
} }
return device; 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;
}
} }

View File

@ -68,4 +68,22 @@ public interface DeviceHelperI {
* @return * @return
*/ */
public List<Tbl_Device_User> getTbl_Device_UsersListByDeviceId(Integer deviceId); public List<Tbl_Device_User> 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;
} }

View File

@ -26,6 +26,9 @@ public class RedisKeyHelper implements RedisKeyHelperI {
@Autowired @Autowired
private RedisHelperI redisHelperI; private RedisHelperI redisHelperI;
@Autowired
private DeviceHelperI deviceHelper;
/** /**
* 根据phoneNumber获取Tbl_User用户信息的Redis缓存key键值 * 根据phoneNumber获取Tbl_User用户信息的Redis缓存key键值
* *
@ -373,6 +376,15 @@ public class RedisKeyHelper implements RedisKeyHelperI {
*/ */
@Override @Override
public void deleteRedisByTbl_Device(Tbl_Device device) { 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) { if (device.getDeviceId() != null && device.getDeviceId() > 0) {
redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId())); redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId()));
} }
@ -392,12 +404,22 @@ public class RedisKeyHelper implements RedisKeyHelperI {
*/ */
@Override @Override
public void deleteRedisByTbl_Device_Statistics(Tbl_Device_Statistics device) { 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) { if (device.getDeviceId() != null && device.getDeviceId() > 0) {
redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId())); redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId()));
} }
if (StringUtils.isNotBlank(device.getMacAddress())) { if (StringUtils.isNotBlank(device.getMacAddress())) {
redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByMacAddress(device.getMacAddress())); redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByMacAddress(device.getMacAddress()));
} }
} }
/** /**
@ -407,12 +429,26 @@ public class RedisKeyHelper implements RedisKeyHelperI {
*/ */
@Override @Override
public void deleteRedisByTbl_Device_User(Tbl_Device_User tbl_Device_User) { 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) { 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())); redisHelperI.deleteRedis(getTbl_Device_UserRedisKeyByDeviceIdAndUserId(tbl_Device_User.getUserId(), tbl_Device_User.getDeviceId()));
} }
if (tbl_Device_User.getDeviceId() != null && tbl_Device_User.getDeviceId() > 0) { if (tbl_Device_User.getDeviceId() != null && tbl_Device_User.getDeviceId() > 0) {
redisHelperI.deleteRedis(getListTbl_Device_UserKeyByDeviceId(tbl_Device_User.getDeviceId())); 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.delRedisByTagKey(RedisKey.LIVEMESSAGE_ROOMID + tbl_Live_Message.getRoomId());
redisHelperI.deleteRedis(RedisKey.LIVEMESSAGE_COUNT + tbl_Live_Message.getRoomId()); redisHelperI.deleteRedis(RedisKey.LIVEMESSAGE_COUNT + tbl_Live_Message.getRoomId());
} }
} }