175 lines
5.0 KiB
Java
175 lines
5.0 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.ifish.helper;
|
|
|
|
import com.ifish.bean.Tbl_Device;
|
|
import com.ifish.bean.Tbl_Device_Statistics;
|
|
import com.ifish.bean.Tbl_Device_User;
|
|
import com.ifish.bean.Tbl_User;
|
|
import com.ifish.util.RedisKey;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
/**
|
|
*
|
|
* @author Administrator
|
|
*/
|
|
@Component
|
|
public class RedisKeyHelper implements RedisKeyHelperI {
|
|
|
|
@Autowired
|
|
private RedisHelperI redisHelperI;
|
|
|
|
/**
|
|
* 根据userId获取Tbl_User用户信息的Redis缓存key键值
|
|
*
|
|
* @param userId
|
|
* @return
|
|
*/
|
|
public String getTbl_UserRedisKeyByUserId(Integer userId) {
|
|
return RedisKey.USER_ID_KEY + userId;
|
|
}
|
|
|
|
/**
|
|
* 根据mac地址获取Tbl_Device的redis缓存key键值
|
|
*
|
|
* @param macAddress
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String getTbl_DeviceRedisKeyByMacAddress(String macAddress) {
|
|
return RedisKey.DEVICE_KEY_MACADDRESS + macAddress;
|
|
}
|
|
|
|
/**
|
|
* 根据Id获取Tbl_Device的redis缓存key键值
|
|
*
|
|
* @param macAddress
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String getTbl_DeviceRedisKeyByDeviceId(Integer deviceId) {
|
|
return RedisKey.DEVICE_KEY_DEVICEID + deviceId;
|
|
}
|
|
|
|
/**
|
|
* 根据设备ID和用户ID获取Tbl_Device_User的redis缓存key键值
|
|
*
|
|
* @param userId
|
|
* @param deviceId
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String getTbl_Device_UserRedisKeyByDeviceIdAndUserId(Integer userId, Integer deviceId) {
|
|
return RedisKey.DEVICE_USER_DEVICEID_AND_USERID + "u_" + userId + "_d_" + deviceId;
|
|
}
|
|
|
|
/**
|
|
* 根据设备ID获取Tbl_Device_User(列表)的redis缓存key键值
|
|
*
|
|
* @param userId
|
|
* @param deviceId
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String getListTbl_Device_UserKeyByDeviceId(Integer deviceId) {
|
|
return RedisKey.DEVICE_USER_LIST_DEVICEID + deviceId;
|
|
}
|
|
|
|
/**
|
|
* 根据mac地址获取Tbl_Device_Statistics的redis缓存key键值
|
|
*
|
|
* @param macAddress
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String getTbl_Device_StatisticsRedisKeyByMacAddress(String macAddress) {
|
|
return RedisKey.DEVICE_STATISTICS_MACADDRESS + macAddress;
|
|
}
|
|
|
|
/**
|
|
* 根据Id获取Tbl_Device_Statistics的redis缓存key键值
|
|
*
|
|
* @param macAddress
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String getTbl_Device_StatisticsRedisKeyByDeviceId(Integer deviceId) {
|
|
return RedisKey.DEVICE_STATISTICS_DEVICEID + deviceId;
|
|
}
|
|
|
|
/**
|
|
* 根据typeCode获取Tbl_HardWare_Type的redis缓存key键值
|
|
*
|
|
* @param typeCode
|
|
* @return
|
|
*/
|
|
public String getTbl_HardWare_TypeRedisKeyByTypeCode(String typeCode) {
|
|
return RedisKey.HARD_WARE_TYPE + typeCode;
|
|
}
|
|
|
|
/**
|
|
* 删除redis中某个设备详情Tbl_Device的缓存
|
|
*
|
|
* @param device
|
|
* @return
|
|
*/
|
|
@Override
|
|
public void deleteRedisByTbl_Device(Tbl_Device device) {
|
|
if (device.getDeviceId() > 0) {
|
|
redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId()));
|
|
}
|
|
if (StringUtils.isNotBlank(device.getMacAddress())) {
|
|
redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByMacAddress(device.getMacAddress()));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除redis中某个设备统计信息Tbl_Device_Statistics的缓存
|
|
*
|
|
* @param device
|
|
* @return
|
|
*/
|
|
@Override
|
|
public void deleteRedisByTbl_Device_Statistics(Tbl_Device_Statistics device) {
|
|
if (device.getDeviceId() > 0) {
|
|
redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId()));
|
|
}
|
|
if (StringUtils.isNotBlank(device.getMacAddress())) {
|
|
redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByMacAddress(device.getMacAddress()));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除redis中某个设备和用户关系Tbl_Device_User的缓存
|
|
*
|
|
* @param tbl_Device_User
|
|
*/
|
|
@Override
|
|
public void deleteRedisByTbl_Device_User(Tbl_Device_User tbl_Device_User) {
|
|
if (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() > 0) {
|
|
redisHelperI.deleteRedis(getListTbl_Device_UserKeyByDeviceId(tbl_Device_User.getDeviceId()));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除redis中某个用户Tbl_User的缓存
|
|
*
|
|
* @param tbl_User
|
|
*/
|
|
@Override
|
|
public void deleteRedisByTbl_User(Tbl_User tbl_User) {
|
|
if (tbl_User.getUserId() > 0) {
|
|
redisHelperI.deleteRedis(getTbl_UserRedisKeyByUserId(tbl_User.getUserId()));
|
|
}
|
|
}
|
|
|
|
}
|