|
|
@@ -41,10 +41,12 @@ public class XfTermServiceImpl implements IXfTermService {
|
|
|
private final XfTermMapper baseMapper;
|
|
|
private final DefaultConfig defaultConfig;
|
|
|
|
|
|
+ private String cache = CacheNames.PT_TERM_MAC_MAP + "_hik";
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public XfTermVo queryByMac(String termMac) {
|
|
|
- boolean existsObject = RedisUtils.isExistsObject(CacheNames.PT_TERM_MAC_MAP);
|
|
|
+ boolean existsObject = RedisUtils.isExistsObject(cache);
|
|
|
if(!existsObject){
|
|
|
// 缓存设备mac地址
|
|
|
XfTermVo byMac = getByMac(termMac);
|
|
|
@@ -53,21 +55,21 @@ public class XfTermServiceImpl implements IXfTermService {
|
|
|
}
|
|
|
Map<String, XfTermVo> map = new HashMap<>();
|
|
|
map.put(termMac, byMac);
|
|
|
- RedisUtils.setCacheMap(CacheNames.PT_TERM_MAC_MAP, map);
|
|
|
- RedisUtils.expire(CacheNames.PT_TERM_MAC_MAP, Duration.ofHours(1));
|
|
|
+ RedisUtils.setCacheMap(cache, map);
|
|
|
+ RedisUtils.expire(cache, Duration.ofHours(1));
|
|
|
return byMac;
|
|
|
}
|
|
|
- Object value = RedisUtils.getCacheMapValue(CacheNames.PT_TERM_MAC_MAP, termMac);
|
|
|
+ XfTermVo value = RedisUtils.getCacheMapValue(cache, termMac);
|
|
|
if(ObjUtil.isNull(value)){
|
|
|
// 缓存设备mac地址
|
|
|
XfTermVo byMac = getByMac(termMac);
|
|
|
if(ObjUtil.isNull(byMac)){
|
|
|
return null;
|
|
|
}
|
|
|
- RedisUtils.setCacheMapValue(CacheNames.PT_TERM_MAC_MAP, termMac, byMac);
|
|
|
+ RedisUtils.setCacheMapValue(cache, termMac, byMac);
|
|
|
return byMac;
|
|
|
}
|
|
|
- return (XfTermVo) value;
|
|
|
+ return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -91,22 +93,17 @@ public class XfTermServiceImpl implements IXfTermService {
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean updateByMac(String termMac, String newIP) {
|
|
|
- List<XfTermVo> termVos = TenantHelper.ignore(() -> {
|
|
|
- LambdaQueryWrapper<XfTerm> select = new LambdaQueryWrapper<XfTerm>().eq(XfTerm::getTermMac, termMac)
|
|
|
- .select(XfTerm::getTermId, XfTerm::getTermIp, XfTerm::getTermMac);
|
|
|
- return baseMapper.selectVoList(select);
|
|
|
- });
|
|
|
- if(CollectionUtil.isNotEmpty(termVos) && termVos.size()==1){
|
|
|
- XfTermVo xfTermVo = termVos.get(0);
|
|
|
+ XfTermVo xfTermVo = queryByMac(termMac);
|
|
|
+ if(xfTermVo!=null){
|
|
|
if(StringUtils.isBlank(xfTermVo.getTermIp()) || !xfTermVo.getTermIp().equals(newIP)){
|
|
|
XfTerm xfTerm = new XfTerm();
|
|
|
xfTerm.setTermId(xfTermVo.getTermId());
|
|
|
xfTerm.setTermIp(newIP);
|
|
|
xfTermVo.setTermIp(newIP);
|
|
|
boolean b = baseMapper.updateById(xfTerm) > 0;
|
|
|
- boolean existsObject = RedisUtils.isExistsObject(CacheNames.PT_TERM_MAC_MAP);
|
|
|
+ boolean existsObject = RedisUtils.isExistsObject(cache);
|
|
|
if(existsObject){
|
|
|
- RedisUtils.setCacheMapValue(CacheNames.PT_TERM_MAC_MAP, termMac, xfTermVo);
|
|
|
+ RedisUtils.setCacheMapValue(cache, termMac, xfTermVo);
|
|
|
}
|
|
|
return b;
|
|
|
}
|