Exemple #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();
   }
 }
Exemple #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;
  }
Exemple #3
0
 @Override
 public void run() {
   long starttime = System.currentTimeMillis();
   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);
     }
   }
 }
Exemple #4
0
 /**
  * 返回轮询结果
  *
  * @param req
  * @param page页面
  * @return
  */
 public String polling(HttpServletRequest req, int page) {
   Map<String, Object> datas = new HashMap<String, Object>();
   // 机位
   List<String> seats = null;
   // 教室编号
   List<String> innerids = null;
   // 名字服务需要的数据
   Map<String, Object> data = new HashMap<String, Object>();
   String loginname = ShiroDbRealm.getCurrentLoginName();
   if (loginname == null) {
     return "unauthc";
   }
   DevicePoling devicePoling = devicePolingMapper.findDevicePolingSetByAreaid(loginname);
   seats = Arrays.asList(devicePoling.getDeviceinfo().split(","));
   innerids = Arrays.asList(devicePoling.getAreainfo().split(","));
   List<Map<String, String>> macList =
       deviceMapper.getMacByInnerId(innerids, AppConstants.TYPE_DEVICETYPE_RECORD);
   data.put("seats", seats); // car0,car1,car4
   // 轮询方式
   String roundType = devicePoling.getRoundType();
   String ipPort = serverService.getWebServer();
   String url = "http://" + ipPort + "/deviceService/polling/" + roundType;
   // 视频轮询
   List<List<Map<String, Object>>> pollingData =
       (List<List<Map<String, Object>>>) req.getSession().getAttribute(roundType);
   if (roundType.equals("flowType")) {
     if (page == 0 && (pollingData == null || pollingData.size() == 0)) {
       pollingData = new ArrayList<List<Map<String, Object>>>();
       req.getSession().setAttribute(roundType, pollingData);
       sendToDeviceService(devicePoling, url, pollingData, data, macList);
     }
     if (pollingData != null && pollingData.size() > page) {
       datas.put("data", pollingData.get(page));
     }
   } else {
     data.put("macList", macList);
     String result = HttpSend.post(url, data);
     List<Map<String, Object>> files = cutPic(result, macList, seats);
     String path = "http://" + req.getLocalAddr() + "/images";
     datas.put("url", path);
     datas.put("data", files);
   }
   datas.put("polingtime", devicePoling.getPolingtime());
   datas.put("polingset", devicePoling.getPolingset());
   return JsonUtil.toJson(datas);
 }