예제 #1
0
  @Override
  public void parse(InputStream in, ICallback callback) {
    Workbook wb = null;
    try {
      callback.begin();

      wb = WorkbookFactory.create(in);
      int sheetNumber = wb.getNumberOfSheets();
      for (int i = 0; i < sheetNumber; i++) {
        Sheet sheet = wb.getSheetAt(i);
        int line = this.startLine;
        Row row = null;
        while ((row = sheet.getRow(line)) != null) {
          Object[] data = this.readLineData(row);
          if (data != null) callback.visit(data, line);
          line++;
        }
      }

      callback.end();
    } catch (Exception e) {
      Log.logError(e.getMessage());
    } finally {
      try {
        in.close();
      } catch (Exception ex) {
      }
    }
  }
예제 #2
0
  /**
   * ?????????洢??DB????sysCode?????bizType???
   *
   * @param auditLog????????
   * @see
   */
  @Override
  public void append(AuditLog auditLog) {
    if (auditLog == null) {
      return;
    }
    SimpleDateFormat valueFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    StringBuilder sBuilder = new StringBuilder();
    sBuilder.append(valueFormat.format(auditLog.getOpTime()) + "\t");
    sBuilder.append(auditLog.getSysCode() + "\t");
    sBuilder.append(auditLog.getLoginUser() + "\t");
    sBuilder.append(auditLog.getBizType() + "\t");
    sBuilder.append(auditLog.getBsnType() + "\t");
    sBuilder.append(auditLog.getKeyInfo() + "\t");
    sBuilder.append(auditLog.getOpDesc() + "\t");
    sBuilder.append(auditLog.getClientIp() + "\t");
    sBuilder.append(auditLog.getSessionId());
    Log.logDebug(sBuilder.toString());

    // ???????
    DataSource matchedDs = this.dataSources.get(auditLog.getSysCode());
    if (matchedDs == null) {
      matchedDs = this.defaultDs;
    }
    if (matchedDs == null) {
      Log.logError("Matched({0}) DataSource Not Found", auditLog.getSysCode());

      return;
    }

    // ???????????
    String tableName = this.tables.get(auditLog.getBizType().toString());
    if (tableName == null) {
      tableName = this.defaultTable;
    }

    if (tableName == null) {
      Log.logError("Matched({0}) TabledName Not Found", auditLog.getSysCode());

      return;
    }

    Connection con = null;
    PreparedStatement stmt = null;
    try {
      con = matchedDs.getConnection();

      sBuilder = new StringBuilder();
      sBuilder.append("insert into ").append(tableName);
      sBuilder.append(
          "(op_time,sys_code,login_user,biz_type,bsn_type,key_info,op_desc,client_ip,session_id)");
      sBuilder.append(" values(?,?,?,?,?,?,?,?,?)");
      stmt = con.prepareStatement(sBuilder.toString());
      stmt.setTimestamp(1, new java.sql.Timestamp(auditLog.getOpTime().getTime()));
      stmt.setString(2, auditLog.getSysCode() == null ? "" : auditLog.getSysCode());
      stmt.setString(3, auditLog.getLoginUser() == null ? "" : auditLog.getLoginUser());
      stmt.setLong(4, auditLog.getBizType() == null ? 0 : auditLog.getBizType());
      stmt.setString(5, auditLog.getBsnType() == null ? "" : auditLog.getBsnType());
      stmt.setString(6, auditLog.getKeyInfo());
      stmt.setString(7, auditLog.getOpDesc());
      stmt.setString(8, auditLog.getClientIp() == null ? "" : auditLog.getClientIp());
      stmt.setString(9, auditLog.getSessionId() == null ? "" : auditLog.getSessionId());
      stmt.executeUpdate();
    } catch (SQLException e) {
      throw new BaseRuntimeException(e);
    } finally {
      try {
        try {
          if (stmt != null) stmt.close();
        } catch (SQLException ex) {
          Log.logError("Error Close Statement", ex);
        }
        if (con != null) {
          con.close();
        }
      } catch (SQLException ex) {
        Log.logError("Error Close Resource", ex);
      }
    }
  }