Exemplo n.º 1
0
 /**
  * 第三方请求并处理返回轮询数据
  *
  * @param devicePoling 发送数据
  * @param url
  * @param pollingData 返回结果
  */
 private void sendToDeviceService(
     DevicePoling devicePoling,
     String url,
     List<List<Map<String, Object>>> pollingData,
     Map<String, Object> data,
     List<Map<String, String>> macList) {
   int set = Integer.parseInt(devicePoling.getPolingset());
   // 机位字典
   List<Map<String, Object>> dics = syscodeMapper.getCode("RoundRobin");
   int i = 0;
   for (Map<String, String> map : macList) {
     data.put("macInfo", map);
     String result = HttpSend.post(url, data);
     List<Map<String, Object>> resultList = JsonUtil.jsonToObject(result, List.class);
     if (resultList != null) {
       String className = map.get("className");
       transforData(resultList, className, dics);
       handleData(resultList, set, pollingData);
       if (pollingData.size() > 0 && pollingData.get(0).size() == set) {
         i++;
         break;
       }
     }
     i++;
   }
   for (int j = 0; j < i; j++) {
     macList.remove(0);
   }
   if (macList.size() > 0) {
     new pollingThread(set, url, dics, data, pollingData, macList).start();
   }
 }
Exemplo n.º 2
0
  /**
   * 轮询截图
   *
   * @param req
   * @return true为截图成功 false执行截图失败
   */
  private List<Map<String, Object>> cutPic(
      String result, List<Map<String, String>> macList, List<String> seats) {
    Map<String, Object> resultMap = JsonUtil.jsonToObject(result, Map.class);
    try {
      // 服务器开始执行截图
      // response_code 0 表示开始截图
      if (resultMap != null && "0".equals(resultMap.get("response_code") + "")) {
        List<Map<String, Object>> pathList = new ArrayList<Map<String, Object>>();
        // 机位字典
        List<Map<String, Object>> dics = syscodeMapper.getCode("RoundRobin");
        for (Map<String, String> map : macList) {
          Map<String, Object> p = new HashMap<String, Object>();
          String mac = map.get("mac");
          String className = map.get("className");
          List<Map<String, Object>> seatList = new ArrayList<Map<String, Object>>();
          for (String seat : seats) {
            String path =
                AppConstants.POLLING_IMAGE_PATH + File.separator + mac + File.separator + seat;
            long time = System.currentTimeMillis();
            File f = new File(path);
            Map<String, Object> seatMap = new HashMap<String, Object>();
            if (f.exists()) {
              File[] fs = f.listFiles();
              for (File file : fs) {
                long seconds = Math.abs((file.lastModified() - time) / 1000);
                if (seconds >= 0 && seconds < 3) {
                  for (Map<String, Object> dic : dics) {
                    if (seat.equals(dic.get("value"))) {
                      seatMap.put("fileName", file.getName());
                      seatMap.put("seat", seat);
                      seatMap.put("seatName", dic.get("name"));
                      seatList.add(seatMap);
                      break;
                    }
                  }
                  break;
                }
              }
            }
          }
          if (seatList.size() != 0) {
            p.put("mac", mac);
            p.put("className", className);
            p.put("seats", seatList);
            pathList.add(p);
          }
        }
        return pathList;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }