示例#1
0
 private void updateSvOrganNumber(
     Map<String, int[]> organNumberMap,
     Map<String, ListSvOrganDeviceDTO.Node> organCacheMap,
     ListSvOrganDeviceDTO.Node node,
     boolean onlineFlag) {
   ListSvOrganDeviceDTO.Node parent = organCacheMap.get(node.getPid());
   if (null == parent) {
     return;
   }
   int[] parentNumber = organNumberMap.get(node.getPid());
   // 在线
   if (onlineFlag) {
     parentNumber[0]++;
     parentNumber[1]++;
   } else {
     parentNumber[1]++;
   }
   organNumberMap.put(node.getPid(), parentNumber);
   updateSvOrganNumber(organNumberMap, organCacheMap, parent, onlineFlag);
 }
示例#2
0
  @Logon
  public Object listSvOrganDeviceJson(HttpServletRequest request) {
    SimpleRequestReader reader = new SimpleRequestReader(request);
    Long userId = reader.getUserId();
    // 获取用户组根机构
    User user = userManager.getUser(userId);
    VirtualOrgan rootOrgan = organManager.getUgRootOrgan(user.getUserGroupId());
    // 用户组资源集合
    Map<Long, VirtualOrgan> map = organManager.mapUgSvVirtualOrgan(rootOrgan.getId());

    List<Long> svDeviceIds = new LinkedList<Long>();
    for (VirtualOrgan vo : map.values()) {
      if (vo.getType().intValue() >= TypeDefinition.VIDEO_DVR
          && vo.getType().intValue() < TypeDefinition.VIDEO_DVR + 1000) {
        svDeviceIds.add(vo.getDeviceId());
      }
    }

    // 查询视频设备Map, 小于500个用in查询,大于500个查询全表
    if (svDeviceIds.size() > 500) {
      svDeviceIds = null;
    }
    Map<Long, SvDevice> svDeviceMap = svDeviceManager.mapSvDevice(svDeviceIds);
    // 查询机构Map
    Map<Long, Organ> organMap = organManager.getOrgans();
    // 查询厂商Map
    Map<Long, DicManufacture> manufacturerMap = dicManufactureManager.getvDicManufactureList();
    // 获取当前在线设备列表
    Map<String, OnlineReal> onlineMap = onlineManager.mapOnlineDevice();
    // 记录各机构节点的在线/总数量, key为机构ID, value[0]为在线数量, value[1]为总数量
    Map<String, int[]> organNumberMap = new HashMap<String, int[]>();
    // 所有的机构节点缓存, 处理最后的在线/总量改名, key为机构ID
    Map<String, ListSvOrganDeviceDTO.Node> organCacheMap =
        new HashMap<String, ListSvOrganDeviceDTO.Node>();

    ListSvOrganDeviceDTO dto = new ListSvOrganDeviceDTO();
    List<ListSvOrganDeviceDTO.Node> children = dto.getChildren();

    // 首先构建所有的机构
    for (VirtualOrgan vo : map.values()) {
      Integer type = vo.getType();
      if (type.intValue() <= TypeDefinition.VIRTUAL_ORGAN && vo.getVisible().intValue() == 1) {
        // 初始化机构设备在线统计数字
        organNumberMap.put(vo.getId().toString(), initNumber());

        VirtualOrgan parent = map.get(vo.getParentId());

        ListSvOrganDeviceDTO.Node node = dto.new Node();
        node.setId(vo.getId().toString());
        node.setName(vo.getName());
        node.setRealName(vo.getName());
        // 只支持一层的不可见,将下级的资源加入到上级中
        if (null != parent) {
          if (parent.getVisible().intValue() == 1) {
            node.setPid(vo.getParentId().toString());
          } else {
            node.setPid(MyStringUtil.object2StringNotNull(parent.getParentId()));
          }
        } else {
          node.setPid("");
        }
        node.setType(type.toString());
        // 默认都是在线
        node.setIsOnline(true);
        // 真实机构
        if (TypeDefinition.ORGAN_GENERAL <= type.intValue()
            && TypeDefinition.VIRTUAL_ORGAN > type.intValue()) {
          Organ realOrgan = organMap.get(vo.getDeviceId());
          if (null == realOrgan) {
            logger.error(
                "VirtualOrgan["
                    + vo.getId()
                    + "] is a dirty data, which deviceId["
                    + vo.getDeviceId()
                    + "] is not found in Organ !");
            continue;
          }
          node.setStakeNumber(MyStringUtil.object2StringNotNull(realOrgan.getBeginStake()));
          node.setStandarNumber(MyStringUtil.object2StringNotNull(realOrgan.getStandardNumber()));
        }
        // 虚拟机构
        else {
          // 默认都是在线
          node.setIsOnline(true);
        }
        organCacheMap.put(node.getId(), node);
        children.add(node);
      }
    }

    // 构建设备
    for (VirtualOrgan vo : map.values()) {
      Integer type = vo.getType();
      if (type.intValue() <= TypeDefinition.VIRTUAL_ORGAN) {
        continue;
      }
      // 不可见的忽略
      if (vo.getVisible().intValue() == 0) {
        continue;
      }
      VirtualOrgan parent = map.get(vo.getParentId());

      ListSvOrganDeviceDTO.Node node = dto.new Node();
      node.setId(vo.getId().toString());
      node.setName(vo.getName());
      node.setRealName(vo.getName());
      // 只支持一层的不可见,将下级的资源加入到上级中
      if (null != parent) {
        if (parent.getVisible().intValue() == 1) {
          node.setPid(vo.getParentId().toString());
        } else {
          node.setPid(MyStringUtil.object2StringNotNull(parent.getParentId()));
        }
      } else {
        node.setPid("");
      }
      node.setType(type.toString());
      // 默认都是在线
      node.setIsOnline(true);
      SvDevice svDevice = svDeviceMap.get(vo.getDeviceId());
      if (null == svDevice) {
        logger.error(
            "VirtualOrgan["
                + vo.getId()
                + "] is a dirty data, which deviceId["
                + vo.getDeviceId()
                + "] is not found in SvDevice !");
        continue;
      }
      node.setIp(svDevice.getIp());
      node.setLocation(svDevice.getLocation());
      node.setPort(svDevice.getPort());
      // 设置厂商
      if (null == svDevice.getManufacturerId()) {
        logger.warn("Manufacture for SvDevice[" + svDevice.getId() + "] is null !");
      } else {
        DicManufacture manufacture = manufacturerMap.get(svDevice.getManufacturerId());
        if (null != manufacture) {
          node.setManufacturer(manufacture.getName());
        } else {
          logger.error(
              "SvDevice["
                  + svDevice.getId()
                  + "] is a dirty data, which  Manufacture["
                  + svDevice.getManufacturerId()
                  + "] is not found in DicManufacture !");
        }
      }
      node.setStakeNumber(svDevice.getStakeNumber());
      node.setStandarNumber(svDevice.getStandardNumber());

      // 离线
      if (null == onlineMap.get(svDevice.getStandardNumber())) {
        node.setIsOnline(false);
        updateSvOrganNumber(organNumberMap, organCacheMap, node, false);
      }
      // 在线
      else {
        updateSvOrganNumber(organNumberMap, organCacheMap, node, true);
      }

      children.add(node);
    }

    // 替换机构名称加上(在线/总量)
    for (ListSvOrganDeviceDTO.Node organ : organCacheMap.values()) {
      int[] countNumber = organNumberMap.get(organ.getId());
      organ.setName(organ.getName() + "(" + countNumber[0] + "/" + countNumber[1] + ")");
      organ.setOnlineCount(countNumber[0]);
      organ.setTotalCount(countNumber[1]);
    }

    dto.setCode(ErrorCode.SUCCESS);
    dto.setMessage("");
    dto.setMethod(request.getHeader(Header.METHOD));
    return dto;
  }