Пример #1
1
  /**
   * 停用访客策略
   *
   * @param fangke
   * @param request
   * @return
   */
  @RequestMapping(value = "/removeInvalidrfid.do")
  public boolean doRemoveInvalidrfid() {

    // fangkeService.remove(fangke);
    log.info("删除访客策略数据");

    CommandProtocal command = new CommandProtocal();
    command.setCommandType(CommandType.DELETE); // 删除类型
    command.setJopName("invalidrfid"); // 决策的ID,和数据库中保存一致
    command.setStrategyType(StrategyType.VISITOR); // 无意义

    /** 设置监控的规则* */
    CommandBody body = new CommandBody();
    command.setBody(body);

    try {
      CommandMinaClient client = CommandMinaClient.getCommandMinaClient();
      // 到远程服务器没有开启时,client为空
      if (client != null) {
        InetSocketAddress socketAddress =
            (InetSocketAddress) client.getIOSession().getLocalAddress();
        String address =
            socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort();
        command.setClientIP(address); // 设置IP地址
        log.fatal(address);
        log.fatal(client.getIOSession().getLocalAddress().toString());
        client.Send(command);
      }
    } catch (NullPointerException e) {
      log.error("客户端无法获取与服务器端的session");
      return false;
    }

    return true;
  }
Пример #2
0
  /**
   * 访客策略添加功能(监控所有位置,所有物品)
   *
   * @param fangke
   * @return
   * @throws ParseException
   */
  @SuppressWarnings("deprecation")
  @RequestMapping(value = "/insertInvalidrfid.do")
  public boolean doInsertInvalidrfid() throws ParseException {

    CommandProtocal command = new CommandProtocal();
    command.setCommandType(CommandType.ADD); // 增加类型
    command.setJopName("invalidrfid"); // 决策的ID,和数据库中保存一致
    command.setStrategyType(StrategyType.VISITOR); // 会议监控

    /** 设置监控的规则* */
    CommandBody body = new CommandBody();

    /** 监控对象* */
    Vector<String> UIDVector = new Vector<String>();

    List<Item> items = itemsService.queryAllItems();

    for (Item item : items) {
      UIDVector.add(item.getItemID());
    }

    // UIDVector.add("36001000931EB80113000001");
    // UIDVector.add("360000000000006010100096");
    body.setUIDVector(UIDVector);

    /** 监控范围(所有位置)* */
    Vector<String> anVector = new Vector<String>();
    // Reader reader = new Reader();
    // reader.setPositionID(fangke.getFangkeLocation());
    List<Reader> readerList = readersService.queryAllReaders();
    for (Reader r : readerList) {
      anVector.add(r.getReaderIP());
    }
    // anVector.add("192.168.140.133:0");
    // anVector.add("192.168.140.133:1");//门禁1
    // anVector.add("192.168.140.133:2");
    // anVector.add("192.168.140.133:3");//门禁1

    body.setAnVector(anVector);

    /** shortTimeVector表示,每天的某个时间端* */
    Vector<PeriodsTime> shortTimeVector = new Vector<PeriodsTime>();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date beginDate = df.parse("2014-07-17 00:00:00");
    long beginTime =
        (beginDate.getHours() * 60 + beginDate.getMinutes()) * 60 + beginDate.getSeconds();
    java.util.Date endDate = df.parse("2014-07-17 23:59:59");
    long endTime = (endDate.getHours() * 60 + endDate.getMinutes()) * 60 + endDate.getSeconds();
    PeriodsTime periodsTime = new PeriodsTime();
    periodsTime.setBeginTime(beginTime);
    periodsTime.setEndTime(endTime);
    shortTimeVector.add(periodsTime);
    body.setShortPeriodsTime(shortTimeVector);

    command.setBody(body);

    /** 扫描频率*** */
    body.setTimeInterval(5); // 在访客监控中,无效

    try {
      CommandMinaClient client = CommandMinaClient.getCommandMinaClient();
      // 到远程服务器没有开启时,client为空
      if (client != null) {
        InetSocketAddress socketAddress =
            (InetSocketAddress) client.getIOSession().getLocalAddress();
        String address =
            socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort();
        command.setClientIP(address); // 设置IP地址
        log.fatal(address);
        client.Send(command);

        /*fangke.setFangkeStatus("Start");
        if(fangke.getFangkeID() != null && !"".equals(fangke.getFangkeID())){
        	log.info("修改访客策略数据");
        	fangkeService.update(fangke);
        }else{
        	log.info("新增访客策略数据");
        	fangke.setFangkeID("invalidrfid");
        	fangkeService.save(fangke);
        }

        String[] ulist = fangke.getParam1().split(",");
        for (String s : ulist)
        {
        	UserRule ur = new UserRule();
        	ur.setRuleID("invalidrfid");
        	ur.setRuleStatus("start");
        	ur.setUserName(s);
        	userRulesService.saveUserRule(ur);
        }*/

      }
    } catch (NullPointerException e) {
      log.error("客户端无法获取与服务器端的session");
      return false;
    }

    return true;
  }