public void process(ActionContext ac) throws Throwable {
   try {
     if (pool == null) pool = Mvcs.getIoc().get(JedisPool.class);
     int uid = Toolkit.uid();
     if (uid > 0) {
       try (Jedis jedis = pool.getResource()) {
         Pipeline pipe = jedis.pipelined();
         pipe.setbit(RKEY_ONLINE_DAY + Toolkit.today_yyyyMMdd(), uid, true);
         pipe.setbit(RKEY_ONLINE_HOUR + Toolkit.today_yyyyMMddHH(), uid, true);
         pipe.sync();
       }
     }
   } catch (Exception e) {
     if (e instanceof JedisConnectionException) {
       log.debug("jedis is down? ignore error");
     } else {
       log.debug("something wrong? ignore error", e);
     }
   }
   doNext(ac);
 }
  public void init() {
    try {
      super.init();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    // 添加全局变量
    Map<String, Object> share = groupTemplate.getSharedVars();
    if (share == null) {
      share = new NutMap();
      groupTemplate.setSharedVars(share);
    }
    Ioc ioc = Mvcs.getIoc();
    share.put("ioc", ioc);
    PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");
    share.put("conf", conf.toMap());

    if (!conf.getBoolean("cdn.enable", false) || Strings.isBlank(conf.get("cdn.urlbase"))) {
      share.put("cdnbase", "");
    } else {
      share.put("cdnbase", conf.get("cdn.urlbase"));
      MarkdownFunction.cdnbase = conf.get("cdn.urlbase");
    }
  }
Exemplo n.º 3
0
  @POST
  @At("/ht/savepamdata")
  @Ok("json")
  public JSONObject saveParameterDataFromAccess(
      String mdbPath,
      String stationId,
      String mdbTableName,
      String dateField,
      ServletContext context) {
    JSONObject json = new JSONObject();
    json.put(Constant.SUCCESS, false);
    // log.info("tableName:"+ mdbTableName + " timefield:" + dateField + " station:" +stationId) ;

    try {
      long start = System.currentTimeMillis();
      AccessUtil au = new AccessUtil(this.getAppRealPath(context) + mdbPath);
      Ioc ioc = Mvcs.getIoc();
      if (null != ioc) {
        PropertiesProxy prop = ioc.get(PropertiesProxy.class, "config");
        if (StringUtil.checkNotNull(prop.get("accessdriver"))) {
          au.setDburl(prop.get("accessdriver"));
        }
      }
      log.info(au.getDburl());
      Connection con = au.getConnection();

      Statement stat = con.createStatement();
      total = au.getTotalRowNumber(stat, mdbTableName);

      long pageTotal = au.getTotalPageNumber(total);

      long insertdb = 0;
      String tmpl =
          "select top PAGESPEED * from TABLENAME where ID >(select top 1 max(ID) from (select top BEFOREROW ID from TABLENAME order by ID asc)) order by ID asc ";
      tmpl =
          tmpl.replaceAll("ID", dateField)
              .replaceAll("PAGESPEED", String.valueOf(au.pageSpeed))
              .replaceAll("TABLENAME", mdbTableName);
      for (int i = 1; i <= pageTotal; i++) {
        int ii = (i - 1) * au.pageSpeed;
        String sql = tmpl.replaceAll("BEFOREROW", String.valueOf(ii));

        if (i == 1) {
          sql = sql.substring(0, sql.indexOf("where"));
          sql += "order by ID asc".replace("ID", dateField);
        }
        ResultSet rset = au.execSQL(stat, sql);
        if (null != rset) {
          // 把当前结果集中存在的fieldsName找出来
          List<String> available = new ArrayList<String>();
          List<String> list = au.getAllColumnName(rset.getMetaData());
          for (String str : au.fieldsName) {
            if (au.isExistString(list, str)) {
              available.add(str);
            }
          }

          List<Parameter> data = new ArrayList();
          while (rset.next()) {
            Parameter p = new Parameter();
            String time = rset.getString(dateField);

            p.setSrcTimestr(time);
            p.setCreateDate(DateUtil.convertStringToDate(time, DateUtil.pattern5));
            p.setStationID(stationId);
            // StringBuilder ss = new StringBuilder(rset.getString("mytime")).append("\t");
            // 遍历全部字段并存到java object 中
            for (String fn : available) {
              // ss.append(rset.getString(fn)).append("\t") ;
              BeanUtils.setProperty(p, fn, String.valueOf(rset.getString(fn)));
            }

            data.add(p);
            dls.insertNDY(tableName, p.getStationID(), null, p.getCreateDate());
          }
          // log.info("得到: " + data.size()) ;
          if (null != data && data.size() > 0) {
            // 把已经存在的对象删除掉
            batchDeleteParameter(stationId, data);
            insertdb += data.size();
            for (Parameter pa : data) {
              baseService.dao.insert(stationId, cov(pa, true));
            }
            // baseService.dao.insert(data) ;
            dls.insert("01", tableName, getHTLoginUserName());
            courr = insertdb;
          }
        }
      }
      // log.info("共得到: " + insertdb) ;
      long end = System.currentTimeMillis();

      json.put(Constant.SUCCESS, true);
      json.put("usetime", (end - start) / 1000 + " 秒");
      json.put("insertRow", insertdb + " 条");
      // log.debug(json.get("usetime")) ;
    } catch (Exception e) {
      // e.printStackTrace();
      json.put(Constant.INFO, e.getLocalizedMessage());
    } finally {
      return json;
    }
  }