fengxiang
2018-02-07 024e698be593014fff2f16112f46ab144257a1f9
地图相关 mac 大小写保持一致性
1 files modified
18 ■■■■■ changed files
src/main/java/com/moral/service/impl/DeviceServiceImpl.java 18 ●●●●● patch | view | raw | blame | history
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());