我有一个系统,要将本系统的操作日志推送给别人的系统,这个对接有什么设计思路吗?我的想法是生成一个文件让对方读取,但是日志推送是用线程定时读的,还有更正的地方或者实现思路吗?请大佬帮我解答一下,十分感激.现在输出是写死的 需要输出到别的系统
public class NoticesThread extends Thread
{
private String sql = " select t.id, "+
" t.content, "+
" t.log_type, "+
" u.name as userName, "+
" d.name as departName "+
" from ry_gis_opr_log t "+
" left join cfg_user u "+
" on t.operator_fk = u.id "+
" left join ry_gis_department d "+
" on t.belongto_fk = d.id "+
" where t.log_type = '上传' "+
" and t.is_fail != 1 " +
" and t.belongto_fk != 0" +
" and t.id > ? " +
" order by t.id desc ";
boolean isStart = true;
Long startLogId = 0l;
public void run() {
Properties prop = new Properties();
try {
InputStream in = new NoticesThread().getClass().getResourceAsStream("/config/jdbc.properties");
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
final String driverName = prop.getProperty("jdbc.driverClassName");
final String url = prop.getProperty("jdbc.url");
final String oracleUser = prop.getProperty("jdbc.username");
final String password = prop.getProperty("jdbc.password");
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Connection conn = null;
PreparedStatement st = null;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url, oracleUser, password);
st = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
st.setLong(1, startLogId);
ResultSet rs = st.executeQuery();
if(!isStart){
if(rs.first()) {
startLogId = rs.getLong(1);
String content = rs.getString(2);
String userName = rs.getString(4);
String departName = rs.getString(5);
System.out.println("---logId:" + startLogId + "---content:"+content +"----userName:" + userName +"---departName:" + departName);
}
while(rs.next()){
Long logId = rs.getLong(1);
String content = rs.getString(2);
String userName = rs.getString(4);
String departName = rs.getString(5);
System.out.println("---logId:" + logId + "---content:"+content +"----userName:" + userName +"---departName:" + departName);
}
} else {
isStart = false;
if(rs.first()) {
startLogId = rs.getLong(1);
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(conn != null) {
conn.close();
}
if(st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}, 0, 5000);