From 024e698be593014fff2f16112f46ab144257a1f9 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Wed, 07 Feb 2018 09:42:21 +0800
Subject: [PATCH] 地图相关 mac 大小写保持一致性
---
src/main/java/com/moral/service/impl/DeviceServiceImpl.java | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java
index e8c755f..bf3ad03 100644
--- a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -14,6 +14,7 @@
import com.moral.common.util.RedisUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
@@ -164,17 +165,18 @@
private void loadDeviceState(List<Device> list){
//���redis������������
list.stream().map( device -> {
- String state = getSateFromRedis(device.getMonitorPointId(),device.getMac());
+ String mac = Optional.of(device.getMac()).get();
+ String state = getSateFromRedis(device.getMonitorPointId(),mac.toLowerCase());
device.setState(state);
return device;
}).count();
}
private String getSateFromRedis(Integer mpId,String mac){
- Map<String,String> states = getStateMapFromRedis(mpId,mac);
+ Map<String,String> stateMap = getStateMapFromRedis(mpId,mac);
String state = null;
- if(states != null){
- state = states.get("state");
+ if(stateMap != null){
+ state = stateMap.get("state");
}
state = state == null ?Constants.DEVICE_STATE_OFFLINE:state;
return state;
@@ -235,6 +237,10 @@
@Override
public void addOrModify(Device device){
try{
+ //mac ���������
+ if(StringUtils.isBlank(device.getMac())){
+ device.setMac(device.getMac().toLowerCase());
+ }
if(device.getId()==null){
device.setIsDelete(Constants.IS_DELETE_FALSE);
deviceMapper.insertSelective(device);
@@ -263,6 +269,7 @@
@Override
public List<Map<String,String>> queryDevicesState(List<String> macList,Boolean withData) {
List<Map<String,String>> list = macList.stream().map(mac->{
+ mac = mac.toLowerCase();
Device device = getDeviceWithOrgIdsByMac(mac);
Map<String,String> resultMap = new HashMap<>();
Map<String,String> stateMap = getStateMapFromRedis(device.getMonitorPointId(),mac);
@@ -270,6 +277,7 @@
resultMap.putAll(stateMap);
}else{
resultMap.put("state",Constants.DEVICE_STATE_OFFLINE);
+ resultMap.put("mac",mac);
}
if(BooleanUtils.isTrue(withData)){
String dataKey = "data_"+mac;
@@ -277,8 +285,6 @@
if(!MapUtils.isEmpty(dataMap)){
resultMap.putAll(dataMap);
}
- }else{
- resultMap.put("mac",mac);
}
return resultMap;
}).collect(Collectors.toList());
--
Gitblit v1.8.0