xufenglei
2018-11-21 a4c1346fe8b37507d69413632848d30a5826efc6
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -305,4 +306,47 @@
      }
      return monitorPoints;
   }
    @SuppressWarnings("unchecked")
   @Override
   public Collection<Object> getDevicesStateByRegion(Map<String, Object> parameters) {
       //校验参数
      Object organizationId = parameters.remove("organizationId");
      ValidateUtil.notNull(organizationId, "param.is.null");
      ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null");
      //组装查询条件
      ParameterUtils.getRegionType4RegionCode(parameters);
      if (Constants.isNotSpecialOrgId(Integer.valueOf(organizationId.toString()))) {
         Set<Integer> organizationIds = organizationService.getChildOrganizationIds(Integer.valueOf(organizationId.toString()));
         parameters.put("orgIds", organizationIds);
      }
      List<Map<String, Object>> monitorPoints  = deviceMapper.getDevicesStateByRegion(parameters);
      Map<String, Object> result = new HashMap<String, Object>();
      Map<String,Object> device;
      List<Map<String, Object>> devices;
      for (Map<String, Object> map : monitorPoints) {
         String id = map.get("id").toString();
         device = new HashMap<String,Object>();
         device.put("id", map.remove("deviceId"));
         device.put("name", map.remove("deviceName"));
         device.put("state", map.remove("state"));
         device.put("mac", map.remove("mac"));
         if (result.containsKey(id)) {
            Map<String, Object> monitorPoint = (Map<String, Object>) result.get(id);
            devices = (List<Map<String, Object>>) monitorPoint.get("devices");
         } else {
            devices = new ArrayList<Map<String, Object>>();
            result.put(id, map);
         }
         devices.add(device);
         map.put("devices", devices);
         result.put(id, map);
      }
      return result.values();
   }
}